Exemple #1
0
            private static void Free(
                IntPtr backend)
            {
                OdbBackend odbBackend = MarshalOdbBackend(backend);

                if (odbBackend == null)
                {
                    return;
                }

                try
                {
                    odbBackend.Free();

                    var disposable = odbBackend as IDisposable;

                    if (disposable == null)
                    {
                        return;
                    }

                    disposable.Dispose();
                }
                catch (Exception ex)
                {
                    Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
                }
            }
Exemple #2
0
            private static int ExistsPrefix(
                ref GitOid found_oid,
                IntPtr backend,
                ref GitOid short_oid,
                UIntPtr len)
            {
                OdbBackend odbBackend = MarshalOdbBackend(backend);

                if (odbBackend == null)
                {
                    return((int)GitErrorCode.Error);
                }

                try
                {
                    ObjectId found;
                    var      shortSha = ObjectId.ToString(short_oid.Id, (int)len);

                    found_oid.Id = ObjectId.Zero.RawId;
                    int result = odbBackend.ExistsPrefix(shortSha, out found);

                    if (result == (int)GitErrorCode.Ok)
                    {
                        found_oid.Id = found.RawId;
                    }

                    return(result);
                }
                catch (Exception ex)
                {
                    Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
                    return((int)GitErrorCode.Error);
                }
            }
Exemple #3
0
            private static int ReadStream(
                out IntPtr stream_out,
                IntPtr backend,
                ref GitOid oid)
            {
                stream_out = IntPtr.Zero;

                OdbBackend odbBackend = MarshalOdbBackend(backend);

                if (odbBackend == null)
                {
                    return((int)GitErrorCode.Error);
                }

                try
                {
                    OdbBackendStream stream;
                    int toReturn = odbBackend.ReadStream(new ObjectId(oid), out stream);

                    if (toReturn == 0)
                    {
                        stream_out = stream.GitOdbBackendStreamPointer;
                    }

                    return(toReturn);
                }
                catch (Exception ex)
                {
                    Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
                    return((int)GitErrorCode.Error);
                }
            }
Exemple #4
0
            private static unsafe int Write(
                IntPtr backend,
                ref GitOid oid,
                IntPtr data,
                UIntPtr len,
                GitObjectType type)
            {
                long length = ConverToLong(len);

                OdbBackend odbBackend = MarshalOdbBackend(backend);

                if (odbBackend == null)
                {
                    return((int)GitErrorCode.Error);
                }

                try
                {
                    using (var stream = new UnmanagedMemoryStream((byte *)data, length))
                    {
                        return(odbBackend.Write(new ObjectId(oid), stream, length, type.ToObjectType()));
                    }
                }
                catch (Exception ex)
                {
                    Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
                    return((int)GitErrorCode.Error);
                }
            }
Exemple #5
0
            private static int WriteStream(
                out IntPtr stream_out,
                IntPtr backend,
                long len,
                GitObjectType type)
            {
                stream_out = IntPtr.Zero;

                OdbBackend odbBackend = MarshalOdbBackend(backend);

                if (odbBackend == null)
                {
                    return((int)GitErrorCode.Error);
                }

                ObjectType objectType = type.ToObjectType();

                try
                {
                    OdbBackendStream stream;
                    int toReturn = odbBackend.WriteStream(len, objectType, out stream);

                    if (toReturn == 0)
                    {
                        stream_out = stream.GitOdbBackendStreamPointer;
                    }

                    return(toReturn);
                }
                catch (Exception ex)
                {
                    Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
                    return((int)GitErrorCode.Error);
                }
            }
Exemple #6
0
        /// <summary>
        /// Adds the provided backend to the object database with the specified priority.
        /// <para>
        /// If the provided backend implements <see cref="IDisposable"/>, the <see cref="IDisposable.Dispose"/>
        /// method will be honored and invoked upon the disposal of the repository.
        /// </para>
        /// </summary>
        /// <param name="backend">The backend to add</param>
        /// <param name="priority">The priority at which libgit2 should consult this backend (higher values are consulted first)</param>
        public virtual void AddBackend(OdbBackend backend, int priority)
        {
            Ensure.ArgumentNotNull(backend, "backend");
            Ensure.ArgumentConformsTo(priority, s => s > 0, "priority");

            Proxy.git_odb_add_backend(handle, backend.GitOdbBackendPointer, priority);
        }
