Browse Source

Use AutoClosable to close resources in bundle org.eclipse.jgit

- use try-with-resource where possible
- replace use of deprecated release() by close()

Change-Id: I0f139c3535679087b7fa09649166bca514750b81
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
tags/v4.0.0.201505260635-rc2
Matthias Sohn 9 years ago
parent
commit
0e73d39506
40 changed files with 369 additions and 439 deletions
  1. 1
    4
      org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java
  2. 14
    11
      org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java
  3. 1
    4
      org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java
  4. 1
    4
      org.eclipse.jgit/src/org/eclipse/jgit/api/ListNotesCommand.java
  5. 1
    4
      org.eclipse.jgit/src/org/eclipse/jgit/api/ListTagCommand.java
  6. 6
    4
      org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java
  7. 127
    113
      org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
  8. 4
    8
      org.eclipse.jgit/src/org/eclipse/jgit/api/RemoveNoteCommand.java
  9. 4
    14
      org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java
  10. 6
    7
      org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java
  11. 1
    2
      org.eclipse.jgit/src/org/eclipse/jgit/api/RmCommand.java
  12. 1
    4
      org.eclipse.jgit/src/org/eclipse/jgit/api/ShowNoteCommand.java
  13. 5
    14
      org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java
  14. 7
    10
      org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java
  15. 2
    4
      org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java
  16. 2
    8
      org.eclipse.jgit/src/org/eclipse/jgit/api/TagCommand.java
  17. 3
    3
      org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java
  18. 1
    1
      org.eclipse.jgit/src/org/eclipse/jgit/diff/RenameDetector.java
  19. 3
    12
      org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
  20. 7
    13
      org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java
  21. 1
    1
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java
  22. 3
    3
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java
  23. 4
    9
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackCompactor.java
  24. 1
    4
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsRefDatabase.java
  25. 3
    1
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/LargePackedWholeObject.java
  26. 1
    1
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/PackInputStream.java
  27. 1
    4
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
  28. 1
    3
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectoryRename.java
  29. 1
    1
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaTask.java
  30. 1
    1
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
  31. 100
    96
      org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
  32. 2
    8
      org.eclipse.jgit/src/org/eclipse/jgit/lib/RefUpdate.java
  33. 3
    12
      org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
  34. 9
    8
      org.eclipse.jgit/src/org/eclipse/jgit/merge/RecursiveMerger.java
  35. 4
    1
      org.eclipse.jgit/src/org/eclipse/jgit/notes/LeafBucket.java
  36. 6
    9
      org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java
  37. 2
    2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/PushProcess.java
  38. 24
    24
      org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
  39. 2
    2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java
  40. 3
    5
      org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java

+ 1
- 4
org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java View File

RefNotFoundException, InvalidRefNameException { RefNotFoundException, InvalidRefNameException {
checkCallable(); checkCallable();
processOptions(); processOptions();
RevWalk revWalk = new RevWalk(repo);
try {
try (RevWalk revWalk = new RevWalk(repo)) {
Ref refToCheck = repo.getRef(name); Ref refToCheck = repo.getRef(name);
boolean exists = refToCheck != null boolean exists = refToCheck != null
&& refToCheck.getName().startsWith(Constants.R_HEADS); && refToCheck.getName().startsWith(Constants.R_HEADS);
return result; return result;
} catch (IOException ioe) { } catch (IOException ioe) {
throw new JGitInternalException(ioe.getMessage(), ioe); throw new JGitInternalException(ioe.getMessage(), ioe);
} finally {
revWalk.release();
} }
} }



+ 14
- 11
org.eclipse.jgit/src/org/eclipse/jgit/api/DeleteBranchCommand.java View File

if (!force) { if (!force) {
// check if the branches to be deleted // check if the branches to be deleted
// are all merged into the current branch // are all merged into the current branch
RevWalk walk = new RevWalk(repo);
RevCommit tip = walk.parseCommit(repo.resolve(Constants.HEAD));
for (String branchName : branchNames) {
if (branchName == null)
continue;
Ref currentRef = repo.getRef(branchName);
if (currentRef == null)
continue;
try (RevWalk walk = new RevWalk(repo)) {
RevCommit tip = walk
.parseCommit(repo.resolve(Constants.HEAD));
for (String branchName : branchNames) {
if (branchName == null)
continue;
Ref currentRef = repo.getRef(branchName);
if (currentRef == null)
continue;


RevCommit base = walk.parseCommit(repo.resolve(branchName));
if (!walk.isMergedInto(base, tip)) {
throw new NotMergedException();
RevCommit base = walk
.parseCommit(repo.resolve(branchName));
if (!walk.isMergedInto(base, tip)) {
throw new NotMergedException();
}
} }
} }
} }

+ 1
- 4
org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java View File

if (containsCommitish == null) if (containsCommitish == null)
return refs; return refs;


RevWalk walk = new RevWalk(repo);
try {
try (RevWalk walk = new RevWalk(repo)) {
ObjectId resolved = repo.resolve(containsCommitish); ObjectId resolved = repo.resolve(containsCommitish);
if (resolved == null) if (resolved == null)
throw new RefNotFoundException(MessageFormat.format( throw new RefNotFoundException(MessageFormat.format(
RevCommit containsCommit = walk.parseCommit(resolved); RevCommit containsCommit = walk.parseCommit(resolved);
return RevWalkUtils.findBranchesReachableFrom(containsCommit, walk, return RevWalkUtils.findBranchesReachableFrom(containsCommit, walk,
refs); refs);
} finally {
walk.release();
} }
} }



+ 1
- 4
org.eclipse.jgit/src/org/eclipse/jgit/api/ListNotesCommand.java View File

public List<Note> call() throws GitAPIException { public List<Note> call() throws GitAPIException {
checkCallable(); checkCallable();
List<Note> notes = new ArrayList<Note>(); List<Note> notes = new ArrayList<Note>();
RevWalk walk = new RevWalk(repo);
NoteMap map = NoteMap.newEmptyMap(); NoteMap map = NoteMap.newEmptyMap();
try {
try (RevWalk walk = new RevWalk(repo)) {
Ref ref = repo.getRef(notesRef); Ref ref = repo.getRef(notesRef);
// if we have a notes ref, use it // if we have a notes ref, use it
if (ref != null) { if (ref != null) {
notes.add(i.next()); notes.add(i.next());
} catch (IOException e) { } catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e); throw new JGitInternalException(e.getMessage(), e);
} finally {
walk.release();
} }


return notes; return notes;

+ 1
- 4
org.eclipse.jgit/src/org/eclipse/jgit/api/ListTagCommand.java View File

checkCallable(); checkCallable();
Map<String, Ref> refList; Map<String, Ref> refList;
List<Ref> tags = new ArrayList<Ref>(); List<Ref> tags = new ArrayList<Ref>();
RevWalk revWalk = new RevWalk(repo);
try {
try (RevWalk revWalk = new RevWalk(repo)) {
refList = repo.getRefDatabase().getRefs(Constants.R_TAGS); refList = repo.getRefDatabase().getRefs(Constants.R_TAGS);
for (Ref ref : refList.values()) { for (Ref ref : refList.values()) {
tags.add(ref); tags.add(ref);
} }
} catch (IOException e) { } catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e); throw new JGitInternalException(e.getMessage(), e);
} finally {
revWalk.release();
} }
Collections.sort(tags, new Comparator<Ref>() { Collections.sort(tags, new Comparator<Ref>() {
public int compare(Ref o1, Ref o2) { public int compare(Ref o1, Ref o2) {

+ 6
- 4
org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java View File

mergeStatus = MergeStatus.MERGED_NOT_COMMITTED; mergeStatus = MergeStatus.MERGED_NOT_COMMITTED;
} }
if (commit && !squash) { if (commit && !squash) {
newHeadId = new Git(getRepository()).commit()
.setReflogComment(refLogMessage.toString())
.call().getId();
try (Git git = new Git(getRepository())) {
newHeadId = git.commit()
.setReflogComment(refLogMessage.toString())
.call().getId();
}
mergeStatus = MergeStatus.MERGED; mergeStatus = MergeStatus.MERGED;
} }
if (commit && squash) { if (commit && squash) {
e), e); e), e);
} finally { } finally {
if (revWalk != null) if (revWalk != null)
revWalk.release();
revWalk.close();
} }
} }



