Browse Source

Use try-with-resource to close resources in CheckoutCommand

Change-Id: Ia4d4f9bff03a03d116b80022d7691df67bf8b51b
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
tags/v4.0.0.201505050340-m2
Matthias Sohn 9 years ago
parent
commit
7343c7a10f
1 changed files with 26 additions and 28 deletions
  1. 26
    28
      org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java

+ 26
- 28
org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java View File

} }


if (createBranch) { if (createBranch) {
Git git = new Git(repo);
CreateBranchCommand command = git.branchCreate();
command.setName(name);
if (startCommit != null)
command.setStartPoint(startCommit);
else
command.setStartPoint(startPoint);
if (upstreamMode != null)
command.setUpstreamMode(upstreamMode);
command.call();
try (Git git = new Git(repo)) {
CreateBranchCommand command = git.branchCreate();
command.setName(name);
if (startCommit != null)
command.setStartPoint(startCommit);
else
command.setStartPoint(startPoint);
if (upstreamMode != null)
command.setUpstreamMode(upstreamMode);
command.call();
}
} }


Ref headRef = repo.getRef(Constants.HEAD); Ref headRef = repo.getRef(Constants.HEAD);
JGitText.get().refNotResolved, name)); JGitText.get().refNotResolved, name));
} }


RevWalk revWalk = new RevWalk(repo);
AnyObjectId headId = headRef.getObjectId();
RevCommit headCommit = headId == null ? null : revWalk
.parseCommit(headId);
RevCommit newCommit = revWalk.parseCommit(branch);
RevCommit headCommit = null;
RevCommit newCommit = null;
try (RevWalk revWalk = new RevWalk(repo)) {
AnyObjectId headId = headRef.getObjectId();
headCommit = headId == null ? null
: revWalk.parseCommit(headId);
newCommit = revWalk.parseCommit(branch);
}
RevTree headTree = headCommit == null ? null : headCommit.getTree(); RevTree headTree = headCommit == null ? null : headCommit.getTree();
DirCacheCheckout dco; DirCacheCheckout dco;
DirCache dc = repo.lockDirCache(); DirCache dc = repo.lockDirCache();
*/ */
protected CheckoutCommand checkoutPaths() throws IOException, protected CheckoutCommand checkoutPaths() throws IOException,
RefNotFoundException { RefNotFoundException {
RevWalk revWalk = new RevWalk(repo);
DirCache dc = repo.lockDirCache(); DirCache dc = repo.lockDirCache();
try {
TreeWalk treeWalk = new TreeWalk(revWalk.getObjectReader());
try (RevWalk revWalk = new RevWalk(repo);
TreeWalk treeWalk = new TreeWalk(revWalk.getObjectReader())) {
treeWalk.setRecursive(true); treeWalk.setRecursive(true);
if (!checkoutAllPaths) if (!checkoutAllPaths)
treeWalk.setFilter(PathFilterGroup.createFromStrings(paths)); treeWalk.setFilter(PathFilterGroup.createFromStrings(paths));
try {
if (isCheckoutIndex())
checkoutPathsFromIndex(treeWalk, dc);
else {
RevCommit commit = revWalk.parseCommit(getStartPointObjectId());
checkoutPathsFromCommit(treeWalk, dc, commit);
}
} finally {
treeWalk.release();
if (isCheckoutIndex())
checkoutPathsFromIndex(treeWalk, dc);
else {
RevCommit commit = revWalk.parseCommit(getStartPointObjectId());
checkoutPathsFromCommit(treeWalk, dc, commit);
} }
} finally { } finally {
dc.unlock(); dc.unlock();
revWalk.release();
} }
return this; return this;
} }

Loading…
Cancel
Save