{"thread":{"id":"43619","subject":"[PATCH 3/3] git-fetch: allow regular expressions in the refspec","startedAt":"2006-12-04T19:45:33Z","lastAt":"2006-12-04T19:45:33Z","messageCount":1,"participants":["Michael Loeffler"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"296040","messageId":"1165261534.20871.1.camel@ibook.zvpunry.de","threadId":"43619","inReplyTo":null,"subject":"[PATCH 3/3] git-fetch: allow regular expressions in the refspec","fromName":"Michael Loeffler","fromEmail":"zvpunry@zvpunry.de","sentAt":"2006-12-04T19:45:33Z","receivedAt":"2006-12-04T19:45:33Z","isPatch":true,"sender":{"key":"zvpunry@zvpunry.de","avatar":null},"body":"This allows the use of regex in refspecs, but it does not support\nextended regex because the option -r is a GNU-sed extension.\n\nNow it is possible to write the following refspecs:\n\nPull: refs/heads/master:refs/remotes/origin/master\nPull: refs/heads/:refs/remotes/origin/\nPull: refs/heads/\\(.*fetch.*\\):refs/heads/fetch/\\1\n\nSigned-off-by: Michael Loeffler <zvpunry@zvpunry.de>\n---\nThis patch has still some problems with MacOS X (I think it is the\nsed-script). I will look at it tomorrow.\n\nWhat do you think about this?\n\ndiff --git a/git-parse-remote.sh b/git-parse-remote.sh\nindex 38af4cb..0162154 100755\n--- a/git-parse-remote.sh\n+++ b/git-parse-remote.sh\n@@ -100,30 +100,86 @@ expand_refs_wildcard () {\n \tfor ref\n \tdo\n \t\tlref=${ref#'+'}\n-\t\t# a non glob pattern is given back as-is.\n-\t\texpr \"z$lref\" : 'zrefs/.*/:refs/.*/$' >/dev/null || {\n-\t\t\techo \"$ref\"\n-\t\t\tcontinue\n-\t\t}\n-\n-\t\tfrom=`expr \"z$lref\" : 'z\\(refs/.*/\\):refs/.*/$'`\n-\t\tto=`expr \"z$lref\" : 'zrefs/.*/:\\(refs/.*/\\)$'`\n \t\tlocal_force=\n \t\ttest \"z$lref\" = \"z$ref\" || local_force='+'\n-\t\techo \"$ls_remote_result\" |\n-\t\t(\n-\t\t\tIFS='\t'\n-\t\t\twhile read sha1 name\n-\t\t\tdo\n-\t\t\t\tmapped=${name#\"$from\"}\n-\t\t\t\tif test \"z$name\" != \"z${name%'^{}'}\" ||\n-\t\t\t\t\ttest \"z$name\" = \"z$mapped\"\n-\t\t\t\tthen\n-\t\t\t\t\tcontinue\n-\t\t\t\tfi\n-\t\t\t\techo \"${local_force}${name}:${to}${mapped}\"\n-\t\t\tdone\n-\t\t)\n+\n+\t\tif expr \"z$lref\" : 'zrefs/.*/:refs/.*/$' >/dev/null\n+\t\tthen\n+\t\t\tfrom=`expr \"z$lref\" : 'z\\(refs/.*/\\):refs/.*/$'`\n+\t\t\tto=`expr \"z$lref\" : 'zrefs/.*/:\\(refs/.*/\\)$'`\n+\t\t\techo \"$ls_remote_result\" |\n+\t\t\t(\n+\t\t\t\tIFS='\t'\n+\t\t\t\twhile read sha1 name\n+\t\t\t\tdo\n+\t\t\t\t\tmapped=${name#\"$from\"}\n+\t\t\t\t\tif test \"z$name\" != \"z${name%'^{}'}\" ||\n+\t\t\t\t\t\ttest \"z$name\" = \"z$mapped\"\n+\t\t\t\t\tthen\n+\t\t\t\t\t\tcontinue\n+\t\t\t\t\tfi\n+\t\t\t\t\techo \"${local_force}${name}:${to}${mapped}\"\n+\t\t\t\tdone\n+\t\t\t)\n+\t\telse\n+\t\t\tlocal srcref dstref sedscript mapped\n+\n+\t\t\tsrcref=`expr \"z$lref\" : \"z\\(refs/[^:]*\\):refs/[^:]*$\"`\n+\t\t\tdstref=`expr \"z$lref\" : \"zrefs/[^:]*:\\(refs/[^:]*\\)$\"`\n+\t\t\tsedscript=\"\n+# ignore dereferenced tags\n+/\\^{}$/{\n+\t# delete pattern space and start next cycle\n+\td\n+}\n+\n+# remove sha1 and the '\\t'\n+s/^[a-f0-9]\\{40\\}\\t//\n+\n+# for each matching ref, do the following\n+\\:${srcref}:{\n+\t# copy the ref name into the hold space\n+\th\n+\n+\t# prepend local_force to the new srcref\n+\ts/^/${local_force}/\n+\n+\t# append an colon to the new srcref\n+\ts/$/:/\n+\n+\t# exchange pattern and hold space\n+\tx\n+\n+\t# do the substitution\n+\ts:${srcref}:${dstref}:\n+\n+\t# append the new dstref to the hold space\n+\tH\n+\n+\t# exchange pattern and hold space\n+\tx\n+\n+\t# remove the embedded newline to build the new refspec\n+\ts/:\\n/:/\n+\n+\t# print the new refspec\n+\tp\n+}\n+\"\n+\t\t\tmapped=$(echo \"$ls_remote_result\" | sed -n -e \"$sedscript\")\n+\n+\t\t\tif test \"$?\" -ne 0\n+\t\t\tthen\n+\t\t\t\techo \"The failed refspec was: ${srcref}:${dstref}\" >&2\n+\t\t\tfi\n+\n+\t\t\tif test -z \"$mapped\"\n+\t\t\tthen\n+\t\t\t\techo \"$ref\"\n+\t\t\telse\n+\t\t\t\techo \"$mapped\"\n+\t\t\tfi\n+\t\tfi\n \tdone\n }\n \n-- \n1.4.4\n\n"}]}