+ 127
- 113
org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java View File

.call(); .call();
} catch (StashApplyFailureException e) { } catch (StashApplyFailureException e) {
conflicts = true; conflicts = true;
RevWalk rw = new RevWalk(repo);
ObjectId stashId = repo.resolve(stash);
RevCommit commit = rw.parseCommit(stashId);
updateStashRef(commit, commit.getAuthorIdent(),
commit.getShortMessage());
try (RevWalk rw = new RevWalk(repo)) {
ObjectId stashId = repo.resolve(stash);
RevCommit commit = rw.parseCommit(stashId);
updateStashRef(commit, commit.getAuthorIdent(),
commit.getShortMessage());
}
} }
} }
return conflicts; return conflicts;
// here we should skip this step in order to avoid // here we should skip this step in order to avoid
// confusing pseudo-changed // confusing pseudo-changed
String ourCommitName = getOurCommitName(); String ourCommitName = getOurCommitName();
CherryPickResult cherryPickResult = new Git(repo).cherryPick()
try (Git git = new Git(repo)) {
CherryPickResult cherryPickResult = git.cherryPick()
.include(commitToPick).setOurCommitName(ourCommitName) .include(commitToPick).setOurCommitName(ourCommitName)
.setReflogPrefix(REFLOG_PREFIX).setStrategy(strategy) .setReflogPrefix(REFLOG_PREFIX).setStrategy(strategy)
.call(); .call();
switch (cherryPickResult.getStatus()) {
case FAILED:
if (operation == Operation.BEGIN)
return abort(RebaseResult.failed(cherryPickResult
.getFailingPaths()));
else
switch (cherryPickResult.getStatus()) {
case FAILED:
if (operation == Operation.BEGIN)
return abort(RebaseResult
.failed(cherryPickResult.getFailingPaths()));
else
return stop(commitToPick, Status.STOPPED);
case CONFLICTING:
return stop(commitToPick, Status.STOPPED); return stop(commitToPick, Status.STOPPED);
case CONFLICTING:
return stop(commitToPick, Status.STOPPED);
case OK:
newHead = cherryPickResult.getNewHead();
case OK:
newHead = cherryPickResult.getNewHead();
}
} }
} }
return null; return null;
// Use the cherry-pick strategy if all non-first parents did not // Use the cherry-pick strategy if all non-first parents did not
// change. This is different from C Git, which always uses the merge // change. This is different from C Git, which always uses the merge
// strategy (see below). // strategy (see below).
if (otherParentsUnchanged) {
boolean isMerge = commitToPick.getParentCount() > 1;
String ourCommitName = getOurCommitName();
CherryPickCommand pickCommand = new Git(repo).cherryPick()
.include(commitToPick).setOurCommitName(ourCommitName)
.setReflogPrefix(REFLOG_PREFIX).setStrategy(strategy);
if (isMerge) {
pickCommand.setMainlineParentNumber(1);
// We write a MERGE_HEAD and later commit explicitly
pickCommand.setNoCommit(true);
writeMergeInfo(commitToPick, newParents);
}
CherryPickResult cherryPickResult = pickCommand.call();
switch (cherryPickResult.getStatus()) {
case FAILED:
if (operation == Operation.BEGIN)
return abort(RebaseResult.failed(cherryPickResult
.getFailingPaths()));
else
return stop(commitToPick, Status.STOPPED);
case CONFLICTING:
return stop(commitToPick, Status.STOPPED);
case OK:
try (Git git = new Git(repo)) {
if (otherParentsUnchanged) {
boolean isMerge = commitToPick.getParentCount() > 1;
String ourCommitName = getOurCommitName();
CherryPickCommand pickCommand = git.cherryPick()
.include(commitToPick)
.setOurCommitName(ourCommitName)
.setReflogPrefix(REFLOG_PREFIX)
.setStrategy(strategy);
if (isMerge) { if (isMerge) {
// Commit the merge (setup above using writeMergeInfo())
CommitCommand commit = new Git(repo).commit();
pickCommand.setMainlineParentNumber(1);
// We write a MERGE_HEAD and later commit explicitly
pickCommand.setNoCommit(true);
writeMergeInfo(commitToPick, newParents);
}
CherryPickResult cherryPickResult = pickCommand.call();
switch (cherryPickResult.getStatus()) {
case FAILED:
if (operation == Operation.BEGIN)
return abort(RebaseResult.failed(
cherryPickResult.getFailingPaths()));
else
return stop(commitToPick, Status.STOPPED);
case CONFLICTING:
return stop(commitToPick, Status.STOPPED);
case OK:
if (isMerge) {
// Commit the merge (setup above using
// writeMergeInfo())
CommitCommand commit = git.commit();
commit.setAuthor(commitToPick.getAuthorIdent());
commit.setReflogComment(REFLOG_PREFIX + " " //$NON-NLS-1$
+ commitToPick.getShortMessage());
newHead = commit.call();
} else
newHead = cherryPickResult.getNewHead();
break;
}
} else {
// Use the merge strategy to redo merges, which had some of
// their non-first parents rewritten
MergeCommand merge = git.merge()
.setFastForward(MergeCommand.FastForwardMode.NO_FF)
.setCommit(false);
for (int i = 1; i < commitToPick.getParentCount(); i++)
merge.include(newParents.get(i));
MergeResult mergeResult = merge.call();
if (mergeResult.getMergeStatus().isSuccessful()) {
CommitCommand commit = git.commit();
commit.setAuthor(commitToPick.getAuthorIdent()); commit.setAuthor(commitToPick.getAuthorIdent());
commit.setMessage(commitToPick.getFullMessage());
commit.setReflogComment(REFLOG_PREFIX + " " //$NON-NLS-1$ commit.setReflogComment(REFLOG_PREFIX + " " //$NON-NLS-1$
+ commitToPick.getShortMessage()); + commitToPick.getShortMessage());
newHead = commit.call(); newHead = commit.call();
} else
newHead = cherryPickResult.getNewHead();
break;
}
} else {
// Use the merge strategy to redo merges, which had some of
// their non-first parents rewritten
MergeCommand merge = new Git(repo).merge()
.setFastForward(MergeCommand.FastForwardMode.NO_FF)
.setCommit(false);
for (int i = 1; i < commitToPick.getParentCount(); i++)
merge.include(newParents.get(i));
MergeResult mergeResult = merge.call();
if (mergeResult.getMergeStatus().isSuccessful()) {
CommitCommand commit = new Git(repo).commit();
commit.setAuthor(commitToPick.getAuthorIdent());
commit.setMessage(commitToPick.getFullMessage());
commit.setReflogComment(REFLOG_PREFIX + " " //$NON-NLS-1$
+ commitToPick.getShortMessage());
newHead = commit.call();
} else {
if (operation == Operation.BEGIN
&& mergeResult.getMergeStatus() == MergeResult.MergeStatus.FAILED)
return abort(RebaseResult.failed(mergeResult
.getFailingPaths()));
return stop(commitToPick, Status.STOPPED);
} else {
if (operation == Operation.BEGIN && mergeResult
.getMergeStatus() == MergeResult.MergeStatus.FAILED)
return abort(RebaseResult
.failed(mergeResult.getFailingPaths()));
return stop(commitToPick, Status.STOPPED);
}
} }
} }
} }
String commitMessage = rebaseState String commitMessage = rebaseState
.readFile(MESSAGE_SQUASH); .readFile(MESSAGE_SQUASH);


