Exemple #1
0
        /// <summary>Determine the differences between two trees.</summary>
        /// <remarks>
        /// Determine the differences between two trees.
        /// No output is created, instead only the file paths that are different are
        /// returned. Callers may choose to format these paths themselves, or convert
        /// them into
        /// <see cref="NGit.Patch.FileHeader">NGit.Patch.FileHeader</see>
        /// instances with a complete edit list by
        /// calling
        /// <see cref="ToFileHeader(DiffEntry)">ToFileHeader(DiffEntry)</see>
        /// .
        /// </remarks>
        /// <param name="a">the old (or previous) side.</param>
        /// <param name="b">the new (or updated) side.</param>
        /// <returns>the paths that are different.</returns>
        /// <exception cref="System.IO.IOException">trees cannot be read or file contents cannot be read.
        ///     </exception>
        public virtual IList <DiffEntry> Scan(AnyObjectId a, AnyObjectId b)
        {
            AssertHaveRepository();
            RevWalk rw = new RevWalk(reader);

            return(Scan(rw.ParseTree(a), rw.ParseTree(b)));
        }
Exemple #2
0
 /// <summary>Merge together two or more tree-ish objects.</summary>
 /// <remarks>
 /// Merge together two or more tree-ish objects.
 /// <p>
 /// Any tree-ish may be supplied as inputs. Commits and/or tags pointing at
 /// trees or commits may be passed as input objects.
 /// </remarks>
 /// <param name="tips">
 /// source trees to be combined together. The merge base is not
 /// included in this set.
 /// </param>
 /// <returns>
 /// true if the merge was completed without conflicts; false if the
 /// merge strategy cannot handle this merge or there were conflicts
 /// preventing it from automatically resolving all paths.
 /// </returns>
 /// <exception cref="NGit.Errors.IncorrectObjectTypeException">
 /// one of the input objects is not a commit, but the strategy
 /// requires it to be a commit.
 /// </exception>
 /// <exception cref="System.IO.IOException">
 /// one or more sources could not be read, or outputs could not
 /// be written to the Repository.
 /// </exception>
 public virtual bool Merge(params AnyObjectId[] tips)
 {
     sourceObjects = new RevObject[tips.Length];
     for (int i = 0; i < tips.Length; i++)
     {
         sourceObjects[i] = walk.ParseAny(tips[i]);
     }
     sourceCommits = new RevCommit[sourceObjects.Length];
     for (int i_1 = 0; i_1 < sourceObjects.Length; i_1++)
     {
         try
         {
             sourceCommits[i_1] = walk.ParseCommit(sourceObjects[i_1]);
         }
         catch (IncorrectObjectTypeException)
         {
             sourceCommits[i_1] = null;
         }
     }
     sourceTrees = new RevTree[sourceObjects.Length];
     for (int i_2 = 0; i_2 < sourceObjects.Length; i_2++)
     {
         sourceTrees[i_2] = walk.ParseTree(sourceObjects[i_2]);
     }
     try
     {
         bool ok = MergeImpl();
         if (ok && inserter != null)
         {
             inserter.Flush();
         }
         return(ok);
     }
     finally
     {
         if (inserter != null)
         {
             inserter.Release();
         }
         reader.Release();
     }
 }
        /// <summary>Checks if a file with the given path exists in the HEAD tree</summary>
        /// <param name="path"></param>
        /// <returns>true if the file exists</returns>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        private bool InHead(string path)
        {
            ObjectId headId = db.Resolve(Constants.HEAD);
            RevWalk  rw     = new RevWalk(db);
            TreeWalk tw     = null;

            try
            {
                tw = TreeWalk.ForPath(db, path, rw.ParseTree(headId));
                return(tw != null);
            }
            finally
            {
                rw.Release();
                rw.Dispose();
                if (tw != null)
                {
                    tw.Release();
                }
            }
        }
Exemple #4
0
 /// <summary>Checks if a file with the given path exists in the HEAD tree</summary>
 /// <param name="path"></param>
 /// <returns>true if the file exists</returns>
 /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
 private bool InHead(string path)
 {
     ObjectId headId = db.Resolve(Constants.HEAD);
     RevWalk rw = new RevWalk(db);
     TreeWalk tw = null;
     try
     {
         tw = TreeWalk.ForPath(db, path, rw.ParseTree(headId));
         return tw != null;
     }
     finally
     {
         rw.Release();
         rw.Dispose();
         if (tw != null)
         {
             tw.Release();
         }
     }
 }
Exemple #5
0
        /// <summary>
        /// Return a list of those objects in the index which differ from whats in
        /// HEAD
        /// </summary>
        /// <returns>a set of ObjectIds of changed objects in the index</returns>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        /// <exception cref="NGit.Errors.CorruptObjectException">NGit.Errors.CorruptObjectException
        ///     </exception>
        /// <exception cref="NGit.Errors.NoWorkTreeException">NGit.Errors.NoWorkTreeException
        ///     </exception>
        private ICollection <ObjectId> ListNonHEADIndexObjects()
        {
            RevWalk revWalk = null;

            try
            {
                if (repo.GetIndexFile() == null)
                {
                    return(Sharpen.Collections.EmptySet <ObjectId>());
                }
            }
            catch (NoWorkTreeException)
            {
                return(Sharpen.Collections.EmptySet <ObjectId>());
            }
            TreeWalk treeWalk = new TreeWalk(repo);

            try
            {
                treeWalk.AddTree(new DirCacheIterator(repo.ReadDirCache()));
                ObjectId headID = repo.Resolve(Constants.HEAD);
                if (headID != null)
                {
                    revWalk = new RevWalk(repo);
                    treeWalk.AddTree(revWalk.ParseTree(headID));
                    revWalk.Dispose();
                    revWalk = null;
                }
                treeWalk.Filter    = TreeFilter.ANY_DIFF;
                treeWalk.Recursive = true;
                ICollection <ObjectId> ret = new HashSet <ObjectId>();
                while (treeWalk.Next())
                {
                    ObjectId objectId = treeWalk.GetObjectId(0);
                    switch (treeWalk.GetRawMode(0) & FileMode.TYPE_MASK)
                    {
                    case FileMode.TYPE_MISSING:
                    case FileMode.TYPE_GITLINK:
                    {
                        continue;
                        goto case FileMode.TYPE_TREE;
                    }

                    case FileMode.TYPE_TREE:
                    case FileMode.TYPE_FILE:
                    case FileMode.TYPE_SYMLINK:
                    {
                        ret.AddItem(objectId);
                        continue;
                        goto default;
                    }

                    default:
                    {
                        throw new IOException(MessageFormat.Format(JGitText.Get().corruptObjectInvalidMode3
                                                                   , string.Format("%o", Sharpen.Extensions.ValueOf(treeWalk.GetRawMode(0)), (objectId
                                                                                                                                              == null) ? "null" : objectId.Name, treeWalk.PathString, repo.GetIndexFile())));
                    }
                    }
                }
                return(ret);
            }
            finally
            {
                if (revWalk != null)
                {
                    revWalk.Dispose();
                }
                treeWalk.Release();
            }
        }