Browse Source

Update Fetch to use FetchCommand API

Change-Id: I06ddc74f1ef658f4876e2bbcc3eaad3475a5371e
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
stable-0.10
Chris Aniszczyk 14 years ago
parent
commit
6b6c8dd01b
  1. 5
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AbstractFetchCommand.java
  2. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java
  3. 42
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java

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

@ -57,14 +57,13 @@ import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.transport.FetchResult; import org.eclipse.jgit.transport.FetchResult;
import org.eclipse.jgit.transport.TrackingRefUpdate; import org.eclipse.jgit.transport.TrackingRefUpdate;
import org.eclipse.jgit.transport.Transport;
import org.kohsuke.args4j.Option; import org.kohsuke.args4j.Option;
abstract class AbstractFetchCommand extends TextBuiltin { abstract class AbstractFetchCommand extends TextBuiltin {
@Option(name = "--verbose", aliases = { "-v" }, usage = "usage_beMoreVerbose") @Option(name = "--verbose", aliases = { "-v" }, usage = "usage_beMoreVerbose")
private boolean verbose; private boolean verbose;
protected void showFetchResult(final Transport tn, final FetchResult r) { protected void showFetchResult(final FetchResult r) {
ObjectReader reader = db.newObjectReader(); ObjectReader reader = db.newObjectReader();
try { try {
boolean shownURI = false; boolean shownURI = false;
@ -78,7 +77,7 @@ abstract class AbstractFetchCommand extends TextBuiltin {
final String dst = abbreviateRef(u.getLocalName(), true); final String dst = abbreviateRef(u.getLocalName(), true);
if (!shownURI) { if (!shownURI) {
out.format(CLIText.get().fromURI, tn.getURI()); out.format(CLIText.get().fromURI, r.getURI());
out.println(); out.println();
shownURI = true; shownURI = true;
} }

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java

@ -146,7 +146,7 @@ class Clone extends AbstractFetchCommand {
} finally { } finally {
tn.close(); tn.close();
} }
showFetchResult(tn, r); showFetchResult(r);
return r; return r;
} }

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

@ -47,13 +47,14 @@ package org.eclipse.jgit.pgm;
import java.util.List; import java.util.List;
import org.kohsuke.args4j.Argument; import org.eclipse.jgit.api.FetchCommand;
import org.kohsuke.args4j.Option; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.TextProgressMonitor; import org.eclipse.jgit.lib.TextProgressMonitor;
import org.eclipse.jgit.transport.FetchResult; import org.eclipse.jgit.transport.FetchResult;
import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.Transport; import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
@Command(common = true, usage = "usage_updateRemoteRefsFromAnotherRepository") @Command(common = true, usage = "usage_updateRemoteRefsFromAnotherRepository")
class Fetch extends AbstractFetchCommand { class Fetch extends AbstractFetchCommand {
@ -90,24 +91,21 @@ class Fetch extends AbstractFetchCommand {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
final Transport tn = Transport.open(db, remote); Git git = new Git(db);
if (fsck != null) FetchCommand fetch = git.fetch();
tn.setCheckFetchedObjects(fsck.booleanValue()); fetch.setCheckFetchedObjects(fsck.booleanValue());
if (prune != null) fetch.setRemoveDeletedRefs(prune.booleanValue());
tn.setRemoveDeletedRefs(prune.booleanValue()); fetch.setRefSpecs(toget);
tn.setDryRun(dryRun); fetch.setTimeout(timeout);
if (thin != null) fetch.setDryRun(dryRun);
tn.setFetchThin(thin.booleanValue()); fetch.setRemote(remote);
if (0 <= timeout) fetch.setThin(thin.booleanValue());
tn.setTimeout(timeout); fetch.setProgressMonitor(new TextProgressMonitor());
final FetchResult r;
try { FetchResult result = fetch.call();
r = tn.fetch(new TextProgressMonitor(), toget); if (result.getTrackingRefUpdates().isEmpty())
if (r.getTrackingRefUpdates().isEmpty()) return;
return;
} finally { showFetchResult(result);
tn.close();
}
showFetchResult(tn, r);
} }
} }

Loading…
Cancel
Save