if (nextStep == null
|| ((nextStep.getAction() != Action.FIXUP) && (nextStep
.getAction() != Action.SQUASH))) {
// this is the last step in this sequence
if (sequenceContainsSquash) {
commitMessage = interactiveHandler
.modifyCommitMessage(commitMessage);
}
retNewHead = new Git(repo).commit()
.setMessage(stripCommentLines(commitMessage))
.setAmend(true).setNoVerify(true).call();
rebaseState.getFile(MESSAGE_SQUASH).delete();
rebaseState.getFile(MESSAGE_FIXUP).delete();
try (Git git = new Git(repo)) {
if (nextStep == null || ((nextStep.getAction() != Action.FIXUP)
&& (nextStep.getAction() != Action.SQUASH))) {
// this is the last step in this sequence
if (sequenceContainsSquash) {
commitMessage = interactiveHandler
.modifyCommitMessage(commitMessage);
}
retNewHead = git.commit()
.setMessage(stripCommentLines(commitMessage))
.setAmend(true).setNoVerify(true).call();
rebaseState.getFile(MESSAGE_SQUASH).delete();
rebaseState.getFile(MESSAGE_FIXUP).delete();


} else {
// Next step is either Squash or Fixup
retNewHead = new Git(repo).commit().setMessage(commitMessage)
.setAmend(true).setNoVerify(true).call();
} else {
// Next step is either Squash or Fixup
retNewHead = git.commit().setMessage(commitMessage)
.setAmend(true).setNoVerify(true).call();
}
} }
return retNewHead; return retNewHead;
} }
} finally { } finally {
dc.unlock(); dc.unlock();
} }
RevWalk rw = new RevWalk(repo);
RevCommit commit = rw.parseCommit(repo.resolve(Constants.HEAD));
rw.release();
return commit;
try (RevWalk rw = new RevWalk(repo)) {
RevCommit commit = rw.parseCommit(repo.resolve(Constants.HEAD));
return commit;
}
} }


