Beispiel #1
0
 /// <summary>Scan index and merge tree (no HEAD).</summary>
 /// <remarks>
 /// Scan index and merge tree (no HEAD). Used e.g. for initial checkout when
 /// there is no head yet.
 /// </remarks>
 /// <exception cref="NGit.Errors.MissingObjectException">NGit.Errors.MissingObjectException
 ///     </exception>
 /// <exception cref="NGit.Errors.IncorrectObjectTypeException">NGit.Errors.IncorrectObjectTypeException
 ///     </exception>
 /// <exception cref="NGit.Errors.CorruptObjectException">NGit.Errors.CorruptObjectException
 ///     </exception>
 /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
 public virtual void PrescanOneTree()
 {
     removed.Clear();
     updated.Clear();
     conflicts.Clear();
     builder = dc.Builder();
     walk    = new NameConflictTreeWalk(repo);
     walk.AddTree(mergeCommitTree);
     walk.AddTree(new DirCacheBuildIterator(builder));
     walk.AddTree(workingTree);
     while (walk.Next())
     {
         ProcessEntry(walk.GetTree <CanonicalTreeParser>(0), walk.GetTree <DirCacheBuildIterator
                                                                           >(1), walk.GetTree <WorkingTreeIterator>(2));
         if (walk.IsSubtree)
         {
             walk.EnterSubtree();
         }
     }
     conflicts.RemoveAll(removed);
 }
            /// <exception cref="System.IO.IOException"></exception>
            protected internal override bool MergeImpl()
            {
                tw.AddTree(MergeBase());
                tw.AddTree(sourceTrees[0]);
                tw.AddTree(sourceTrees[1]);
                bool hasConflict = false;

                builder = cache.Builder();
                while (tw.Next())
                {
                    int modeO = tw.GetRawMode(T_OURS);
                    int modeT = tw.GetRawMode(T_THEIRS);
                    if (modeO == modeT && tw.IdEqual(T_OURS, T_THEIRS))
                    {
                        Add(T_OURS, DirCacheEntry.STAGE_0);
                        continue;
                    }
                    int modeB = tw.GetRawMode(T_BASE);
                    if (modeB == modeO && tw.IdEqual(T_BASE, T_OURS))
                    {
                        Add(T_THEIRS, DirCacheEntry.STAGE_0);
                    }
                    else
                    {
                        if (modeB == modeT && tw.IdEqual(T_BASE, T_THEIRS))
                        {
                            Add(T_OURS, DirCacheEntry.STAGE_0);
                        }
                        else
                        {
                            if (NonTree(modeB))
                            {
                                Add(T_BASE, DirCacheEntry.STAGE_1);
                                hasConflict = true;
                            }
                            if (NonTree(modeO))
                            {
                                Add(T_OURS, DirCacheEntry.STAGE_2);
                                hasConflict = true;
                            }
                            if (NonTree(modeT))
                            {
                                Add(T_THEIRS, DirCacheEntry.STAGE_3);
                                hasConflict = true;
                            }
                            if (tw.IsSubtree)
                            {
                                tw.EnterSubtree();
                            }
                        }
                    }
                }
                builder.Finish();
                builder = null;
                if (hasConflict)
                {
                    return(false);
                }
                try
                {
                    ObjectInserter odi = GetObjectInserter();
                    resultTree = cache.WriteTree(odi);
                    odi.Flush();
                    return(true);
                }
                catch (UnmergedPathException)
                {
                    resultTree = null;
                    return(false);
                }
            }
Beispiel #3
0
        /// <exception cref="System.IO.IOException"></exception>
        protected internal override bool MergeImpl()
        {
            bool implicitDirCache = false;

            if (dircache == null)
            {
                dircache         = GetRepository().LockDirCache();
                implicitDirCache = true;
            }
            try
            {
                builder = dircache.Builder();
                DirCacheBuildIterator buildIt = new DirCacheBuildIterator(builder);
                tw = new NameConflictTreeWalk(db);
                tw.AddTree(MergeBase());
                tw.AddTree(sourceTrees[0]);
                tw.AddTree(sourceTrees[1]);
                tw.AddTree(buildIt);
                if (workingTreeIterator != null)
                {
                    tw.AddTree(workingTreeIterator);
                }
                while (tw.Next())
                {
                    if (!ProcessEntry(tw.GetTree <CanonicalTreeParser>(T_BASE), tw.GetTree <CanonicalTreeParser
                                                                                            >(T_OURS), tw.GetTree <CanonicalTreeParser>(T_THEIRS), tw.GetTree <DirCacheBuildIterator
                                                                                                                                                               >(T_INDEX), (workingTreeIterator == null) ? null : tw.GetTree <WorkingTreeIterator
                                                                                                                                                                                                                              >(T_FILE)))
                    {
                        CleanUp();
                        return(false);
                    }
                    if (tw.IsSubtree && enterSubtree)
                    {
                        tw.EnterSubtree();
                    }
                }
                if (!inCore)
                {
                    // All content-merges are successfully done. If we can now write the
                    // new index we are on quite safe ground. Even if the checkout of
                    // files coming from "theirs" fails the user can work around such
                    // failures by checking out the index again.
                    if (!builder.Commit())
                    {
                        CleanUp();
                        throw new IndexWriteException();
                    }
                    builder = null;
                    // No problem found. The only thing left to be done is to checkout
                    // all files from "theirs" which have been selected to go into the
                    // new index.
                    Checkout();
                }
                else
                {
                    builder.Finish();
                    builder = null;
                }
                if (GetUnmergedPaths().IsEmpty())
                {
                    resultTree = dircache.WriteTree(oi);
                    return(true);
                }
                else
                {
                    resultTree = null;
                    return(false);
                }
            }
            finally
            {
                if (implicitDirCache)
                {
                    dircache.Unlock();
                }
            }
        }