* [PATCH 3/3] git-fetch: allow regular expressions in the refspec
@ 2006-12-04 19:45 Michael Loeffler
0 siblings, 0 replies; only message in thread
From: Michael Loeffler @ 2006-12-04 19:45 UTC (permalink / raw)
To: git
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2006-12-04 19:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-04 19:45 [PATCH 3/3] git-fetch: allow regular expressions in the refspec Michael Loeffler
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox