Browse Source

Merge branch 'stable-4.1'

* stable-4.1:
  pgm: Open RevWalk and TreeWalk in try-with-resource
  ant: Open Repository and Git in try-with-resource
  pgm: Create instances of Git in try-with-resource
  FanoutBucket: Create ObjectInserter.Formatter in try-with-resource
  Fix compiler warnings in DiffFormatter.writeGitLinkText

Change-Id: I448ecc9a1334977d9f304dd61ea20c7a8e692b10
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-4.2
Matthias Sohn 9 years ago
parent
commit
d652a6bfd7
  1. 6
      org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitAddTask.java
  2. 6
      org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitCheckoutTask.java
  3. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java
  4. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java
  5. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java
  6. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java
  7. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java
  8. 5
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java
  9. 3
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/DiffTree.java
  10. 3
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java
  11. 3
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java
  12. 8
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java
  13. 3
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java
  14. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reflog.java
  15. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java
  16. 5
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java
  17. 3
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Show.java
  18. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java
  19. 6
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java
  20. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java
  21. 5
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java
  22. 6
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java
  23. 5
      org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
  24. 4
      org.eclipse.jgit/src/org/eclipse/jgit/notes/FanoutBucket.java

6
org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitAddTask.java

@ -117,10 +117,10 @@ public class GitAddTask extends Task {
} }
AddCommand gitAdd; AddCommand gitAdd;
try { try (Repository repo = new FileRepositoryBuilder().readEnvironment()
Repository repo = new FileRepositoryBuilder().readEnvironment()
.findGitDir(src).build(); .findGitDir(src).build();
gitAdd = new Git(repo).add(); Git git = new Git(repo);) {
gitAdd = git.add();
} catch (IOException e) { } catch (IOException e) {
throw new BuildException("Could not access repository " + src, e); throw new BuildException("Could not access repository " + src, e);
} }

6
org.eclipse.jgit.ant/src/org/eclipse/jgit/ant/tasks/GitCheckoutTask.java

@ -105,10 +105,10 @@ public class GitCheckoutTask extends Task {
@Override @Override
public void execute() throws BuildException { public void execute() throws BuildException {
CheckoutCommand checkout; CheckoutCommand checkout;
try { try (Repository repo = new FileRepositoryBuilder().readEnvironment()
Repository repo = new FileRepositoryBuilder().readEnvironment()
.findGitDir(src).build(); .findGitDir(src).build();
checkout = new Git(repo).checkout(); Git git = new Git(repo)) {
checkout = git.checkout();
} catch (IOException e) { } catch (IOException e) {
throw new BuildException("Could not access repository " + src, e); throw new BuildException("Could not access repository " + src, e);
} }

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java

@ -62,10 +62,12 @@ class Add extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
AddCommand addCmd = new Git(db).add(); try (Git git = new Git(db)) {
AddCommand addCmd = git.add();
addCmd.setUpdate(update); addCmd.setUpdate(update);
for (String p : filepatterns) for (String p : filepatterns)
addCmd.addFilepattern(p); addCmd.addFilepattern(p);
addCmd.call(); addCmd.call();
} }
} }
}

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java

@ -87,8 +87,8 @@ class Archive extends TextBuiltin {
else else
stream = outs; stream = outs;
try { try (Git git = new Git(db)) {
ArchiveCommand cmd = new Git(db).archive() ArchiveCommand cmd = git.archive()
.setTree(tree) .setTree(tree)
.setFormat(format) .setFormat(format)
.setPrefix(prefix) .setPrefix(prefix)

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java

@ -186,7 +186,8 @@ class Branch extends TextBuiltin {
// This can happen if HEAD is stillborn // This can happen if HEAD is stillborn
if (head != null) { if (head != null) {
String current = head.getLeaf().getName(); String current = head.getLeaf().getName();
ListBranchCommand command = new Git(db).branchList(); try (Git git = new Git(db)) {
ListBranchCommand command = git.branchList();
if (all) if (all)
command.setListMode(ListMode.ALL); command.setListMode(ListMode.ALL);
else if (remote) else if (remote)
@ -213,6 +214,7 @@ class Branch extends TextBuiltin {
} }
} }
} }
}
private void addRefs(final Collection<Ref> refs, final String prefix) { private void addRefs(final Collection<Ref> refs, final String prefix) {
for (final Ref ref : RefComparator.sort(refs)) { for (final Ref ref : RefComparator.sort(refs)) {

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java

@ -89,7 +89,8 @@ class Checkout extends TextBuiltin {
throw die(CLIText.get().onBranchToBeBorn); throw die(CLIText.get().onBranchToBeBorn);
} }
CheckoutCommand command = new Git(db).checkout(); try (Git git = new Git(db)) {
CheckoutCommand command = git.checkout();
if (paths.size() > 0) { if (paths.size() > 0) {
command.setStartPoint(name); command.setStartPoint(name);
for (String path : paths) for (String path : paths)
@ -133,3 +134,4 @@ class Checkout extends TextBuiltin {
} }
} }
} }
}

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java

@ -80,7 +80,8 @@ class Commit extends TextBuiltin {
@Override @Override
protected void run() throws NoHeadException, NoMessageException, protected void run() throws NoHeadException, NoMessageException,
ConcurrentRefUpdateException, JGitInternalException, Exception { ConcurrentRefUpdateException, JGitInternalException, Exception {
CommitCommand commitCmd = new Git(db).commit(); try (Git git = new Git(db)) {
CommitCommand commitCmd = git.commit();
if (author != null) if (author != null)
commitCmd.setAuthor(RawParseUtils.parsePersonIdent(author)); commitCmd.setAuthor(RawParseUtils.parsePersonIdent(author));
if (message != null) if (message != null)
@ -114,3 +115,4 @@ class Commit extends TextBuiltin {
+ commit.getShortMessage()); + commit.getShortMessage());
} }
} }
}

