From 131da2786c1bf275c07ba628af4254a40d1dc42f Mon Sep 17 00:00:00 2001 From: James Moger Date: Fri, 28 Feb 2014 14:34:24 -0500 Subject: [PATCH] Improve getting changed paths in a commit range --- .../java/com/gitblit/utils/JGitUtils.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gitblit/utils/JGitUtils.java b/src/main/java/com/gitblit/utils/JGitUtils.java index 7621c0e0..6a6085e7 100644 --- a/src/main/java/com/gitblit/utils/JGitUtils.java +++ b/src/main/java/com/gitblit/utils/JGitUtils.java @@ -965,6 +965,36 @@ public class JGitUtils { return list; } + /** + * Returns the list of files changed in a specified commit. If the + * repository does not exist or is empty, an empty list is returned. + * + * @param repository + * @param startCommit + * earliest commit + * @param endCommit + * most recent commit. if null, HEAD is assumed. + * @return list of files changed in a commit range + */ + public static List getFilesInRange(Repository repository, String startCommit, String endCommit) { + List list = new ArrayList(); + if (!hasCommits(repository)) { + return list; + } + try { + ObjectId startRange = repository.resolve(startCommit); + ObjectId endRange = repository.resolve(endCommit); + RevWalk rw = new RevWalk(repository); + RevCommit start = rw.parseCommit(startRange); + RevCommit end = rw.parseCommit(endRange); + list.addAll(getFilesInRange(repository, start, end)); + rw.release(); + } catch (Throwable t) { + error(t, repository, "{0} failed to determine files in range {1}..{2}!", startCommit, endCommit); + } + return list; + } + /** * Returns the list of files changed in a specified commit. If the * repository does not exist or is empty, an empty list is returned. @@ -989,7 +1019,7 @@ public class JGitUtils { List diffEntries = df.scan(startCommit.getTree(), endCommit.getTree()); for (DiffEntry diff : diffEntries) { - PathChangeModel pcm = PathChangeModel.from(diff, null); + PathChangeModel pcm = PathChangeModel.from(diff, endCommit.getName()); list.add(pcm); } Collections.sort(list); -- 2.39.5