diff options
author | Shawn Pearce <spearce@spearce.org> | 2014-04-17 14:19:23 -0700 |
---|---|---|
committer | Shawn Pearce <spearce@spearce.org> | 2014-04-17 15:51:50 -0700 |
commit | 5a4e34009be6ab108d3165a436da38cb23fb8a0f (patch) | |
tree | f87a9279b783ac0ac70b822d7b0c7c312bd61f33 /org.eclipse.jgit.pgm | |
parent | 551f3a0fa5460513008e26bd2bb1ac73c185f5f5 (diff) | |
download | jgit-5a4e34009be6ab108d3165a436da38cb23fb8a0f.tar.gz jgit-5a4e34009be6ab108d3165a436da38cb23fb8a0f.zip |
blame: Automatically increase commit abbreviation length
Ensure commit object names are unique by extending the default
abbreviation as long as necessary. This allows `jgit blame` to
more closely match the formatted output of `git blame` on large
histories like Gerrit Code Review's ReceiveCommits.java file.
Change-Id: I5f7c4855769ee9dcba973389df9e109005dcdb5b
Diffstat (limited to 'org.eclipse.jgit.pgm')
-rw-r--r-- | org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java index 164da3f1db..307d947f39 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java @@ -143,6 +143,7 @@ class Blame extends TextBuiltin { revision = null; } + boolean autoAbbrev = abbrev == 0; if (abbrev == 0) abbrev = db.getConfig().getInt("core", "abbrev", 7); //$NON-NLS-1$ //$NON-NLS-2$ if (!showBlankBoundary) @@ -156,6 +157,7 @@ class Blame extends TextBuiltin { dateFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ZZZZ"); //$NON-NLS-1$ BlameGenerator generator = new BlameGenerator(db, file); + RevFlag scanned = generator.newFlag("SCANNED"); //$NON-NLS-1$ reader = db.newObjectReader(); try { generator.setTextComparator(comparator); @@ -198,9 +200,17 @@ class Blame extends TextBuiltin { int pathWidth = 1; int maxSourceLine = 1; for (int line = begin; line < end; line++) { - authorWidth = Math.max(authorWidth, author(line).length()); - dateWidth = Math.max(dateWidth, date(line).length()); - pathWidth = Math.max(pathWidth, path(line).length()); + RevCommit c = blame.getSourceCommit(line); + if (c != null && !c.has(scanned)) { + c.add(scanned); + if (autoAbbrev) + abbrev = Math.max(abbrev, uniqueAbbrevLen(c)); + authorWidth = Math.max(authorWidth, author(line).length()); + dateWidth = Math.max(dateWidth, date(line).length()); + pathWidth = Math.max(pathWidth, path(line).length()); + } + while (line + 1 < end && blame.getSourceCommit(line + 1) == c) + line++; maxSourceLine = Math.max(maxSourceLine, blame.getSourceLine(line)); } @@ -232,6 +242,10 @@ class Blame extends TextBuiltin { } } + private int uniqueAbbrevLen(RevCommit commit) throws IOException { + return reader.abbreviate(commit, abbrev).length(); + } + private void parseLineRangeOption() { String beginStr, endStr; if (rangeString.startsWith("/")) { //$NON-NLS-1$ |