/** /**
throw new UnmergedPathsException(); throw new UnmergedPathsException();


// determine whether we need to commit // determine whether we need to commit
TreeWalk treeWalk = new TreeWalk(repo);
treeWalk.reset();
treeWalk.setRecursive(true);
treeWalk.addTree(new DirCacheIterator(dc));
ObjectId id = repo.resolve(Constants.HEAD + "^{tree}"); //$NON-NLS-1$
if (id == null)
throw new NoHeadException(
JGitText.get().cannotRebaseWithoutCurrentHead);
boolean needsCommit;
try (TreeWalk treeWalk = new TreeWalk(repo)) {
treeWalk.reset();
treeWalk.setRecursive(true);
treeWalk.addTree(new DirCacheIterator(dc));
ObjectId id = repo.resolve(Constants.HEAD + "^{tree}"); //$NON-NLS-1$
if (id == null)
throw new NoHeadException(
JGitText.get().cannotRebaseWithoutCurrentHead);


treeWalk.addTree(id);
treeWalk.addTree(id);


treeWalk.setFilter(TreeFilter.ANY_DIFF);

boolean needsCommit = treeWalk.next();
treeWalk.release();
treeWalk.setFilter(TreeFilter.ANY_DIFF);


needsCommit = treeWalk.next();
}
if (needsCommit) { if (needsCommit) {
CommitCommand commit = new Git(repo).commit();
commit.setMessage(rebaseState.readFile(MESSAGE));
commit.setAuthor(parseAuthor());
return commit.call();
try (Git git = new Git(repo)) {
CommitCommand commit = git.commit();
commit.setMessage(rebaseState.readFile(MESSAGE));
commit.setAuthor(parseAuthor());
return commit.call();
}
} }
return null; return null;
} }
rebaseState.createFile(AUTHOR_SCRIPT, authorScript); rebaseState.createFile(AUTHOR_SCRIPT, authorScript);
rebaseState.createFile(MESSAGE, commitToPick.getFullMessage()); rebaseState.createFile(MESSAGE, commitToPick.getFullMessage());
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
DiffFormatter df = new DiffFormatter(bos);
df.setRepository(repo);
df.format(commitToPick.getParent(0), commitToPick);
try (DiffFormatter df = new DiffFormatter(bos)) {
df.setRepository(repo);
df.format(commitToPick.getParent(0), commitToPick);
}
rebaseState.createFile(PATCH, new String(bos.toByteArray(), rebaseState.createFile(PATCH, new String(bos.toByteArray(),
Constants.CHARACTER_ENCODING)); Constants.CHARACTER_ENCODING));
rebaseState.createFile(STOPPED_SHA, rebaseState.createFile(STOPPED_SHA,


private List<RevCommit> calculatePickList(RevCommit headCommit) private List<RevCommit> calculatePickList(RevCommit headCommit)
throws GitAPIException, NoHeadException, IOException { throws GitAPIException, NoHeadException, IOException {
LogCommand cmd = new Git(repo).log().addRange(upstreamCommit,
headCommit);
Iterable<RevCommit> commitsToUse = cmd.call();
Iterable<RevCommit> commitsToUse;
try (Git git = new Git(repo)) {
LogCommand cmd = git.log().addRange(upstreamCommit, headCommit);
commitsToUse = cmd.call();
}
List<RevCommit> cherryPickList = new ArrayList<RevCommit>(); List<RevCommit> cherryPickList = new ArrayList<RevCommit>();
for (RevCommit commit : commitsToUse) { for (RevCommit commit : commitsToUse) {
if (preserveMerges || commit.getParentCount() == 1) if (preserveMerges || commit.getParentCount() == 1)
} }
dco.setFailOnConflict(false); dco.setFailOnConflict(false);
dco.checkout(); dco.checkout();
walk.release();
walk.close();
} finally { } finally {
monitor.endTask(); monitor.endTask();
} }
throw new IOException("Could not rewind to upstream commit"); throw new IOException("Could not rewind to upstream commit");
} }
} finally { } finally {
walk.release();
walk.close();
monitor.endTask(); monitor.endTask();
} }
return true; return true;

+ 4
- 8
org.eclipse.jgit/src/org/eclipse/jgit/api/RemoveNoteCommand.java View File



public Note call() throws GitAPIException { public Note call() throws GitAPIException {
checkCallable(); checkCallable();
RevWalk walk = new RevWalk(repo);
ObjectInserter inserter = repo.newObjectInserter();
NoteMap map = NoteMap.newEmptyMap();
RevCommit notesCommit = null;
try {
try (RevWalk walk = new RevWalk(repo);
ObjectInserter inserter = repo.newObjectInserter()) {
NoteMap map = NoteMap.newEmptyMap();
RevCommit notesCommit = null;
Ref ref = repo.getRef(notesRef); Ref ref = repo.getRef(notesRef);
// if we have a notes ref, use it // if we have a notes ref, use it
if (ref != null) { if (ref != null) {
return map.getNote(id); return map.getNote(id);
} catch (IOException e) { } catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e); throw new JGitInternalException(e.getMessage(), e);
} finally {
inserter.release();
walk.release();
} }
} }



+ 4
- 14
org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java View File

} }


private RevCommit parseCommit(final ObjectId commitId) { private RevCommit parseCommit(final ObjectId commitId) {
RevCommit commit;
RevWalk rw = new RevWalk(repo);
try {
commit = rw.parseCommit(commitId);
try (RevWalk rw = new RevWalk(repo)) {
return rw.parseCommit(commitId);
} catch (IOException e) { } catch (IOException e) {
throw new JGitInternalException(MessageFormat.format( throw new JGitInternalException(MessageFormat.format(
JGitText.get().cannotReadCommit, commitId.toString()), e); JGitText.get().cannotReadCommit, commitId.toString()), e);
} finally {
rw.release();
} }
return commit;
} }


private ObjectId resolveRefToCommitId() { private ObjectId resolveRefToCommitId() {


private void resetIndexForPaths(ObjectId commitTree) { private void resetIndexForPaths(ObjectId commitTree) {
DirCache dc = null; DirCache dc = null;
try {
try (final TreeWalk tw = new TreeWalk(repo)) {
dc = repo.lockDirCache(); dc = repo.lockDirCache();
DirCacheBuilder builder = dc.builder(); DirCacheBuilder builder = dc.builder();


final TreeWalk tw = new TreeWalk(repo);
tw.addTree(new DirCacheBuildIterator(builder)); tw.addTree(new DirCacheBuildIterator(builder));
if (commitTree != null) if (commitTree != null)
tw.addTree(commitTree); tw.addTree(commitTree);


private void resetIndex(ObjectId commitTree) throws IOException { private void resetIndex(ObjectId commitTree) throws IOException {
DirCache dc = repo.lockDirCache(); DirCache dc = repo.lockDirCache();
TreeWalk walk = null;
try {
try (TreeWalk walk = new TreeWalk(repo)) {
DirCacheBuilder builder = dc.builder(); DirCacheBuilder builder = dc.builder();


walk = new TreeWalk(repo);
if (commitTree != null) if (commitTree != null)
walk.addTree(commitTree); walk.addTree(commitTree);
else else
builder.commit(); builder.commit();
} finally { } finally {
dc.unlock(); dc.unlock();
if (walk != null)
walk.release();
} }
} }



+ 6
- 7
org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java View File

RevCommit newHead = null; RevCommit newHead = null;
checkCallable(); checkCallable();


RevWalk revWalk = new RevWalk(repo);
try {
try (RevWalk revWalk = new RevWalk(repo)) {


// get the head commit // get the head commit
Ref headRef = repo.getRef(Constants.HEAD); Ref headRef = repo.getRef(Constants.HEAD);
merger.getResultTreeId()); merger.getResultTreeId());
dco.setFailOnConflict(true); dco.setFailOnConflict(true);
dco.checkout(); dco.checkout();
newHead = new Git(getRepository()).commit()
.setMessage(newMessage)
.setReflogComment("revert: " + shortMessage).call(); //$NON-NLS-1$
try (Git git = new Git(getRepository())) {
newHead = git.commit().setMessage(newMessage)
.setReflogComment("revert: " + shortMessage) //$NON-NLS-1$
.call();
}
revertedRefs.add(src); revertedRefs.add(src);
headCommit = newHead; headCommit = newHead;
} else { } else {
MessageFormat.format( MessageFormat.format(
JGitText.get().exceptionCaughtDuringExecutionOfRevertCommand, JGitText.get().exceptionCaughtDuringExecutionOfRevertCommand,
e), e); e), e);
} finally {
revWalk.release();
} }
return newHead; return newHead;
} }

+ 1
- 2
org.eclipse.jgit/src/org/eclipse/jgit/api/RmCommand.java View File

checkCallable(); checkCallable();
DirCache dc = null; DirCache dc = null;


try {
try (final TreeWalk tw = new TreeWalk(repo)) {
dc = repo.lockDirCache(); dc = repo.lockDirCache();
DirCacheBuilder builder = dc.builder(); DirCacheBuilder builder = dc.builder();
final TreeWalk tw = new TreeWalk(repo);
tw.reset(); // drop the first empty tree, which we do not need here tw.reset(); // drop the first empty tree, which we do not need here
tw.setRecursive(true); tw.setRecursive(true);
tw.setFilter(PathFilterGroup.createFromStrings(filepatterns)); tw.setFilter(PathFilterGroup.createFromStrings(filepatterns));

+ 1
- 4
org.eclipse.jgit/src/org/eclipse/jgit/api/ShowNoteCommand.java View File



public Note call() throws GitAPIException { public Note call() throws GitAPIException {
checkCallable(); checkCallable();
RevWalk walk = new RevWalk(repo);
NoteMap map = NoteMap.newEmptyMap(); NoteMap map = NoteMap.newEmptyMap();
RevCommit notesCommit = null; RevCommit notesCommit = null;
try {
try (RevWalk walk = new RevWalk(repo)) {
Ref ref = repo.getRef(notesRef); Ref ref = repo.getRef(notesRef);
// if we have a notes ref, use it // if we have a notes ref, use it
if (ref != null) { if (ref != null) {
return map.getNote(id); return map.getNote(id);
} catch (IOException e) { } catch (IOException e) {
throw new JGitInternalException(e.getMessage(), e); throw new JGitInternalException(e.getMessage(), e);
} finally {
walk.release();
} }
} }



+ 5
- 14
org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java View File

JGitText.get().stashApplyOnUnsafeRepository, JGitText.get().stashApplyOnUnsafeRepository,
repo.getRepositoryState())); repo.getRepositoryState()));


ObjectReader reader = repo.newObjectReader();
try {
RevWalk revWalk = new RevWalk(reader);
try (ObjectReader reader = repo.newObjectReader();
RevWalk revWalk = new RevWalk(reader)) {


ObjectId headCommit = repo.resolve(Constants.HEAD); ObjectId headCommit = repo.resolve(Constants.HEAD);
if (headCommit == null) if (headCommit == null)
throw e; throw e;
} catch (IOException e) { } catch (IOException e) {
throw new JGitInternalException(JGitText.get().stashApplyFailed, e); throw new JGitInternalException(JGitText.get().stashApplyFailed, e);
} finally {
reader.release();
} }
} }




private void resetIndex(RevTree tree) throws IOException { private void resetIndex(RevTree tree) throws IOException {
DirCache dc = repo.lockDirCache(); DirCache dc = repo.lockDirCache();
TreeWalk walk = null;
try {
try (TreeWalk walk = new TreeWalk(repo)) {
DirCacheBuilder builder = dc.builder(); DirCacheBuilder builder = dc.builder();


walk = new TreeWalk(repo);
walk.addTree(tree); walk.addTree(tree);
walk.addTree(new DirCacheIterator(dc)); walk.addTree(new DirCacheIterator(dc));
walk.setRecursive(true); walk.setRecursive(true);
builder.commit(); builder.commit();
} finally { } finally {
dc.unlock(); dc.unlock();
if (walk != null)
walk.release();
} }
} }


private void resetUntracked(RevTree tree) throws CheckoutConflictException, private void resetUntracked(RevTree tree) throws CheckoutConflictException,
IOException { IOException {
TreeWalk walk = new TreeWalk(repo); // maybe NameConflictTreeWalk;
try {
// TODO maybe NameConflictTreeWalk ?
try (TreeWalk walk = new TreeWalk(repo)) {
walk.addTree(tree); walk.addTree(tree);
walk.addTree(new FileTreeIterator(repo)); walk.addTree(new FileTreeIterator(repo));
walk.setRecursive(true); walk.setRecursive(true);


checkoutPath(entry, reader); checkoutPath(entry, reader);
} }
} finally {
walk.release();
} }
} }



+ 7
- 10
org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java View File



private RevCommit parseCommit(final ObjectReader reader, private RevCommit parseCommit(final ObjectReader reader,
final ObjectId headId) throws IOException { final ObjectId headId) throws IOException {
final RevWalk walk = new RevWalk(reader);
return walk.parseCommit(headId);
try (final RevWalk walk = new RevWalk(reader)) {
return walk.parseCommit(headId);
}
} }


private CommitBuilder createBuilder() { private CommitBuilder createBuilder() {
checkCallable(); checkCallable();


Ref head = getHead(); Ref head = getHead();
ObjectReader reader = repo.newObjectReader();
try {
try (ObjectReader reader = repo.newObjectReader()) {
RevCommit headCommit = parseCommit(reader, head.getObjectId()); RevCommit headCommit = parseCommit(reader, head.getObjectId());
DirCache cache = repo.lockDirCache(); DirCache cache = repo.lockDirCache();
ObjectInserter inserter = repo.newObjectInserter();
ObjectId commitId; ObjectId commitId;
try {
TreeWalk treeWalk = new TreeWalk(reader);
try (ObjectInserter inserter = repo.newObjectInserter();
TreeWalk treeWalk = new TreeWalk(reader)) {

treeWalk.setRecursive(true); treeWalk.setRecursive(true);
treeWalk.addTree(headCommit.getTree()); treeWalk.addTree(headCommit.getTree());
treeWalk.addTree(new DirCacheIterator(cache)); treeWalk.addTree(new DirCacheIterator(cache));
} }


} finally { } finally {
inserter.release();
cache.unlock(); cache.unlock();
} }


return parseCommit(reader, commitId); return parseCommit(reader, commitId);
} catch (IOException e) { } catch (IOException e) {
throw new JGitInternalException(JGitText.get().stashFailed, e); throw new JGitInternalException(JGitText.get().stashFailed, e);
} finally {
reader.release();
} }
} }
} }

+ 2
- 4
org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java View File

RefNotFoundException, GitAPIException { RefNotFoundException, GitAPIException {
checkCallable(); checkCallable();


try {
SubmoduleWalk generator = SubmoduleWalk.forIndex(repo);
try (SubmoduleWalk generator = SubmoduleWalk.forIndex(repo)) {
if (!paths.isEmpty()) if (!paths.isEmpty())
generator.setFilter(PathFilterGroup.createFromStrings(paths)); generator.setFilter(PathFilterGroup.createFromStrings(paths));
List<String> updated = new ArrayList<String>(); List<String> updated = new ArrayList<String>();
submoduleRepo = clone.call().getRepository(); submoduleRepo = clone.call().getRepository();
} }


try {
RevWalk walk = new RevWalk(submoduleRepo);
try (RevWalk walk = new RevWalk(submoduleRepo)) {
RevCommit commit = walk RevCommit commit = walk
.parseCommit(generator.getObjectId()); .parseCommit(generator.getObjectId());



+ 2
- 8
org.eclipse.jgit/src/org/eclipse/jgit/api/TagCommand.java View File

RepositoryState state = repo.getRepositoryState(); RepositoryState state = repo.getRepositoryState();
processOptions(state); processOptions(state);


RevWalk revWalk = new RevWalk(repo);
try {
try (RevWalk revWalk = new RevWalk(repo)) {
// if no id is set, we should attempt to use HEAD // if no id is set, we should attempt to use HEAD
if (id == null) { if (id == null) {
ObjectId objectId = repo.resolve(Constants.HEAD + "^{commit}"); //$NON-NLS-1$ ObjectId objectId = repo.resolve(Constants.HEAD + "^{commit}"); //$NON-NLS-1$
newTag.setObjectId(id); newTag.setObjectId(id);


// write the tag object // write the tag object
ObjectInserter inserter = repo.newObjectInserter();
try {
try (ObjectInserter inserter = repo.newObjectInserter()) {
ObjectId tagId = inserter.insert(newTag); ObjectId tagId = inserter.insert(newTag);
inserter.flush(); inserter.flush();


String tag = newTag.getTag(); String tag = newTag.getTag();
return updateTagRef(tagId, revWalk, tag, newTag.toString()); return updateTagRef(tagId, revWalk, tag, newTag.toString());


} finally {
inserter.release();
} }


} catch (IOException e) { } catch (IOException e) {
throw new JGitInternalException( throw new JGitInternalException(
JGitText.get().exceptionCaughtDuringExecutionOfTagCommand, JGitText.get().exceptionCaughtDuringExecutionOfTagCommand,
e); e);
} finally {
revWalk.release();
} }
} }



+ 3
- 3
org.eclipse.jgit/src/org/eclipse/jgit/blame/BlameGenerator.java View File

throw new IllegalStateException(); throw new IllegalStateException();


if (revPool != null) if (revPool != null)
revPool.release();
revPool.close();


if (reverse) if (reverse)
revPool = new ReverseWalk(getRepository()); revPool = new ReverseWalk(getRepository());
r.computeAll(); r.computeAll();
return r; return r;
} finally { } finally {
release();
close();
} }
} }


} }


private boolean done() { private boolean done() {
release();
close();
return false; return false;
} }



+ 1
- 1
org.eclipse.jgit/src/org/eclipse/jgit/diff/RenameDetector.java View File

try { try {
return compute(objectReader, pm); return compute(objectReader, pm);
} finally { } finally {
objectReader.release();
objectReader.close();
} }
} }
return Collections.unmodifiableList(entries); return Collections.unmodifiableList(entries);

+ 3
- 12
org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java View File

MissingObjectException, IncorrectObjectTypeException, MissingObjectException, IncorrectObjectTypeException,
CheckoutConflictException, IndexWriteException { CheckoutConflictException, IndexWriteException {
toBeDeleted.clear(); toBeDeleted.clear();
ObjectReader objectReader = repo.getObjectDatabase().newReader();
try {
try (ObjectReader objectReader = repo.getObjectDatabase().newReader()) {
if (headCommitTree != null) if (headCommitTree != null)
preScanTwoTrees(); preScanTwoTrees();
else else
// commit the index builder - a new index is persisted // commit the index builder - a new index is persisted
if (!builder.commit()) if (!builder.commit())
throw new IndexWriteException(); throw new IndexWriteException();
} finally {
objectReader.release();
} }
return toBeDeleted.size() == 0; return toBeDeleted.size() == 0;
} }
*/ */
private boolean isModifiedSubtree_IndexWorkingtree(String path) private boolean isModifiedSubtree_IndexWorkingtree(String path)
throws CorruptObjectException, IOException { throws CorruptObjectException, IOException {
NameConflictTreeWalk tw = new NameConflictTreeWalk(repo);
try {
try (NameConflictTreeWalk tw = new NameConflictTreeWalk(repo)) {
tw.addTree(new DirCacheIterator(dc)); tw.addTree(new DirCacheIterator(dc));
tw.addTree(new FileTreeIterator(repo)); tw.addTree(new FileTreeIterator(repo));
tw.setRecursive(true); tw.setRecursive(true);
} }
} }
return false; return false;
} finally {
tw.release();
} }
} }


