aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2015-10-01 16:07:02 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2015-10-01 16:55:26 +0900
commit3096ab6502471ec2f2f76040f72d31680e2b61ca (patch)
tree768a981be6fe27a9d11fa93dec6f136943535b49 /org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java
parent581698331a0e80eb02fdd7549cfce1c0e6f9ac87 (diff)
downloadjgit-3096ab6502471ec2f2f76040f72d31680e2b61ca.tar.gz
jgit-3096ab6502471ec2f2f76040f72d31680e2b61ca.zip
pgm: Create instances of Git in try-with-resource
To prevent potential resource leak. Change-Id: I8ac4ae61193324849bafb46501a55f93c5029a4e Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
Diffstat (limited to 'org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java62
1 files changed, 32 insertions, 30 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java
index 14c449a6b3..f18242d684 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java
@@ -80,37 +80,39 @@ class Commit extends TextBuiltin {
@Override
protected void run() throws NoHeadException, NoMessageException,
ConcurrentRefUpdateException, JGitInternalException, Exception {
- CommitCommand commitCmd = new Git(db).commit();
- if (author != null)
- commitCmd.setAuthor(RawParseUtils.parsePersonIdent(author));
- if (message != null)
- commitCmd.setMessage(message);
- if (only && paths.isEmpty())
- throw die(CLIText.get().pathsRequired);
- if (only && all)
- throw die(CLIText.get().onlyOneOfIncludeOnlyAllInteractiveCanBeUsed);
- if (!paths.isEmpty())
- for (String p : paths)
- commitCmd.setOnly(p);
- commitCmd.setAmend(amend);
- commitCmd.setAll(all);
- Ref head = db.getRef(Constants.HEAD);
- RevCommit commit;
- try {
- commit = commitCmd.call();
- } catch (JGitInternalException e) {
- throw die(e.getMessage());
- }
+ try (Git git = new Git(db)) {
+ CommitCommand commitCmd = git.commit();
+ if (author != null)
+ commitCmd.setAuthor(RawParseUtils.parsePersonIdent(author));
+ if (message != null)
+ commitCmd.setMessage(message);
+ if (only && paths.isEmpty())
+ throw die(CLIText.get().pathsRequired);
+ if (only && all)
+ throw die(CLIText.get().onlyOneOfIncludeOnlyAllInteractiveCanBeUsed);
+ if (!paths.isEmpty())
+ for (String p : paths)
+ commitCmd.setOnly(p);
+ commitCmd.setAmend(amend);
+ commitCmd.setAll(all);
+ Ref head = db.getRef(Constants.HEAD);
+ RevCommit commit;
+ try {
+ commit = commitCmd.call();
+ } catch (JGitInternalException e) {
+ throw die(e.getMessage());
+ }
- String branchName;
- if (!head.isSymbolic())
- branchName = CLIText.get().branchDetachedHEAD;
- else {
- branchName = head.getTarget().getName();
- if (branchName.startsWith(Constants.R_HEADS))
- branchName = branchName.substring(Constants.R_HEADS.length());
+ String branchName;
+ if (!head.isSymbolic())
+ branchName = CLIText.get().branchDetachedHEAD;
+ else {
+ branchName = head.getTarget().getName();
+ if (branchName.startsWith(Constants.R_HEADS))
+ branchName = branchName.substring(Constants.R_HEADS.length());
+ }
+ outw.println("[" + branchName + " " + commit.name() + "] " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + commit.getShortMessage());
}
- outw.println("[" + branchName + " " + commit.name() + "] " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + commit.getShortMessage());
}
}