Exemple #7
0
            private unsafe static int Read(
                out IntPtr buffer_p,
                out UIntPtr len_p,
                out GitObjectType type_p,
                IntPtr backend,
                ref GitOid oid)
            {
                buffer_p = IntPtr.Zero;
                len_p    = UIntPtr.Zero;
                type_p   = GitObjectType.Bad;

                OdbBackend odbBackend = MarshalOdbBackend(backend);

                if (odbBackend == null)
                {
                    return((int)GitErrorCode.Error);
                }

                UnmanagedMemoryStream memoryStream = null;

                try
                {
                    ObjectType objectType;
                    int        toReturn = odbBackend.Read(new ObjectId(oid), out memoryStream, out objectType);

                    if (toReturn != 0)
                    {
                        return(toReturn);
                    }

                    if (memoryStream == null)
                    {
                        return((int)GitErrorCode.Error);
                    }

                    len_p  = new UIntPtr((ulong)memoryStream.Capacity);
                    type_p = objectType.ToGitObjectType();

                    memoryStream.Seek(0, SeekOrigin.Begin);
                    buffer_p = new IntPtr(memoryStream.PositionPointer);
                }
                catch (Exception ex)
                {
                    Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
                    return((int)GitErrorCode.Error);
                }
                finally
                {
                    if (memoryStream != null)
                    {
                        memoryStream.Dispose();
                    }
                }

                return((int)GitErrorCode.Ok);
            }
Exemple #8
0
            private static bool Exists(
                IntPtr backend,
                ref GitOid oid)
            {
                OdbBackend odbBackend = MarshalOdbBackend(backend);

                if (odbBackend == null)
                {
                    return(false); // Weird
                }

                try
                {
                    return(odbBackend.Exists(new ObjectId(oid)));
                }
                catch (Exception ex)
                {
                    Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
                    return(false);
                }
            }
Exemple #9
0
            private static int Foreach(
                IntPtr backend,
                GitOdbBackend.foreach_callback_callback cb,
                IntPtr data)
            {
                OdbBackend odbBackend = MarshalOdbBackend(backend);

                if (odbBackend == null)
                {
                    return((int)GitErrorCode.Error);
                }

                try
                {
                    return(odbBackend.ForEach(new ForeachState(cb, data).ManagedCallback));
                }
                catch (Exception ex)
                {
                    Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
                    return((int)GitErrorCode.Error);
                }
            }
Exemple #10
0
            private static int ReadHeader(
                out UIntPtr len_p,
                out GitObjectType type_p,
                IntPtr backend,
                ref GitOid oid)
            {
                len_p  = UIntPtr.Zero;
                type_p = GitObjectType.Bad;

                OdbBackend odbBackend = MarshalOdbBackend(backend);

                if (odbBackend == null)
                {
                    return((int)GitErrorCode.Error);
                }

                try
                {
                    int        length;
                    ObjectType objectType;
                    int        toReturn = odbBackend.ReadHeader(new ObjectId(oid), out length, out objectType);

                    if (toReturn != 0)
                    {
                        return(toReturn);
                    }

                    len_p  = new UIntPtr((uint)length);
                    type_p = objectType.ToGitObjectType();
                }
                catch (Exception ex)
                {
                    Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
                    return((int)GitErrorCode.Error);
                }

                return((int)GitErrorCode.Ok);
            }
Exemple #11
0
            private static unsafe int Write(IntPtr stream, IntPtr buffer, UIntPtr len)
            {
                OdbBackendStream odbBackendStream = GCHandle.FromIntPtr(Marshal.ReadIntPtr(stream, GitOdbBackendStream.GCHandleOffset)).Target as OdbBackendStream;

                if (odbBackendStream != null)
                {
                    long length = OdbBackend.ConverToLong(len);

                    using (UnmanagedMemoryStream dataStream = new UnmanagedMemoryStream((byte *)buffer, length))
                    {
                        try
                        {
                            return(odbBackendStream.Write(dataStream, length));
                        }
                        catch (Exception ex)
                        {
                            Proxy.git_error_set_str(GitErrorCategory.Odb, ex);
                        }
                    }
                }

                return((int)GitErrorCode.Error);
            }
Exemple #12
0
 /// <summary>
 /// Base constructor for OdbBackendStream. Make sure that your derived class calls this base constructor.
 /// </summary>
 /// <param name="backend">The backend to which this backend stream is attached.</param>
 protected OdbBackendStream(OdbBackend backend)
 {
     this.backend = backend;
 }