From 782dbfc60f01021e29d31ac5189eed77c55583ab Mon Sep 17 00:00:00 2001 From: Chris Aniszczyk Date: Sun, 10 Oct 2010 15:55:03 -0500 Subject: [PATCH] Update Push to use latest API Change-Id: I57ea8634a46472f40046f4ec69de505abbf5f6cf Signed-off-by: Chris Aniszczyk --- .../src/org/eclipse/jgit/pgm/Push.java | 48 +++++++------------ 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java index 05966416c..b6a10518a 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Push.java @@ -1,4 +1,5 @@ /* + * Copyright (C) 2010, Chris Aniszczyk * Copyright (C) 2008, Marek Zawirski * and other copyright owners as documented in the project's IP log. * @@ -46,9 +47,10 @@ package org.eclipse.jgit.pgm; import java.io.IOException; import java.text.MessageFormat; import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.PushCommand; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectReader; @@ -57,9 +59,9 @@ import org.eclipse.jgit.lib.TextProgressMonitor; import org.eclipse.jgit.transport.PushResult; import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RemoteRefUpdate; +import org.eclipse.jgit.transport.RemoteRefUpdate.Status; import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.URIish; -import org.eclipse.jgit.transport.RemoteRefUpdate.Status; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; @@ -108,37 +110,21 @@ class Push extends TextBuiltin { @Override protected void run() throws Exception { - if (force) { - final List orig = new ArrayList(refSpecs); - refSpecs.clear(); - for (final RefSpec spec : orig) - refSpecs.add(spec.setForceUpdate(true)); - } - - final List transports; - transports = Transport.openAll(db, remote, Transport.Operation.PUSH); - for (final Transport transport : transports) { - if (0 <= timeout) - transport.setTimeout(timeout); - transport.setPushThin(thin); - if (receivePack != null) - transport.setOptionReceivePack(receivePack); - transport.setDryRun(dryRun); - - final Collection toPush = transport - .findRemoteRefUpdatesFor(refSpecs); - - final URIish uri = transport.getURI(); - final PushResult result; - try { - result = transport.push(new TextProgressMonitor(), toPush); - } finally { - transport.close(); - } - + Git git = new Git(db); + PushCommand push = git.push(); + push.setDryRun(dryRun); + push.setForce(force); + push.setProgressMonitor(new TextProgressMonitor()); + push.setReceivePack(receivePack); + push.setRefSpecs(refSpecs); + push.setRemote(remote); + push.setThin(thin); + push.setTimeout(timeout); + Iterable results = push.call(); + for (PushResult result : results) { ObjectReader reader = db.newObjectReader(); try { - printPushResult(reader, uri, result); + printPushResult(reader, result.getURI(), result); } finally { reader.release(); }