Use try-with-resource for reader in Blame.run()
Change-Id: I115aa9854fefeccc2348686e6377b30413911c17 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
parent
cced939504
commit
562976f417
|
@ -122,8 +122,6 @@ void ignoreAllSpace(@SuppressWarnings("unused") boolean on) {
|
||||||
@Argument(index = 1, required = false, metaVar = "metaVar_file")
|
@Argument(index = 1, required = false, metaVar = "metaVar_file")
|
||||||
private String file;
|
private String file;
|
||||||
|
|
||||||
private ObjectReader reader;
|
|
||||||
|
|
||||||
private final Map<RevCommit, String> abbreviatedCommits = new HashMap<>();
|
private final Map<RevCommit, String> abbreviatedCommits = new HashMap<>();
|
||||||
|
|
||||||
private SimpleDateFormat dateFmt;
|
private SimpleDateFormat dateFmt;
|
||||||
|
@ -157,8 +155,8 @@ protected void run() throws Exception {
|
||||||
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$
|
||||||
|
|
||||||
reader = db.newObjectReader();
|
try (ObjectReader reader = db.newObjectReader();
|
||||||
try (BlameGenerator generator = new BlameGenerator(db, file)) {
|
BlameGenerator generator = new BlameGenerator(db, file)) {
|
||||||
RevFlag scanned = generator.newFlag("SCANNED"); //$NON-NLS-1$
|
RevFlag scanned = generator.newFlag("SCANNED"); //$NON-NLS-1$
|
||||||
generator.setTextComparator(comparator);
|
generator.setTextComparator(comparator);
|
||||||
|
|
||||||
|
@ -204,7 +202,7 @@ protected void run() throws Exception {
|
||||||
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(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());
|
||||||
|
@ -224,7 +222,7 @@ protected void run() throws Exception {
|
||||||
|
|
||||||
for (int line = begin; line < end;) {
|
for (int line = begin; line < end;) {
|
||||||
RevCommit c = blame.getSourceCommit(line);
|
RevCommit c = blame.getSourceCommit(line);
|
||||||
String commit = abbreviate(c);
|
String commit = abbreviate(reader, c);
|
||||||
String author = null;
|
String author = null;
|
||||||
String date = null;
|
String date = null;
|
||||||
if (!noAuthor) {
|
if (!noAuthor) {
|
||||||
|
@ -246,12 +244,11 @@ protected void run() throws Exception {
|
||||||
outw.print('\n');
|
outw.print('\n');
|
||||||
} while (++line < end && blame.getSourceCommit(line) == c);
|
} while (++line < end && blame.getSourceCommit(line) == c);
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
reader.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int uniqueAbbrevLen(RevCommit commit) throws IOException {
|
private int uniqueAbbrevLen(ObjectReader reader, RevCommit commit)
|
||||||
|
throws IOException {
|
||||||
return reader.abbreviate(commit, abbrev).length();
|
return reader.abbreviate(commit, abbrev).length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,7 +342,8 @@ private String date(int line) {
|
||||||
dateFmt.format(author.getWhen()));
|
dateFmt.format(author.getWhen()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String abbreviate(RevCommit commit) throws IOException {
|
private String abbreviate(ObjectReader reader, RevCommit commit)
|
||||||
|
throws IOException {
|
||||||
String r = abbreviatedCommits.get(commit);
|
String r = abbreviatedCommits.get(commit);
|
||||||
if (r != null)
|
if (r != null)
|
||||||
return r;
|
return r;
|
||||||
|
|
Loading…
Reference in New Issue