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

[EGIT PATCH 15/23] Add String versions of methods in RefSpec

From
MZMarek Zawirski <marek.zawirski@gmail.com>
Date
Jun 27, 2008, 22:06 UTC
Message-ID
<1214604407-30572-16-git-send-email-marek.zawirski@gmail.com>
In-Reply-To
<1214604407-30572-15-git-send-email-marek.zawirski@gmail.com>

matchDestination(), matchSource(), expandFromSourec() can take String as parameter now, not only Ref (we just need a ref name).

Signed-off-by: Marek Zawirski <marek.zawirski@gmail.com>
---
 .../src/org/spearce/jgit/transport/RefSpec.java    |   46 +++++++++++++++++--
 1 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/RefSpec.java b/org.spearce.jgit/src/org/spearce/jgit/transport/RefSpec.java
index 38489be..1589e19 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/RefSpec.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/RefSpec.java
@@ -281,6 +281,17 @@ public class RefSpec {
 	}
 
 	/**
+	 * Does this specification's source description match the ref name?
+	 * 
+	 * @param r
+	 *            ref name that should be tested.
+	 * @return true if the names match; false otherwise.
+	 */
+	public boolean matchSource(final String r) {
+		return match(r, getSource());
+	}
+
+	/**
 	 * Does this specification's source description match the ref?
 	 * 
 	 * @param r
@@ -288,7 +299,18 @@ public class RefSpec {
 	 * @return true if the names match; false otherwise.
 	 */
 	public boolean matchSource(final Ref r) {
-		return match(r, getSource());
+		return match(r.getName(), getSource());
+	}
+
+	/**
+	 * Does this specification's destination description match the ref name?
+	 * 
+	 * @param r
+	 *            ref name that should be tested.
+	 * @return true if the names match; false otherwise.
+	 */
+	public boolean matchDestination(final String r) {
+		return match(r, getDestination());
 	}
 
 	/**
@@ -299,7 +321,21 @@ public class RefSpec {
 	 * @return true if the names match; false otherwise.
 	 */
 	public boolean matchDestination(final Ref r) {
-		return match(r, getDestination());
+		return match(r.getName(), getDestination());
+	}
+
+	/**
+	 * Expand this specification to exactly match a ref name.
+	 * <p>
+	 * Callers must first verify the passed ref name matches this specification,
+	 * otherwise expansion results may be unpredictable.
+	 * 
+	 * @param r
+	 *            a ref name that matched our source specification.
+	 * @return a new specification that is not a wildcard.
+	 */
+	public RefSpec expandFromSource(final String r) {
+		return isWildcard() ? new RefSpec(this, r) : this;
 	}
 
 	/**
@@ -316,12 +352,12 @@ public class RefSpec {
 		return isWildcard() ? new RefSpec(this, r.getName()) : this;
 	}
 
-	private boolean match(final Ref r, final String s) {
+	private boolean match(final String refName, final String s) {
 		if (s == null)
 			return false;
 		if (isWildcard())
-			return r.getName().startsWith(s.substring(0, s.length() - 1));
-		return r.getName().equals(s);
+			return refName.startsWith(s.substring(0, s.length() - 1));
+		return refName.equals(s);
 	}
 
 	public int hashCode() {
-- 
1.5.5.3
Previous: Marek ZawirskiNext: Marek Zawirski
Message 16 of 26 in “Push implementation”
  1. 00/23 Push implementationMarek Zawirski, Jun 27, 2008
  2. 01/23 Fix: let FetchProcess use fetch() instead of doFetch()Marek Zawirski, Jun 27, 2008
  3. 02/23 RefUpdate: new possible result Result.IO_FAILUREMarek Zawirski, Jun 27, 2008
  4. 03/23 Refactor TrackingRefUpdate to not hold RefSpecMarek Zawirski, Jun 27, 2008
  5. 04/23 New constructor without RefSpec for TrackingRefUpdateMarek Zawirski, Jun 27, 2008
  6. 05/23 Add RemoteRefUpdate classMarek Zawirski, Jun 27, 2008
  7. 06/23 Refactor: extract superclass OperationResult from FetchResultMarek Zawirski, Jun 27, 2008
  8. 07/23 Add PushResult classMarek Zawirski, Jun 27, 2008
  9. 08/23 Support for fetchThin and pushThin options in TransportMarek Zawirski, Jun 27, 2008
  10. 09/23 Big refactor: *Connection hierarchyMarek Zawirski, Jun 27, 2008
  11. 10/23 Add ignoreMissingUninteresting option to PackWriterMarek Zawirski, Jun 27, 2008
  12. 11/23 Add BasePackPushConnection implementing git-send-pack protocolMarek Zawirski, Jun 27, 2008
  13. 12/23 Fix: let RevWalk reset correctly before isMergedInto()Marek Zawirski, Jun 27, 2008
  14. 13/23 Add PushProcess class implementing git-send-pack logicMarek Zawirski, Jun 27, 2008
  15. 14/23 Clarify Repository#resolve() documentationMarek Zawirski, Jun 27, 2008
  16. 15/23 Add String versions of methods in RefSpecMarek Zawirski, Jun 27, 2008
  17. 16/23 Transport* - general support for push() and implementationsMarek Zawirski, Jun 27, 2008
  18. 17/23 Test cases for PushProcessMarek Zawirski, Jun 27, 2008
  19. 18/23 Test cases for RefSpec to RemoteRefUpdate conversionsMarek Zawirski, Jun 27, 2008
  20. 19/23 Repository search for command line toolsMarek Zawirski, Jun 27, 2008
  21. 20/23 Push command line utilityMarek Zawirski, Jun 27, 2008
  22. 21/23 Don't accept RefSpec with null source for fetchMarek Zawirski, Jun 27, 2008
  23. 22/23 Add new handy constructors to TransportException, PackProtocolExceptionMarek Zawirski, Jun 27, 2008
  24. 23/23 Use new TransportException constructorsMarek Zawirski, Jun 27, 2008
  25. Robin RosenbergJun 28, 2008
  26. Robin RosenbergJun 27, 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.