|
|
@ -85,6 +85,7 @@ import org.eclipse.jgit.revwalk.RevTree; |
|
|
|
import org.eclipse.jgit.treewalk.AbstractTreeIterator; |
|
|
|
import org.eclipse.jgit.treewalk.AbstractTreeIterator; |
|
|
|
import org.eclipse.jgit.treewalk.CanonicalTreeParser; |
|
|
|
import org.eclipse.jgit.treewalk.CanonicalTreeParser; |
|
|
|
import org.eclipse.jgit.treewalk.NameConflictTreeWalk; |
|
|
|
import org.eclipse.jgit.treewalk.NameConflictTreeWalk; |
|
|
|
|
|
|
|
import org.eclipse.jgit.treewalk.TreeWalk; |
|
|
|
import org.eclipse.jgit.treewalk.WorkingTreeIterator; |
|
|
|
import org.eclipse.jgit.treewalk.WorkingTreeIterator; |
|
|
|
import org.eclipse.jgit.util.FS; |
|
|
|
import org.eclipse.jgit.util.FS; |
|
|
|
import org.eclipse.jgit.util.FileUtils; |
|
|
|
import org.eclipse.jgit.util.FileUtils; |
|
|
@ -106,7 +107,12 @@ public class ResolveMerger extends ThreeWayMerger { |
|
|
|
COULD_NOT_DELETE |
|
|
|
COULD_NOT_DELETE |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private NameConflictTreeWalk tw; |
|
|
|
/** |
|
|
|
|
|
|
|
* The tree walk which we'll iterate over to merge entries. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @since 3.4 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected NameConflictTreeWalk tw; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* string versions of a list of commit SHA1s |
|
|
|
* string versions of a list of commit SHA1s |
|
|
@ -115,17 +121,47 @@ public class ResolveMerger extends ThreeWayMerger { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected String commitNames[]; |
|
|
|
protected String commitNames[]; |
|
|
|
|
|
|
|
|
|
|
|
private static final int T_BASE = 0; |
|
|
|
/** |
|
|
|
|
|
|
|
* Index of the base tree within the {@link #tw tree walk}. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @since 3.4 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected static final int T_BASE = 0; |
|
|
|
|
|
|
|
|
|
|
|
private static final int T_OURS = 1; |
|
|
|
/** |
|
|
|
|
|
|
|
* Index of our tree in withthe {@link #tw tree walk}. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @since 3.4 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected static final int T_OURS = 1; |
|
|
|
|
|
|
|
|
|
|
|
private static final int T_THEIRS = 2; |
|
|
|
/** |
|
|
|
|
|
|
|
* Index of their tree within the {@link #tw tree walk}. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @since 3.4 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected static final int T_THEIRS = 2; |
|
|
|
|
|
|
|
|
|
|
|
private static final int T_INDEX = 3; |
|
|
|
/** |
|
|
|
|
|
|
|
* Index of the index tree within the {@link #tw tree walk}. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @since 3.4 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected static final int T_INDEX = 3; |
|
|
|
|
|
|
|
|
|
|
|
private static final int T_FILE = 4; |
|
|
|
/** |
|
|
|
|
|
|
|
* Index of the working directory tree within the {@link #tw tree walk}. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @since 3.4 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected static final int T_FILE = 4; |
|
|
|
|
|
|
|
|
|
|
|
private DirCacheBuilder builder; |
|
|
|
/** |
|
|
|
|
|
|
|
* Builder to update the cache during this merge. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @since 3.4 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected DirCacheBuilder builder; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* merge result as tree |
|
|
|
* merge result as tree |
|
|
@ -134,19 +170,59 @@ public class ResolveMerger extends ThreeWayMerger { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected ObjectId resultTree; |
|
|
|
protected ObjectId resultTree; |
|
|
|
|
|
|
|
|
|
|
|
private List<String> unmergedPaths = new ArrayList<String>(); |
|
|
|
/** |
|
|
|
|
|
|
|
* Paths that could not be merged by this merger because of an unsolvable |
|
|
|
|
|
|
|
* conflict. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @since 3.4 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected List<String> unmergedPaths = new ArrayList<String>(); |
|
|
|
|
|
|
|
|
|
|
|
private List<String> modifiedFiles = new LinkedList<String>(); |
|
|
|
/** |
|
|
|
|
|
|
|
* Files modified during this merge operation. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @since 3.4 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected List<String> modifiedFiles = new LinkedList<String>(); |
|
|
|
|
|
|
|
|
|
|
|
private Map<String, DirCacheEntry> toBeCheckedOut = new HashMap<String, DirCacheEntry>(); |
|
|
|
/** |
|
|
|
|
|
|
|
* If the merger has nothing to do for a file but check it out at the end of |
|
|
|
|
|
|
|
* the operation, it can be added here. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @since 3.4 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected Map<String, DirCacheEntry> toBeCheckedOut = new HashMap<String, DirCacheEntry>(); |
|
|
|
|
|
|
|
|
|
|
|
private List<String> toBeDeleted = new ArrayList<String>(); |
|
|
|
/** |
|
|
|
|
|
|
|
* Paths in this list will be deleted from the local copy at the end of the |
|
|
|
|
|
|
|
* operation. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @since 3.4 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected List<String> toBeDeleted = new ArrayList<String>(); |
|
|
|
|
|
|
|
|
|
|
|
private Map<String, MergeResult<? extends Sequence>> mergeResults = new HashMap<String, MergeResult<? extends Sequence>>(); |
|
|
|
/** |
|
|
|
|
|
|
|
* Low-level textual merge results. Will be passed on to the callers in case |
|
|
|
|
|
|
|
* of conflicts. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @since 3.4 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected Map<String, MergeResult<? extends Sequence>> mergeResults = new HashMap<String, MergeResult<? extends Sequence>>(); |
|
|
|
|
|
|
|
|
|
|
|
private Map<String, MergeFailureReason> failingPaths = new HashMap<String, MergeFailureReason>(); |
|
|
|
/** |
|
|
|
|
|
|
|
* Paths for which the merge failed altogether. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @since 3.4 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected Map<String, MergeFailureReason> failingPaths = new HashMap<String, MergeFailureReason>(); |
|
|
|
|
|
|
|
|
|
|
|
private boolean enterSubtree; |
|
|
|
/** |
|
|
|
|
|
|
|
* Updated as we merge entries of the tree walk. Tells us whether we should |
|
|
|
|
|
|
|
* recurse into the entry if it is a subtree. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @since 3.4 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected boolean enterSubtree; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set to true if this merge should work in-memory. The repos dircache and |
|
|
|
* Set to true if this merge should work in-memory. The repos dircache and |
|
|
@ -277,8 +353,10 @@ public class ResolveMerger extends ThreeWayMerger { |
|
|
|
* @throws IOException |
|
|
|
* @throws IOException |
|
|
|
* @throws CorruptObjectException |
|
|
|
* @throws CorruptObjectException |
|
|
|
* @throws NoWorkTreeException |
|
|
|
* @throws NoWorkTreeException |
|
|
|
|
|
|
|
* @since 3.4 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void cleanUp() throws NoWorkTreeException, CorruptObjectException, |
|
|
|
protected void cleanUp() throws NoWorkTreeException, |
|
|
|
|
|
|
|
CorruptObjectException, |
|
|
|
IOException { |
|
|
|
IOException { |
|
|
|
if (inCore) { |
|
|
|
if (inCore) { |
|
|
|
modifiedFiles.clear(); |
|
|
|
modifiedFiles.clear(); |
|
|
@ -386,8 +464,9 @@ public class ResolveMerger extends ThreeWayMerger { |
|
|
|
* @throws IncorrectObjectTypeException |
|
|
|
* @throws IncorrectObjectTypeException |
|
|
|
* @throws CorruptObjectException |
|
|
|
* @throws CorruptObjectException |
|
|
|
* @throws IOException |
|
|
|
* @throws IOException |
|
|
|
|
|
|
|
* @since 3.4 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private boolean processEntry(CanonicalTreeParser base, |
|
|
|
protected boolean processEntry(CanonicalTreeParser base, |
|
|
|
CanonicalTreeParser ours, CanonicalTreeParser theirs, |
|
|
|
CanonicalTreeParser ours, CanonicalTreeParser theirs, |
|
|
|
DirCacheBuildIterator index, WorkingTreeIterator work) |
|
|
|
DirCacheBuildIterator index, WorkingTreeIterator work) |
|
|
|
throws MissingObjectException, IncorrectObjectTypeException, |
|
|
|
throws MissingObjectException, IncorrectObjectTypeException, |
|
|
@ -932,19 +1011,8 @@ public class ResolveMerger extends ThreeWayMerger { |
|
|
|
if (workingTreeIterator != null) |
|
|
|
if (workingTreeIterator != null) |
|
|
|
tw.addTree(workingTreeIterator); |
|
|
|
tw.addTree(workingTreeIterator); |
|
|
|
|
|
|
|
|
|
|
|
while (tw.next()) { |
|
|
|
if (!mergeTreeWalk(tw)) { |
|
|
|
if (!processEntry( |
|
|
|
return false; |
|
|
|
tw.getTree(T_BASE, CanonicalTreeParser.class), |
|
|
|
|
|
|
|
tw.getTree(T_OURS, CanonicalTreeParser.class), |
|
|
|
|
|
|
|
tw.getTree(T_THEIRS, CanonicalTreeParser.class), |
|
|
|
|
|
|
|
tw.getTree(T_INDEX, DirCacheBuildIterator.class), |
|
|
|
|
|
|
|
(workingTreeIterator == null) ? null : tw.getTree(T_FILE, |
|
|
|
|
|
|
|
WorkingTreeIterator.class))) { |
|
|
|
|
|
|
|
cleanUp(); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (tw.isSubtree() && enterSubtree) |
|
|
|
|
|
|
|
tw.enterSubtree(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!inCore) { |
|
|
|
if (!inCore) { |
|
|
@ -976,4 +1044,32 @@ public class ResolveMerger extends ThreeWayMerger { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Process the given TreeWalk's entries. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param treeWalk |
|
|
|
|
|
|
|
* The walk to iterate over. |
|
|
|
|
|
|
|
* @return Whether the trees merged cleanly. |
|
|
|
|
|
|
|
* @throws IOException |
|
|
|
|
|
|
|
* @since 3.4 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected boolean mergeTreeWalk(TreeWalk treeWalk) throws IOException { |
|
|
|
|
|
|
|
boolean hasWorkingTreeIterator = tw.getTreeCount() > T_FILE; |
|
|
|
|
|
|
|
while (treeWalk.next()) { |
|
|
|
|
|
|
|
if (!processEntry( |
|
|
|
|
|
|
|
treeWalk.getTree(T_BASE, CanonicalTreeParser.class), |
|
|
|
|
|
|
|
treeWalk.getTree(T_OURS, CanonicalTreeParser.class), |
|
|
|
|
|
|
|
treeWalk.getTree(T_THEIRS, CanonicalTreeParser.class), |
|
|
|
|
|
|
|
treeWalk.getTree(T_INDEX, DirCacheBuildIterator.class), |
|
|
|
|
|
|
|
hasWorkingTreeIterator ? treeWalk.getTree(T_FILE, |
|
|
|
|
|
|
|
WorkingTreeIterator.class) : null)) { |
|
|
|
|
|
|
|
cleanUp(); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (treeWalk.isSubtree() && enterSubtree) |
|
|
|
|
|
|
|
treeWalk.enterSubtree(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|