5
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Describe.java

@ -61,7 +61,8 @@ class Describe extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
DescribeCommand cmd = new Git(db).describe(); try (Git git = new Git(db)) {
DescribeCommand cmd = git.describe();
if (tree != null) if (tree != null)
cmd.setTarget(tree); cmd.setTarget(tree);
cmd.setLong(longDesc); cmd.setLong(longDesc);
@ -76,5 +77,5 @@ class Describe extends TextBuiltin {
outw.println(result); outw.println(result);
} }
}
} }

3
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/DiffTree.java

@ -74,7 +74,7 @@ class DiffTree extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
final TreeWalk walk = new TreeWalk(db); try (final TreeWalk walk = new TreeWalk(db)) {
walk.setRecursive(recursive); walk.setRecursive(recursive);
for (final AbstractTreeIterator i : trees) for (final AbstractTreeIterator i : trees)
walk.addTree(i); walk.addTree(i);
@ -117,3 +117,4 @@ class DiffTree extends TextBuiltin {
} }
} }
} }
}

3
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java

@ -104,7 +104,7 @@ class Fetch extends AbstractFetchCommand {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
FetchCommand fetch = git.fetch(); FetchCommand fetch = git.fetch();
if (fsck != null) if (fsck != null)
fetch.setCheckFetchedObjects(fsck.booleanValue()); fetch.setCheckFetchedObjects(fsck.booleanValue());
@ -132,3 +132,4 @@ class Fetch extends AbstractFetchCommand {
showFetchResult(result); showFetchResult(result);
} }
} }
}

3
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java

@ -72,7 +72,7 @@ class LsTree extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
final TreeWalk walk = new TreeWalk(db); try (final TreeWalk walk = new TreeWalk(db)) {
walk.reset(); // drop the first empty tree, which we do not need here walk.reset(); // drop the first empty tree, which we do not need here
if (paths.size() > 0) if (paths.size() > 0)
walk.setFilter(PathFilterGroup.createFromStrings(paths)); walk.setFilter(PathFilterGroup.createFromStrings(paths));
@ -96,3 +96,4 @@ class LsTree extends TextBuiltin {
} }
} }
} }
}

8
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java

