{"thread":{"id":"9557","subject":"[PATCH] t1301-shared-repo.sh: fix 'stat' portability issue","startedAt":"2007-08-16T15:21:03Z","lastAt":"2007-08-17T23:37:56Z","messageCount":5,"participants":["Arjen Laarhoven","Junio C Hamano","Uwe Kleine-König"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"50892","messageId":"1187277663740-git-send-email-arjen@yaph.org","threadId":"9557","inReplyTo":null,"subject":"[PATCH] t1301-shared-repo.sh: fix 'stat' portability issue","fromName":"Arjen Laarhoven","fromEmail":"arjen@yaph.org","sentAt":"2007-08-16T15:21:03Z","receivedAt":"2007-08-16T15:21:03Z","isPatch":true,"sender":{"key":"arjen@yaph.org","avatar":"https://gravatar.com/avatar/f776c2c0c5ea62d70827b942eb7d95ce85661a3d70bc3f03cf9773815c599c01?d=mp&s=160"},"body":"The t1301-shared-repo.sh testscript uses /usr/bin/stat to get the file\nmode, which isn't portable.  There already is a dependency on Perl, so\nuse a Perl one-liner to do the file mode test, but portable.\n\nSigned-off-by: Arjen Laarhoven <arjen@yaph.org>\n---\n t/t1301-shared-repo.sh |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh\nindex bb5f302..888c5fb 100755\n--- a/t/t1301-shared-repo.sh\n+++ b/t/t1301-shared-repo.sh\n@@ -21,7 +21,7 @@ test_expect_success 'update-server-info honors core.sharedRepository' '\n \tgit commit -m a1 &&\n \tumask 0277 &&\n \tgit update-server-info &&\n-\ttest 444 = $(stat -c %a .git/info/refs)\n+\t$(perl -e '\\''exit !(((stat \".git/info/refs\")[2] & 0777) == 0444)'\\'')\n '\n \n test_done\n-- \n1.5.3.rc4.67.gf9286\n"},{"id":"50901","messageId":"7v3ayjjnz7.fsf@gitster.siamese.dyndns.org","threadId":"9557","inReplyTo":"1187277663740-git-send-email-arjen@yaph.org","subject":"Re: [PATCH] t1301-shared-repo.sh: fix 'stat' portability issue","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-16T19:09:16Z","receivedAt":"2007-08-16T19:09:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Arjen Laarhoven <arjen@yaph.org> writes:\n\n> The t1301-shared-repo.sh testscript uses /usr/bin/stat to get the file\n> mode, which isn't portable.  There already is a dependency on Perl, so\n> use a Perl one-liner to do the file mode test, but portable.\n>\n> Signed-off-by: Arjen Laarhoven <arjen@yaph.org>\n> ---\n>  t/t1301-shared-repo.sh |    2 +-\n>  1 files changed, 1 insertions(+), 1 deletions(-)\n>\n> diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh\n> index bb5f302..888c5fb 100755\n> --- a/t/t1301-shared-repo.sh\n> +++ b/t/t1301-shared-repo.sh\n> @@ -21,7 +21,7 @@ test_expect_success 'update-server-info honors core.sharedRepository' '\n>  \tgit commit -m a1 &&\n>  \tumask 0277 &&\n>  \tgit update-server-info &&\n> -\ttest 444 = $(stat -c %a .git/info/refs)\n> +\t$(perl -e '\\''exit !(((stat \".git/info/refs\")[2] & 0777) == 0444)'\\'')\n>  '\n\nWhy is this inside a $()?\n\nI am just wondering if this is more portable and readable...\n\n\t... &&\n\tcurrent=\"$(ls -l .git/info/refs)\" &&\n\tcase \"$current\" in\n        -r--r--r--*)\n        \t: happy\n                ;;\n\t*)\n        \techo Oops, .git/info/refs is not 0444\n                false\n                ;;\n\tesac\n"},{"id":"50904","messageId":"20070816220217.GH25161@regex.yaph.org","threadId":"9557","inReplyTo":"7v3ayjjnz7.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] t1301-shared-repo.sh: fix 'stat' portability issue","fromName":"Arjen Laarhoven","fromEmail":"arjen@yaph.org","sentAt":"2007-08-16T22:02:17Z","receivedAt":"2007-08-16T22:02:17Z","isPatch":true,"sender":{"key":"arjen@yaph.org","avatar":"https://gravatar.com/avatar/f776c2c0c5ea62d70827b942eb7d95ce85661a3d70bc3f03cf9773815c599c01?d=mp&s=160"},"body":"The t1301-shared-repo.sh testscript uses /usr/bin/stat to get the file\nmode, which isn't portable.  Implement the test in shell using 'ls' as\nshown by Junio.\n\nSigned-off-by: Arjen Laarhoven <arjen@yaph.org>\n---\n t/t1301-shared-repo.sh |   11 ++++++++++-\n 1 files changed, 10 insertions(+), 1 deletions(-)\n\ndiff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh\nindex bb5f302..6bfe19a 100755\n--- a/t/t1301-shared-repo.sh\n+++ b/t/t1301-shared-repo.sh\n@@ -21,7 +21,16 @@ test_expect_success 'update-server-info honors core.sharedRepository' '\n \tgit commit -m a1 &&\n \tumask 0277 &&\n \tgit update-server-info &&\n-\ttest 444 = $(stat -c %a .git/info/refs)\n+\tactual=\"$(ls -l .git/info/refs)\" &&\n+\tcase \"$actual\" in\n+\t-r--r--r--*)\n+\t\t: happy\n+\t\t;;\n+\t*)\n+\t\techo Oops, .git/info/refs is not 0444\n+\t\tfalse\n+\t\t;;\n+\tesac\n '\n \n test_done\n-- \n1.5.3.rc4.67.gf9286\n\n> > -\ttest 444 = $(stat -c %a .git/info/refs)\n> > +\t$(perl -e '\\''exit !(((stat \".git/info/refs\")[2] & 0777) == 0444)'\\'')\n> >  '\n> \n> Why is this inside a $()?\n\nBah.\n\n> I am just wondering if this is more portable and readable...\n> \n> \t... &&\n> \tcurrent=\"$(ls -l .git/info/refs)\" &&\n> \tcase \"$current\" in\n>         -r--r--r--*)\n>         \t: happy\n>                 ;;\n> \t*)\n>         \techo Oops, .git/info/refs is not 0444\n>                 false\n>                 ;;\n> \tesac\n"},{"id":"50933","messageId":"20070817124828.GB11107@informatik.uni-freiburg.de","threadId":"9557","inReplyTo":"20070816220217.GH25161@regex.yaph.org","subject":"Re: [PATCH] t1301-shared-repo.sh: fix 'stat' portability issue","fromName":"Uwe Kleine-König","fromEmail":"ukleinek@informatik.uni-freiburg.de","sentAt":"2007-08-17T12:48:28Z","receivedAt":"2007-08-17T12:48:28Z","isPatch":true,"sender":{"key":"u.kleine-koenig@pengutronix.de","avatar":"https://gravatar.com/avatar/354b5e3ceb2806a2f1e1e382ac29ddbdad18288654da62b61eb13583a857eee7?d=mp&s=160"},"body":"Hello,\n\n> +\tactual=\"$(ls -l .git/info/refs)\" &&\n> +\tcase \"$actual\" in\n> +\t-r--r--r--*)\n> +\t\t: happy\n> +\t\t;;\n> +\t*)\n> +\t\techo Oops, .git/info/refs is not 0444\n> +\t\tfalse\n> +\t\t;;\n> +\tesac\n\nDon't know if this matters here, but a while ago I learnd that if I\nreally need to parse output of ls -l, then I should set LANG=C and\nLC_ALL=C.  I didn't see any breakage when LS_COLORS is set, but maybe\nyou want to reset that, too?\n\nBest regards\nUwe\n\n-- \nUwe Kleine-König\n\nhttp://www.google.com/search?q=2004+in+roman+numerals\n"},{"id":"50968","messageId":"7v4pixg2az.fsf@gitster.siamese.dyndns.org","threadId":"9557","inReplyTo":"20070817124828.GB11107@informatik.uni-freiburg.de","subject":"Re: [PATCH] t1301-shared-repo.sh: fix 'stat' portability issue","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-17T23:37:56Z","receivedAt":"2007-08-17T23:37:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Uwe Kleine-König <ukleinek@informatik.uni-freiburg.de> writes:\n\n> Don't know if this matters here, but a while ago I learnd that if I\n> really need to parse output of ls -l, then I should set LANG=C and\n> LC_ALL=C.  I didn't see any breakage when LS_COLORS is set, but maybe\n> you want to reset that, too?\n\nYeah, I usually try to be defensive and I know LANG/LC_ALL\nmatters if you want to parse \"ls -l\" for dates, but it should\nnot matter for perm bits.  If LS_COLORS is honoured when it is\noutputting to non-terminal (as in var=`ls`), it's severely\nbroken, so...\n"}]}