diff options
Diffstat (limited to 'org.eclipse.jgit')
4 files changed, 35 insertions, 21 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java index fe0db33d3a..11848e2c99 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java @@ -119,6 +119,8 @@ public class DiffFormatter { private ObjectReader reader; + private DiffConfig diffCfg; + private int context = 3; private int abbreviationLength = 7; @@ -173,6 +175,7 @@ public class DiffFormatter { db = repository; reader = db.newObjectReader(); + diffCfg = db.getConfig().get(DiffConfig.KEY); ContentSource cs = ContentSource.create(reader); source = new ContentSource.Pair(cs, cs); @@ -534,7 +537,7 @@ public class DiffFormatter { String oldPath = ((FollowFilter) pathFilter).getPath(); for (DiffEntry ent : files) { if (isRename(ent) && ent.getNewPath().equals(oldPath)) { - pathFilter = FollowFilter.create(ent.getOldPath()); + pathFilter = FollowFilter.create(ent.getOldPath(), diffCfg); return Collections.singletonList(ent); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RenameDetector.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RenameDetector.java index f229a04a06..7648a48ac7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RenameDetector.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RenameDetector.java @@ -111,7 +111,7 @@ public class RenameDetector { private boolean done; - private final Repository repo; + private final ObjectReader objectReader; /** Similarity score required to pair an add/delete as a rename. */ private int renameScore = 60; @@ -136,11 +136,20 @@ public class RenameDetector { * the repository to use for rename detection */ public RenameDetector(Repository repo) { - this.repo = repo; + this(repo.newObjectReader(), repo.getConfig().get(DiffConfig.KEY)); + } - DiffConfig cfg = repo.getConfig().get(DiffConfig.KEY); + /** + * Create a new rename detector with a specified reader and diff config. + * + * @param reader + * reader to obtain objects from the repository with. + * @param cfg + * diff config specifying rename detection options. + */ + public RenameDetector(ObjectReader reader, DiffConfig cfg) { + objectReader = reader.newReader(); renameLimit = cfg.getRenameLimit(); - reset(); } @@ -310,11 +319,10 @@ public class RenameDetector { */ public List<DiffEntry> compute(ProgressMonitor pm) throws IOException { if (!done) { - ObjectReader reader = repo.newObjectReader(); try { - return compute(reader, pm); + return compute(objectReader, pm); } finally { - reader.release(); + objectReader.release(); } } return Collections.unmodifiableList(entries); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FollowFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FollowFilter.java index ab2cf2bccb..9928286dcd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FollowFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FollowFilter.java @@ -45,6 +45,7 @@ package org.eclipse.jgit.revwalk; import java.io.IOException; +import org.eclipse.jgit.diff.DiffConfig; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.treewalk.TreeWalk; @@ -77,20 +78,25 @@ public class FollowFilter extends TreeFilter { * the path to filter on. Must not be the empty string. All * trailing '/' characters will be trimmed before string's length * is checked or is used as part of the constructed filter. + * @param cfg + * diff config specifying rename detection options. * @return a new filter for the requested path. * @throws IllegalArgumentException * the path supplied was the empty string. + * @since 3.0 */ - public static FollowFilter create(String path) { - return new FollowFilter(PathFilter.create(path)); + public static FollowFilter create(String path, DiffConfig cfg) { + return new FollowFilter(PathFilter.create(path), cfg); } private final PathFilter path; + final DiffConfig cfg; private RenameCallback renameCallback; - FollowFilter(final PathFilter path) { + FollowFilter(final PathFilter path, final DiffConfig cfg) { this.path = path; + this.cfg = cfg; } /** @return the path this filter matches. */ @@ -112,7 +118,7 @@ public class FollowFilter extends TreeFilter { @Override public TreeFilter clone() { - return new FollowFilter(path.clone()); + return new FollowFilter(path.clone(), cfg); } @SuppressWarnings("nls") diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteTreeFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteTreeFilter.java index 9e1f02139f..a84e80e650 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteTreeFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteTreeFilter.java @@ -46,15 +46,15 @@ package org.eclipse.jgit.revwalk; import java.io.IOException; import java.util.List; +import org.eclipse.jgit.diff.DiffConfig; import org.eclipse.jgit.diff.DiffEntry; -import org.eclipse.jgit.diff.RenameDetector; import org.eclipse.jgit.diff.DiffEntry.ChangeType; +import org.eclipse.jgit.diff.RenameDetector; import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.StopWalkException; import org.eclipse.jgit.lib.ObjectId; -import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.filter.RevFilter; import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.filter.TreeFilter; @@ -82,10 +82,7 @@ class RewriteTreeFilter extends RevFilter { private final TreeWalk pathFilter; - private final Repository repository; - RewriteTreeFilter(final RevWalk walker, final TreeFilter t) { - repository = walker.repository; pathFilter = new TreeWalk(walker.reader); pathFilter.setFilter(t); pathFilter.setRecursive(t.shouldBeRecursive()); @@ -142,7 +139,7 @@ class RewriteTreeFilter extends RevFilter { // commit. We need to update our filter to its older // name, if we can discover it. Find out what that is. // - updateFollowFilter(trees); + updateFollowFilter(trees, ((FollowFilter) tw.getFilter()).cfg); } return true; } @@ -235,7 +232,7 @@ class RewriteTreeFilter extends RevFilter { return false; } - private void updateFollowFilter(ObjectId[] trees) + private void updateFollowFilter(ObjectId[] trees, DiffConfig cfg) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { TreeWalk tw = pathFilter; @@ -244,14 +241,14 @@ class RewriteTreeFilter extends RevFilter { tw.reset(trees); List<DiffEntry> files = DiffEntry.scan(tw); - RenameDetector rd = new RenameDetector(repository); + RenameDetector rd = new RenameDetector(tw.getObjectReader(), cfg); rd.addAll(files); files = rd.compute(); TreeFilter newFilter = oldFilter; for (DiffEntry ent : files) { if (isRename(ent) && ent.getNewPath().equals(oldFilter.getPath())) { - newFilter = FollowFilter.create(ent.getOldPath()); + newFilter = FollowFilter.create(ent.getOldPath(), cfg); RenameCallback callback = oldFilter.getRenameCallback(); if (callback != null) { callback.renamed(ent); |