*/ */
private boolean isModifiedSubtree_IndexTree(String path, ObjectId tree) private boolean isModifiedSubtree_IndexTree(String path, ObjectId tree)
throws CorruptObjectException, IOException { throws CorruptObjectException, IOException {
NameConflictTreeWalk tw = new NameConflictTreeWalk(repo);
try {
try (NameConflictTreeWalk tw = new NameConflictTreeWalk(repo)) {
tw.addTree(new DirCacheIterator(dc)); tw.addTree(new DirCacheIterator(dc));
tw.addTree(tree); tw.addTree(tree);
tw.setRecursive(true); tw.setRecursive(true);
return true; return true;
} }
return false; return false;
} finally {
tw.release();
} }
} }



+ 7
- 13
org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java View File

*/ */
protected byte[] readFileFromRepo(Repository repo, protected byte[] readFileFromRepo(Repository repo,
String ref, String path) throws GitAPIException, IOException { String ref, String path) throws GitAPIException, IOException {
ObjectReader reader = repo.newObjectReader();
byte[] result;
try {
try (ObjectReader reader = repo.newObjectReader()) {
ObjectId oid = repo.resolve(ref + ":" + path); //$NON-NLS-1$ ObjectId oid = repo.resolve(ref + ":" + path); //$NON-NLS-1$
result = reader.open(oid).getBytes(Integer.MAX_VALUE);
} finally {
reader.release();
return reader.open(oid).getBytes(Integer.MAX_VALUE);
} }
return result;
} }
} }


DirCache index = DirCache.newInCore(); DirCache index = DirCache.newInCore();
DirCacheBuilder builder = index.builder(); DirCacheBuilder builder = index.builder();
ObjectInserter inserter = repo.newObjectInserter(); ObjectInserter inserter = repo.newObjectInserter();
RevWalk rw = new RevWalk(repo);
try {
try (RevWalk rw = new RevWalk(repo)) {
Config cfg = new Config(); Config cfg = new Config();
for (Project proj : bareProjects) { for (Project proj : bareProjects) {
String name = proj.path; String name = proj.path;
return rw.parseCommit(commitId); return rw.parseCommit(commitId);
} catch (IOException e) { } catch (IOException e) {
throw new ManifestErrorException(e); throw new ManifestErrorException(e);
} finally {
rw.release();
} }
} else { } else {
return git return git
try { try {
Repository subRepo = add.call(); Repository subRepo = add.call();
if (revision != null) { if (revision != null) {
Git sub = new Git(subRepo);
sub.checkout().setName(findRef(revision, subRepo)).call();
try (Git sub = new Git(subRepo)) {
sub.checkout().setName(findRef(revision, subRepo))
.call();
}
subRepo.close(); subRepo.close();
git.add().addFilepattern(name).call(); git.add().addFilepattern(name).call();
} }

+ 1
- 1
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java View File

objdb.rollbackPack(newPackDesc); objdb.rollbackPack(newPackDesc);
} }
} finally { } finally {
ctx.release();
ctx.close();
} }
} }



+ 3
- 3
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java View File



@Override @Override
public void release() { public void release() {
ctx.release();
ctx.close();
} }
} }


// The newly created pack is registered in the cache. // The newly created pack is registered in the cache.
return ctx.open(id, type).openStream(); return ctx.open(id, type).openStream();
} finally { } finally {
ctx.release();
ctx.close();
} }
} }


