]> source.dussan.org Git - jgit.git/commitdiff
Building bitmaps: Simplify the logic to sort by chains 81/59281/5
authorTerry Parker <tparker@google.com>
Thu, 29 Oct 2015 18:02:01 +0000 (11:02 -0700)
committerTerry Parker <tparker@google.com>
Thu, 29 Oct 2015 18:25:24 +0000 (11:25 -0700)
Change-Id: I3da98e85107154c159093c138893f54dfa7ef435
Signed-off-by: Terry Parker <tparker@google.com>
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriterBitmapPreparer.java

index e250289bd7e7e5d4ce1ea0a08109b22120040733..a58caa924b9749e6936a998053b78c6687f9cd58 100644 (file)
@@ -269,29 +269,22 @@ class PackWriterBitmapPreparer {
                                        // selected commit to fullBitmap.
                                }
 
-                               // Sort the commits by independent chains in its history,
-                               // yielding better compression when building bitmaps.
-                               List<List<BitmapCommit>> candidateChain = new ArrayList<
-                                               List<BitmapCommit>>();
+                               // Sort the commits by independent chains in this branch's
+                               // history, yielding better compression when building bitmaps.
+                               List<BitmapCommit> longestAncestorChain = null;
                                for (List<BitmapCommit> chain : chains) {
                                        BitmapCommit mostRecentCommit = chain.get(chain.size() - 1);
                                        if (fullBitmap.contains(mostRecentCommit)) {
-                                               candidateChain.add(chain);
+                                               if (longestAncestorChain == null
+                                                               || longestAncestorChain.size() < chain.size()) {
+                                                       longestAncestorChain = chain;
+                                               }
                                        }
                                }
 
-                               List<BitmapCommit> longestAncestorChain;
-                               if (candidateChain.isEmpty()) {
+                               if (longestAncestorChain == null) {
                                        longestAncestorChain = new ArrayList<BitmapCommit>();
                                        chains.add(longestAncestorChain);
-                               } else {
-                                       longestAncestorChain = candidateChain.get(0);
-                                       // Append to longest
-                                       for (List<BitmapCommit> chain : candidateChain) {
-                                               if (chain.size() > longestAncestorChain.size()) {
-                                                       longestAncestorChain = chain;
-                                               }
-                                       }
                                }
                                longestAncestorChain.add(new BitmapCommit(
                                                c, !longestAncestorChain.isEmpty(), flags));