git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[EGIT PATCH 07/31] Add openAll() and applyConfig() methods to Transport

From
MZMarek Zawirski <marek.zawirski@gmail.com>
Date
Aug 17, 2008, 20:43 UTC
Message-ID
<1219005852-21496-8-git-send-email-marek.zawirski@gmail.com>
In-Reply-To
<1219005852-21496-7-git-send-email-marek.zawirski@gmail.com>

openAll() method honours many URIs in remote configuration when opening transports. Old open() calls remained, they still open only 1 transport at time.

openAll() is used during push operation - pgm.Push implementation was fixed to use it.

applyConfig() is used internally here, but could be interesting for clients and it's safe to call it.

Signed-off-by: Marek Zawirski <marek.zawirski@gmail.com>
---
 .../src/org/spearce/jgit/pgm/Push.java             |   44 ++++++-----
 .../src/org/spearce/jgit/transport/Transport.java  |   83 ++++++++++++++++++--
 2 files changed, 99 insertions(+), 28 deletions(-)
diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Push.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Push.java
index 6b35ab8..a952309 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Push.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Push.java
@@ -86,7 +86,7 @@ class Push extends TextBuiltin {
 	@Option(name = "--receive-pack", metaVar = "path")
 	private String receivePack;
 
-	private boolean first = true;
+	private boolean shownURI;
 
 	@Override
 	protected void run() throws Exception {
@@ -97,27 +97,31 @@ class Push extends TextBuiltin {
 				refSpecs.add(spec.setForceUpdate(true));
 		}
 
-		final Transport transport = Transport.open(db, remote);
-		transport.setPushThin(thin);
-		if (receivePack != null)
-			transport.setOptionReceivePack(receivePack);
-		final Collection<RemoteRefUpdate> toPush = transport
-				.findRemoteRefUpdatesFor(refSpecs);
+		final List<Transport> transports = Transport.openAll(db, remote);
+		for (final Transport transport : transports) {
+			transport.setPushThin(thin);
+			if (receivePack != null)
+				transport.setOptionReceivePack(receivePack);
 
-		final PushResult result = transport.push(new TextProgressMonitor(),
-				toPush);
-		transport.close();
+			final Collection<RemoteRefUpdate> toPush = transport
+					.findRemoteRefUpdatesFor(refSpecs);
 
-		printPushResult(result);
+			final PushResult result = transport.push(new TextProgressMonitor(),
+					toPush);
+			printPushResult(transport, result);
+		}
 	}
 
-	private void printPushResult(final PushResult result) {
+	private void printPushResult(final Transport transport,
+			final PushResult result) {
+		shownURI = false;
 		boolean everythingUpToDate = true;
+
 		// at first, print up-to-date ones...
 		for (final RemoteRefUpdate rru : result.getRemoteUpdates()) {
 			if (rru.getStatus() == Status.UP_TO_DATE) {
 				if (verbose)
-					printRefUpdateResult(result, rru);
+					printRefUpdateResult(transport, result, rru);
 			} else
 				everythingUpToDate = false;
 		}
@@ -125,25 +129,25 @@ class Push extends TextBuiltin {
 		for (final RemoteRefUpdate rru : result.getRemoteUpdates()) {
 			// ...then successful updates...
 			if (rru.getStatus() == Status.OK)
-				printRefUpdateResult(result, rru);
+				printRefUpdateResult(transport, result, rru);
 		}
 
 		for (final RemoteRefUpdate rru : result.getRemoteUpdates()) {
 			// ...finally, others (problematic)
 			if (rru.getStatus() != Status.OK
 					&& rru.getStatus() != Status.UP_TO_DATE)
-				printRefUpdateResult(result, rru);
+				printRefUpdateResult(transport, result, rru);
 		}
 
 		if (everythingUpToDate)
 			out.println("Everything up-to-date");
 	}
 
-	private void printRefUpdateResult(final PushResult result,
-			final RemoteRefUpdate rru) {
-		if (first) {
-			first = false;
-			out.format("To %s\n", result.getURI());
+	private void printRefUpdateResult(final Transport transport,
+			final PushResult result, final RemoteRefUpdate rru) {
+		if (!shownURI) {
+			shownURI = true;
+			out.format("To %s\n", transport.getURI());
 		}
 
 		final String remoteName = rru.getRemoteName();
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/Transport.java b/org.spearce.jgit/src/org/spearce/jgit/transport/Transport.java
index 30175e3..73aa771 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/Transport.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/Transport.java
@@ -75,8 +75,10 @@ public abstract class Transport {
 	 * @param local
 	 *            existing local repository.
 	 * @param remote
-	 *            location of the remote repository.
-	 * @return the new transport instance. Never null.
+	 *            location of the remote repository - may be URI or remote
+	 *            configuration name.
+	 * @return the new transport instance. Never null. In case of multiple URIs
+	 *         in remote configuration, only the first is chosen.
 	 * @throws URISyntaxException
 	 *             the location is not a remote defined in the configuration
 	 *             file and is not a well-formed URL.
@@ -93,6 +95,35 @@ public abstract class Transport {
 	}
 
 	/**
+	 * Open new transport instances to connect two repositories.
+	 * 
+	 * @param local
+	 *            existing local repository.
+	 * @param remote
+	 *            location of the remote repository - may be URI or remote
+	 *            configuration name.
+	 * @return the list of new transport instances for every URI in remote
+	 *         configuration.
+	 * @throws URISyntaxException
+	 *             the location is not a remote defined in the configuration
+	 *             file and is not a well-formed URL.
+	 * @throws NotSupportedException
+	 *             the protocol specified is not supported.
+	 */
+	public static List<Transport> openAll(final Repository local,
+			final String remote) throws NotSupportedException,
+			URISyntaxException {
+		final RemoteConfig cfg = new RemoteConfig(local.getConfig(), remote);
+		final List<URIish> uris = cfg.getURIs();
+		if (uris.size() == 0) {
+			final ArrayList<Transport> transports = new ArrayList<Transport>(1);
+			transports.add(open(local, new URIish(remote)));
+			return transports;
+		}
+		return openAll(local, cfg);
+	}
+
+	/**
 	 * Open a new transport instance to connect two repositories.
 	 * 
 	 * @param local
@@ -100,7 +131,8 @@ public abstract class Transport {
 	 * @param cfg
 	 *            configuration describing how to connect to the remote
 	 *            repository.
-	 * @return the new transport instance. Never null.
+	 * @return the new transport instance. Never null. In case of multiple URIs
+	 *         in remote configuration, only the first is chosen.
 	 * @throws NotSupportedException
 	 *             the protocol specified is not supported.
 	 * @throws IllegalArgumentException
@@ -114,15 +146,36 @@ public abstract class Transport {
 					"Remote config \""
 					+ cfg.getName() + "\" has no URIs associated");
 		final Transport tn = open(local, cfg.getURIs().get(0));
-		tn.setOptionUploadPack(cfg.getUploadPack());
-		tn.fetch = cfg.getFetchRefSpecs();
-		tn.tagopt = cfg.getTagOpt();
-		tn.setOptionReceivePack(cfg.getReceivePack());
-		tn.push = cfg.getPushRefSpecs();
+		tn.applyConfig(cfg);
 		return tn;
 	}
 
 	/**
+	 * Open new transport instances to connect two repositories.
+	 * 
+	 * @param local
+	 *            existing local repository.
+	 * @param cfg
+	 *            configuration describing how to connect to the remote
+	 *            repository.
+	 * @return the list of new transport instances for every URI in remote
+	 *         configuration.
+	 * @throws NotSupportedException
+	 *             the protocol specified is not supported.
+	 */
+	public static List<Transport> openAll(final Repository local,
+			final RemoteConfig cfg) throws NotSupportedException {
+		final List<URIish> uris = cfg.getURIs();
+		final List<Transport> transports = new ArrayList<Transport>(uris.size());
+		for (final URIish uri : uris) {
+			final Transport tn = open(local, uri);
+			tn.applyConfig(cfg);
+			transports.add(tn);
+		}
+		return transports;
+	}
+
+	/**
 	 * Open a new transport instance to connect two repositories.
 	 * 
 	 * @param local
@@ -357,6 +410,20 @@ public abstract class Transport {
 	public void setPushThin(final boolean pushThin) {
 		this.pushThin = pushThin;
 	}
+	
+	/**
+	 * Apply provided remote configuration on this transport.
+	 * 
+	 * @param cfg
+	 *            configuration to apply on this transport.
+	 */
+	public void applyConfig(final RemoteConfig cfg) {
+		setOptionUploadPack(cfg.getUploadPack());
+		fetch = cfg.getFetchRefSpecs();
+		setTagOpt(cfg.getTagOpt());
+		optionReceivePack = cfg.getReceivePack();
+		push = cfg.getPushRefSpecs();
+	}
 
 	/**
 	 * Fetch objects and refs from the remote repository to the local one.
-- 
1.5.6.3
Previous: Marek ZawirskiNext: Marek Zawirski
Message 8 of 62 in “Push GUI, GUI improvements, various jgit stuff”
  1. 00/31 Push GUI, GUI improvements, various jgit stuffMarek Zawirski, Aug 17, 2008
  2. 01/31 Fix Repository.mapObject() for missing objectsMarek Zawirski, Aug 17, 2008
  3. 02/31 Fix Repository isValidRefName() for empty namesMarek Zawirski, Aug 17, 2008
  4. 03/31 Fix Repository.resolve() to not throw runtime exceptionsMarek Zawirski, Aug 17, 2008
  5. 04/31 Document/fix Transport open method for specific caseMarek Zawirski, Aug 17, 2008
  6. 05/31 Fix RefSpec javadoc regarding spec expandingMarek Zawirski, Aug 17, 2008
  7. 06/31 Make wildcard checking public in RefSpecMarek Zawirski, Aug 17, 2008
  8. 07/31 Add openAll() and applyConfig() methods to TransportMarek Zawirski, Aug 17, 2008
  9. 08/31 Add dryRun option to Transport and console pushMarek Zawirski, Aug 17, 2008
  10. 09/31 Extract Transport findRemoteRefUpdatesFor() as static methodMarek Zawirski, Aug 17, 2008
  11. 10/31 Improve javadoc of Transport push()Marek Zawirski, Aug 17, 2008
  12. 11/31 Clean up exception issues in RemoteRefUpdateMarek Zawirski, Aug 17, 2008
  13. 12/31 Add another RemoteRefUpdate constructor, useful for 2-stage pushMarek Zawirski, Aug 17, 2008
  14. 13/31 Add getAllRemoteConfigs() to RemoteConfigMarek Zawirski, Aug 17, 2008
  15. 14/31 Add setFetchRefSpecs and setPushRefSpecs to RemoteConfigMarek Zawirski, Aug 17, 2008
  16. 15/31 Add simple abbreviate() method to ObjectIdMarek Zawirski, Aug 17, 2008
  17. 16/31 Remove debug/test console output from GitIndexMarek Zawirski, Aug 17, 2008
  18. 17/31 Fix typo in uitext.properties messageMarek Zawirski, Aug 17, 2008
  19. 18/31 Refactor/rewrite CloneSourcePage to universal RepositorySelectionPageMarek Zawirski, Aug 17, 2008
  20. 19/31 Clone wizard and related: refactor, clean-up, fixes or improvementsMarek Zawirski, Aug 17, 2008
  21. 20/31 Move clone logic away from GitCloneWizard to CloneOperationMarek Zawirski, Aug 17, 2008
  22. 21/31 Add canCreateSubdir() heuristic in CloneDestinationPageMarek Zawirski, Aug 17, 2008
  23. 22/31 Set FileDialog selection appropriately in clone wizardMarek Zawirski, Aug 17, 2008
  24. 23/31 Allow selecting empty dir in clone wizardMarek Zawirski, Aug 17, 2008
  25. 24/31 Clone wizard: force dir to suggested path only if repo selection changeMarek Zawirski, Aug 17, 2008
  26. 25/31 Create ListRemoteOperation for listing remote repo branchesMarek Zawirski, Aug 17, 2008
  27. 26/31 Make Clone's SourceBranchPage more user-friendlyMarek Zawirski, Aug 17, 2008
  28. 27/31 Add few EPL Eclipse iconsMarek Zawirski, Aug 17, 2008
  29. 28/31 Checkbox images/screenshotsMarek Zawirski, Aug 17, 2008
  30. 29/31 Universal GUI for specifications edition: RefSpecPanel and relatedMarek Zawirski, Aug 17, 2008
  31. 30/31 Add PushOperation to pluginMarek Zawirski, Aug 17, 2008
  32. 31/31 Push GUIMarek Zawirski, Aug 17, 2008
  33. Robin RosenbergAug 19, 2008
  34. Shawn O. PearceAug 19, 2008
  35. Shawn O. PearceAug 19, 2008
  36. Shawn O. PearceAug 19, 2008
  37. Robin RosenbergAug 19, 2008
  38. Marek ZawirskiAug 20, 2008
  39. 1/6 Remove DEFAULT_DRY_RUN constant from TransportMarek Zawirski, Aug 20, 2008
  40. 2/6 Emphasize that db is a local one in RemoteRefUpdateMarek Zawirski, Aug 20, 2008
  41. 3/6 Handle URIs parsing errors in PushAction betterMarek Zawirski, Aug 20, 2008
  42. 4/6 Fix proposal provider for fetch in RefSpecPanelMarek Zawirski, Aug 20, 2008
  43. 5/6 Fix disappearing "save configuration" label in RefSpecPageMarek Zawirski, Aug 20, 2008
  44. 6/6 Fix RefSpecPage formattingMarek Zawirski, Aug 20, 2008
  45. Shawn O. PearceAug 20, 2008
  46. Git-aware Issue Tracking?Petr Baudis, Aug 20, 2008
  47. Shawn O. PearceAug 20, 2008
  48. Robin RosenbergAug 20, 2008
  49. Martin LanghoffAug 21, 2008
  50. Jakub NarebskiAug 20, 2008
  51. Pierre HabouzitAug 21, 2008
  52. Jakub NarebskiAug 21, 2008
  53. Mike DalessioAug 20, 2008
  54. Imran M YousufAug 21, 2008
  55. Marek ZawirskiAug 25, 2008
  56. Shawn O. PearceAug 25, 2008
  57. Robin RosenbergAug 21, 2008
  58. Shawn O. PearceAug 21, 2008
  59. Robin RosenbergAug 21, 2008
  60. Shawn O. PearceAug 22, 2008
  61. Marek ZawirskiAug 25, 2008
  62. Shawn O. PearceAug 25, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.