new ReadBackStream(pos), inf, bufsz), bufsz)) { new ReadBackStream(pos), inf, bufsz), bufsz)) {
@Override @Override
public void close() throws IOException { public void close() throws IOException {
ctx.release();
ctx.close();
super.close(); super.close();
} }
}; };

+ 4
- 9
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackCompactor.java View File

*/ */
public DfsPackCompactor exclude(DfsPackFile pack) throws IOException { public DfsPackCompactor exclude(DfsPackFile pack) throws IOException {
final PackIndex idx; final PackIndex idx;
DfsReader ctx = (DfsReader) repo.newObjectReader();
try {
try (DfsReader ctx = (DfsReader) repo.newObjectReader()) {
idx = pack.getPackIndex(ctx); idx = pack.getPackIndex(ctx);
} finally {
ctx.release();
} }
return exclude(new PackWriter.ObjectIdSet() { return exclude(new PackWriter.ObjectIdSet() {
public boolean contains(AnyObjectId id) { public boolean contains(AnyObjectId id) {
pm = NullProgressMonitor.INSTANCE; pm = NullProgressMonitor.INSTANCE;


DfsObjDatabase objdb = repo.getObjectDatabase(); DfsObjDatabase objdb = repo.getObjectDatabase();
DfsReader ctx = (DfsReader) objdb.newReader();
try {
try (DfsReader ctx = (DfsReader) objdb.newReader()) {
PackConfig pc = new PackConfig(repo); PackConfig pc = new PackConfig(repo);
pc.setIndexVersion(2); pc.setIndexVersion(2);
pc.setDeltaCompress(false); pc.setDeltaCompress(false);
writeIndex(objdb, pack, pw); writeIndex(objdb, pack, pw);


PackWriter.Statistics stats = pw.getStatistics(); PackWriter.Statistics stats = pw.getStatistics();
pw.release();
pw.close();
pw = null; pw = null;


pack.setPackStats(stats); pack.setPackStats(stats);
} }
} finally { } finally {
if (pw != null) if (pw != null)
pw.release();
pw.close();
} }
} finally { } finally {
rw = null; rw = null;
ctx.release();
} }
} }



+ 1
- 4
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsRefDatabase.java View File



private Ref doPeel(final Ref leaf) throws MissingObjectException, private Ref doPeel(final Ref leaf) throws MissingObjectException,
IOException { IOException {
RevWalk rw = new RevWalk(repository);
try {
try (RevWalk rw = new RevWalk(repository)) {
RevObject obj = rw.parseAny(leaf.getObjectId()); RevObject obj = rw.parseAny(leaf.getObjectId());
if (obj instanceof RevTag) { if (obj instanceof RevTag) {
return new ObjectIdRef.PeeledTag( return new ObjectIdRef.PeeledTag(
leaf.getName(), leaf.getName(),
leaf.getObjectId()); leaf.getObjectId());
} }
} finally {
rw.release();
} }
} }



+ 3
- 1
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/LargePackedWholeObject.java View File

ObjectId obj = pack.getReverseIdx(ctx).findObject(objectOffset); ObjectId obj = pack.getReverseIdx(ctx).findObject(objectOffset);
return ctx.open(obj, type).openStream(); return ctx.open(obj, type).openStream();
} finally { } finally {
ctx.release();
ctx.close();
} }
} finally {
ctx.close();
} }


// Align buffer to inflater size, at a larger than default block. // Align buffer to inflater size, at a larger than default block.

+ 1
- 1
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/PackInputStream.java View File



@Override @Override
public void close() { public void close() {
ctx.release();
ctx.close();
} }
} }

+ 1
- 4
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java View File



private ObjectIdRef doPeel(final Ref leaf) throws MissingObjectException, private ObjectIdRef doPeel(final Ref leaf) throws MissingObjectException,
IOException { IOException {
RevWalk rw = new RevWalk(getRepository());
try {
try (RevWalk rw = new RevWalk(getRepository())) {
RevObject obj = rw.parseAny(leaf.getObjectId()); RevObject obj = rw.parseAny(leaf.getObjectId());
if (obj instanceof RevTag) { if (obj instanceof RevTag) {
return new ObjectIdRef.PeeledTag(leaf.getStorage(), leaf return new ObjectIdRef.PeeledTag(leaf.getStorage(), leaf
return new ObjectIdRef.PeeledNonTag(leaf.getStorage(), leaf return new ObjectIdRef.PeeledNonTag(leaf.getStorage(), leaf
.getName(), leaf.getObjectId()); .getName(), leaf.getObjectId());
} }
} finally {
rw.release();
} }
} }



+ 1
- 3
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectoryRename.java View File

objId = source.getOldObjectId(); objId = source.getOldObjectId();
updateHEAD = needToUpdateHEAD(); updateHEAD = needToUpdateHEAD();
tmp = refdb.newTemporaryUpdate(); tmp = refdb.newTemporaryUpdate();
final RevWalk rw = new RevWalk(refdb.getRepository());
try {
try (final RevWalk rw = new RevWalk(refdb.getRepository())) {
// First backup the source so its never unreachable. // First backup the source so its never unreachable.
tmp.setNewObjectId(objId); tmp.setNewObjectId(objId);
tmp.setForceUpdate(true); tmp.setForceUpdate(true);
} catch (IOException err) { } catch (IOException err) {
FileUtils.delete(refdb.fileFor(tmp.getName())); FileUtils.delete(refdb.fileFor(tmp.getName()));
} }
rw.release();
} }
} }



+ 1
- 1
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaTask.java View File

runWindow(w); runWindow(w);
} finally { } finally {
block.pm.endWorker(); block.pm.endWorker();
or.release();
or.close();
or = null; or = null;
} }
return null; return null;

+ 1
- 1
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java View File

} }


stats.totalBytes = out.length(); stats.totalBytes = out.length();
reader.release();
reader.close();
endPhase(writeMonitor); endPhase(writeMonitor);
} }



+ 100
- 96
org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java View File

