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
This commit is contained in:
parent
551f3a0fa5
commit
5a4e34009b
|
@ -143,6 +143,7 @@ protected void run() throws Exception {
|
||||||
revision = null;
|
revision = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean autoAbbrev = abbrev == 0;
|
||||||
if (abbrev == 0)
|
if (abbrev == 0)
|
||||||
abbrev = db.getConfig().getInt("core", "abbrev", 7); //$NON-NLS-1$ //$NON-NLS-2$
|
abbrev = db.getConfig().getInt("core", "abbrev", 7); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
if (!showBlankBoundary)
|
if (!showBlankBoundary)
|
||||||
|
@ -156,6 +157,7 @@ protected void run() throws Exception {
|
||||||
dateFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ZZZZ"); //$NON-NLS-1$
|
dateFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ZZZZ"); //$NON-NLS-1$
|
||||||
|
|
||||||
BlameGenerator generator = new BlameGenerator(db, file);
|
BlameGenerator generator = new BlameGenerator(db, file);
|
||||||
|
RevFlag scanned = generator.newFlag("SCANNED"); //$NON-NLS-1$
|
||||||
reader = db.newObjectReader();
|
reader = db.newObjectReader();
|
||||||
try {
|
try {
|
||||||
generator.setTextComparator(comparator);
|
generator.setTextComparator(comparator);
|
||||||
|
@ -198,9 +200,17 @@ protected void run() throws Exception {
|
||||||
int pathWidth = 1;
|
int pathWidth = 1;
|
||||||
int maxSourceLine = 1;
|
int maxSourceLine = 1;
|
||||||
for (int line = begin; line < end; line++) {
|
for (int line = begin; line < end; line++) {
|
||||||
|
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());
|
authorWidth = Math.max(authorWidth, author(line).length());
|
||||||
dateWidth = Math.max(dateWidth, date(line).length());
|
dateWidth = Math.max(dateWidth, date(line).length());
|
||||||
pathWidth = Math.max(pathWidth, path(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));
|
maxSourceLine = Math.max(maxSourceLine, blame.getSourceLine(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,6 +242,10 @@ protected void run() throws Exception {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int uniqueAbbrevLen(RevCommit commit) throws IOException {
|
||||||
|
return reader.abbreviate(commit, abbrev).length();
|
||||||
|
}
|
||||||
|
|
||||||
private void parseLineRangeOption() {
|
private void parseLineRangeOption() {
|
||||||
String beginStr, endStr;
|
String beginStr, endStr;
|
||||||
if (rangeString.startsWith("/")) { //$NON-NLS-1$
|
if (rangeString.startsWith("/")) { //$NON-NLS-1$
|
||||||
|
|
|
@ -422,6 +422,18 @@ public BlameGenerator reverse(AnyObjectId start,
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocate a new RevFlag for use by the caller.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* unique name of the flag in the blame context.
|
||||||
|
* @return the newly allocated flag.
|
||||||
|
* @since 3.4
|
||||||
|
*/
|
||||||
|
public RevFlag newFlag(String name) {
|
||||||
|
return revPool.newFlag(name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the generator in a blocking fashion until all data is ready.
|
* Execute the generator in a blocking fashion until all data is ready.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue