From 6b6c8dd01bb1b4c83bcf899b1cff7b67de6a354c Mon Sep 17 00:00:00 2001 From: Chris Aniszczyk Date: Fri, 24 Sep 2010 15:23:34 -0500 Subject: [PATCH] Update Fetch to use FetchCommand API Change-Id: I06ddc74f1ef658f4876e2bbcc3eaad3475a5371e Signed-off-by: Chris Aniszczyk --- .../jgit/pgm/AbstractFetchCommand.java | 5 +-- .../src/org/eclipse/jgit/pgm/Clone.java | 2 +- .../src/org/eclipse/jgit/pgm/Fetch.java | 42 +++++++++---------- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AbstractFetchCommand.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AbstractFetchCommand.java index fd7fd4459..6624d49a2 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AbstractFetchCommand.java +++ b/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.transport.FetchResult; import org.eclipse.jgit.transport.TrackingRefUpdate; -import org.eclipse.jgit.transport.Transport; import org.kohsuke.args4j.Option; abstract class AbstractFetchCommand extends TextBuiltin { @Option(name = "--verbose", aliases = { "-v" }, usage = "usage_beMoreVerbose") private boolean verbose; - protected void showFetchResult(final Transport tn, final FetchResult r) { + protected void showFetchResult(final FetchResult r) { ObjectReader reader = db.newObjectReader(); try { boolean shownURI = false; @@ -78,7 +77,7 @@ abstract class AbstractFetchCommand extends TextBuiltin { final String dst = abbreviateRef(u.getLocalName(), true); if (!shownURI) { - out.format(CLIText.get().fromURI, tn.getURI()); + out.format(CLIText.get().fromURI, r.getURI()); out.println(); shownURI = true; } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java index 1b0498967..0bc72a71e 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java @@ -146,7 +146,7 @@ class Clone extends AbstractFetchCommand { } finally { tn.close(); } - showFetchResult(tn, r); + showFetchResult(r); return r; } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java index a68145bf7..e2467b2c3 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java +++ b/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 org.kohsuke.args4j.Argument; -import org.kohsuke.args4j.Option; +import org.eclipse.jgit.api.FetchCommand; +import org.eclipse.jgit.api.Git; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.TextProgressMonitor; import org.eclipse.jgit.transport.FetchResult; 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") class Fetch extends AbstractFetchCommand { @@ -90,24 +91,21 @@ class Fetch extends AbstractFetchCommand { @Override protected void run() throws Exception { - final Transport tn = Transport.open(db, remote); - if (fsck != null) - tn.setCheckFetchedObjects(fsck.booleanValue()); - if (prune != null) - tn.setRemoveDeletedRefs(prune.booleanValue()); - tn.setDryRun(dryRun); - if (thin != null) - tn.setFetchThin(thin.booleanValue()); - if (0 <= timeout) - tn.setTimeout(timeout); - final FetchResult r; - try { - r = tn.fetch(new TextProgressMonitor(), toget); - if (r.getTrackingRefUpdates().isEmpty()) - return; - } finally { - tn.close(); - } - showFetchResult(tn, r); + Git git = new Git(db); + FetchCommand fetch = git.fetch(); + fetch.setCheckFetchedObjects(fsck.booleanValue()); + fetch.setRemoveDeletedRefs(prune.booleanValue()); + fetch.setRefSpecs(toget); + fetch.setTimeout(timeout); + fetch.setDryRun(dryRun); + fetch.setRemote(remote); + fetch.setThin(thin.booleanValue()); + fetch.setProgressMonitor(new TextProgressMonitor()); + + FetchResult result = fetch.call(); + if (result.getTrackingRefUpdates().isEmpty()) + return; + + showFetchResult(result); } }