throws IOException { throws IOException {
dirCache = repository.readDirCache(); dirCache = repository.readDirCache();


TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.setRecursive(true);
// add the trees (tree, dirchache, workdir)
if (tree != null)
treeWalk.addTree(tree);
else
treeWalk.addTree(new EmptyTreeIterator());
treeWalk.addTree(new DirCacheIterator(dirCache));
treeWalk.addTree(initialWorkingTreeIterator);
Collection<TreeFilter> filters = new ArrayList<TreeFilter>(4);
if (monitor != null) {
// Get the maximum size of the work tree and index
// and add some (quite arbitrary)
if (estIndexSize == 0)
estIndexSize = dirCache.getEntryCount();
int total = Math.max(estIndexSize * 10 / 9,
estWorkTreeSize * 10 / 9);
monitor.beginTask(title, total);
filters.add(new ProgressReportingFilter(monitor, total));
}
try (TreeWalk treeWalk = new TreeWalk(repository)) {
treeWalk.setRecursive(true);
// add the trees (tree, dirchache, workdir)
if (tree != null)
treeWalk.addTree(tree);
else
treeWalk.addTree(new EmptyTreeIterator());
treeWalk.addTree(new DirCacheIterator(dirCache));
treeWalk.addTree(initialWorkingTreeIterator);
Collection<TreeFilter> filters = new ArrayList<TreeFilter>(4);
if (monitor != null) {
// Get the maximum size of the work tree and index
// and add some (quite arbitrary)
if (estIndexSize == 0)
estIndexSize = dirCache.getEntryCount();
int total = Math.max(estIndexSize * 10 / 9,
estWorkTreeSize * 10 / 9);
monitor.beginTask(title, total);
filters.add(new ProgressReportingFilter(monitor, total));
}


if (filter != null)
filters.add(filter);
filters.add(new SkipWorkTreeFilter(INDEX));
indexDiffFilter = new IndexDiffFilter(INDEX, WORKDIR);
filters.add(indexDiffFilter);
treeWalk.setFilter(AndTreeFilter.create(filters));
fileModes.clear();
while (treeWalk.next()) {
AbstractTreeIterator treeIterator = treeWalk.getTree(TREE,
AbstractTreeIterator.class);
DirCacheIterator dirCacheIterator = treeWalk.getTree(INDEX,
DirCacheIterator.class);
WorkingTreeIterator workingTreeIterator = treeWalk.getTree(WORKDIR,
WorkingTreeIterator.class);

if (dirCacheIterator != null) {
final DirCacheEntry dirCacheEntry = dirCacheIterator
.getDirCacheEntry();
if (dirCacheEntry != null) {
int stage = dirCacheEntry.getStage();
if (stage > 0) {
String path = treeWalk.getPathString();
addConflict(path, stage);
continue;
if (filter != null)
filters.add(filter);
filters.add(new SkipWorkTreeFilter(INDEX));
indexDiffFilter = new IndexDiffFilter(INDEX, WORKDIR);
filters.add(indexDiffFilter);
treeWalk.setFilter(AndTreeFilter.create(filters));
fileModes.clear();
while (treeWalk.next()) {
AbstractTreeIterator treeIterator = treeWalk.getTree(TREE,
AbstractTreeIterator.class);
DirCacheIterator dirCacheIterator = treeWalk.getTree(INDEX,
DirCacheIterator.class);
WorkingTreeIterator workingTreeIterator = treeWalk
.getTree(WORKDIR, WorkingTreeIterator.class);

if (dirCacheIterator != null) {
final DirCacheEntry dirCacheEntry = dirCacheIterator
.getDirCacheEntry();
if (dirCacheEntry != null) {
int stage = dirCacheEntry.getStage();
if (stage > 0) {
String path = treeWalk.getPathString();
addConflict(path, stage);
continue;
}
} }
} }
}


if (treeIterator != null) {
if (dirCacheIterator != null) {
if (!treeIterator.idEqual(dirCacheIterator)
|| treeIterator.getEntryRawMode()
!= dirCacheIterator.getEntryRawMode()) {
// in repo, in index, content diff => changed
if (treeIterator != null) {
if (dirCacheIterator != null) {
if (!treeIterator.idEqual(dirCacheIterator)
|| treeIterator
.getEntryRawMode() != dirCacheIterator
.getEntryRawMode()) {
// in repo, in index, content diff => changed
if (!isEntryGitLink(treeIterator)
|| !isEntryGitLink(dirCacheIterator)
|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
changed.add(treeWalk.getPathString());
}
} else {
// in repo, not in index => removed
if (!isEntryGitLink(treeIterator) if (!isEntryGitLink(treeIterator)
|| !isEntryGitLink(dirCacheIterator)
|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL) || ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
changed.add(treeWalk.getPathString());
removed.add(treeWalk.getPathString());
if (workingTreeIterator != null)
untracked.add(treeWalk.getPathString());
} }
} else { } else {
// in repo, not in index => removed
if (!isEntryGitLink(treeIterator)
|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
removed.add(treeWalk.getPathString());
if (workingTreeIterator != null)
untracked.add(treeWalk.getPathString());
}
} else {
if (dirCacheIterator != null) {
// not in repo, in index => added
if (!isEntryGitLink(dirCacheIterator)
|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
added.add(treeWalk.getPathString());
} else {
// not in repo, not in index => untracked
if (workingTreeIterator != null
&& !workingTreeIterator.isEntryIgnored()) {
untracked.add(treeWalk.getPathString());
if (dirCacheIterator != null) {
// not in repo, in index => added
if (!isEntryGitLink(dirCacheIterator)
|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
added.add(treeWalk.getPathString());
} else {
// not in repo, not in index => untracked
if (workingTreeIterator != null
&& !workingTreeIterator.isEntryIgnored()) {
untracked.add(treeWalk.getPathString());
}
} }
} }
}


if (dirCacheIterator != null) {
if (workingTreeIterator == null) {
// in index, not in workdir => missing
if (!isEntryGitLink(dirCacheIterator)
|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
missing.add(treeWalk.getPathString());
} else {
if (workingTreeIterator.isModified(
dirCacheIterator.getDirCacheEntry(), true,
treeWalk.getObjectReader())) {
// in index, in workdir, content differs => modified
if (!isEntryGitLink(dirCacheIterator) || !isEntryGitLink(workingTreeIterator)
|| (ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL && ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY))
modified.add(treeWalk.getPathString());
if (dirCacheIterator != null) {
if (workingTreeIterator == null) {
// in index, not in workdir => missing
if (!isEntryGitLink(dirCacheIterator)
|| ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL)
missing.add(treeWalk.getPathString());
} else {
if (workingTreeIterator.isModified(
dirCacheIterator.getDirCacheEntry(), true,
treeWalk.getObjectReader())) {
// in index, in workdir, content differs => modified
if (!isEntryGitLink(dirCacheIterator)
|| !isEntryGitLink(workingTreeIterator)
|| (ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL
&& ignoreSubmoduleMode != IgnoreSubmoduleMode.DIRTY))
modified.add(treeWalk.getPathString());
}
} }
} }
}


for (int i = 0; i < treeWalk.getTreeCount(); i++) {
Set<String> values = fileModes.get(treeWalk.getFileMode(i));
String path = treeWalk.getPathString();
if (path != null) {
if (values == null)
values = new HashSet<String>();
values.add(path);
fileModes.put(treeWalk.getFileMode(i), values);
for (int i = 0; i < treeWalk.getTreeCount(); i++) {
Set<String> values = fileModes.get(treeWalk.getFileMode(i));
String path = treeWalk.getPathString();
if (path != null) {
if (values == null)
values = new HashSet<String>();
values.add(path);
fileModes.put(treeWalk.getFileMode(i), values);
}
} }
} }
} }

+ 2
- 8
org.eclipse.jgit/src/org/eclipse/jgit/lib/RefUpdate.java View File

* an unexpected IO error occurred while writing changes. * an unexpected IO error occurred while writing changes.
*/ */
public Result update() throws IOException { public Result update() throws IOException {
RevWalk rw = new RevWalk(getRepository());
try {
try (RevWalk rw = new RevWalk(getRepository())) {
return update(rw); return update(rw);
} finally {
rw.release();
} }
} }


* @throws IOException * @throws IOException
*/ */
public Result delete() throws IOException { public Result delete() throws IOException {
RevWalk rw = new RevWalk(getRepository());
try {
try (RevWalk rw = new RevWalk(getRepository())) {
return delete(rw); return delete(rw);
} finally {
rw.release();
} }
} }



+ 3
- 12
org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java View File

public ObjectId resolve(final String revstr) public ObjectId resolve(final String revstr)
throws AmbiguousObjectException, IncorrectObjectTypeException, throws AmbiguousObjectException, IncorrectObjectTypeException,
RevisionSyntaxException, IOException { RevisionSyntaxException, IOException {
RevWalk rw = new RevWalk(this);
try {
try (RevWalk rw = new RevWalk(this)) {
Object resolved = resolve(rw, revstr); Object resolved = resolve(rw, revstr);
if (resolved instanceof String) { if (resolved instanceof String) {
final Ref ref = getRef((String)resolved); final Ref ref = getRef((String)resolved);
} else { } else {
return (ObjectId) resolved; return (ObjectId) resolved;
} }
} finally {
rw.release();
} }
} }


*/ */
public String simplify(final String revstr) public String simplify(final String revstr)
throws AmbiguousObjectException, IOException { throws AmbiguousObjectException, IOException {
RevWalk rw = new RevWalk(this);
try {
try (RevWalk rw = new RevWalk(this)) {
Object resolved = resolve(rw, revstr); Object resolved = resolve(rw, revstr);
if (resolved != null) if (resolved != null)
if (resolved instanceof String) if (resolved instanceof String)
else else
return ((AnyObjectId) resolved).getName(); return ((AnyObjectId) resolved).getName();
return null; return null;
} finally {
rw.release();
} }
} }


private ObjectId resolveAbbreviation(final String revstr) throws IOException, private ObjectId resolveAbbreviation(final String revstr) throws IOException,
AmbiguousObjectException { AmbiguousObjectException {
AbbreviatedObjectId id = AbbreviatedObjectId.fromString(revstr); AbbreviatedObjectId id = AbbreviatedObjectId.fromString(revstr);
ObjectReader reader = newObjectReader();
try {
try (ObjectReader reader = newObjectReader()) {
Collection<ObjectId> matches = reader.resolve(id); Collection<ObjectId> matches = reader.resolve(id);
if (matches.size() == 0) if (matches.size() == 0)
return null; return null;
return matches.iterator().next(); return matches.iterator().next();
else else
throw new AmbiguousObjectException(id, matches); throw new AmbiguousObjectException(id, matches);
} finally {
reader.release();
} }
} }



+ 9
- 8
org.eclipse.jgit/src/org/eclipse/jgit/merge/RecursiveMerger.java View File

private DirCache dircacheFromTree(ObjectId treeId) throws IOException { private DirCache dircacheFromTree(ObjectId treeId) throws IOException {
DirCache ret = DirCache.newInCore(); DirCache ret = DirCache.newInCore();
DirCacheBuilder aBuilder = ret.builder(); DirCacheBuilder aBuilder = ret.builder();
TreeWalk atw = new TreeWalk(reader);
atw.addTree(treeId);
atw.setRecursive(true);
while (atw.next()) {
DirCacheEntry e = new DirCacheEntry(atw.getRawPath());
e.setFileMode(atw.getFileMode(0));
e.setObjectId(atw.getObjectId(0));
aBuilder.add(e);
try (TreeWalk atw = new TreeWalk(reader)) {
atw.addTree(treeId);
atw.setRecursive(true);
while (atw.next()) {
DirCacheEntry e = new DirCacheEntry(atw.getRawPath());
e.setFileMode(atw.getFileMode(0));
e.setObjectId(atw.getObjectId(0));
aBuilder.add(e);
}
} }
aBuilder.finish(); aBuilder.finish();
return ret; return ret;

+ 4
- 1
org.eclipse.jgit/src/org/eclipse/jgit/notes/LeafBucket.java View File

import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.ObjectInserter.Formatter;
import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.TreeFormatter; import org.eclipse.jgit.lib.TreeFormatter;




@Override @Override
ObjectId getTreeId() { ObjectId getTreeId() {
return new ObjectInserter.Formatter().idFor(build());
try (Formatter f = new ObjectInserter.Formatter()) {
return f.idFor(build());
}
} }


private TreeFormatter build() { private TreeFormatter build() {

+ 6
- 9
org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java View File

DirCache index = repository.readDirCache(); DirCache index = repository.readDirCache();
generator.setTree(new DirCacheIterator(index)); generator.setTree(new DirCacheIterator(index));
} catch (IOException e) { } catch (IOException e) {
generator.release();
generator.close();
throw e; throw e;
} }
return generator; return generator;
if (filter.isDone(generator.walk)) if (filter.isDone(generator.walk))
return generator; return generator;
} catch (IOException e) { } catch (IOException e) {
generator.release();
generator.close();
throw e; throw e;
} }
generator.release();
generator.close();
return null; return null;
} }


if (filter.isDone(generator.walk)) if (filter.isDone(generator.walk))
return generator; return generator;
} catch (IOException e) { } catch (IOException e) {
generator.release();
generator.close();
throw e; throw e;
} }
generator.release();
generator.close();
return null; return null;
} }


config.load(); config.load();
modulesConfig = config; modulesConfig = config;
} else { } else {
TreeWalk configWalk = new TreeWalk(repository);
try {
try (TreeWalk configWalk = new TreeWalk(repository)) {
configWalk.addTree(rootTree); configWalk.addTree(rootTree);


// The root tree may be part of the submodule walk, so we need to revert // The root tree may be part of the submodule walk, so we need to revert
if (idx > 0) if (idx > 0)
rootTree.next(idx); rootTree.next(idx);
} }
} finally {
configWalk.release();
} }
} }
return this; return this;

