From a9c6f575c25b89dcd69558b32d816ca79802028a Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sun, 9 Sep 2007 16:26:20 +0200 Subject: [PATCH] Improve sort order in history viewer When all versions are displayed, the sort order became fuzzy since HEAD could appear anywhere depending on whether it introduced changes or not. This makes it appear as high as possible regardless of whether it introduces changes or not.It may low if the HEAD commit is on another branch with newer commits. Workspace and index. when present, will always be fiirst. Index is compared only to workspace and HEAD, while workspace is compared to all HEAD:s. Signed-off-by: Robin Rosenberg --- .../org/spearce/jgit/lib/TopologicalWalker.java | 29 ++++++++++++++++------ 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/TopologicalWalker.java b/org.spearce.jgit/src/org/spearce/jgit/lib/TopologicalWalker.java index 7ef95e3f..cbd743d8 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/TopologicalWalker.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/TopologicalWalker.java @@ -69,16 +69,17 @@ public class TopologicalWalker extends Walker { return 0; Date when1 = commitTime.get(i1); - if (when1 == null) - return i1.compareTo(i2); - Date when2 = commitTime.get(i2); + if (when1 == null) { + if (when2 == null) + return i1.compareTo(i2); + return 1; + } if (when2 == null) - return i1.compareTo(i2); - + return -1; int c = when2.compareTo(when1); if (c == 0) - return -1; + return i1.compareTo(i2); return c; } }); @@ -92,6 +93,10 @@ public class TopologicalWalker extends Walker { // else topoSorter.put(pred); } else topoSorter.put(succ); + if (pred != null) + collectSortOrder(pred, null); + if (succ != null) + collectSortOrder(succ, null); } protected void collect(Commit commit, int count, int breadth) { @@ -100,10 +105,18 @@ public class TopologicalWalker extends Walker { if (commitId == null) commitId = ObjectId.zeroId(); collected.put(commitId, commitId); - if (commitId.equals(ObjectId.zeroId()) || commitId.equals(starts[0].getCommitId())) + collectSortOrder(commitId, commit); + } + + private void collectSortOrder(ObjectId commitId, Commit commit) { + if (commitId.equals(ObjectId.zeroId())) commitTime.put(commitId, new Date(Long.MAX_VALUE)); else - commitTime.put(commitId, commit.getAuthor().getWhen()); + if (commitId.equals(starts[0].getCommitId())) + commitTime.put(commitId, new Date(Long.MAX_VALUE-1)); + else + if (commit != null) + commitTime.put(commitId, commit.getAuthor().getWhen()); } protected boolean isCancelled() { -- 2.11.4.GIT