git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marek Zawirski <marek.zawirski@gmail.com>
To: robin.rosenberg@dewire.com, spearce@spearce.org
Cc: git@vger.kernel.org, Marek Zawirski <marek.zawirski@gmail.com>
Subject: [EGIT PATCH 09/31] Extract Transport findRemoteRefUpdatesFor() as static method
Date: Sun, 17 Aug 2008 22:43:50 +0200	[thread overview]
Message-ID: <1219005852-21496-10-git-send-email-marek.zawirski@gmail.com> (raw)
In-Reply-To: <1219005852-21496-9-git-send-email-marek.zawirski@gmail.com>

This method could be used outside of specific URI scope, so let it be
static. Otherwise, if someone want to generate remote ref updates from
refspecs he/she may have to create some dummy transport just for that.

Signed-off-by: Marek Zawirski <marek.zawirski@gmail.com>
---
 .../src/org/spearce/jgit/transport/Transport.java  |  147 ++++++++++++--------
 1 files changed, 90 insertions(+), 57 deletions(-)

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 98853e6..e986e48 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/Transport.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/Transport.java
@@ -211,7 +211,92 @@ public abstract class Transport {
 
 		throw new NotSupportedException("URI not supported: " + remote);
 	}
+	
+	/**
+	 * Convert push remote refs update specification from {@link RefSpec} form
+	 * to {@link RemoteRefUpdate}. Conversion expands wildcards by matching
+	 * source part to local refs. expectedOldObjectId in RemoteRefUpdate is
+	 * always set as null. Tracking branch is configured if RefSpec destination
+	 * matches source of any fetch ref spec for this transport remote
+	 * configuration.
+	 * 
+	 * @param db
+	 *            local database.
+	 * @param specs
+	 *            collection of RefSpec to convert.
+	 * @param fetchSpecs
+	 *            fetch specifications used for finding localtracking refs. May
+	 *            be null or empty collection.
+	 * @return collection of set up {@link RemoteRefUpdate}.
+	 * @throws TransportException
+	 *             when problem occurred during conversion or specification set
+	 *             up: most probably, missing objects or refs.
+	 */
+	public static Collection<RemoteRefUpdate> findRemoteRefUpdatesFor(
+			final Repository db, final Collection<RefSpec> specs,
+			Collection<RefSpec> fetchSpecs) throws TransportException {
+		if (fetchSpecs == null)
+			fetchSpecs = Collections.emptyList();
+		final List<RemoteRefUpdate> result = new LinkedList<RemoteRefUpdate>();
+		final Collection<RefSpec> procRefs = expandPushWildcardsFor(db, specs);
+
+		for (final RefSpec spec : procRefs) {
+			try {
+				final String srcRef = spec.getSource();
+				// null destination (no-colon in ref-spec) is a special case
+				final String remoteName = (spec.getDestination() == null ? spec
+						.getSource() : spec.getDestination());
+				final boolean forceUpdate = spec.isForceUpdate();
+				final String localName = findTrackingRefName(remoteName,
+						fetchSpecs);
+
+				final RemoteRefUpdate rru = new RemoteRefUpdate(db, srcRef,
+						remoteName, forceUpdate, localName, null);
+				result.add(rru);
+			} catch (TransportException x) {
+				throw x;
+			} catch (Exception x) {
+				throw new TransportException(
+						"Problem with resolving push ref spec \"" + spec
+								+ "\" locally: " + x.getMessage(), x);
+			}
+		}
+		return result;
+	}
+
+	private static Collection<RefSpec> expandPushWildcardsFor(
+			final Repository db, final Collection<RefSpec> specs) {
+		final Map<String, Ref> localRefs = db.getAllRefs();
+		final Collection<RefSpec> procRefs = new HashSet<RefSpec>();
 
+		for (final RefSpec spec : specs) {
+			if (spec.isWildcard()) {
+				for (final Ref localRef : localRefs.values()) {
+					if (spec.matchSource(localRef))
+						procRefs.add(spec.expandFromSource(localRef));
+				}
+			} else {
+				procRefs.add(spec);
+			}
+		}
+		return procRefs;
+	}
+
+	private static String findTrackingRefName(final String remoteName,
+			final Collection<RefSpec> fetchSpecs) {
+		// try to find matching tracking refs
+		for (final RefSpec fetchSpec : fetchSpecs) {
+			if (fetchSpec.matchSource(remoteName)) {
+				if (fetchSpec.isWildcard())
+					return fetchSpec.expandFromSource(remoteName)
+							.getDestination();
+				else
+					return fetchSpec.getDestination();
+			}
+		}
+		return null;
+	}
+	
 	/**
 	 * Default setting for {@link #fetchThin} option.
 	 */
