{"thread":{"id":"54256","subject":"[PATCH 0/4] sample hooks: become hash agnostic","startedAt":"2020-09-18T11:19:34Z","lastAt":"2020-09-23T16:34:26Z","messageCount":23,"participants":["Denton Liu","Taylor Blau","Eric Sunshine","Junio C Hamano","brian m. carlson","Chris Torek","Andreas Schwab"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"405847","messageId":"cover.1600427894.git.liu.denton@gmail.com","threadId":"54256","inReplyTo":null,"subject":"[PATCH 0/4] sample hooks: become hash agnostic","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-09-18T11:19:01Z","receivedAt":"2020-09-18T11:19:34Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"There are currently two hooks that have hardcoded 40 zeros as the null\nOID and, thus, are not hash-agnostic. Rewrite these to use the newly\nintroduced `git rev-parse --null-oid` so that they become hash-agnostic.\n\nDenton Liu (4):\n  hooks--pre-push.sample: prefer $() for command substitution\n  builtin/rev-parse: learn --null-oid\n  hooks--pre-push.sample: use hash-agnostic null OID\n  hooks--update.sample: use hash-agnostic null OID\n\n Documentation/git-rev-parse.txt  | 4 ++++\n builtin/rev-parse.c              | 4 ++++\n t/t1500-rev-parse.sh             | 6 ++++++\n templates/hooks--pre-push.sample | 8 ++++----\n templates/hooks--update.sample   | 2 +-\n 5 files changed, 19 insertions(+), 5 deletions(-)\n\n-- \n2.28.0.618.gf4bc123cb7\n\n"},{"id":"405848","messageId":"004f2e4c92918a7a4e452d49e98ef15f1c5ac545.1600427894.git.liu.denton@gmail.com","threadId":"54256","inReplyTo":"cover.1600427894.git.liu.denton@gmail.com","subject":"[PATCH 2/4] builtin/rev-parse: learn --null-oid","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-09-18T11:19:03Z","receivedAt":"2020-09-18T11:19:36Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"When a user needed the null OID for scripting purposes, it used to be\nvery easy: hardcode 40 zeros. However, since Git started supporting\nSHA-256, this assumption became false which may break some scripts.\nAllow users to fix their broken scripts by providing users with a\nhash-agnostic method of obtaining the null OID.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n Documentation/git-rev-parse.txt | 4 ++++\n builtin/rev-parse.c             | 4 ++++\n t/t1500-rev-parse.sh            | 6 ++++++\n 3 files changed, 14 insertions(+)\n\ndiff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt\nindex 19b12b6d43..b370d425d7 100644\n--- a/Documentation/git-rev-parse.txt\n+++ b/Documentation/git-rev-parse.txt\n@@ -285,6 +285,10 @@ print a message to stderr and exit with nonzero status.\n Other Options\n ~~~~~~~~~~~~~\n \n+--null-oid::\n+\tPrint the null OID (the OID containing all zeros). This OID is\n+\tused to represent a non-existent object.\n+\n --since=datestring::\n --after=datestring::\n \tParse the date string, and output the corresponding\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex ed200c8af1..4e4ca99775 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -910,6 +910,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\t}\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(arg, \"--null-oid\")) {\n+\t\t\t\tputs(oid_to_hex(&null_oid));\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (skip_prefix(arg, \"--since=\", &arg)) {\n \t\t\t\tshow_datestring(\"--max-age=\", arg);\n \t\t\t\tcontinue;\ndiff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh\nindex 408b97d5af..8c1bd543ef 100755\n--- a/t/t1500-rev-parse.sh\n+++ b/t/t1500-rev-parse.sh\n@@ -185,4 +185,10 @@ test_expect_success 'showing the superproject correctly' '\n \ttest_cmp expect out\n '\n \n+test_expect_success 'rev-parse --null-oid' '\n+\techo \"$(test_oid zero)\" >expect &&\n+\tgit rev-parse --null-oid >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.28.0.618.gf4bc123cb7\n\n"},{"id":"405849","messageId":"ed1ade73281bb78ab3a1d4fd1291a951ca52f0b4.1600427894.git.liu.denton@gmail.com","threadId":"54256","inReplyTo":"cover.1600427894.git.liu.denton@gmail.com","subject":"[PATCH 1/4] hooks--pre-push.sample: prefer $() for command substitution","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-09-18T11:19:02Z","receivedAt":"2020-09-18T11:19:37Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"The preferred form for a command substitution is $() over ``. Use this\nform for the command substitution in the sample hook.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n templates/hooks--pre-push.sample | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/templates/hooks--pre-push.sample b/templates/hooks--pre-push.sample\nindex 6187dbf439..64b5707553 100755\n--- a/templates/hooks--pre-push.sample\n+++ b/templates/hooks--pre-push.sample\n@@ -41,7 +41,7 @@ do\n \t\tfi\n \n \t\t# Check for WIP commit\n-\t\tcommit=`git rev-list -n 1 --grep '^WIP' \"$range\"`\n+\t\tcommit=\"$(git rev-list -n 1 --grep '^WIP' \"$range\")\"\n \t\tif [ -n \"$commit\" ]\n \t\tthen\n \t\t\techo >&2 \"Found WIP commit in $local_ref, not pushing\"\n-- \n2.28.0.618.gf4bc123cb7\n\n"},{"id":"405850","messageId":"9d6c2951ab0a2c2e92353c238b008538fe6a6327.1600427894.git.liu.denton@gmail.com","threadId":"54256","inReplyTo":"cover.1600427894.git.liu.denton@gmail.com","subject":"[PATCH 3/4] hooks--pre-push.sample: use hash-agnostic null OID","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-09-18T11:19:04Z","receivedAt":"2020-09-18T11:19:38Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"The pre-push sample hook has the null OID hardcoded as 40 zeros.\nHowever, with the introduction of SHA-256 support, this assumption no\nlonger holds true. Replace the hardcoded $z40 with a call to\n`git rev-parse --null-oid` so the sample hook becomes hash-agnostic.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n templates/hooks--pre-push.sample | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/templates/hooks--pre-push.sample b/templates/hooks--pre-push.sample\nindex 64b5707553..b3bc5276bf 100755\n--- a/templates/hooks--pre-push.sample\n+++ b/templates/hooks--pre-push.sample\n@@ -22,16 +22,16 @@\n remote=\"$1\"\n url=\"$2\"\n \n-z40=0000000000000000000000000000000000000000\n+null_oid=\"$(git rev-parse --null-oid)\"\n \n while read local_ref local_sha remote_ref remote_sha\n do\n-\tif [ \"$local_sha\" = $z40 ]\n+\tif [ \"$local_sha\" = \"$null_oid\" ]\n \tthen\n \t\t# Handle delete\n \t\t:\n \telse\n-\t\tif [ \"$remote_sha\" = $z40 ]\n+\t\tif [ \"$remote_sha\" = \"$null_oid\" ]\n \t\tthen\n \t\t\t# New branch, examine all commits\n \t\t\trange=\"$local_sha\"\n-- \n2.28.0.618.gf4bc123cb7\n\n"},{"id":"405851","messageId":"42d282988961545fb1ab6405a08368d14ffa1450.1600427894.git.liu.denton@gmail.com","threadId":"54256","inReplyTo":"cover.1600427894.git.liu.denton@gmail.com","subject":"[PATCH 4/4] hooks--update.sample: use hash-agnostic null OID","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-09-18T11:19:05Z","receivedAt":"2020-09-18T11:19:42Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"The update sample hook has the null OID hardcoded as 40 zeros. However,\nwith the introduction of SHA-256 support, this assumption no longer\nholds true. Replace the hardcoded $z40 with a call to\n`git rev-parse --null-oid` so the sample hook becomes hash-agnostic.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n templates/hooks--update.sample | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/templates/hooks--update.sample b/templates/hooks--update.sample\nindex 5014c4b31c..5316362af5 100755\n--- a/templates/hooks--update.sample\n+++ b/templates/hooks--update.sample\n@@ -60,7 +60,7 @@ esac\n \n # --- Check types\n # if $newrev is 0000...0000, it's a commit to delete a ref.\n-zero=\"0000000000000000000000000000000000000000\"\n+zero=\"$(git rev-list --null-oid)\"\n if [ \"$newrev\" = \"$zero\" ]; then\n \tnewrev_type=delete\n else\n-- \n2.28.0.618.gf4bc123cb7\n\n"},{"id":"405862","messageId":"20200918141125.GB1602321@nand.local","threadId":"54256","inReplyTo":"004f2e4c92918a7a4e452d49e98ef15f1c5ac545.1600427894.git.liu.denton@gmail.com","subject":"Re: [PATCH 2/4] builtin/rev-parse: learn --null-oid","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2020-09-18T14:11:25Z","receivedAt":"2020-09-18T14:11:31Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Hi Denton,\n\nOn Fri, Sep 18, 2020 at 04:19:03AM -0700, Denton Liu wrote:\n> When a user needed the null OID for scripting purposes, it used to be\n> very easy: hardcode 40 zeros. However, since Git started supporting\n> SHA-256, this assumption became false which may break some scripts.\n> Allow users to fix their broken scripts by providing users with a\n> hash-agnostic method of obtaining the null OID.\n\nI have not been very involved in the hash transition, so please take my\ncomments with a grain of salt (and if they are misplaced, feel free to\nignore them).\n\nThis '--null-oid' thing makes me wonder exactly what it does. Yours\ngives a type-less object back, but what about scripts that want the OID\nof the empty blob or tree?\n\nWould having something like '--null-oid[=<type>]' be useful for them? On\nthe one hand, it seems like a thing that would be useful, but on the\nother, those aren't *the* null OID when 'type' is 'blob' or 'tree'. A\nmore appropriate name in that case might be '--empty-oid=tree'.\n\nSo, that's an argument that '--null-oid' and '--empty-oid[=<type>]'\nshould be two distinct things. I think I like that best. Do you have any\nthoughts about it?\n\nThanks,\nTaylor\n"},{"id":"405864","messageId":"20200918141614.GC1602321@nand.local","threadId":"54256","inReplyTo":"20200918141125.GB1602321@nand.local","subject":"Re: [PATCH 2/4] builtin/rev-parse: learn --null-oid","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2020-09-18T14:16:14Z","receivedAt":"2020-09-18T14:16:20Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Fri, Sep 18, 2020 at 10:11:25AM -0400, Taylor Blau wrote:\n> Hi Denton,\n>\n> On Fri, Sep 18, 2020 at 04:19:03AM -0700, Denton Liu wrote:\n> > When a user needed the null OID for scripting purposes, it used to be\n> > very easy: hardcode 40 zeros. However, since Git started supporting\n> > SHA-256, this assumption became false which may break some scripts.\n> > Allow users to fix their broken scripts by providing users with a\n> > hash-agnostic method of obtaining the null OID.\n>\n> I have not been very involved in the hash transition, so please take my\n> comments with a grain of salt (and if they are misplaced, feel free to\n> ignore them).\n\nSame disclaimer above applies here, too ;-). There are a number of spots\nin the test suite that reference 'ZERO_OID', as well as OIDs for the\nempty tree and blob. Maybe the definition of those could be updated to\nuse any new flags you do/don't introduce?\n\nI'd be just as happy if that were to occur in a different series than\nthis, since I don't want to hold you up by adding a bunch of new things\nto your list.\n\nIn either case, I think '--zero-oid' makes more sense than '--null-oid'\n(and it matches the tests that are already written). The pair\n'--zero-oid' and '--empty-oid=<type>' make sense to me.\n\nThanks,\nTaylor\n"},{"id":"405882","messageId":"CAPig+cSCqU2SDVNZB8_eTiV6j3La=ik-JeWp4dSma77mcv1Ccg@mail.gmail.com","threadId":"54256","inReplyTo":"ed1ade73281bb78ab3a1d4fd1291a951ca52f0b4.1600427894.git.liu.denton@gmail.com","subject":"Re: [PATCH 1/4] hooks--pre-push.sample: prefer $() for command substitution","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2020-09-18T16:57:26Z","receivedAt":"2020-09-18T16:57:40Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Fri, Sep 18, 2020 at 7:19 AM Denton Liu <liu.denton@gmail.com> wrote:\n> The preferred form for a command substitution is $() over ``. Use this\n> form for the command substitution in the sample hook.\n>\n> Signed-off-by: Denton Liu <liu.denton@gmail.com>\n> ---\n> diff --git a/templates/hooks--pre-push.sample b/templates/hooks--pre-push.sample\n> @@ -41,7 +41,7 @@ do\n> -               commit=`git rev-list -n 1 --grep '^WIP' \"$range\"`\n> +               commit=\"$(git rev-list -n 1 --grep '^WIP' \"$range\")\"\n\nThe double quotes around $(...) are unnecessary and just add noise.\n\n>                 if [ -n \"$commit\" ]\n\nIf you're looking for style fixes, then this would be another\ncandidate (using 'test' instead of '[').\n"},{"id":"405884","messageId":"CAPig+cRKrgOhu3bH=TjdWnPaDfKmcM0OcL2ajktc-itGyyi1Ww@mail.gmail.com","threadId":"54256","inReplyTo":"9d6c2951ab0a2c2e92353c238b008538fe6a6327.1600427894.git.liu.denton@gmail.com","subject":"Re: [PATCH 3/4] hooks--pre-push.sample: use hash-agnostic null OID","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2020-09-18T17:06:13Z","receivedAt":"2020-09-18T17:06:30Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Fri, Sep 18, 2020 at 7:19 AM Denton Liu <liu.denton@gmail.com> wrote:\n> The pre-push sample hook has the null OID hardcoded as 40 zeros.\n> However, with the introduction of SHA-256 support, this assumption no\n> longer holds true. Replace the hardcoded $z40 with a call to\n> `git rev-parse --null-oid` so the sample hook becomes hash-agnostic.\n>\n> Signed-off-by: Denton Liu <liu.denton@gmail.com>\n> ---\n> diff --git a/templates/hooks--pre-push.sample b/templates/hooks--pre-push.sample\n> @@ -22,16 +22,16 @@\n> +null_oid=\"$(git rev-parse --null-oid)\"\n>\n>  while read local_ref local_sha remote_ref remote_sha\n>  do\n> -       if [ \"$local_sha\" = $z40 ]\n> +       if [ \"$local_sha\" = \"$null_oid\" ]\n\nSeeing this made me wonder if, rather than introducing a --null-oid\noption (or --zero-oid per Taylor's suggestion), it would make more\nsense to answer the question more directly. For instance:\n\n    if test rev-parse --is-null-oid \"$local_sha\"\n    then\n        ...\n\nOr, if following Taylor's suggestion, you would add --is-zero-oid,\n--is-empty-blob, --is-empty-tree.\n\nOn the other hand, as this is used in a loop, being able to ask for\nthe null (or zero) OID just once before the loop does make sense, so\nmaybe the --is-*-oid forms are less practical.\n\nBy the way, if you're cleaning up the sample scripts to make them\nhash-agnostic, then it would also make sense to s/sha/oid/.\n"},{"id":"405885","messageId":"CAPig+cTVwOiB2OB1oHCsBn_DNMncDpiD0Pi-tuaUmKyMf9qEEw@mail.gmail.com","threadId":"54256","inReplyTo":"42d282988961545fb1ab6405a08368d14ffa1450.1600427894.git.liu.denton@gmail.com","subject":"Re: [PATCH 4/4] hooks--update.sample: use hash-agnostic null OID","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2020-09-18T17:08:05Z","receivedAt":"2020-09-18T17:08:19Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Fri, Sep 18, 2020 at 7:19 AM Denton Liu <liu.denton@gmail.com> wrote:\n> The update sample hook has the null OID hardcoded as 40 zeros. However,\n> with the introduction of SHA-256 support, this assumption no longer\n> holds true. Replace the hardcoded $z40 with a call to\n> `git rev-parse --null-oid` so the sample hook becomes hash-agnostic.\n>\n> Signed-off-by: Denton Liu <liu.denton@gmail.com>\n> ---\n> diff --git a/templates/hooks--update.sample b/templates/hooks--update.sample\n> @@ -60,7 +60,7 @@ esac\n> -zero=\"0000000000000000000000000000000000000000\"\n> +zero=\"$(git rev-list --null-oid)\"\n\nDefinitely want a s/rev-list/rev-parse/ here.\n"},{"id":"405905","messageId":"xmqqy2l7kl0p.fsf@gitster.c.googlers.com","threadId":"54256","inReplyTo":"20200918141614.GC1602321@nand.local","subject":"Re: [PATCH 2/4] builtin/rev-parse: learn --null-oid","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-09-18T18:16:54Z","receivedAt":"2020-09-18T18:16:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Taylor Blau <me@ttaylorr.com> writes:\n\n> In either case, I think '--zero-oid' makes more sense than '--null-oid'\n> (and it matches the tests that are already written). The pair\n> '--zero-oid' and '--empty-oid=<type>' make sense to me.\n\nI am not sure rev-parse should even know about \"empty-oid\".  An end\nuser or a script who wants to learn what name an empty blob has can\nand should ask \"git hash-object -t blob --stdin </dev/null\".\n\nI can buy --zero-oid might be handy, but don't see a pressing need\nif it is merely to support our test suite and sample hooks.\nInstead, something like\n\n  ZERO_OID=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')\n\nshould suffice, no?\n\nTake this as a mild indifference, not as a strong rejection.\n\n"},{"id":"405906","messageId":"20200918182150.GC1612043@nand.local","threadId":"54256","inReplyTo":"xmqqy2l7kl0p.fsf@gitster.c.googlers.com","subject":"Re: [PATCH 2/4] builtin/rev-parse: learn --null-oid","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2020-09-18T18:21:50Z","receivedAt":"2020-09-18T18:21:56Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Fri, Sep 18, 2020 at 11:16:54AM -0700, Junio C Hamano wrote:\n> Taylor Blau <me@ttaylorr.com> writes:\n>\n> > In either case, I think '--zero-oid' makes more sense than '--null-oid'\n> > (and it matches the tests that are already written). The pair\n> > '--zero-oid' and '--empty-oid=<type>' make sense to me.\n>\n> I am not sure rev-parse should even know about \"empty-oid\".  An end\n> user or a script who wants to learn what name an empty blob has can\n> and should ask \"git hash-object -t blob --stdin </dev/null\".\n\nYeah, my uncertainty (\"should this be '--empty-oid' or '--null-oid'?\")\nis probably a good indication (to me, at least) that the option\nshouldn't even exist.\n\n> I can buy --zero-oid might be handy, but don't see a pressing need\n> if it is merely to support our test suite and sample hooks.\n> Instead, something like\n>\n>   ZERO_OID=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')\n>\n> should suffice, no?\n\nAbsolutely.\n\n> Take this as a mild indifference, not as a strong rejection.\n\nFor what it's worth, I'm probably as indifferent as you. I would be\nslightly less so if there was evidence of lots of out-of-tree scripts\nthat care about these special OIDs, but I haven't looked too far.\n\n\nThanks,\nTaylor\n"},{"id":"405912","messageId":"20200918212609.GC67496@camp.crustytoothpaste.net","threadId":"54256","inReplyTo":"20200918141125.GB1602321@nand.local","subject":"Re: [PATCH 2/4] builtin/rev-parse: learn --null-oid","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2020-09-18T21:26:09Z","receivedAt":"2020-09-18T21:34:03Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2020-09-18 at 14:11:25, Taylor Blau wrote:\n> Hi Denton,\n> \n> On Fri, Sep 18, 2020 at 04:19:03AM -0700, Denton Liu wrote:\n> > When a user needed the null OID for scripting purposes, it used to be\n> > very easy: hardcode 40 zeros. However, since Git started supporting\n> > SHA-256, this assumption became false which may break some scripts.\n> > Allow users to fix their broken scripts by providing users with a\n> > hash-agnostic method of obtaining the null OID.\n> \n> I have not been very involved in the hash transition, so please take my\n> comments with a grain of salt (and if they are misplaced, feel free to\n> ignore them).\n> \n> This '--null-oid' thing makes me wonder exactly what it does. Yours\n> gives a type-less object back, but what about scripts that want the OID\n> of the empty blob or tree?\n> \n> Would having something like '--null-oid[=<type>]' be useful for them? On\n> the one hand, it seems like a thing that would be useful, but on the\n> other, those aren't *the* null OID when 'type' is 'blob' or 'tree'. A\n> more appropriate name in that case might be '--empty-oid=tree'.\n> \n> So, that's an argument that '--null-oid' and '--empty-oid[=<type>]'\n> should be two distinct things. I think I like that best. Do you have any\n> thoughts about it?\n\nSo I definitely want to distinguish between the null (all-zeros) OID and\nthe OID of an empty object, and I think using \"null\" and \"empty\" are\nfine.\n\nWhat I typically do when I write shell scripts, and which may obviate\nthe need for this patch is turn this:\n\n  [ \"$oid\" = 0000000000000000000000000000000000000000 ]\n\ninto this:\n\n  echo \"$oid\" | grep -qsE '^0+$'\n\nThis is slightly less efficient, but it's also backwards compatible\nwith older Git version assuming you have a POSIX grep.\n\nIf you still want this option, then that's fine, but please make\n--null-oid take the same arguments as --show-object-format (and default\nto the same value).  Git will soon learn about writing SHA-1 while\nstoring in SHA-256, and it makes everyone's life better if we can plan\nfor the future by making it understand these options now.\n\nI'm not sure we need an empty tree and empty blob object, because it's\npretty easy to write these:\n\n  git hash-object -t tree /dev/null\n  git hash-object -t blob /dev/null\n\nThat's what I've done in some of the transition code at least.\n-- \nbrian m. carlson: Houston, Texas, US\n"},{"id":"405913","messageId":"20200918213507.GD67496@camp.crustytoothpaste.net","threadId":"54256","inReplyTo":"cover.1600427894.git.liu.denton@gmail.com","subject":"Re: [PATCH 0/4] sample hooks: become hash agnostic","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2020-09-18T21:35:07Z","receivedAt":"2020-09-18T21:35:44Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2020-09-18 at 11:19:01, Denton Liu wrote:\n> There are currently two hooks that have hardcoded 40 zeros as the null\n> OID and, thus, are not hash-agnostic. Rewrite these to use the newly\n> introduced `git rev-parse --null-oid` so that they become hash-agnostic.\n\nI've looked over this series and I fully agree that the scripts should\nbe hash agnostic.  I offered an alternative which you may find simpler\nand more appealing (or not), but with the constraint that if we add\n--null-oid, it should accept an argument, I have no comments beyond what\nother folks have added.\n-- \nbrian m. carlson: Houston, Texas, US\n"},{"id":"405964","messageId":"CAPx1Gvd6vcvM410wZUZygr4-2Ob6gaScF3DnBtWWsT95XDmKSQ@mail.gmail.com","threadId":"54256","inReplyTo":"20200918212609.GC67496@camp.crustytoothpaste.net","subject":"Re: [PATCH 2/4] builtin/rev-parse: learn --null-oid","fromName":"Chris Torek","fromEmail":"chris.torek@gmail.com","sentAt":"2020-09-20T04:25:33Z","receivedAt":"2020-09-20T04:25:47Z","isPatch":true,"sender":{"key":"chris.torek@gmail.com","avatar":"https://avatars.githubusercontent.com/u/16826774?v=4"},"body":"On Fri, Sep 18, 2020 at 2:34 PM brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n> So I definitely want to distinguish between the null (all-zeros) OID and\n> the OID of an empty object, and I think using \"null\" and \"empty\" are\n> fine.\n\n(I like this myself)\n\n> What I typically do when I write shell scripts, and which may obviate\n> the need for this patch is turn this:\n>\n>   [ \"$oid\" = 0000000000000000000000000000000000000000 ]\n>\n> into this:\n>\n>   echo \"$oid\" | grep -qsE '^0+$'\n>\n> This is slightly less efficient, but it's also backwards compatible\n> with older Git version assuming you have a POSIX grep.\n\nNote that a lot of `grep`s do not have `-q` and/or `-s` so the\nportable variant of this is `grep '^0+$' >/dev/null` (you only need\nthe `2>&1` part if you're concerned about bad input files or\nan error on a pipe or something).\n\n> I'm not sure we need an empty tree and empty blob object, because it's\n> pretty easy to write these:\n>\n>   git hash-object -t tree /dev/null\n>   git hash-object -t blob /dev/null\n>\n> That's what I've done in some of the transition code at least.\n\nThat's what's recommended in my 2012 stackoverflow Q&A, too.\nThe use of `/dev/null` directly here is perhaps unsatisfactory on\nold Windows systems, though...?\n\nChris\n"},{"id":"405992","messageId":"20200920153537.GA2726066@nand.local","threadId":"54256","inReplyTo":"20200918212609.GC67496@camp.crustytoothpaste.net","subject":"Re: [PATCH 2/4] builtin/rev-parse: learn --null-oid","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2020-09-20T15:35:37Z","receivedAt":"2020-09-20T15:35:44Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Fri, Sep 18, 2020 at 09:26:09PM +0000, brian m. carlson wrote:\n> What I typically do when I write shell scripts, and which may obviate\n> the need for this patch is turn this:\n>\n>   [ \"$oid\" = 0000000000000000000000000000000000000000 ]\n>\n> into this:\n>\n>   echo \"$oid\" | grep -qsE '^0+$'\n>\n> This is slightly less efficient, but it's also backwards compatible\n> with older Git version assuming you have a POSIX grep.\n\nYeah, I mostly just have no idea how common this is in the wild. If many\nscripts care about the null OID, then a '--null-oid' makes sense to me.\nBut if it's only a few, then it does not.\n\n> If you still want this option, then that's fine, but please make\n> --null-oid take the same arguments as --show-object-format (and default\n> to the same value).  Git will soon learn about writing SHA-1 while\n> storing in SHA-256, and it makes everyone's life better if we can plan\n> for the future by making it understand these options now.\n\nAgreed.\n\n> I'm not sure we need an empty tree and empty blob object, because it's\n> pretty easy to write these:\n>\n>   git hash-object -t tree /dev/null\n>   git hash-object -t blob /dev/null\n>\n> That's what I've done in some of the transition code at least.\n\nI could go either way. This for some reason seems more common to me, so\nI wouldn't mind making it easier for callers, but I don't care so much\nbecause what you already wrote is easy enough as-is.\n\n> --\n> brian m. carlson: Houston, Texas, US\n\nThanks,\nTaylor\n"},{"id":"405994","messageId":"87h7rsl9kj.fsf@igel.home","threadId":"54256","inReplyTo":"20200918212609.GC67496@camp.crustytoothpaste.net","subject":"Re: [PATCH 2/4] builtin/rev-parse: learn --null-oid","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2020-09-20T16:03:24Z","receivedAt":"2020-09-20T16:03:29Z","isPatch":true,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"On Sep 18 2020, brian m. carlson wrote:\n\n> What I typically do when I write shell scripts, and which may obviate\n> the need for this patch is turn this:\n>\n>   [ \"$oid\" = 0000000000000000000000000000000000000000 ]\n>\n> into this:\n>\n>   echo \"$oid\" | grep -qsE '^0+$'\n>\n> This is slightly less efficient, but it's also backwards compatible\n> with older Git version assuming you have a POSIX grep.\n\nYou can also use\n\n  case $oid in *[1-9a-f]*) ... ;; *) ... ;; esac\n\nwhich doesn't need an external process.\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1\n\"And now for something completely different.\"\n"},{"id":"405999","messageId":"20200920185817.GJ67496@camp.crustytoothpaste.net","threadId":"54256","inReplyTo":"CAPx1Gvd6vcvM410wZUZygr4-2Ob6gaScF3DnBtWWsT95XDmKSQ@mail.gmail.com","subject":"Re: [PATCH 2/4] builtin/rev-parse: learn --null-oid","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2020-09-20T18:58:17Z","receivedAt":"2020-09-20T18:58:25Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2020-09-20 at 04:25:33, Chris Torek wrote:\n> On Fri, Sep 18, 2020 at 2:34 PM brian m. carlson\n> <sandals@crustytoothpaste.net> wrote:\n> > What I typically do when I write shell scripts, and which may obviate\n> > the need for this patch is turn this:\n> >\n> >   [ \"$oid\" = 0000000000000000000000000000000000000000 ]\n> >\n> > into this:\n> >\n> >   echo \"$oid\" | grep -qsE '^0+$'\n> >\n> > This is slightly less efficient, but it's also backwards compatible\n> > with older Git version assuming you have a POSIX grep.\n> \n> Note that a lot of `grep`s do not have `-q` and/or `-s` so the\n> portable variant of this is `grep '^0+$' >/dev/null` (you only need\n> the `2>&1` part if you're concerned about bad input files or\n> an error on a pipe or something).\n\nIf we're looking for best compatibility here, then using egrep and\n/dev/null is best, I agree.  I personally use the POSIX version because\nit's been that way since at least 2001 and I don't have a problem with\nrequiring compliance with a 19-year-old standard.  But for Git, we\nshould definitely do whatever we do in the testsuite if we use this\napproach, since presumably that works everywhere.\n\nAs Andreas pointed out, there are ways to avoid the external process\nthat we could stuff in a shell function.  I'm not picky.\n\n> > I'm not sure we need an empty tree and empty blob object, because it's\n> > pretty easy to write these:\n> >\n> >   git hash-object -t tree /dev/null\n> >   git hash-object -t blob /dev/null\n> >\n> > That's what I've done in some of the transition code at least.\n> \n> That's what's recommended in my 2012 stackoverflow Q&A, too.\n> The use of `/dev/null` directly here is perhaps unsatisfactory on\n> old Windows systems, though...?\n\nI believe all modern versions of Git for Windows provide /dev/null via\nthe shell, since it's required for a lot of things to work, so I'm not\nworried about this case.  It is definitely good to think about Windows,\nthough.\n-- \nbrian m. carlson: Houston, Texas, US\n"},{"id":"406181","messageId":"cover.1600853895.git.liu.denton@gmail.com","threadId":"54256","inReplyTo":"cover.1600427894.git.liu.denton@gmail.com","subject":"[PATCH v2 0/3] sample hooks: become hash agnostic","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-09-23T09:38:42Z","receivedAt":"2020-09-23T09:38:57Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"There are currently two hooks that have hardcoded 40 zeros as the null\nOID and, thus, are not hash-agnostic. Rewrite these to get the zero OID using\n\n\tgit hash-object --stdin </dev/null | tr '[0-9a-f]' '0'\n\nso that the zero OID is hash-agnostic.\n\nThis was initially done by introducing `git rev-parse --null-oid` to get the\nzero OID but that seems like overkill. From a cursory search of Github, the\nonly instances of the zero OID being used come from clones of the git.git\nrepository (tests and sample hooks). Since we don't want to introduce an option\nthat no one will use, don't go this route and just do the easiest thing.\n\nIf in the future, someone decides that `git rev-parse --zero-oid` is useful,\nthey can also adjust these hooks accordingly.\n\nChanges since v1:\n\n* Don't implement `git rev-parse --null-oid`\n\nDenton Liu (3):\n  hooks--pre-push.sample: modernize script\n  hooks--pre-push.sample: use hash-agnostic zero OID\n  hooks--update.sample: use hash-agnostic zero OID\n\n templates/hooks--pre-push.sample | 18 +++++++++---------\n templates/hooks--update.sample   |  2 +-\n 2 files changed, 10 insertions(+), 10 deletions(-)\n\nRange-diff against v1:\n1:  ed1ade7328 < -:  ---------- hooks--pre-push.sample: prefer $() for command substitution\n2:  004f2e4c92 < -:  ---------- builtin/rev-parse: learn --null-oid\n3:  9d6c2951ab < -:  ---------- hooks--pre-push.sample: use hash-agnostic null OID\n-:  ---------- > 1:  95dd0b19ba hooks--pre-push.sample: modernize script\n-:  ---------- > 2:  afb460d9fd hooks--pre-push.sample: use hash-agnostic zero OID\n4:  42d2829889 ! 3:  784135549f hooks--update.sample: use hash-agnostic null OID\n    @@ Metadata\n     Author: Denton Liu <liu.denton@gmail.com>\n     \n      ## Commit message ##\n    -    hooks--update.sample: use hash-agnostic null OID\n    +    hooks--update.sample: use hash-agnostic zero OID\n     \n    -    The update sample hook has the null OID hardcoded as 40 zeros. However,\n    +    The update sample hook has the zero OID hardcoded as 40 zeros. However,\n         with the introduction of SHA-256 support, this assumption no longer\n         holds true. Replace the hardcoded $z40 with a call to\n    -    `git rev-parse --null-oid` so the sample hook becomes hash-agnostic.\n    +\n    +            git hash-object --stdin </dev/null | tr '[0-9a-f]' '0'\n    +\n    +    so the sample hook becomes hash-agnostic.\n     \n      ## templates/hooks--update.sample ##\n     @@ templates/hooks--update.sample: esac\n    @@ templates/hooks--update.sample: esac\n      # --- Check types\n      # if $newrev is 0000...0000, it's a commit to delete a ref.\n     -zero=\"0000000000000000000000000000000000000000\"\n    -+zero=\"$(git rev-list --null-oid)\"\n    ++zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')\n      if [ \"$newrev\" = \"$zero\" ]; then\n      \tnewrev_type=delete\n      else\n-- \n2.28.0.760.g8d73e04208\n\n"},{"id":"406182","messageId":"95dd0b19ba45ebe364235fa62e18aad932506fc9.1600853895.git.liu.denton@gmail.com","threadId":"54256","inReplyTo":"cover.1600853895.git.liu.denton@gmail.com","subject":"[PATCH v2 1/3] hooks--pre-push.sample: modernize script","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-09-23T09:38:43Z","receivedAt":"2020-09-23T09:38:58Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"The preferred form for a command substitution is $() over ``. Use this\nform for the command substitution in the sample hook.\n\nThe preferred form for conditional tests is to use `test` over [].\nReplace [] with `test`.\n\nFinally, replace all instances of \"sha\" with \"oid\".\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n templates/hooks--pre-push.sample | 16 ++++++++--------\n 1 file changed, 8 insertions(+), 8 deletions(-)\n\ndiff --git a/templates/hooks--pre-push.sample b/templates/hooks--pre-push.sample\nindex 6187dbf439..d0f30190ac 100755\n--- a/templates/hooks--pre-push.sample\n+++ b/templates/hooks--pre-push.sample\n@@ -14,7 +14,7 @@\n # Information about the commits which are being pushed is supplied as lines to\n # the standard input in the form:\n #\n-#   <local ref> <local sha1> <remote ref> <remote sha1>\n+#   <local ref> <local oid> <remote ref> <remote oid>\n #\n # This sample shows how to prevent push of commits where the log message starts\n # with \"WIP\" (work in progress).\n@@ -24,25 +24,25 @@ url=\"$2\"\n \n z40=0000000000000000000000000000000000000000\n \n-while read local_ref local_sha remote_ref remote_sha\n+while read local_ref local_oid remote_ref remote_oid\n do\n-\tif [ \"$local_sha\" = $z40 ]\n+\tif test \"$local_oid\" = $z40\n \tthen\n \t\t# Handle delete\n \t\t:\n \telse\n-\t\tif [ \"$remote_sha\" = $z40 ]\n+\t\tif test \"$remote_oid\" = $z40\n \t\tthen\n \t\t\t# New branch, examine all commits\n-\t\t\trange=\"$local_sha\"\n+\t\t\trange=\"$local_oid\"\n \t\telse\n \t\t\t# Update to existing branch, examine new commits\n-\t\t\trange=\"$remote_sha..$local_sha\"\n+\t\t\trange=\"$remote_oid..$local_oid\"\n \t\tfi\n \n \t\t# Check for WIP commit\n-\t\tcommit=`git rev-list -n 1 --grep '^WIP' \"$range\"`\n-\t\tif [ -n \"$commit\" ]\n+\t\tcommit=$(git rev-list -n 1 --grep '^WIP' \"$range\")\n+\t\tif test -n \"$commit\"\n \t\tthen\n \t\t\techo >&2 \"Found WIP commit in $local_ref, not pushing\"\n \t\t\texit 1\n-- \n2.28.0.760.g8d73e04208\n\n"},{"id":"406183","messageId":"784135549f2fd23a5135cb2b6c2c5ba525885814.1600853895.git.liu.denton@gmail.com","threadId":"54256","inReplyTo":"cover.1600853895.git.liu.denton@gmail.com","subject":"[PATCH v2 3/3] hooks--update.sample: use hash-agnostic zero OID","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-09-23T09:38:45Z","receivedAt":"2020-09-23T09:39:01Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"The update sample hook has the zero OID hardcoded as 40 zeros. However,\nwith the introduction of SHA-256 support, this assumption no longer\nholds true. Replace the hardcoded $z40 with a call to\n\n\tgit hash-object --stdin </dev/null | tr '[0-9a-f]' '0'\n\nso the sample hook becomes hash-agnostic.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n templates/hooks--update.sample | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/templates/hooks--update.sample b/templates/hooks--update.sample\nindex 5014c4b31c..c4d426bc6e 100755\n--- a/templates/hooks--update.sample\n+++ b/templates/hooks--update.sample\n@@ -60,7 +60,7 @@ esac\n \n # --- Check types\n # if $newrev is 0000...0000, it's a commit to delete a ref.\n-zero=\"0000000000000000000000000000000000000000\"\n+zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')\n if [ \"$newrev\" = \"$zero\" ]; then\n \tnewrev_type=delete\n else\n-- \n2.28.0.760.g8d73e04208\n\n"},{"id":"406184","messageId":"afb460d9fd6799f6362455bbe1fe476fabe401d6.1600853895.git.liu.denton@gmail.com","threadId":"54256","inReplyTo":"cover.1600853895.git.liu.denton@gmail.com","subject":"[PATCH v2 2/3] hooks--pre-push.sample: use hash-agnostic zero OID","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2020-09-23T09:38:44Z","receivedAt":"2020-09-23T09:39:02Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"The pre-push sample hook has the zero OID hardcoded as 40 zeros.\nHowever, with the introduction of SHA-256 support, this assumption no\nlonger holds true. Replace the hardcoded $z40 with a call to\n\n\tgit hash-object --stdin </dev/null | tr '[0-9a-f]' '0'\n\nso the sample hook becomes hash-agnostic.\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n templates/hooks--pre-push.sample | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/templates/hooks--pre-push.sample b/templates/hooks--pre-push.sample\nindex d0f30190ac..4ce688d32b 100755\n--- a/templates/hooks--pre-push.sample\n+++ b/templates/hooks--pre-push.sample\n@@ -22,16 +22,16 @@\n remote=\"$1\"\n url=\"$2\"\n \n-z40=0000000000000000000000000000000000000000\n+zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')\n \n while read local_ref local_oid remote_ref remote_oid\n do\n-\tif test \"$local_oid\" = $z40\n+\tif test \"$local_oid\" = \"$zero\"\n \tthen\n \t\t# Handle delete\n \t\t:\n \telse\n-\t\tif test \"$remote_oid\" = $z40\n+\t\tif test \"$remote_oid\" = \"$zero\"\n \t\tthen\n \t\t\t# New branch, examine all commits\n \t\t\trange=\"$local_oid\"\n-- \n2.28.0.760.g8d73e04208\n\n"},{"id":"406200","messageId":"xmqqa6xgjvud.fsf@gitster.c.googlers.com","threadId":"54256","inReplyTo":"cover.1600853895.git.liu.denton@gmail.com","subject":"Re: [PATCH v2 0/3] sample hooks: become hash agnostic","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-09-23T16:34:18Z","receivedAt":"2020-09-23T16:34:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Denton Liu <liu.denton@gmail.com> writes:\n\n> There are currently two hooks that have hardcoded 40 zeros as the null\n> OID and, thus, are not hash-agnostic. Rewrite these to get the zero OID using\n>\n> \tgit hash-object --stdin </dev/null | tr '[0-9a-f]' '0'\n>\n> so that the zero OID is hash-agnostic.\n>\n> This was initially done by introducing `git rev-parse --null-oid` to get the\n> zero OID but that seems like overkill. From a cursory search of Github, the\n> only instances of the zero OID being used come from clones of the git.git\n> repository (tests and sample hooks). Since we don't want to introduce an option\n> that no one will use, don't go this route and just do the easiest thing.\n\nPatches 2&3/3 look quite sensible.\n\nPatch 1/3 is a borderline Meh, as we do not need to force _our_\ncoding convention to the end-users, even though we do do so on\nourselves.  But let's take it to make things more consistent.\n\nThanks.\n"}]}