aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm/src
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2019-01-17 23:30:29 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2019-01-17 23:30:29 +0100
commit562976f417f21f3f2852ba9e91e12c292c39fa02 (patch)
tree4c58bb71e958868a90334f1e1d7e1a389365a416 /org.eclipse.jgit.pgm/src
parentcced9395045664b13c76f547edfdd7451507230c (diff)
downloadjgit-562976f417f21f3f2852ba9e91e12c292c39fa02.tar.gz
jgit-562976f417f21f3f2852ba9e91e12c292c39fa02.zip
Use try-with-resource for reader in Blame.run()
Change-Id: I115aa9854fefeccc2348686e6377b30413911c17 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.pgm/src')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Blame.java18
1 files changed, 8 insertions, 10 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 13a38dddf4..7337421c82 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
@@ -122,8 +122,6 @@ class Blame extends TextBuiltin {
@Argument(index = 1, required = false, metaVar = "metaVar_file")
private String file;
- private ObjectReader reader;
-
private final Map<RevCommit, String> abbreviatedCommits = new HashMap<>();
private SimpleDateFormat dateFmt;
@@ -157,8 +155,8 @@ class Blame extends TextBuiltin {
else
dateFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ZZZZ"); //$NON-NLS-1$
- reader = db.newObjectReader();
- try (BlameGenerator generator = new BlameGenerator(db, file)) {
+ try (ObjectReader reader = db.newObjectReader();
+ BlameGenerator generator = new BlameGenerator(db, file)) {
RevFlag scanned = generator.newFlag("SCANNED"); //$NON-NLS-1$
generator.setTextComparator(comparator);
@@ -204,7 +202,7 @@ class Blame extends TextBuiltin {
if (c != null && !c.has(scanned)) {
c.add(scanned);
if (autoAbbrev)
- abbrev = Math.max(abbrev, uniqueAbbrevLen(c));
+ abbrev = Math.max(abbrev, uniqueAbbrevLen(reader, c));
authorWidth = Math.max(authorWidth, author(line).length());
dateWidth = Math.max(dateWidth, date(line).length());
pathWidth = Math.max(pathWidth, path(line).length());
@@ -224,7 +222,7 @@ class Blame extends TextBuiltin {
for (int line = begin; line < end;) {
RevCommit c = blame.getSourceCommit(line);
- String commit = abbreviate(c);
+ String commit = abbreviate(reader, c);
String author = null;
String date = null;
if (!noAuthor) {
@@ -246,12 +244,11 @@ class Blame extends TextBuiltin {
outw.print('\n');
} 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();
}
@@ -345,7 +342,8 @@ class Blame extends TextBuiltin {
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);
if (r != null)
return r;