Browse Source

ResolveMerger: Use the ObjectReader to access objects

This is necessary to ensure objects accessed by the TreeWalk come from
the associated ObjectInserter when the merger is a RecursiveMerger
instance and a virtual common base was constructed but not flushed.

Change-Id: Iebe739d30fd868ebc4f61dbfb714673146a2c3ec
stable-3.5
Shawn Pearce 10 years ago
parent
commit
9bb891e44d
  1. 2
      org.eclipse.jgit/src/org/eclipse/jgit/merge/RecursiveMerger.java
  2. 13
      org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java

2
org.eclipse.jgit/src/org/eclipse/jgit/merge/RecursiveMerger.java

@ -265,7 +265,7 @@ public class RecursiveMerger extends ResolveMerger {
private DirCache dircacheFromTree(ObjectId treeId) throws IOException { private DirCache dircacheFromTree(ObjectId treeId) throws IOException {
DirCache ret = DirCache.newInCore(); DirCache ret = DirCache.newInCore();
DirCacheBuilder builder = ret.builder(); DirCacheBuilder builder = ret.builder();
TreeWalk tw = new TreeWalk(db); TreeWalk tw = new TreeWalk(reader);
tw.addTree(treeId); tw.addTree(treeId);
tw.setRecursive(true); tw.setRecursive(true);
while (tw.next()) { while (tw.next()) {

13
org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java

@ -81,6 +81,7 @@ import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevTree; import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.treewalk.AbstractTreeIterator; import org.eclipse.jgit.treewalk.AbstractTreeIterator;
@ -682,11 +683,11 @@ public class ResolveMerger extends ThreeWayMerger {
CanonicalTreeParser ours, CanonicalTreeParser theirs) CanonicalTreeParser ours, CanonicalTreeParser theirs)
throws IOException { throws IOException {
RawText baseText = base == null ? RawText.EMPTY_TEXT : getRawText( RawText baseText = base == null ? RawText.EMPTY_TEXT : getRawText(
base.getEntryObjectId(), db); base.getEntryObjectId(), reader);
RawText ourText = ours == null ? RawText.EMPTY_TEXT : getRawText( RawText ourText = ours == null ? RawText.EMPTY_TEXT : getRawText(
ours.getEntryObjectId(), db); ours.getEntryObjectId(), reader);
RawText theirsText = theirs == null ? RawText.EMPTY_TEXT : getRawText( RawText theirsText = theirs == null ? RawText.EMPTY_TEXT : getRawText(
theirs.getEntryObjectId(), db); theirs.getEntryObjectId(), reader);
return (mergeAlgorithm.merge(RawTextComparator.DEFAULT, baseText, return (mergeAlgorithm.merge(RawTextComparator.DEFAULT, baseText,
ourText, theirsText)); ourText, theirsText));
} }
@ -866,11 +867,11 @@ public class ResolveMerger extends ThreeWayMerger {
return FileMode.MISSING.getBits(); return FileMode.MISSING.getBits();
} }
private static RawText getRawText(ObjectId id, Repository db) private static RawText getRawText(ObjectId id, ObjectReader reader)
throws IOException { throws IOException {
if (id.equals(ObjectId.zeroId())) if (id.equals(ObjectId.zeroId()))
return new RawText(new byte[] {}); return new RawText(new byte[] {});
return new RawText(db.open(id, OBJ_BLOB).getCachedBytes()); return new RawText(reader.open(id, OBJ_BLOB).getCachedBytes());
} }
private static boolean nonTree(final int mode) { private static boolean nonTree(final int mode) {
@ -1028,7 +1029,7 @@ public class ResolveMerger extends ThreeWayMerger {
builder = dircache.builder(); builder = dircache.builder();
DirCacheBuildIterator buildIt = new DirCacheBuildIterator(builder); DirCacheBuildIterator buildIt = new DirCacheBuildIterator(builder);
tw = new NameConflictTreeWalk(db); tw = new NameConflictTreeWalk(reader);
tw.addTree(baseTree); tw.addTree(baseTree);
tw.addTree(headTree); tw.addTree(headTree);
tw.addTree(mergeTree); tw.addTree(mergeTree);

Loading…
Cancel
Save