{"thread":{"id":"15137","subject":"[PATCH] filter-branch: Grok special characters in tag names","startedAt":"2008-08-21T14:45:11Z","lastAt":"2008-08-21T21:34:52Z","messageCount":6,"participants":["Johannes Sixt","Brandon Casey","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"87991","messageId":"1219329911-31620-1-git-send-email-johannes.sixt@telecom.at","threadId":"15137","inReplyTo":null,"subject":"[PATCH] filter-branch: Grok special characters in tag names","fromName":"Johannes Sixt","fromEmail":"johannes.sixt@telecom.at","sentAt":"2008-08-21T14:45:11Z","receivedAt":"2008-08-21T14:45:11Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"The tag rewriting code used a 'sed' expression to substitute the new tag\nname into the corresponding field of the annotated tag object. But this is\nproblematic if the tag name contains special characters. In particular,\nif the tag name contained a slash, then the 'sed' expression had a syntax\nerror. We now protect against this by using 'printf' to assemble the\ntag header.\n\nSigned-off-by: Johannes Sixt <johannes.sixt@telecom.at>\n---\n git-filter-branch.sh     |   12 +++++++-----\n t/t7003-filter-branch.sh |    8 ++++++++\n 2 files changed, 15 insertions(+), 5 deletions(-)\n\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex 2688254..81392ad 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -412,15 +412,17 @@ if [ \"$filter_tag_name\" ]; then\n \t\techo \"$ref -> $new_ref ($sha1 -> $new_sha1)\"\n \n \t\tif [ \"$type\" = \"tag\" ]; then\n-\t\t\tnew_sha1=$(git cat-file tag \"$ref\" |\n+\t\t\tnew_sha1=$( ( printf 'object %s\\ntype commit\\ntag %s\\n' \\\n+\t\t\t\t\t\t\"$new_sha1\" \"$new_ref\"\n+\t\t\t\tgit cat-file tag \"$ref\" |\n \t\t\t\tsed -n \\\n \t\t\t\t    -e \"1,/^$/{\n-\t\t\t\t\t  s/^object .*/object $new_sha1/\n-\t\t\t\t\t  s/^type .*/type commit/\n-\t\t\t\t\t  s/^tag .*/tag $new_ref/\n+\t\t\t\t\t  /^object /d\n+\t\t\t\t\t  /^type /d\n+\t\t\t\t\t  /^tag /d\n \t\t\t\t\t}\" \\\n \t\t\t\t    -e '/^-----BEGIN PGP SIGNATURE-----/q' \\\n-\t\t\t\t    -e 'p' |\n+\t\t\t\t    -e 'p' ) |\n \t\t\t\tgit mktag) ||\n \t\t\t\tdie \"Could not create new tag object for $ref\"\n \t\t\tif git cat-file tag \"$ref\" | \\\ndiff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh\nindex 233254f..95f13a8 100755\n--- a/t/t7003-filter-branch.sh\n+++ b/t/t7003-filter-branch.sh\n@@ -254,4 +254,12 @@ test_expect_success 'Tag name filtering strips gpg signature' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'Tag name filtering allows slashes in tag names' '\n+\tgit tag -m tag-with-slash X/1 &&\n+\tgit cat-file tag X/1 | sed -e s,X/1,X/2, > expect &&\n+\tgit filter-branch -f --tag-name-filter \"echo X/2\" &&\n+\tgit cat-file tag X/2 > actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n1.6.0.137.g19b5f8c\n"},{"id":"88006","messageId":"NWVPkDIELqWBHTU58gfzDqO8HR575ZDJVO2pYdPMtqv9aBLzMLvyZg@cipher.nrlssc.navy.mil","threadId":"15137","inReplyTo":"1219329911-31620-1-git-send-email-johannes.sixt@telecom.at","subject":"Re: [PATCH] filter-branch: Grok special characters in tag names","fromName":"Brandon Casey","fromEmail":"casey@nrlssc.navy.mil","sentAt":"2008-08-21T16:38:20Z","receivedAt":"2008-08-21T16:38:20Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"Johannes Sixt wrote:\n\n> diff --git a/git-filter-branch.sh b/git-filter-branch.sh\n> index 2688254..81392ad 100755\n> --- a/git-filter-branch.sh\n> +++ b/git-filter-branch.sh\n> @@ -412,15 +412,17 @@ if [ \"$filter_tag_name\" ]; then\n>  \t\techo \"$ref -> $new_ref ($sha1 -> $new_sha1)\"\n>  \n>  \t\tif [ \"$type\" = \"tag\" ]; then\n> -\t\t\tnew_sha1=$(git cat-file tag \"$ref\" |\n> +\t\t\tnew_sha1=$( ( printf 'object %s\\ntype commit\\ntag %s\\n' \\\n> +\t\t\t\t\t\t\"$new_sha1\" \"$new_ref\"\n> +\t\t\t\tgit cat-file tag \"$ref\" |\n>  \t\t\t\tsed -n \\\n>  \t\t\t\t    -e \"1,/^$/{\n> -\t\t\t\t\t  s/^object .*/object $new_sha1/\n> -\t\t\t\t\t  s/^type .*/type commit/\n> -\t\t\t\t\t  s/^tag .*/tag $new_ref/\n> +\t\t\t\t\t  /^object /d\n> +\t\t\t\t\t  /^type /d\n> +\t\t\t\t\t  /^tag /d\n\nJunio complained that my initial version of this was fragile which has\nsimilarities with the above. Initially, I was blindly changing the first line\nto contain \"object...\", second line to \"type...\", etc.\n\nWould something like the following be equivalent _and_ clearer? Emphasis on \"and\"\nbecause both are necessary, not because I strongly feel it to be so.\n\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex a324cf0..11c5c04 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -419,9 +419,12 @@ if [ \"$filter_tag_name\" ]; then\n \t\t\tnew_sha1=$(git cat-file tag \"$ref\" |\n \t\t\t\tsed -n \\\n \t\t\t\t    -e \"1,/^$/{\n-\t\t\t\t\t  s/^object .*/object $new_sha1/\n-\t\t\t\t\t  s/^type .*/type commit/\n-\t\t\t\t\t  s/^tag .*/tag $new_ref/\n+\t\t\t\t\t  /^object .*/c\\\\\n+object $new_sha1\n+\t\t\t\t\t  /^type .*/c\\\\\n+type commit\n+\t\t\t\t\t  /^tag .*/c\\\\\n+tag $new_ref\n \t\t\t\t\t}\" \\\n \t\t\t\t    -e '/^-----BEGIN PGP SIGNATURE-----/q' \\\n \t\t\t\t    -e 'p' |\n\n\n-brandon\n"},{"id":"88018","messageId":"200808212107.33474.johannes.sixt@telecom.at","threadId":"15137","inReplyTo":"NWVPkDIELqWBHTU58gfzDqO8HR575ZDJVO2pYdPMtqv9aBLzMLvyZg@cipher.nrlssc.navy.mil","subject":"Re: [PATCH] filter-branch: Grok special characters in tag names","fromName":"Johannes Sixt","fromEmail":"johannes.sixt@telecom.at","sentAt":"2008-08-21T19:07:33Z","receivedAt":"2008-08-21T19:07:33Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"On Donnerstag, 21. August 2008, Brandon Casey wrote:\n> Johannes Sixt wrote:\n> > diff --git a/git-filter-branch.sh b/git-filter-branch.sh\n> > index 2688254..81392ad 100755\n> > --- a/git-filter-branch.sh\n> > +++ b/git-filter-branch.sh\n> > @@ -412,15 +412,17 @@ if [ \"$filter_tag_name\" ]; then\n> >  \t\techo \"$ref -> $new_ref ($sha1 -> $new_sha1)\"\n> >\n> >  \t\tif [ \"$type\" = \"tag\" ]; then\n> > -\t\t\tnew_sha1=$(git cat-file tag \"$ref\" |\n> > +\t\t\tnew_sha1=$( ( printf 'object %s\\ntype commit\\ntag %s\\n' \\\n> > +\t\t\t\t\t\t\"$new_sha1\" \"$new_ref\"\n> > +\t\t\t\tgit cat-file tag \"$ref\" |\n> >  \t\t\t\tsed -n \\\n> >  \t\t\t\t    -e \"1,/^$/{\n> > -\t\t\t\t\t  s/^object .*/object $new_sha1/\n> > -\t\t\t\t\t  s/^type .*/type commit/\n> > -\t\t\t\t\t  s/^tag .*/tag $new_ref/\n> > +\t\t\t\t\t  /^object /d\n> > +\t\t\t\t\t  /^type /d\n> > +\t\t\t\t\t  /^tag /d\n>\n> Junio complained that my initial version of this was fragile which has\n> similarities with the above. Initially, I was blindly changing the first\n> line to contain \"object...\", second line to \"type...\", etc.\n\nI don't see what's wrong with that. \"object\" must be the first line anyway, \notherwise git mktag chokes.\n\n> Would something like the following be equivalent _and_ clearer? Emphasis on\n> \"and\" because both are necessary, not because I strongly feel it to be so.\n>\n> diff --git a/git-filter-branch.sh b/git-filter-branch.sh\n> index a324cf0..11c5c04 100755\n> --- a/git-filter-branch.sh\n> +++ b/git-filter-branch.sh\n> @@ -419,9 +419,12 @@ if [ \"$filter_tag_name\" ]; then\n>  \t\t\tnew_sha1=$(git cat-file tag \"$ref\" |\n>  \t\t\t\tsed -n \\\n>  \t\t\t\t    -e \"1,/^$/{\n> -\t\t\t\t\t  s/^object .*/object $new_sha1/\n> -\t\t\t\t\t  s/^type .*/type commit/\n> -\t\t\t\t\t  s/^tag .*/tag $new_ref/\n> +\t\t\t\t\t  /^object .*/c\\\\\n> +object $new_sha1\n> +\t\t\t\t\t  /^type .*/c\\\\\n> +type commit\n> +\t\t\t\t\t  /^tag .*/c\\\\\n> +tag $new_ref\n>  \t\t\t\t\t}\" \\\n>  \t\t\t\t    -e '/^-----BEGIN PGP SIGNATURE-----/q' \\\n>  \t\t\t\t    -e 'p' |\n\nThis looks fine, too. (The '.*' in /^foo .*/c\\\\ is unnecessary.)\n\n-- Hannes\n"},{"id":"88020","messageId":"ON1COPVuxZx0fvgxvAxMTeg1TI9wGwA6G-XV3THb5Y5XvUoIzNchBg@cipher.nrlssc.navy.mil","threadId":"15137","inReplyTo":"200808212107.33474.johannes.sixt@telecom.at","subject":"Re: [PATCH] filter-branch: Grok special characters in tag names","fromName":"Brandon Casey","fromEmail":"casey@nrlssc.navy.mil","sentAt":"2008-08-21T19:35:03Z","receivedAt":"2008-08-21T19:35:03Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"Johannes Sixt wrote:\n\n> (The '.*' in /^foo .*/c\\\\ is unnecessary.)\n\nYeah, I noticed after I sent it.\n\n-brandon\n"},{"id":"88034","messageId":"7v3akyi07f.fsf@gitster.siamese.dyndns.org","threadId":"15137","inReplyTo":"NWVPkDIELqWBHTU58gfzDqO8HR575ZDJVO2pYdPMtqv9aBLzMLvyZg@cipher.nrlssc.navy.mil","subject":"Re: [PATCH] filter-branch: Grok special characters in tag names","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-21T20:26:28Z","receivedAt":"2008-08-21T20:26:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Brandon Casey <casey@nrlssc.navy.mil> writes:\n\n> Junio complained that my initial version of this was fragile which has\n> similarities with the above. Initially, I was blindly changing the first line\n> to contain \"object...\", second line to \"type...\", etc.\n\nWas it more about not limiting the munging to only the header part?  In\nany case, I think what Hannes has in the patch is fine (although I did not\nlook the lines that follow outside the context).\n\n> Would something like the following be equivalent _and_ clearer? Emphasis\n> on \"and\" because both are necessary, not because I strongly feel it to\n> be so.\n\nI was bitten by a/i/c followed by literal text that behave differently\nwith various implementations of sed, and learned to stay away from the\nconstruct long time ago.  Things might have gotten better these days, but\nold habit and gut-reaction is hard to shake off.\n"},{"id":"88046","messageId":"yncKq2pMiBaRiN-VbWFQsKLk4CfOXCHjFSB_xG9FtqweMeZ_6Hwf-w@cipher.nrlssc.navy.mil","threadId":"15137","inReplyTo":"7v3akyi07f.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] filter-branch: Grok special characters in tag names","fromName":"Brandon Casey","fromEmail":"casey@nrlssc.navy.mil","sentAt":"2008-08-21T21:34:52Z","receivedAt":"2008-08-21T21:34:52Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"Junio C Hamano wrote:\n> Brandon Casey <casey@nrlssc.navy.mil> writes:\n> \n>> Junio complained that my initial version of this was fragile which has\n>> similarities with the above. Initially, I was blindly changing the first line\n>> to contain \"object...\", second line to \"type...\", etc.\n> \n> Was it more about not limiting the munging to only the header part?\n\nNo. I originally had something like\n\n   1c\\object $new_sha1\n   2c\\tag commit\n   ...\n\nblindly changing line one to \"object ...\", line two to \"tag ...\" etc.\nThat aspect is what you commented about. So it would have modified the\nproper parts of a well-formed tag.\n\nI took your comments to be concerned with future proofing or dealing\nwith a corrupt/flawed tag (allowing the flaws to propagate so mktag\nwould error out), but you didn't state that explicitly.\n\nYou also educated me about addresses like 1,/regex/ which was used to limit\nthe munging to only the header part.\n\n> In\n> any case, I think what Hannes has in the patch is fine (although I did not\n> look the lines that follow outside the context).\n\nThat's fine.\n\n-brandon\n"}]}