]> source.dussan.org Git - gitblit.git/commitdiff
Improve getting changed paths in a commit range
authorJames Moger <james.moger@gitblit.com>
Fri, 28 Feb 2014 19:34:24 +0000 (14:34 -0500)
committerJames Moger <james.moger@gitblit.com>
Sat, 1 Mar 2014 14:21:32 +0000 (09:21 -0500)
src/main/java/com/gitblit/utils/JGitUtils.java

index 7621c0e0adcf40bf6c8b72ff5fa7f357b69e3199..6a6085e7c465fb5ea74a8eb38970a57c03fcd957 100644 (file)
@@ -965,6 +965,36 @@ public class JGitUtils {
                return list;\r
        }\r
 \r
+       /**\r
+        * Returns the list of files changed in a specified commit. If the\r
+        * repository does not exist or is empty, an empty list is returned.\r
+        *\r
+        * @param repository\r
+        * @param startCommit\r
+        *            earliest commit\r
+        * @param endCommit\r
+        *            most recent commit. if null, HEAD is assumed.\r
+        * @return list of files changed in a commit range\r
+        */\r
+       public static List<PathChangeModel> getFilesInRange(Repository repository, String startCommit, String endCommit) {\r
+               List<PathChangeModel> list = new ArrayList<PathChangeModel>();\r
+               if (!hasCommits(repository)) {\r
+                       return list;\r
+               }\r
+               try {\r
+                       ObjectId startRange = repository.resolve(startCommit);\r
+                       ObjectId endRange = repository.resolve(endCommit);\r
+                       RevWalk rw = new RevWalk(repository);\r
+                       RevCommit start = rw.parseCommit(startRange);\r
+                       RevCommit end = rw.parseCommit(endRange);\r
+                       list.addAll(getFilesInRange(repository, start, end));\r
+                       rw.release();\r
+               } catch (Throwable t) {\r
+                       error(t, repository, "{0} failed to determine files in range {1}..{2}!", startCommit, endCommit);\r
+               }\r
+               return list;\r
+       }\r
+\r
        /**\r
         * Returns the list of files changed in a specified commit. If the\r
         * repository does not exist or is empty, an empty list is returned.\r
@@ -989,7 +1019,7 @@ public class JGitUtils {
 \r
                        List<DiffEntry> diffEntries = df.scan(startCommit.getTree(), endCommit.getTree());\r
                        for (DiffEntry diff : diffEntries) {\r
-                               PathChangeModel pcm = PathChangeModel.from(diff,  null);\r
+                               PathChangeModel pcm = PathChangeModel.from(diff,  endCommit.getName());\r
                                list.add(pcm);\r
                        }\r
                        Collections.sort(list);\r