{"thread":{"id":"32906","subject":"[PATCH] Documentation: filter-branch env-filter example","startedAt":"2013-02-14T19:34:11Z","lastAt":"2013-02-14T21:51:26Z","messageCount":5,"participants":["Tadeusz Andrzej Kadłubowski","Junio C Hamano","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"209538","messageId":"511D3C33.6070902@hell.org.pl","threadId":"32906","inReplyTo":null,"subject":"[PATCH] Documentation: filter-branch env-filter example","fromName":"Tadeusz Andrzej Kadłubowski","fromEmail":"yess@hell.org.pl","sentAt":"2013-02-14T19:34:11Z","receivedAt":"2013-02-14T19:34:11Z","isPatch":true,"sender":{"key":"yess@hell.org.pl","avatar":"https://avatars.githubusercontent.com/u/207712?v=4"},"body":"filter-branch --env-filter example that shows how to change the email address\nin all commits by a certain developer.\n---\n Documentation/git-filter-branch.txt | 13 +++++++++++++\n 1 file changed, 13 insertions(+)\n\ndiff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt\nindex dfd12c9..2664cec 100644\n--- a/Documentation/git-filter-branch.txt\n+++ b/Documentation/git-filter-branch.txt\n@@ -329,6 +329,19 @@ git filter-branch --msg-filter '\n ' HEAD~10..HEAD\n --------------------------------------------------------\n\n+You can modify committer/author personal information using `--env-filter`.\n+For example, to update some developer's email address use this command:\n+\n+--------------------------------------------------------\n+git filter-branch --env-filter '\n+\tif [ $GIT_AUTHOR_EMAIL = john@old.example.com ]\n+\tthen\n+\t\tGIT_AUTHOR_EMAIL=john@new.example.com\n+\tfi\n+\texport GIT_AUTHOR_EMAIL\n+' -- --all\n+--------------------------------------------------------\n+\n To restrict rewriting to only part of the history, specify a revision\n range in addition to the new branch name.  The new branch name will\n point to the top-most revision that a 'git rev-list' of this range\n-- \n1.7.11.7\n"},{"id":"209539","messageId":"7vy5eqy6z3.fsf@alter.siamese.dyndns.org","threadId":"32906","inReplyTo":"511D3C33.6070902@hell.org.pl","subject":"Re: [PATCH] Documentation: filter-branch env-filter example","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-02-14T20:29:36Z","receivedAt":"2013-02-14T20:29:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Tadeusz Andrzej Kadłubowski  <yess@hell.org.pl> writes:\n\n> filter-branch --env-filter example that shows how to change the email address\n> in all commits by a certain developer.\n> ---\n\nThanks.  Sign-off?\n\n>  Documentation/git-filter-branch.txt | 13 +++++++++++++\n>  1 file changed, 13 insertions(+)\n>\n> diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt\n> index dfd12c9..2664cec 100644\n> --- a/Documentation/git-filter-branch.txt\n> +++ b/Documentation/git-filter-branch.txt\n> @@ -329,6 +329,19 @@ git filter-branch --msg-filter '\n>  ' HEAD~10..HEAD\n>  --------------------------------------------------------\n>\n> +You can modify committer/author personal information using `--env-filter`.\n> +For example, to update some developer's email address use this command:\n> +\n> +--------------------------------------------------------\n> +git filter-branch --env-filter '\n> +\tif [ $GIT_AUTHOR_EMAIL = john@old.example.com ]\n\nQuote the variable in double-quotes, like this:\n\n\tif [ \"$GIT_AUTHOR_EMAIL\" = john@old.example.com ]\n\nOtherwise the comparison will break, if the e-mail part had a\nwhitespace in it, or if it were empty, which is an example of a more\nlikely situation where you would want to fix commits using a\nprocedure like this, no?\n\nBut more on the example later...\n\n> +\tthen\n> +\t\tGIT_AUTHOR_EMAIL=john@new.example.com\n> +\tfi\n> +\texport GIT_AUTHOR_EMAIL\n> +' -- --all\n> +--------------------------------------------------------\n> +\n\nI do not think an illustration of env-filter is a bad addition\nper-se, but the sample scenario is not a realistic one.  No sane\nproject should be encouraged to rewrite their entire history every\ntime one of the contributors change his e-mail address.  That is\nwhat the mailmap mechanism is for.\n\nThe only scenario that justifies use of the given sample I can think\nof is to rewrite the author and committer in an unpublished project\nbecause you noticed that you forgot to set user.name and user.email\nup before you created these commits correctly.\n\nTaking all of the above, the added text may look more like this, I\nthink:\n\n\tThe `--env-filter` can be used to modify committer and/or\n\tauthor identity.  For example, if you found out that your\n\tcommits have wrong identity of yours due to misconfigured\n\tuser.email, you can make correction, before publishing the\n\tproject, like this:\n\n\t--------------------------------------------------------\n        git filter-branch --env-filter '\n        \tif test \"$GIT_AUTHOR_EMAIL\" = \"root@localhost\"\n                then\n\t\t\tGIT_AUTHOR_EMAIL=yess@example.com\n\t\t\texport GIT_AUTHOR_EMAIL\n\t\tfi\n        \tif test \"$GIT_COMMITTER_EMAIL\" = \"root@localhost\"\n                then\n\t\t\tGIT_COMMITTER_EMAIL=yess@example.com\n\t\t\texport GIT_COMMITTER_EMAIL\n\t\tfi\n\t' -- --all\n\t--------------------------------------------------------\n\nBy the way, I left the \"export\" in; \"git filter-branch --help\"\nexplicitly says that you need to re-export it.  But I am not sure if\nthey are necessary, especially after 3c730fab2cae (filter-branch:\nuse git-sh-setup's ident parsing functions, 2012-10-18) by Peff,\nwhich added extra \"export\" to make sure all six identity variables\nare exported.  After applying the above rewrite, we may want to do\nthe following as a separate, follow-up patch.\n\n Documentation/git-filter-branch.txt | 5 +----\n 1 file changed, 1 insertion(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt\nindex 8ebe999..066548e 100644\n--- a/Documentation/git-filter-branch.txt\n+++ b/Documentation/git-filter-branch.txt\n@@ -83,8 +83,7 @@ OPTIONS\n \tThis filter may be used if you only need to modify the environment\n \tin which the commit will be performed.  Specifically, you might\n \twant to rewrite the author/committer name/email/time environment\n-\tvariables (see linkgit:git-commit-tree[1] for details).  Do not forget\n-\tto re-export the variables.\n+\tvariables (see linkgit:git-commit-tree[1] for details).\n \n --tree-filter <command>::\n \tThis is the filter for rewriting the tree and its contents.\n@@ -340,12 +339,10 @@ git filter-branch --env-filter '\n \tif test \"$GIT_AUTHOR_EMAIL\" = \"root@localhost\"\n \tthen\n \t\tGIT_AUTHOR_EMAIL=yess@example.com\n-\t\texport GIT_AUTHOR_EMAIL\n \tfi\n \tif test \"$GIT_COMMITTER_EMAIL\" = \"root@localhost\"\n \tthen\n \t\tGIT_COMMITTER_EMAIL=yess@example.com\n-\t\texport GIT_COMMITTER_EMAIL\n \tfi\n ' -- --all\n --------------------------------------------------------\n"},{"id":"209540","messageId":"20130214210910.GA6660@sigill.intra.peff.net","threadId":"32906","inReplyTo":"7vy5eqy6z3.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Documentation: filter-branch env-filter example","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-02-14T21:09:10Z","receivedAt":"2013-02-14T21:09:10Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Feb 14, 2013 at 12:29:36PM -0800, Junio C Hamano wrote:\n\n> Quote the variable in double-quotes, like this:\n> \n> \tif [ \"$GIT_AUTHOR_EMAIL\" = john@old.example.com ]\n> \n> Otherwise the comparison will break, if the e-mail part had a\n> whitespace in it, or if it were empty, which is an example of a more\n> likely situation where you would want to fix commits using a\n> procedure like this, no?\n\nYeah, definitely. If you are cleaning up a broken ident that cannot be\nparsed, the failure mode is to put the whole author line in\n$GIT_AUTHOR_EMAIL, which would almost certainly include spaces.\n\n> Taking all of the above, the added text may look more like this, I\n> think:\n> \n> \tThe `--env-filter` can be used to modify committer and/or\n> \tauthor identity.  For example, if you found out that your\n> \tcommits have wrong identity of yours due to misconfigured\n> \tuser.email, you can make correction, before publishing the\n> \tproject, like this:\n> \n> \t--------------------------------------------------------\n>         git filter-branch --env-filter '\n>         \tif test \"$GIT_AUTHOR_EMAIL\" = \"root@localhost\"\n>                 then\n> \t\t\tGIT_AUTHOR_EMAIL=yess@example.com\n> \t\t\texport GIT_AUTHOR_EMAIL\n> \t\tfi\n>         \tif test \"$GIT_COMMITTER_EMAIL\" = \"root@localhost\"\n>                 then\n> \t\t\tGIT_COMMITTER_EMAIL=yess@example.com\n> \t\t\texport GIT_COMMITTER_EMAIL\n> \t\tfi\n> \t' -- --all\n> \t--------------------------------------------------------\n\nThat looks better, though there are a few English nits; here's my edited\nversion:\n\n        The `--env-filter` option can be used to modify committer and/or\n\tauthor identity.  For example, if you found out that your\n\tcommits have the wrong identity due to a misconfigured\n        user.email, you can make a correction, before publishing the\n\tproject, like this:\n\n> By the way, I left the \"export\" in; \"git filter-branch --help\"\n> explicitly says that you need to re-export it.  But I am not sure if\n> they are necessary, especially after 3c730fab2cae (filter-branch:\n> use git-sh-setup's ident parsing functions, 2012-10-18) by Peff,\n> which added extra \"export\" to make sure all six identity variables\n> are exported.  After applying the above rewrite, we may want to do\n> the following as a separate, follow-up patch.\n\nI think it has always been the case that we export them after setting\nthem; just look at the preimage from 3c730fab, and you can see exports\nthere.\n\nI think the advice in the documentation about re-exporting is because\nsome versions of the bourne shell will not reliably pass the new version\nof the variable when you do this:\n\n  VAR=old\n  export VAR\n  VAR=new\n  some_subprocess ;# we see $VAR=old here!\n\nI do not recall ever running across such a shell myself, but rather\nhearing about it third-hand in a portability guide somewhere. Apple's\nshell documentation seems to indicate that /bin/sh in older versions of\nOS X had this behavior:\n\n  https://developer.apple.com/library/mac/documentation/opensource/conceptual/shellscripting/shell_scripts/shell_scripts.html#//apple_ref/doc/uid/TP40004268-CH237-SW11\n\nwhich makes me think that BSD ash may behave that way. It is certainly\nnot necessary to re-export under bash or dash. I shudder to think what\nhorrible, 1980's-era behavior is codified in Solaris /bin/sh.\n\nWe could explicitly re-export all of the ident variables preemptively\nbefore calling commit-tree, just to save the user the hassle of\nremembering to do so.  It would be a no-op on sane shells, and I doubt\nthe runtime cost is very high. I suppose it would break somebody who\nexplicitly did:\n\n  unset GIT_COMMITTER_NAME ;# use the value from user.name\n\nin their env-filter, but that seems like a pretty unlikely corner case.\n\n-Peff\n"},{"id":"209541","messageId":"20130214212459.GA8005@sigill.intra.peff.net","threadId":"32906","inReplyTo":"20130214210910.GA6660@sigill.intra.peff.net","subject":"Re: [PATCH] Documentation: filter-branch env-filter example","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-02-14T21:24:59Z","receivedAt":"2013-02-14T21:24:59Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Feb 14, 2013 at 04:09:10PM -0500, Jeff King wrote:\n\n> I think the advice in the documentation about re-exporting is because\n> some versions of the bourne shell will not reliably pass the new version\n> of the variable when you do this:\n> \n>   VAR=old\n>   export VAR\n>   VAR=new\n>   some_subprocess ;# we see $VAR=old here!\n> \n> I do not recall ever running across such a shell myself, but rather\n> hearing about it third-hand in a portability guide somewhere.\n\nThe closest I could find in the autoconf shell guidelines[1] is that the\nautomagic export marking for incoming variables is not always accurate:\n\n\texport\n            The builtin export dubs a shell variable environment\n            variable. Each update of exported variables corresponds to\n            an update of the environment variables.  Conversely, each\n            environment variable received by the shell when it is\n            launched should be imported as a shell variable marked as\n            exported.\n\n            Alas, many shells, such as Solaris 2.5, IRIX 6.3, IRIX 5.2,\n            AIX 4.1.5, and Digital UNIX 4.0, forget to export the\n            environment variables they receive. As a result, two\n            variables coexist: the environment variable and the shell\n            variable. The following code demonstrates this failure:\n\n\t    #! /bin/sh\n\t    echo $FOO\n\t    FOO=bar\n\t    echo $FOO\n\t    exec /bin/sh $0\n\n            when run with `FOO=foo' in the environment, these shells\n            will print alternately `foo' and `bar', although it should\n            only print `foo' and then a sequence of `bar's.\n\n            Therefore you should export again each environment variable\n            that you update.\n\nI don't know what the behavior would be on such shells of:\n\n\t#!/bin/sh\n\techo $FOO\n\tFOO=bar\n\texport FOO\n\techo $FOO\n\texec /bin/sh $0\n\nI.e., would the \"export\" correctly reconcile the local and environment\ncopies of the variable, or are they forever broken? I don't have such a\nsystem to test on. But that would more closely match what we are doing.\n\n-Peff\n\n[1] https://www.gnu.org/software/autoconf/manual/autoconf.html#Limitations-of-Builtins\n"},{"id":"209542","messageId":"7vtxpey36p.fsf@alter.siamese.dyndns.org","threadId":"32906","inReplyTo":"20130214210910.GA6660@sigill.intra.peff.net","subject":"Re: [PATCH] Documentation: filter-branch env-filter example","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-02-14T21:51:26Z","receivedAt":"2013-02-14T21:51:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> I think it has always been the case that we export them after setting\n> them; just look at the preimage from 3c730fab, and you can see exports\n> there.\n\nYeah, I think the only difference is a broken commit case where sed\nexpression did not find what it was looking for, in which case we do\nnot do the export.\n\n> I think the advice in the documentation about re-exporting is because\n> some versions of the bourne shell will not reliably pass the new version\n> of the variable ...\n\nAhh, old and painful memory of Solaris days comes back to me.  OK,\nlet's keep the export then.\n\nThanks.\n"}]}