Exemple #1
0
            private unsafe static int ReadPrefix(
                out GitOid out_oid,
                out IntPtr buffer_p,
                out UIntPtr len_p,
                out GitObjectType type_p,
                IntPtr backend,
                ref GitOid short_oid,
                UIntPtr len)
            {
                out_oid  = default(GitOid);
                buffer_p = IntPtr.Zero;
                len_p    = UIntPtr.Zero;
                type_p   = GitObjectType.Bad;

                OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend;

                if (odbBackend != null)
                {
                    byte[]        oid;
                    Stream        dataStream = null;
                    GitObjectType objectType;

                    try
                    {
                        // The length of short_oid is described in characters (40 per full ID) vs. bytes (20)
                        // which is what we care about.
                        byte[] shortOidArray = new byte[(long)len >> 1];
                        Array.Copy(short_oid.Id, shortOidArray, shortOidArray.Length);

                        int toReturn = odbBackend.ReadPrefix(shortOidArray, out oid, out dataStream, out objectType);

                        if (0 == toReturn)
                        {
                            // Caller is expected to give us back a stream created with the Allocate() method.
                            UnmanagedMemoryStream memoryStream = dataStream as UnmanagedMemoryStream;

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

                            out_oid.Id = oid;
                            len_p      = new UIntPtr((ulong)memoryStream.Capacity);
                            type_p     = objectType;

                            memoryStream.Seek(0, SeekOrigin.Begin);
                            buffer_p = new IntPtr(memoryStream.PositionPointer);
                        }

                        return(toReturn);
                    }
                    catch (Exception ex)
                    {
                        Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
                    }
                    finally
                    {
                        if (null != dataStream)
                        {
                            dataStream.Dispose();
                        }
                    }
                }

                return((int)GitErrorCode.Error);
            }
Exemple #2
0
            private unsafe static int ReadPrefix(
                out GitOid out_oid,
                out IntPtr buffer_p,
                out UIntPtr len_p,
                out GitObjectType type_p,
                IntPtr backend,
                ref GitOid short_oid,
                UIntPtr len)
            {
                out_oid  = default(GitOid);
                buffer_p = IntPtr.Zero;
                len_p    = UIntPtr.Zero;
                type_p   = GitObjectType.Bad;

                OdbBackend odbBackend = MarshalOdbBackend(backend);

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

                Stream dataStream = null;

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

                    ObjectId   oid;
                    ObjectType objectType;

                    int toReturn = odbBackend.ReadPrefix(shortSha, out oid, out dataStream, out objectType);

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

                    // Caller is expected to give us back a stream created with the Allocate() method.
                    var memoryStream = dataStream as UnmanagedMemoryStream;

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

                    out_oid.Id = oid.RawId;
                    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.giterr_set_str(GitErrorCategory.Odb, ex);
                    return((int)GitErrorCode.Error);
                }
                finally
                {
                    if (null != dataStream)
                    {
                        dataStream.Dispose();
                    }
                }

                return((int)GitErrorCode.Ok);
            }
Exemple #3
0
            private unsafe static int ReadPrefix(
                out GitOid out_oid,
                out IntPtr buffer_p,
                out UIntPtr len_p,
                out GitObjectType type_p,
                IntPtr backend,
                ref GitOid short_oid,
                UIntPtr len)
            {
                out_oid  = default(GitOid);
                buffer_p = IntPtr.Zero;
                len_p    = UIntPtr.Zero;
                type_p   = GitObjectType.Bad;

                OdbBackend odbBackend = MarshalOdbBackend(backend);

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

                Stream dataStream = null;

                try
                {
                    // The length of short_oid is described in characters (40 per full ID) vs. bytes (20)
                    // which is what we care about.
                    var oidLen = (int)len;

                    // Ensure we allocate enough space to cope with odd-sized prefix
                    int arraySize     = (oidLen + 1) >> 1;
                    var shortOidArray = new byte[arraySize];
                    Array.Copy(short_oid.Id, shortOidArray, arraySize);

                    byte[]     oid;
                    ObjectType objectType;

                    int toReturn = odbBackend.ReadPrefix(shortOidArray, oidLen, out oid, out dataStream, out objectType);

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

                    // Caller is expected to give us back a stream created with the Allocate() method.
                    var memoryStream = dataStream as UnmanagedMemoryStream;

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

                    out_oid.Id = oid;
                    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.giterr_set_str(GitErrorCategory.Odb, ex);
                    return((int)GitErrorCode.Error);
                }
                finally
                {
                    if (null != dataStream)
                    {
                        dataStream.Dispose();
                    }
                }

                return((int)GitErrorCode.Ok);
            }