Пример #1
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.giterr_set_str(GitErrorCategory.Odb, ex);
                    return((int)GitErrorCode.Error);
                }
            }
Пример #2
0
 internal static void CopyAllBlobs(this ObjectDatabase source, OdbBackend backend)
 {
     foreach (var blob in source.OfType <Blob>())
     {
         if (!backend.Exists(blob.Id))
         {
             var stream = blob.GetContentStream();
             backend.Write(blob.Id, stream, stream.Length, ObjectType.Blob);
         }
     }
 }
Пример #3
0
            private static unsafe int Write(
                ref GitOid oid,
                IntPtr backend,
                IntPtr data,
                UIntPtr len,
                GitObjectType type)
            {
                OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend;

                ObjectType objectType = type.ToObjectType();

                if (odbBackend != null &&
                    len.ToUInt64() < long.MaxValue)
                {
                    try
                    {
                        using (UnmanagedMemoryStream stream = new UnmanagedMemoryStream((byte *)data, (long)len.ToUInt64()))
                        {
                            byte[] finalOid;

                            int toReturn = odbBackend.Write(oid.Id, stream, (long)len.ToUInt64(), objectType, out finalOid);

                            if (0 == toReturn)
                            {
                                oid.Id = finalOid;
                            }

                            return(toReturn);
                        }
                    }
                    catch (Exception ex)
                    {
                        Proxy.giterr_set_str(GitErrorCategory.Odb, ex);
                    }
                }

                return((int)GitErrorCode.Error);
            }