@@ -573,7 +658,10 @@ public abstract class Transport {
 	 * always set as null. Tracking branch is configured if RefSpec destination
 	 * matches source of any fetch ref spec for this transport remote
 	 * configuration.
-	 *
+	 * <p>
+	 * Conversion is performed for context of this transport (database, fetch
+	 * specifications).
+	 * 
 	 * @param specs
 	 *            collection of RefSpec to convert.
 	 * @return collection of set up {@link RemoteRefUpdate}.
@@ -583,30 +671,7 @@ public abstract class Transport {
 	 */
 	public Collection<RemoteRefUpdate> findRemoteRefUpdatesFor(
 			final Collection<RefSpec> specs) throws TransportException {
-		final List<RemoteRefUpdate> result = new LinkedList<RemoteRefUpdate>();
-		final Collection<RefSpec> procRefs = expandPushWildcardsFor(specs);
-
-		for (final RefSpec spec : procRefs) {
-			try {
-				final String srcRef = spec.getSource();
-				// null destination (no-colon in ref-spec) is a special case
-				final String remoteName = (spec.getDestination() == null ? spec
-						.getSource() : spec.getDestination());
-				final boolean forceUpdate = spec.isForceUpdate();
-				final String localName = findTrackingRefName(remoteName);
-
-				final RemoteRefUpdate rru = new RemoteRefUpdate(local, srcRef,
-						remoteName, forceUpdate, localName, null);
-				result.add(rru);
-			} catch (TransportException x) {
-				throw x;
-			} catch (Exception x) {
-				throw new TransportException(
-						"Problem with resolving push ref spec \"" + spec
-								+ "\" locally: " + x.getMessage(), x);
-			}
-		}
-		return result;
+		return findRemoteRefUpdatesFor(local, specs, fetch);
 	}
 
 	/**
@@ -642,36 +707,4 @@ public abstract class Transport {
 	 * any open file handles used to read the "remote" repository.
 	 */
 	public abstract void close();
-
-	private Collection<RefSpec> expandPushWildcardsFor(
-			final Collection<RefSpec> specs) {
-		final Map<String, Ref> localRefs = local.getAllRefs();
-		final Collection<RefSpec> procRefs = new HashSet<RefSpec>();
-
-		for (final RefSpec spec : specs) {
-			if (spec.isWildcard()) {
-				for (final Ref localRef : localRefs.values()) {
-					if (spec.matchSource(localRef))
-						procRefs.add(spec.expandFromSource(localRef));
-				}
-			} else {
-				procRefs.add(spec);
-			}
-		}
-		return procRefs;
-	}
-
-	private String findTrackingRefName(final String remoteName) {
-		// try to find matching tracking refs
-		for (final RefSpec fetchSpec : fetch) {
-			if (fetchSpec.matchSource(remoteName)) {
-				if (fetchSpec.isWildcard())
-					return fetchSpec.expandFromSource(remoteName)
-							.getDestination();
-				else
-					return fetchSpec.getDestination();
-			}
-		}
-		return null;
-	}
 }
-- 
1.5.6.3

  reply	other threads:[~2008-08-17 20:45 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-17 20:43 [EGIT PATCH 00/31] Push GUI, GUI improvements, various jgit stuff Marek Zawirski
2008-08-17 20:43 ` [EGIT PATCH 01/31] Fix Repository.mapObject() for missing objects Marek Zawirski
2008-08-17 20:43   ` [EGIT PATCH 02/31] Fix Repository isValidRefName() for empty names Marek Zawirski
2008-08-17 20:43     ` [EGIT PATCH 03/31] Fix Repository.resolve() to not throw runtime exceptions Marek Zawirski
2008-08-17 20:43       ` [EGIT PATCH 04/31] Document/fix Transport open method for specific case Marek Zawirski
2008-08-17 20:43         ` [EGIT PATCH 05/31] Fix RefSpec javadoc regarding spec expanding Marek Zawirski
2008-08-17 20:43           ` [EGIT PATCH 06/31] Make wildcard checking public in RefSpec Marek Zawirski
2008-08-17 20:43             ` [EGIT PATCH 07/31] Add openAll() and applyConfig() methods to Transport Marek Zawirski
2008-08-17 20:43               ` [EGIT PATCH 08/31] Add dryRun option to Transport and console push Marek Zawirski
2008-08-17 20:43                 ` Marek Zawirski [this message]
2008-08-17 20:43                   ` [EGIT PATCH 10/31] Improve javadoc of Transport push() Marek Zawirski
2008-08-17 20:43                     ` [EGIT PATCH 11/31] Clean up exception issues in RemoteRefUpdate Marek Zawirski
2008-08-17 20:43                       ` [EGIT PATCH 12/31] Add another RemoteRefUpdate constructor, useful for 2-stage push Marek Zawirski
2008-08-17 20:43                         ` [EGIT PATCH 13/31] Add getAllRemoteConfigs() to RemoteConfig Marek Zawirski
2008-08-17 20:43                           ` [EGIT PATCH 14/31] Add setFetchRefSpecs and setPushRefSpecs " Marek Zawirski
2008-08-17 20:43                             ` [EGIT PATCH 15/31] Add simple abbreviate() method to ObjectId Marek Zawirski
2008-08-17 20:43                               ` [EGIT PATCH 16/31] Remove debug/test console output from GitIndex Marek Zawirski
2008-08-17 20:43                                 ` [EGIT PATCH 17/31] Fix typo in uitext.properties message Marek Zawirski
2008-08-17 20:43                                   ` [EGIT PATCH 18/31] Refactor/rewrite CloneSourcePage to universal RepositorySelectionPage Marek Zawirski
2008-08-17 20:44                                     ` [EGIT PATCH 19/31] Clone wizard and related: refactor, clean-up, fixes or improvements Marek Zawirski
2008-08-17 20:44                                       ` [EGIT PATCH 20/31] Move clone logic away from GitCloneWizard to CloneOperation Marek Zawirski
2008-08-17 20:44                                         ` [EGIT PATCH 21/31] Add canCreateSubdir() heuristic in CloneDestinationPage Marek Zawirski
2008-08-17 20:44                                           ` [EGIT PATCH 22/31] Set FileDialog selection appropriately in clone wizard Marek Zawirski
2008-08-17 20:44                                             ` [EGIT PATCH 23/31] Allow selecting empty dir " Marek Zawirski
2008-08-17 20:44                                               ` [EGIT PATCH 24/31] Clone wizard: force dir to suggested path only if repo selection change Marek Zawirski
2008-08-17 20:44                                                 ` [EGIT PATCH 25/31] Create ListRemoteOperation for listing remote repo branches Marek Zawirski
2008-08-17 20:44                                                   ` [EGIT PATCH 26/31] Make Clone's SourceBranchPage more user-friendly Marek Zawirski
2008-08-17 20:44                                                     ` [EGIT PATCH 27/31] Add few EPL Eclipse icons Marek Zawirski
2008-08-17 20:44                                                       ` [EGIT PATCH 28/31] Checkbox images/screenshots Marek Zawirski
2008-08-17 20:44                                                         ` [EGIT PATCH 29/31] Universal GUI for specifications edition: RefSpecPanel and related Marek Zawirski
2008-08-17 20:44                                                           ` [EGIT PATCH 30/31] Add PushOperation to plugin Marek Zawirski
2008-08-17 20:44                                                             ` [EGIT PATCH 31/31] Push GUI Marek Zawirski
2008-08-19 18:24                                                         ` [EGIT PATCH 28/31] Checkbox images/screenshots Robin Rosenberg
2008-08-19 16:45                         ` [EGIT PATCH 12/31] Add another RemoteRefUpdate constructor, useful for 2-stage push Shawn O. Pearce
2008-08-19 16:28                 ` [EGIT PATCH 08/31] Add dryRun option to Transport and console push Shawn O. Pearce
2008-08-19 17:59 ` [EGIT PATCH 00/31] Push GUI, GUI improvements, various jgit stuff Shawn O. Pearce
2008-08-19 19:21   ` Robin Rosenberg
2008-08-20  2:42     ` Marek Zawirski
2008-08-20  2:57       ` [EGIT PATCH 1/6] Remove DEFAULT_DRY_RUN constant from Transport Marek Zawirski
2008-08-20  2:57         ` [EGIT PATCH 2/6] Emphasize that db is a local one in RemoteRefUpdate Marek Zawirski
2008-08-20  2:57           ` [EGIT PATCH 3/6] Handle URIs parsing errors in PushAction better Marek Zawirski
2008-08-20  2:57             ` [EGIT PATCH 4/6] Fix proposal provider for fetch in RefSpecPanel Marek Zawirski
2008-08-20  2:57               ` [EGIT PATCH 5/6] Fix disappearing "save configuration" label in RefSpecPage Marek Zawirski
2008-08-20  2:57                 ` [EGIT PATCH 6/6] Fix RefSpecPage formatting Marek Zawirski
2008-08-20 14:13       ` [EGIT PATCH 00/31] Push GUI, GUI improvements, various jgit stuff Shawn O. Pearce
2008-08-20 15:23         ` Git-aware Issue Tracking? Petr Baudis
2008-08-20 16:44           ` Shawn O. Pearce
2008-08-20 20:25             ` Robin Rosenberg
2008-08-21  8:47             ` Martin Langhoff
2008-08-20 18:52           ` Jakub Narebski
2008-08-21  8:30             ` Pierre Habouzit
2008-08-21  9:23               ` Jakub Narebski
2008-08-20 20:22           ` Mike Dalessio
2008-08-21  8:55           ` Imran M Yousuf
2008-08-25 13:59         ` [EGIT PATCH 00/31] Push GUI, GUI improvements, various jgit stuff Marek Zawirski
2008-08-25 14:24           ` Shawn O. Pearce
2008-08-21 20:12       ` Robin Rosenberg
2008-08-21 20:16         ` Shawn O. Pearce
2008-08-21 23:25           ` Robin Rosenberg
2008-08-22  3:05             ` Shawn O. Pearce
2008-08-25 14:13             ` Marek Zawirski
2008-08-25 14:15               ` Shawn O. Pearce

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1219005852-21496-10-git-send-email-marek.zawirski@gmail.com \
    --to=marek.zawirski@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=robin.rosenberg@dewire.com \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).