@ -121,7 +121,8 @@ class Merge extends TextBuiltin {
CLIText.get().refDoesNotExistOrNoCommit, ref)); CLIText.get().refDoesNotExistOrNoCommit, ref));
Ref oldHead = db.getRef(Constants.HEAD); Ref oldHead = db.getRef(Constants.HEAD);
Git git = new Git(db); MergeResult result;
try (Git git = new Git(db)) {
MergeCommand mergeCmd = git.merge().setStrategy(mergeStrategy) MergeCommand mergeCmd = git.merge().setStrategy(mergeStrategy)
.setSquash(squash).setFastForward(ff).setCommit(!noCommit); .setSquash(squash).setFastForward(ff).setCommit(!noCommit);
if (srcRef != null) if (srcRef != null)
@ -132,12 +133,12 @@ class Merge extends TextBuiltin {
if (message != null) if (message != null)
mergeCmd.setMessage(message); mergeCmd.setMessage(message);
MergeResult result;
try { try {
result = mergeCmd.call(); result = mergeCmd.call();
} catch (CheckoutConflictException e) { } catch (CheckoutConflictException e) {
result = new MergeResult(e.getConflictingPaths()); // CHECKOUT_CONFLICT result = new MergeResult(e.getConflictingPaths()); // CHECKOUT_CONFLICT
} }
}
switch (result.getMergeStatus()) { switch (result.getMergeStatus()) {
case ALREADY_UP_TO_DATE: case ALREADY_UP_TO_DATE:
@ -206,7 +207,7 @@ class Merge extends TextBuiltin {
private boolean isMergedInto(Ref oldHead, AnyObjectId src) private boolean isMergedInto(Ref oldHead, AnyObjectId src)
throws IOException { throws IOException {
RevWalk revWalk = new RevWalk(db); try (RevWalk revWalk = new RevWalk(db)) {
ObjectId oldHeadObjectId = oldHead.getPeeledObjectId(); ObjectId oldHeadObjectId = oldHead.getPeeledObjectId();
if (oldHeadObjectId == null) if (oldHeadObjectId == null)
oldHeadObjectId = oldHead.getObjectId(); oldHeadObjectId = oldHead.getObjectId();
@ -215,3 +216,4 @@ class Merge extends TextBuiltin {
return revWalk.isMergedInto(oldHeadCommit, srcCommit); return revWalk.isMergedInto(oldHeadCommit, srcCommit);
} }
} }
}

3
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java

@ -109,7 +109,7 @@ class Push extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
PushCommand push = git.push(); PushCommand push = git.push();
push.setDryRun(dryRun); push.setDryRun(dryRun);
push.setForce(force); push.setForce(force);
@ -130,6 +130,7 @@ class Push extends TextBuiltin {
} }
} }
} }
}
private void printPushResult(final ObjectReader reader, final URIish uri, private void printPushResult(final ObjectReader reader, final URIish uri,
final PushResult result) throws IOException { final PushResult result) throws IOException {

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reflog.java

@ -59,7 +59,8 @@ class Reflog extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
ReflogCommand cmd = new Git(db).reflog(); try (Git git = new Git(db)) {
ReflogCommand cmd = git.reflog();
if (ref != null) if (ref != null)
cmd.setRef(ref); cmd.setRef(ref);
Collection<ReflogEntry> entries = cmd.call(); Collection<ReflogEntry> entries = cmd.call();
@ -68,6 +69,7 @@ class Reflog extends TextBuiltin {
outw.println(toString(entry, i++)); outw.println(toString(entry, i++));
} }
} }
}
private String toString(ReflogEntry entry, int i) { private String toString(ReflogEntry entry, int i) {
final StringBuilder s = new StringBuilder(); final StringBuilder s = new StringBuilder();

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java

@ -66,7 +66,8 @@ class Reset extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
ResetCommand command = new Git(db).reset(); try (Git git = new Git(db)) {
ResetCommand command = git.reset();
command.setRef(commit); command.setRef(commit);
ResetType mode = null; ResetType mode = null;
if (soft) if (soft)
@ -80,6 +81,7 @@ class Reset extends TextBuiltin {
command.setMode(mode); command.setMode(mode);
command.call(); command.call();
} }
}
private static ResetType selectMode(ResetType mode, ResetType want) { private static ResetType selectMode(ResetType mode, ResetType want) {
if (mode != null) if (mode != null)

5
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java

@ -63,10 +63,11 @@ class Rm extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
RmCommand command = new Git(db).rm(); try (Git git = new Git(db)) {
RmCommand command = git.rm();
for (String p : paths) for (String p : paths)
command.addFilepattern(p); command.addFilepattern(p);
command.call(); command.call();
} }
}
} }

3
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Show.java

@ -251,7 +251,7 @@ class Show extends TextBuiltin {
private void show(RevTree obj) throws MissingObjectException, private void show(RevTree obj) throws MissingObjectException,
IncorrectObjectTypeException, CorruptObjectException, IOException { IncorrectObjectTypeException, CorruptObjectException, IOException {
final TreeWalk walk = new TreeWalk(db); try (final TreeWalk walk = new TreeWalk(db)) {
walk.reset(); walk.reset();
walk.addTree(obj); walk.addTree(obj);
@ -263,6 +263,7 @@ class Show extends TextBuiltin {
outw.println(); outw.println();
} }
} }
}
private void show(RevWalk rw, final RevCommit c) throws Exception { private void show(RevWalk rw, final RevCommit c) throws Exception {
char[] outbuffer = new char[Constants.OBJECT_ID_LENGTH * 2]; char[] outbuffer = new char[Constants.OBJECT_ID_LENGTH * 2];

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java

@ -88,13 +88,15 @@ class Status extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
StatusCommand statusCommand = new Git(db).status(); try (Git git = new Git(db)) {
StatusCommand statusCommand = git.status();
if (filterPaths != null && filterPaths.size() > 0) if (filterPaths != null && filterPaths.size() > 0)
for (String path : filterPaths) for (String path : filterPaths)
statusCommand.addPath(path); statusCommand.addPath(path);
org.eclipse.jgit.api.Status status = statusCommand.call(); org.eclipse.jgit.api.Status status = statusCommand.call();
printStatus(status); printStatus(status);
} }
}
private void printStatus(org.eclipse.jgit.api.Status status) private void printStatus(org.eclipse.jgit.api.Status status)
throws IOException { throws IOException {

6
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Tag.java

@ -79,15 +79,16 @@ class Tag extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
if (tagName != null) { if (tagName != null) {
TagCommand command = git.tag().setForceUpdate(force) TagCommand command = git.tag().setForceUpdate(force)
.setMessage(message).setName(tagName); .setMessage(message).setName(tagName);
if (object != null) { if (object != null) {
RevWalk walk = new RevWalk(db); try (RevWalk walk = new RevWalk(db)) {
command.setObjectId(walk.parseAny(object)); command.setObjectId(walk.parseAny(object));
} }
}
try { try {
command.call(); command.call();
} catch (RefAlreadyExistsException e) { } catch (RefAlreadyExistsException e) {
@ -103,3 +104,4 @@ class Tag extends TextBuiltin {
} }
} }
} }
}

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java