+ 2
- 2
org.eclipse.jgit/src/org/eclipse/jgit/transport/PushProcess.java View File



/** /**
* Create process for specified transport and refs updates specification. * Create process for specified transport and refs updates specification.
*
*
* @param transport * @param transport
* transport between remote and local repository, used to create * transport between remote and local repository, used to create
* connection. * connection.
} }
return res; return res;
} finally { } finally {
walker.release();
walker.close();
} }
} }



+ 24
- 24
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java View File

service(); service();
} finally { } finally {
msgOut = NullOutputStream.INSTANCE; msgOut = NullOutputStream.INSTANCE;
walk.release();
walk.close();
if (timer != null) { if (timer != null) {
try { try {
timer.terminate(); timer.terminate();
} }


private void processShallow() throws IOException { private void processShallow() throws IOException {
DepthWalk.RevWalk depthWalk =
new DepthWalk.RevWalk(walk.getObjectReader(), depth);
try (DepthWalk.RevWalk depthWalk = new DepthWalk.RevWalk(
walk.getObjectReader(), depth)) {


// Find all the commits which will be shallow
for (ObjectId o : wantIds) {
try {
depthWalk.markRoot(depthWalk.parseCommit(o));
} catch (IncorrectObjectTypeException notCommit) {
// Ignore non-commits in this loop.
// Find all the commits which will be shallow
for (ObjectId o : wantIds) {
try {
depthWalk.markRoot(depthWalk.parseCommit(o));
} catch (IncorrectObjectTypeException notCommit) {
// Ignore non-commits in this loop.
}
} }
}


RevCommit o;
while ((o = depthWalk.next()) != null) {
DepthWalk.Commit c = (DepthWalk.Commit) o;
RevCommit o;
while ((o = depthWalk.next()) != null) {
DepthWalk.Commit c = (DepthWalk.Commit) o;


// Commits at the boundary which aren't already shallow in
// the client need to be marked as such
if (c.getDepth() == depth && !clientShallowCommits.contains(c))
pckOut.writeString("shallow " + o.name()); //$NON-NLS-1$
// Commits at the boundary which aren't already shallow in
// the client need to be marked as such
if (c.getDepth() == depth && !clientShallowCommits.contains(c))
pckOut.writeString("shallow " + o.name()); //$NON-NLS-1$


// Commits not on the boundary which are shallow in the client
// need to become unshallowed
if (c.getDepth() < depth && clientShallowCommits.remove(c)) {
unshallowCommits.add(c.copy());
pckOut.writeString("unshallow " + c.name()); //$NON-NLS-1$
// Commits not on the boundary which are shallow in the client
// need to become unshallowed
if (c.getDepth() < depth && clientShallowCommits.remove(c)) {
unshallowCommits.add(c.copy());
pckOut.writeString("unshallow " + c.name()); //$NON-NLS-1$
}
} }
} }

pckOut.end(); pckOut.end();
} }


statistics = pw.getStatistics(); statistics = pw.getStatistics();
if (statistics != null) if (statistics != null)
logger.onPackStatistics(statistics); logger.onPackStatistics(statistics);
pw.release();
pw.close();
} }


if (sideband) if (sideband)

+ 2
- 2
org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java View File



@Override @Override
public void close() { public void close() {
inserter.release();
reader.release();
inserter.close();
reader.close();
for (final RemotePack p : unfetchedPacks) { for (final RemotePack p : unfetchedPacks) {
if (p.tmpIdx != null) if (p.tmpIdx != null)
p.tmpIdx.delete(); p.tmpIdx.delete();

+ 3
- 5
org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java View File

String pathPack = null; String pathPack = null;
String pathIdx = null; String pathIdx = null;


final PackWriter writer = new PackWriter(transport.getPackConfig(),
local.newObjectReader());
try {
try (final PackWriter writer = new PackWriter(transport.getPackConfig(),
local.newObjectReader())) {
final Set<ObjectId> need = new HashSet<ObjectId>(); final Set<ObjectId> need = new HashSet<ObjectId>();
final Set<ObjectId> have = new HashSet<ObjectId>(); final Set<ObjectId> have = new HashSet<ObjectId>();
for (final RemoteRefUpdate r : updates) for (final RemoteRefUpdate r : updates)
safeDelete(pathPack); safeDelete(pathPack);


throw new TransportException(uri, JGitText.get().cannotStoreObjects, err); throw new TransportException(uri, JGitText.get().cannotStoreObjects, err);
} finally {
writer.release();
} }
} }



Loading…
Cancel
Save