{"thread":{"id":"8693","subject":"[PATCH 1/2] Move the pick_author code to git-sh-setup","startedAt":"2007-06-23T23:01:01Z","lastAt":"2007-06-24T11:14:00Z","messageCount":5,"participants":["Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"45628","messageId":"Pine.LNX.4.64.0706240000340.4059@racer.site","threadId":"8693","inReplyTo":null,"subject":"[PATCH 1/2] Move the pick_author code to git-sh-setup","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-06-23T23:01:01Z","receivedAt":"2007-06-23T23:01:01Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nAt the moment, only git-commit uses that code, to pick the author name,\nemail and date from a given commit.\n\nThis code will be reused in git rebase --interactive.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n git-commit.sh   |   30 ++----------------------------\n git-sh-setup.sh |   27 +++++++++++++++++++++++++++\n 2 files changed, 29 insertions(+), 28 deletions(-)\n\ndiff --git a/git-commit.sh b/git-commit.sh\nindex 5547a02..4bef375 100755\n--- a/git-commit.sh\n+++ b/git-commit.sh\n@@ -483,34 +483,8 @@ fi >>\"$GIT_DIR\"/COMMIT_EDITMSG\n # Author\n if test '' != \"$use_commit\"\n then\n-\tpick_author_script='\n-\t/^author /{\n-\t\ts/'\\''/'\\''\\\\'\\'\\''/g\n-\t\th\n-\t\ts/^author \\([^<]*\\) <[^>]*> .*$/\\1/\n-\t\ts/'\\''/'\\''\\'\\'\\''/g\n-\t\ts/.*/GIT_AUTHOR_NAME='\\''&'\\''/p\n-\n-\t\tg\n-\t\ts/^author [^<]* <\\([^>]*\\)> .*$/\\1/\n-\t\ts/'\\''/'\\''\\'\\'\\''/g\n-\t\ts/.*/GIT_AUTHOR_EMAIL='\\''&'\\''/p\n-\n-\t\tg\n-\t\ts/^author [^<]* <[^>]*> \\(.*\\)$/\\1/\n-\t\ts/'\\''/'\\''\\'\\'\\''/g\n-\t\ts/.*/GIT_AUTHOR_DATE='\\''&'\\''/p\n-\n-\t\tq\n-\t}\n-\t'\n-\tencoding=$(git config i18n.commitencoding || echo UTF-8)\n-\tset_author_env=`git show -s --pretty=raw --encoding=\"$encoding\" \"$use_commit\" |\n-\tLANG=C LC_ALL=C sed -ne \"$pick_author_script\"`\n-\teval \"$set_author_env\"\n-\texport GIT_AUTHOR_NAME\n-\texport GIT_AUTHOR_EMAIL\n-\texport GIT_AUTHOR_DATE\n+\teval $(get_author_ident_from_commit \"$use_commit\")\n+\texport GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE\n fi\n if test '' != \"$force_author\"\n then\ndiff --git a/git-sh-setup.sh b/git-sh-setup.sh\nindex f24c7f2..d861db3 100755\n--- a/git-sh-setup.sh\n+++ b/git-sh-setup.sh\n@@ -53,6 +53,33 @@ require_work_tree () {\n \tdie \"fatal: $0 cannot be used without a working tree.\"\n }\n \n+get_author_ident_from_commit () {\n+\tpick_author_script='\n+\t/^author /{\n+\t\ts/'\\''/'\\''\\\\'\\'\\''/g\n+\t\th\n+\t\ts/^author \\([^<]*\\) <[^>]*> .*$/\\1/\n+\t\ts/'\\''/'\\''\\'\\'\\''/g\n+\t\ts/.*/GIT_AUTHOR_NAME='\\''&'\\''/p\n+\n+\t\tg\n+\t\ts/^author [^<]* <\\([^>]*\\)> .*$/\\1/\n+\t\ts/'\\''/'\\''\\'\\'\\''/g\n+\t\ts/.*/GIT_AUTHOR_EMAIL='\\''&'\\''/p\n+\n+\t\tg\n+\t\ts/^author [^<]* <[^>]*> \\(.*\\)$/\\1/\n+\t\ts/'\\''/'\\''\\'\\'\\''/g\n+\t\ts/.*/GIT_AUTHOR_DATE='\\''&'\\''/p\n+\n+\t\tq\n+\t}\n+\t'\n+\tencoding=$(git config i18n.commitencoding || echo UTF-8)\n+\tgit show -s --pretty=raw --encoding=\"$encoding\" \"$1\" |\n+\tLANG=C LC_ALL=C sed -ne \"$pick_author_script\"\n+}\n+\n if [ -z \"$LONG_USAGE\" ]\n then\n \tLONG_USAGE=\"Usage: $0 $USAGE\"\n-- \n1.5.2.2.279.g74fb3\n"},{"id":"45641","messageId":"7v7ipt3lh6.fsf@assigned-by-dhcp.cox.net","threadId":"8693","inReplyTo":"Pine.LNX.4.64.0706240000340.4059@racer.site","subject":"Re: [PATCH 1/2] Move the pick_author code to git-sh-setup","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-06-24T06:39:01Z","receivedAt":"2007-06-24T06:39:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> -\tset_author_env=`git show -s --pretty=raw --encoding=\"$encoding\" \"$use_commit\" |\n> -\tLANG=C LC_ALL=C sed -ne \"$pick_author_script\"`\n> -\teval \"$set_author_env\"\n> ...\n> +\teval $(get_author_ident_from_commit \"$use_commit\")\n\nAre you sure about this part of the change?  I suspect that you\nare losing IFS by not dq'ing the argument you give to the eval.\n\n    #!/bin/sh\n\n    test1 () {\n        echo \"$1=' d  e'\"\n    }\n\n    eval $(test1 A)\n    eval \"$(test1 B)\"\n    echo \"A=$A\"\n    echo \"B=$B\"\n"},{"id":"45646","messageId":"7vejk125i6.fsf@assigned-by-dhcp.cox.net","threadId":"8693","inReplyTo":"7v7ipt3lh6.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 1/2] Move the pick_author code to git-sh-setup","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-06-24T07:09:21Z","receivedAt":"2007-06-24T07:09:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n>\n>> -\tset_author_env=`git show -s --pretty=raw --encoding=\"$encoding\" \"$use_commit\" |\n>> -\tLANG=C LC_ALL=C sed -ne \"$pick_author_script\"`\n>> -\teval \"$set_author_env\"\n>> ...\n>> +\teval $(get_author_ident_from_commit \"$use_commit\")\n>\n> Are you sure about this part of the change?  I suspect that you\n> are losing IFS by not dq'ing the argument you give to the eval.\n>\n> ...\n\nIf you care about your data in your variable and do not want\nword-splitting at $IFS to happen, you should always dq your\nvariable.  A quick rule of thumb is that the only place that you\ncan get away by not quoting is straight assignment to another\nvariable, like so:\n\n\tvar='a  b c '\n        another=$var\t;# another=\"$var\" is fine but unnecessary.\n"},{"id":"45659","messageId":"Pine.LNX.4.64.0706241118250.4059@racer.site","threadId":"8693","inReplyTo":"7v7ipt3lh6.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 1/2] Move the pick_author code to git-sh-setup","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-06-24T10:22:24Z","receivedAt":"2007-06-24T10:22:24Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 23 Jun 2007, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > -\tset_author_env=`git show -s --pretty=raw --encoding=\"$encoding\" \"$use_commit\" |\n> > -\tLANG=C LC_ALL=C sed -ne \"$pick_author_script\"`\n> > -\teval \"$set_author_env\"\n> > ...\n> > +\teval $(get_author_ident_from_commit \"$use_commit\")\n> \n> Are you sure about this part of the change?\n\nNo, I am not.\n\n> I suspect that you are losing IFS by not dq'ing the argument you give to \n> the eval.\n\nThat is well possible. Quoting in shell is such a hassle, and I never seem \nto get it right.\n\nTherefore I did a minimal test, namely committing with another \nGIT_AUTHOR_NAME (which has spaces in it), and then commiting again, with \n\"-c HEAD\". Which did what I expected: the second commit had the same \nauthor name as the first one.\n\nSo I thought that it was okay.\n\nCiao,\nDscho\n"},{"id":"45665","messageId":"7vd4zlvc3r.fsf@assigned-by-dhcp.cox.net","threadId":"8693","inReplyTo":"Pine.LNX.4.64.0706241118250.4059@racer.site","subject":"Re: [PATCH 1/2] Move the pick_author code to git-sh-setup","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-06-24T11:14:00Z","receivedAt":"2007-06-24T11:14:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> That is well possible. Quoting in shell is such a hassle, and I never seem \n> to get it right.\n>\n> Therefore I did a minimal test,...\n>\n> So I thought that it was okay.\n\nTry the small test script in the message you are responding to.\nIt gives me:\n\n        $ sh ./1.sh\n        A= d e\n        B= d  e\n\nA quick rule of thumb is that the only place that you can get\naway by not quoting is straight assignment to another variable,\nlike so:\n\n\tvar='a  b c '\n        another=$var\t;# another=\"$var\" is fine but unnecessary.\n\nSimilarly for\n\n\tanother=$(some command)\n\nwhich is Ok not to dquote.\n"}]}