Browse Source

Fix missing braces in Blame.run()

Change-Id: I32a0e973bc73e85a67e975b728b425c148059b81
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-5.4
Matthias Sohn 6 years ago
parent
commit
c41bb9d3d9
  1. 46
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java

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

@ -137,24 +137,29 @@ class Blame extends TextBuiltin {
@Override @Override
protected void run() { protected void run() {
if (file == null) { if (file == null) {
if (revision == null) if (revision == null) {
throw die(CLIText.get().fileIsRequired); throw die(CLIText.get().fileIsRequired);
}
file = revision; file = revision;
revision = null; revision = null;
} }
boolean autoAbbrev = abbrev == 0; 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) {
root = db.getConfig().getBoolean("blame", "blankboundary", false); //$NON-NLS-1$ //$NON-NLS-2$ root = db.getConfig().getBoolean("blame", "blankboundary", false); //$NON-NLS-1$ //$NON-NLS-2$
if (!root) }
if (!root) {
root = db.getConfig().getBoolean("blame", "showroot", false); //$NON-NLS-1$ //$NON-NLS-2$ root = db.getConfig().getBoolean("blame", "showroot", false); //$NON-NLS-1$ //$NON-NLS-2$
}
if (showRawTimestamp) if (showRawTimestamp) {
dateFmt = new SimpleDateFormat("ZZZZ"); //$NON-NLS-1$ dateFmt = new SimpleDateFormat("ZZZZ"); //$NON-NLS-1$
else } else {
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$
}
try (ObjectReader reader = db.newObjectReader(); try (ObjectReader reader = db.newObjectReader();
BlameGenerator generator = new BlameGenerator(db, file)) { BlameGenerator generator = new BlameGenerator(db, file)) {
@ -165,11 +170,12 @@ class Blame extends TextBuiltin {
RevCommit rangeStart = null; RevCommit rangeStart = null;
List<RevCommit> rangeEnd = new ArrayList<>(2); List<RevCommit> rangeEnd = new ArrayList<>(2);
for (RevCommit c : reverseRange) { for (RevCommit c : reverseRange) {
if (c.has(RevFlag.UNINTERESTING)) if (c.has(RevFlag.UNINTERESTING)) {
rangeStart = c; rangeStart = c;
else } else {
rangeEnd.add(c); rangeEnd.add(c);
} }
}
generator.reverse(rangeStart, rangeEnd); generator.reverse(rangeStart, rangeEnd);
} else if (revision != null) { } else if (revision != null) {
generator.push(null, db.resolve(revision + "^{commit}")); //$NON-NLS-1$ generator.push(null, db.resolve(revision + "^{commit}")); //$NON-NLS-1$
@ -178,20 +184,23 @@ class Blame extends TextBuiltin {
if (!db.isBare()) { if (!db.isBare()) {
DirCache dc = db.readDirCache(); DirCache dc = db.readDirCache();
int entry = dc.findEntry(file); int entry = dc.findEntry(file);
if (0 <= entry) if (0 <= entry) {
generator.push(null, dc.getEntry(entry).getObjectId()); generator.push(null, dc.getEntry(entry).getObjectId());
}
File inTree = new File(db.getWorkTree(), file); File inTree = new File(db.getWorkTree(), file);
if (db.getFS().isFile(inTree)) if (db.getFS().isFile(inTree)) {
generator.push(null, new RawText(inTree)); generator.push(null, new RawText(inTree));
} }
} }
}
blame = BlameResult.create(generator); blame = BlameResult.create(generator);
begin = 0; begin = 0;
end = blame.getResultContents().size(); end = blame.getResultContents().size();
if (rangeString != null) if (rangeString != null) {
parseLineRangeOption(); parseLineRangeOption();
}
blame.computeRange(begin, end); blame.computeRange(begin, end);
int authorWidth = 8; int authorWidth = 8;
@ -202,14 +211,16 @@ class Blame extends TextBuiltin {
RevCommit c = blame.getSourceCommit(line); RevCommit c = blame.getSourceCommit(line);
if (c != null && !c.has(scanned)) { if (c != null && !c.has(scanned)) {
c.add(scanned); c.add(scanned);
if (autoAbbrev) if (autoAbbrev) {
abbrev = Math.max(abbrev, uniqueAbbrevLen(reader, c)); abbrev = Math.max(abbrev, uniqueAbbrevLen(reader, 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) while (line + 1 < end && blame.getSourceCommit(line + 1) == c) {
line++; line++;
}
maxSourceLine = Math.max(maxSourceLine, blame.getSourceLine(line)); maxSourceLine = Math.max(maxSourceLine, blame.getSourceLine(line));
} }
@ -232,12 +243,15 @@ class Blame extends TextBuiltin {
} }
do { do {
outw.print(commit); 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, date); 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);

Loading…
Cancel
Save