Browse Source

blame: Format commit and author only once per range

When a commit is blamed for multiple lines of the result file the
command line interface prints the same text before each line in that
span.  Format these strings once and reuse them as the line prefix.

For long files (e.g. 2425 lines of ReceiveCommits.java in Gerrit)
this can save as much as 20ms during the output phase of the command
line blame program.

Change-Id: Ie42787d77c8d0cbca7ccbf59c795120494a2a891
stable-3.4
Shawn Pearce 11 years ago
parent
commit
a622451ac9
  1. 16
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java

16
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java

@ -222,19 +222,29 @@ class Blame extends TextBuiltin {
String authorFmt = MessageFormat.format(" (%-{0}s %{1}s", //$NON-NLS-1$ String authorFmt = MessageFormat.format(" (%-{0}s %{1}s", //$NON-NLS-1$
valueOf(authorWidth), valueOf(dateWidth)); valueOf(authorWidth), valueOf(dateWidth));
for (int line = begin; line < end; line++) { for (int line = begin; line < end;) {
outw.print(abbreviate(blame.getSourceCommit(line))); RevCommit c = blame.getSourceCommit(line);
String commit = abbreviate(c);
String author = null;
String date = null;
if (!noAuthor) {
author = author(line);
date = date(line);
}
do {
outw.print(commit);
if (showSourcePath) if (showSourcePath)
outw.format(pathFmt, path(line)); outw.format(pathFmt, path(line));
if (showSourceLine) if (showSourceLine)
outw.format(numFmt, valueOf(blame.getSourceLine(line) + 1)); outw.format(numFmt, valueOf(blame.getSourceLine(line) + 1));
if (!noAuthor) if (!noAuthor)
outw.format(authorFmt, author(line), date(line)); outw.format(authorFmt, author, date);
outw.format(lineFmt, valueOf(line + 1)); outw.format(lineFmt, valueOf(line + 1));
outw.flush(); outw.flush();
blame.getResultContents().writeLine(outs, line); blame.getResultContents().writeLine(outs, line);
outs.flush(); outs.flush();
outw.print('\n'); outw.print('\n');
} while (++line < end && blame.getSourceCommit(line) == c);
} }
} finally { } finally {
generator.release(); generator.release();

Loading…
Cancel
Save