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.giterr_set_str(GitErrorCategory.Odb, ex); return((int)GitErrorCode.Error); } }
/// <summary> /// Adds the provided backend to the object database with the specified priority. /// </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(this.handle, backend.GitOdbBackendPointer, priority); }
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.giterr_set_str(GitErrorCategory.Odb, ex); } }
/// <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); }
private static int ReadStream( out IntPtr stream_out, IntPtr backend, ref GitOid oid) { stream_out = IntPtr.Zero; OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend; if (odbBackend != null) { OdbBackendStream stream; try { int toReturn = odbBackend.ReadStream(oid.Id, out stream); if (0 == toReturn) { stream_out = stream.GitOdbBackendStreamPointer; } return(toReturn); } catch (Exception ex) { Proxy.giterr_set_str(GitErrorCategory.Odb, ex); } } return((int)GitErrorCode.Error); }
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); } }
private static int WriteStream( out IntPtr stream_out, IntPtr backend, UIntPtr length, GitObjectType type) { stream_out = IntPtr.Zero; OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend; if (odbBackend != null && length.ToUInt64() < long.MaxValue) { OdbBackendStream stream; try { int toReturn = odbBackend.WriteStream((long)length.ToUInt64(), type, out stream); if (0 == toReturn) { stream_out = stream.GitOdbBackendStreamPointer; } return(toReturn); } catch (Exception ex) { Proxy.giterr_set_str(GitErrorCategory.Odb, ex); } } return((int)GitErrorCode.Error); }
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.giterr_set_str(GitErrorCategory.Odb, ex); return((int)GitErrorCode.Error); } }
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.giterr_set_str(GitErrorCategory.Odb, ex); return((int)GitErrorCode.Error); } }
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.giterr_set_str(GitErrorCategory.Odb, ex); } } } return((int)GitErrorCode.Error); }
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); } Stream dataStream = null; try { ObjectType objectType; int toReturn = odbBackend.Read(new ObjectId(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); } 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 (dataStream != null) { dataStream.Dispose(); } } return((int)GitErrorCode.Ok); }
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 = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend; if (odbBackend != null) { Stream dataStream = null; GitObjectType objectType; try { int toReturn = odbBackend.Read(oid.Id, 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); } 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); }
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); } } }
private static void Free( IntPtr backend) { GCHandle gcHandle = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)); OdbBackend odbBackend = gcHandle.Target as OdbBackend; if (odbBackend != null) { try { odbBackend.Dispose(); } catch (Exception ex) { Proxy.giterr_set_str(GitErrorCategory.Odb, ex); } } }
private static bool Exists( IntPtr backend, ref GitOid oid) { OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend; if (odbBackend != null) { try { return(odbBackend.Exists(oid.Id)); } catch (Exception ex) { Proxy.giterr_set_str(GitErrorCategory.Odb, ex); } } return(false); }
private static int Foreach( IntPtr backend, GitOdbBackend.foreach_callback_callback cb, IntPtr data) { OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend; if (odbBackend != null) { try { return(odbBackend.ForEach(new ForeachState(cb, data).ManagedCallback)); } catch (Exception ex) { Proxy.giterr_set_str(GitErrorCategory.Odb, ex); } } return((int)GitErrorCode.Error); }
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.giterr_set_str(GitErrorCategory.Odb, ex); return(false); } }
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.giterr_set_str(GitErrorCategory.Odb, ex); return((int)GitErrorCode.Error); } }
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); }
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.giterr_set_str(GitErrorCategory.Odb, ex); return((int)GitErrorCode.Error); } return((int)GitErrorCode.Ok); }
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 = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend; if (odbBackend != null) { int length; GitObjectType objectType; try { int toReturn = odbBackend.ReadHeader(oid.Id, out length, out objectType); if (0 == toReturn) { len_p = new UIntPtr((uint)length); type_p = objectType; } return(toReturn); } catch (Exception ex) { Proxy.giterr_set_str(GitErrorCategory.Odb, ex); } } return((int)GitErrorCode.Error); }
/// <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; }
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); }
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); } UnmanagedMemoryStream memoryStream = null; try { var shortSha = ObjectId.ToString(short_oid.Id, (int)len); ObjectId oid; ObjectType objectType; int toReturn = odbBackend.ReadPrefix(shortSha, out oid, out memoryStream, out objectType); if (toReturn != 0) { return(toReturn); } 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 (memoryStream != null) { memoryStream.Dispose(); } } return((int)GitErrorCode.Ok); }
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); }