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;
try {
Repository repo = new FileRepositoryBuilder().readEnvironment()
try (Repository repo = new FileRepositoryBuilder().readEnvironment()
.findGitDir(src).build();
gitAdd = new Git(repo).add();
Git git = new Git(repo);) {
gitAdd = git.add();
} catch (IOException 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
public void execute() throws BuildException {
CheckoutCommand checkout;
try {
Repository repo = new FileRepositoryBuilder().readEnvironment()
try (Repository repo = new FileRepositoryBuilder().readEnvironment()
.findGitDir(src).build();
checkout = new Git(repo).checkout();
Git git = new Git(repo)) {
checkout = git.checkout();
} catch (IOException 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
protected void run() throws Exception {
AddCommand addCmd = new Git(db).add();
try (Git git = new Git(db)) {
AddCommand addCmd = git.add();
addCmd.setUpdate(update);
for (String p : filepatterns)
addCmd.addFilepattern(p);
addCmd.call();
}
}
}

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

@ -87,8 +87,8 @@ class Archive extends TextBuiltin {
else
stream = outs;
try {
ArchiveCommand cmd = new Git(db).archive()
try (Git git = new Git(db)) {
ArchiveCommand cmd = git.archive()
.setTree(tree)
.setFormat(format)
.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
if (head != null) {
String current = head.getLeaf().getName();
ListBranchCommand command = new Git(db).branchList();
try (Git git = new Git(db)) {
ListBranchCommand command = git.branchList();
if (all)
command.setListMode(ListMode.ALL);
else if (remote)
@ -213,6 +214,7 @@ class Branch extends TextBuiltin {
}
}
}
}
private void addRefs(final Collection<Ref> refs, final String prefix) {
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);
}
CheckoutCommand command = new Git(db).checkout();
try (Git git = new Git(db)) {
CheckoutCommand command = git.checkout();
if (paths.size() > 0) {
command.setStartPoint(name);
for (String path : paths)
@ -132,4 +133,5 @@ class Checkout extends TextBuiltin {
CLIText.get().checkoutConflictPathLine, path));
}
}
}
}

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

@ -80,7 +80,8 @@ class Commit extends TextBuiltin {
@Override
protected void run() throws NoHeadException, NoMessageException,
ConcurrentRefUpdateException, JGitInternalException, Exception {
CommitCommand commitCmd = new Git(db).commit();
try (Git git = new Git(db)) {
CommitCommand commitCmd = git.commit();
if (author != null)
commitCmd.setAuthor(RawParseUtils.parsePersonIdent(author));
if (message != null)
@ -113,4 +114,5 @@ class Commit extends TextBuiltin {
outw.println("[" + branchName + " " + commit.name() + "] " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ commit.getShortMessage());
}
}
}

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

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

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

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

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

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

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

@ -72,7 +72,7 @@ class LsTree extends TextBuiltin {
@Override
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
if (paths.size() > 0)
walk.setFilter(PathFilterGroup.createFromStrings(paths));
@ -95,4 +95,5 @@ class LsTree extends TextBuiltin {
outw.println();
}
}
}
}

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

@ -121,7 +121,8 @@ class Merge extends TextBuiltin {
CLIText.get().refDoesNotExistOrNoCommit, ref));
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)
.setSquash(squash).setFastForward(ff).setCommit(!noCommit);
if (srcRef != null)
@ -132,12 +133,12 @@ class Merge extends TextBuiltin {
if (message != null)
mergeCmd.setMessage(message);
MergeResult result;
try {
result = mergeCmd.call();
} catch (CheckoutConflictException e) {
result = new MergeResult(e.getConflictingPaths()); // CHECKOUT_CONFLICT
}
}
switch (result.getMergeStatus()) {
case ALREADY_UP_TO_DATE:
@ -206,7 +207,7 @@ class Merge extends TextBuiltin {
private boolean isMergedInto(Ref oldHead, AnyObjectId src)
throws IOException {
RevWalk revWalk = new RevWalk(db);
try (RevWalk revWalk = new RevWalk(db)) {
ObjectId oldHeadObjectId = oldHead.getPeeledObjectId();
if (oldHeadObjectId == null)
oldHeadObjectId = oldHead.getObjectId();
@ -214,4 +215,5 @@ class Merge extends TextBuiltin {
RevCommit srcCommit = revWalk.lookupCommit(src);
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
protected void run() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
PushCommand push = git.push();
push.setDryRun(dryRun);
push.setForce(force);
@ -130,6 +130,7 @@ class Push extends TextBuiltin {
}
}
}
}
private void printPushResult(final ObjectReader reader, final URIish uri,
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
protected void run() throws Exception {
ReflogCommand cmd = new Git(db).reflog();
try (Git git = new Git(db)) {
ReflogCommand cmd = git.reflog();
if (ref != null)
cmd.setRef(ref);
Collection<ReflogEntry> entries = cmd.call();
@ -68,6 +69,7 @@ class Reflog extends TextBuiltin {
outw.println(toString(entry, i++));
}
}
}
private String toString(ReflogEntry entry, int i) {
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
protected void run() throws Exception {
ResetCommand command = new Git(db).reset();
try (Git git = new Git(db)) {
ResetCommand command = git.reset();
command.setRef(commit);
ResetType mode = null;
if (soft)
@ -80,6 +81,7 @@ class Reset extends TextBuiltin {
command.setMode(mode);
command.call();
}
}
private static ResetType selectMode(ResetType mode, ResetType want) {
if (mode != null)

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

@ -63,10 +63,11 @@ class Rm extends TextBuiltin {
@Override
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)
command.addFilepattern(p);
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,
IncorrectObjectTypeException, CorruptObjectException, IOException {
final TreeWalk walk = new TreeWalk(db);
try (final TreeWalk walk = new TreeWalk(db)) {
walk.reset();
walk.addTree(obj);
@ -263,6 +263,7 @@ class Show extends TextBuiltin {
outw.println();
}
}
}
private void show(RevWalk rw, final RevCommit c) throws Exception {
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
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)
for (String path : filterPaths)
statusCommand.addPath(path);
org.eclipse.jgit.api.Status status = statusCommand.call();
printStatus(status);
}
}
private void printStatus(org.eclipse.jgit.api.Status status)
throws IOException {

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

@ -79,15 +79,16 @@ class Tag extends TextBuiltin {
@Override
protected void run() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
if (tagName != null) {
TagCommand command = git.tag().setForceUpdate(force)
.setMessage(message).setName(tagName);
if (object != null) {
RevWalk walk = new RevWalk(db);
try (RevWalk walk = new RevWalk(db)) {
command.setObjectId(walk.parseAny(object));
}
}
try {
command.call();
} catch (RefAlreadyExistsException e) {
@ -102,4 +103,5 @@ 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;
AbbreviatedObjectId startId;
try (ObjectReader or = db.newObjectReader()) {
try (ObjectReader or = db.newObjectReader();
RevWalk rw = new RevWalk(or)) {
final MutableObjectId id = new MutableObjectId();
RevWalk rw = new RevWalk(or);
TreeWalk tw = new TreeWalk(or);
tw.setFilter(TreeFilter.ANY_DIFF);
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
protected void run() throws Exception {
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);
// 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 lineCnt = 0;
try (ObjectReader or = db.newObjectReader()) {
final MutableObjectId id = new MutableObjectId();
try (ObjectReader or = db.newObjectReader();
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.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);
}
private static byte[] writeGitLinkText(AbbreviatedObjectId id)
throws IOException {
private static byte[] writeGitLinkText(AbbreviatedObjectId id) {
return encodeASCII("Subproject commit " + id.name() //$NON-NLS-1$
+ "\n");
+ "\n"); //$NON-NLS-1$
}
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() {
try {
return new ObjectInserter.Formatter().idFor(build(false, null));
try (ObjectInserter.Formatter f = new ObjectInserter.Formatter()) {
return f.idFor(build(false, null));
} catch (IOException e) {
// should never happen as we are not inserting
throw new RuntimeException(e);

Loading…
Cancel
Save