Git development
 help / color / mirror / Atom feed
From: Michael Loeffler <zvpunry@zvpunry.de>
To: git@vger.kernel.org
Subject: [PATCH 3/3] git-fetch: allow regular expressions in the refspec
Date: Mon, 04 Dec 2006 20:45:33 +0100	[thread overview]
Message-ID: <1165261534.20871.1.camel@ibook.zvpunry.de> (raw)

This allows the use of regex in refspecs, but it does not support
extended regex because the option -r is a GNU-sed extension.

Now it is possible to write the following refspecs:

Pull: refs/heads/master:refs/remotes/origin/master
Pull: refs/heads/:refs/remotes/origin/
Pull: refs/heads/\(.*fetch.*\):refs/heads/fetch/\1

Signed-off-by: Michael Loeffler <zvpunry@zvpunry.de>
---
This patch has still some problems with MacOS X (I think it is the
sed-script). I will look at it tomorrow.

What do you think about this?

diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index 38af4cb..0162154 100755
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -100,30 +100,86 @@ expand_refs_wildcard () {
 	for ref
 	do
 		lref=${ref#'+'}
-		# a non glob pattern is given back as-is.
-		expr "z$lref" : 'zrefs/.*/:refs/.*/$' >/dev/null || {
-			echo "$ref"
-			continue
-		}
-
-		from=`expr "z$lref" : 'z\(refs/.*/\):refs/.*/$'`
-		to=`expr "z$lref" : 'zrefs/.*/:\(refs/.*/\)$'`
 		local_force=
 		test "z$lref" = "z$ref" || local_force='+'
-		echo "$ls_remote_result" |
-		(
-			IFS='	'
-			while read sha1 name
-			do
-				mapped=${name#"$from"}
-				if test "z$name" != "z${name%'^{}'}" ||
-					test "z$name" = "z$mapped"
-				then
-					continue
-				fi
-				echo "${local_force}${name}:${to}${mapped}"
-			done
-		)
+
+		if expr "z$lref" : 'zrefs/.*/:refs/.*/$' >/dev/null
+		then
+			from=`expr "z$lref" : 'z\(refs/.*/\):refs/.*/$'`
+			to=`expr "z$lref" : 'zrefs/.*/:\(refs/.*/\)$'`
+			echo "$ls_remote_result" |
+			(
+				IFS='	'
+				while read sha1 name
+				do
+					mapped=${name#"$from"}
+					if test "z$name" != "z${name%'^{}'}" ||
+						test "z$name" = "z$mapped"
+					then
+						continue
+					fi
+					echo "${local_force}${name}:${to}${mapped}"
+				done
+			)
+		else
+			local srcref dstref sedscript mapped
+
+			srcref=`expr "z$lref" : "z\(refs/[^:]*\):refs/[^:]*$"`
+			dstref=`expr "z$lref" : "zrefs/[^:]*:\(refs/[^:]*\)$"`
+			sedscript="
+# ignore dereferenced tags
+/\^{}$/{
+	# delete pattern space and start next cycle
+	d
+}
+
+# remove sha1 and the '\t'
+s/^[a-f0-9]\{40\}\t//
+
+# for each matching ref, do the following
+\:${srcref}:{
+	# copy the ref name into the hold space
+	h
+
+	# prepend local_force to the new srcref
+	s/^/${local_force}/
+
+	# append an colon to the new srcref
+	s/$/:/
+
+	# exchange pattern and hold space
+	x
+
+	# do the substitution
+	s:${srcref}:${dstref}:
+
+	# append the new dstref to the hold space
+	H
+
+	# exchange pattern and hold space
+	x
+
+	# remove the embedded newline to build the new refspec
+	s/:\n/:/
+
+	# print the new refspec
+	p
+}
+"
+			mapped=$(echo "$ls_remote_result" | sed -n -e "$sedscript")
+
+			if test "$?" -ne 0
+			then
+				echo "The failed refspec was: ${srcref}:${dstref}" >&2
+			fi
+
+			if test -z "$mapped"
+			then
+				echo "$ref"
+			else
+				echo "$mapped"
+			fi
+		fi
 	done
 }
 
-- 
1.4.4


                 reply	other threads:[~2006-12-04 19:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1165261534.20871.1.camel@ibook.zvpunry.de \
    --to=zvpunry@zvpunry.de \
    --cc=git@vger.kernel.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