@ -173,9 +173,9 @@ class DiffAlgorithms extends TextBuiltin {
int maxN = 0; int maxN = 0;
AbbreviatedObjectId startId; AbbreviatedObjectId startId;
try (ObjectReader or = db.newObjectReader()) { try (ObjectReader or = db.newObjectReader();
RevWalk rw = new RevWalk(or)) {
final MutableObjectId id = new MutableObjectId(); final MutableObjectId id = new MutableObjectId();
RevWalk rw = new RevWalk(or);
TreeWalk tw = new TreeWalk(or); TreeWalk tw = new TreeWalk(or);
tw.setFilter(TreeFilter.ANY_DIFF); tw.setFilter(TreeFilter.ANY_DIFF);
tw.setRecursive(true); tw.setRecursive(true);

5
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java

@ -75,7 +75,10 @@ class ShowPackDelta extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
ObjectReader reader = db.newObjectReader(); ObjectReader reader = db.newObjectReader();
RevObject obj = new RevWalk(reader).parseAny(objectId); RevObject obj;
try (RevWalk rw = new RevWalk(reader)) {
obj = rw.parseAny(objectId);
}
byte[] delta = getDelta(reader, obj); byte[] delta = getDelta(reader, obj);
// We're crossing our fingers that this will be a delta. Double // We're crossing our fingers that this will be a delta. Double

6
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java

@ -300,10 +300,10 @@ class TextHashFunctions extends TextBuiltin {
long fileCnt = 0; long fileCnt = 0;
long lineCnt = 0; long lineCnt = 0;
try (ObjectReader or = db.newObjectReader()) { try (ObjectReader or = db.newObjectReader();
final MutableObjectId id = new MutableObjectId();
RevWalk rw = new RevWalk(or); RevWalk rw = new RevWalk(or);
TreeWalk tw = new TreeWalk(or); TreeWalk tw = new TreeWalk(or)) {
final MutableObjectId id = new MutableObjectId();
tw.reset(rw.parseTree(db.resolve(Constants.HEAD))); tw.reset(rw.parseTree(db.resolve(Constants.HEAD)));
tw.setRecursive(true); tw.setRecursive(true);

5
org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java

@ -665,10 +665,9 @@ public class DiffFormatter implements AutoCloseable {
format(res.header, res.a, res.b); format(res.header, res.a, res.b);
} }
private static byte[] writeGitLinkText(AbbreviatedObjectId id) private static byte[] writeGitLinkText(AbbreviatedObjectId id) {
throws IOException {
return encodeASCII("Subproject commit " + id.name() //$NON-NLS-1$ return encodeASCII("Subproject commit " + id.name() //$NON-NLS-1$
+ "\n"); + "\n"); //$NON-NLS-1$
} }
private String format(AbbreviatedObjectId id) { private String format(AbbreviatedObjectId id) {

4
org.eclipse.jgit/src/org/eclipse/jgit/notes/FanoutBucket.java

@ -260,8 +260,8 @@ class FanoutBucket extends InMemoryNoteBucket {
} }
ObjectId getTreeId() { ObjectId getTreeId() {
try { try (ObjectInserter.Formatter f = new ObjectInserter.Formatter()) {
return new ObjectInserter.Formatter().idFor(build(false, null)); return f.idFor(build(false, null));
} catch (IOException e) { } catch (IOException e) {
// should never happen as we are not inserting // should never happen as we are not inserting
throw new RuntimeException(e); throw new RuntimeException(e);

Loading…
Cancel
Save