protected override void EvaluateInternal(Action <GitObjectSafeHandle> evaluator)
 {
     using (var osw = new ObjectSafeWrapper(id, repo.Handle))
     {
         evaluator(osw.ObjectPtr);
     }
 }
 public static ILazy <TResult> Singleton <TResult>(Repository repo, ObjectId id, Func <GitObjectSafeHandle, TResult> resultSelector)
 {
     return(Singleton(() =>
     {
         using (var osw = new ObjectSafeWrapper(id, repo.Handle))
             return resultSelector(osw.ObjectPtr);
     }));
 }
 internal ContentChanges(Repository repo, Blob oldBlob, Blob newBlob, GitDiffOptions options)
 {
     using (var osw1 = new ObjectSafeWrapper(oldBlob.Id, repo))
     using (var osw2 = new ObjectSafeWrapper(newBlob.Id, repo))
     {
         Ensure.Success(NativeMethods.git_diff_blobs(osw1.ObjectPtr, osw2.ObjectPtr, options, IntPtr.Zero, FileCallback, HunkCallback, LineCallback));
     }
 }
 public static ILazy <TResult> Singleton <TResult>(Repository repo, ObjectId id, Func <ObjectHandle, TResult> resultSelector, bool throwIfMissing = false)
 {
     return(Singleton(() =>
     {
         using (var osw = new ObjectSafeWrapper(id, repo.Handle, throwIfMissing: throwIfMissing))
         {
             return resultSelector(osw.ObjectPtr);
         }
     }));
 }
Exemple #5
0
        private IEnumerable<Commit> RetrieveParentsOfCommit(ObjectId oid)
        {
            using (var obj = new ObjectSafeWrapper(oid, repo))
            {
                uint parentsCount = NativeMethods.git_commit_parentcount(obj.ObjectPtr);

                for (uint i = 0; i < parentsCount; i++)
                {
                    GitObjectSafeHandle parentCommit;
                    Ensure.Success(NativeMethods.git_commit_parent(out parentCommit, obj.ObjectPtr, i));
                    yield return BuildFromPtr(parentCommit, ObjectIdOf(parentCommit), repo);
                }
            }
        }
Exemple #6
0
        private IEnumerable<Commit> RetrieveParentsOfCommit(ObjectId oid)
        {
            using (var obj = new ObjectSafeWrapper(oid, repo))
            {
                uint parentsCount = NativeMethods.git_commit_parentcount(obj.ObjectPtr);

                for (uint i = 0; i < parentsCount; i++)
                {
                    using (var parentCommit = GetParentCommitHandle(i, obj))
                    {
                        yield return BuildFromPtr(parentCommit, ObjectIdOf(parentCommit), repo);
                    }
                }
            }
        }
Exemple #7
0
 private static GitObjectSafeHandle GetParentCommitHandle(uint i, ObjectSafeWrapper obj)
 {
     GitObjectSafeHandle parentCommit;
     Ensure.Success(NativeMethods.git_commit_parent(out parentCommit, obj.ObjectPtr, i));
     return parentCommit;
 }
Exemple #8
0
 unsafe RawContentStream(ObjectSafeWrapper wrapper,
                         Func <GitObjectSafeHandle, IntPtr> bytePtrProvider, long length)
     : base((byte *)bytePtrProvider(wrapper.ObjectPtr).ToPointer(), length)
 {
     this.wrapper = wrapper;
 }
 unsafe RawContentStream(ObjectSafeWrapper wrapper,
     Func<GitObjectSafeHandle, IntPtr> bytePtrProvider, long length)
     : base((byte*)bytePtrProvider(wrapper.ObjectPtr).ToPointer(), length)
 {
     this.wrapper = wrapper;
 }
Exemple #10
0
 private static DiffListSafeHandle BuildDiffListFromTreeAndComparer(Repository repo, ObjectId treeId, TreeComparisonHandleRetriever comparisonHandleRetriever)
 {
     using (var osw = new ObjectSafeWrapper(treeId, repo))
     {
         return BuildDiffListFromComparer(osw.ObjectPtr, comparisonHandleRetriever);
     }
 }
Exemple #11
0
        private DiffListSafeHandle BuildDiffListFromTrees(ObjectId oldTree, ObjectId newTree)
        {
            using (var osw1 = new ObjectSafeWrapper(oldTree, repo))
            using (var osw2 = new ObjectSafeWrapper(newTree, repo))
            {
                DiffListSafeHandle diff;
                GitDiffOptions options = DefaultOptions;
                Ensure.Success(NativeMethods.git_diff_tree_to_tree(repo.Handle, options, osw1.ObjectPtr, osw2.ObjectPtr, out diff));

                return diff;
            }
        }
        internal Commit CreateCommit(string message, Signature author, Signature committer, Tree tree, IEnumerable<Commit> parents, string referenceName)
        {
            Ensure.ArgumentNotNull(message, "message");
            Ensure.ArgumentNotNull(author, "author");
            Ensure.ArgumentNotNull(committer, "committer");
            Ensure.ArgumentNotNull(tree, "tree");
            Ensure.ArgumentNotNull(parents, "parents");

            IEnumerable<ObjectId> parentIds = parents.Select(p => p.Id);

            GitOid commitOid;
            using (var treePtr = new ObjectSafeWrapper(tree.Id, repo))
            using (var parentObjectPtrs = new DisposableEnumerable<ObjectSafeWrapper>(parentIds.Select(id => new ObjectSafeWrapper(id, repo))))
            using (SignatureSafeHandle authorHandle = author.BuildHandle())
            using (SignatureSafeHandle committerHandle = committer.BuildHandle())
            {
                string encoding = null; //TODO: Handle the encoding of the commit to be created

                IntPtr[] parentsPtrs = parentObjectPtrs.Select(o => o.ObjectPtr.DangerousGetHandle()).ToArray();
                int res = NativeMethods.git_commit_create(out commitOid, repo.Handle, referenceName, authorHandle,
                                                      committerHandle, encoding, message, treePtr.ObjectPtr, parentObjectPtrs.Count(), parentsPtrs);
                Ensure.Success(res);
            }

            return repo.Lookup<Commit>(new ObjectId(commitOid));
        }