{"thread":{"id":"48843","subject":"Unexpected behavior with :/<text> references","startedAt":"2018-07-09T03:30:17Z","lastAt":"2018-07-09T20:52:31Z","messageCount":4,"participants":["William Chargin","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"351921","messageId":"CAFW+GMBLeLyJjJPaEXkyQ5fJ=L4q4vQ=26wjZ+n07ZvSaTaCUg@mail.gmail.com","threadId":"48843","inReplyTo":null,"subject":"Unexpected behavior with :/<text> references","fromName":"William Chargin","fromEmail":"wchargin@gmail.com","sentAt":"2018-07-09T03:29:53Z","receivedAt":"2018-07-09T03:30:17Z","isPatch":false,"sender":{"key":"wchargin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4317806?v=4"},"body":"Hello,\n\nI'm experiencing strange behavior with :/<text> references, which seems\nto be inconsistent with the explanation in the docs on two counts.\nFirst, sometimes the matched commit is not the youngest. Second, some\ncommits cannot be found at all, even if they are reachable from HEAD.\n\nHere is a script to reproduce the behavior (Git built from current pu):\n\n    #!/bin/sh\n    export GIT_CONFIG_NOSYSTEM=1\n    export GIT_ATTR_NOSYSTEM=1\n    cd \"$(mktemp -d --suffix .gitrepro)\"\n\n    git --version\n    git init\n\n    git commit -q --allow-empty -m initial\n    git commit -q --allow-empty -m foo\n    git checkout -q -b early-branch\n    git commit -q --allow-empty -m foobar\n    git checkout -q --detach\n    git commit -q --allow-empty -m foobarbaz\n\n    echo\n    echo \"The following should all print 'foobarbaz':\"\n    git show --format=%s ':/foo' --\n    git show --format=%s ':/foobar' --\n    git show --format=%s ':/foobarbaz' --\n\n    echo\n    echo \"With an explicit branch:\"\n    git branch late-branch\n    git show --format=%s ':/foo' --\n    git show --format=%s ':/foobar' --\n    git show --format=%s ':/foobarbaz' --\n\nHere is the output on my machine:\n\n    git version 2.18.0.516.g6fb7f6652\n    Initialized empty Git repository in /tmp/tmp.WeCD0QZPIf.gitrepro/.git/\n\n    The following should all print 'foobarbaz':\n    foo\n    foobar\n    fatal: bad revision ':/foobarbaz'\n\n    With an explicit branch:\n    foo\n    foobarbaz\n    foobarbaz\n\nFirst, the commit with message \"foobar\" clearly matches the regular\nexpression /foo/ as well as /foobar/, but \":/foo\" resolves to an older\ncommit. However, Documentation/revisions.txt indicates that a :/<text>\nreference should resolve to the _youngest_ matching commit.\n\nSecond, the commit with message \"foobarbaz\" is reachable from HEAD, and\nyet the regular expression /foobarbaz/ fails to match it. The same\ndocumentation indicates that :/<text> references find commits reachable\nfrom any ref, and the glossary entry for \"ref\" states that HEAD is a\n\"special-purpose ref\" even though it does not begin with \"refs/\".\n\nIt looks to me like references reachable from `master` are always picked\nover other references, and that references reachable only from HEAD are\nnot matched at all.\n\nIs the observed behavior intentional? If so, what am I misunderstanding?\n\nThanks!\nWC\n\n(for searchability: colon slash text references)\n"},{"id":"351924","messageId":"CAFW+GMAnkLYReotwRvbVt9iPqmuq_8WMc1sck4Jkj_fyafVm3w@mail.gmail.com","threadId":"48843","inReplyTo":"CAFW+GMBLeLyJjJPaEXkyQ5fJ=L4q4vQ=26wjZ+n07ZvSaTaCUg@mail.gmail.com","subject":"Re: Unexpected behavior with :/<text> references","fromName":"William Chargin","fromEmail":"wchargin@gmail.com","sentAt":"2018-07-09T05:13:12Z","receivedAt":"2018-07-09T05:13:36Z","isPatch":false,"sender":{"key":"wchargin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4317806?v=4"},"body":"After further investigation, it appears that \":/foo\" indeed resolves to\nthe commit with message \"foobar\" (in the above example) if the commits\nare not all created at the same time: e.g., by adding `sleep 1` between\nthe commit commands, or exporting `GIT_AUTHOR_DATE`.\n\nThis leaves only the question of why :/<text> references don't resolve\nto commits reachable only from HEAD, and whether this is the best\nbehavior.\n"},{"id":"351971","messageId":"20180709180804.GA6134@sigill.intra.peff.net","threadId":"48843","inReplyTo":"CAFW+GMAnkLYReotwRvbVt9iPqmuq_8WMc1sck4Jkj_fyafVm3w@mail.gmail.com","subject":"Re: Unexpected behavior with :/<text> references","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-07-09T18:08:04Z","receivedAt":"2018-07-09T18:08:09Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Jul 08, 2018 at 10:13:12PM -0700, William Chargin wrote:\n\n> After further investigation, it appears that \":/foo\" indeed resolves to\n> the commit with message \"foobar\" (in the above example) if the commits\n> are not all created at the same time: e.g., by adding `sleep 1` between\n> the commit commands, or exporting `GIT_AUTHOR_DATE`.\n\nI suspect it's actually GIT_COMMITTER_DATE (but I didn't dig into it, so\nI could be wrong). \"Youngest\" in terms of commits generally refers to\nthe committer date.\n\n> This leaves only the question of why :/<text> references don't resolve\n> to commits reachable only from HEAD, and whether this is the best\n> behavior.\n\nI agree that it would make sense to look at HEAD here. The point of \":/\"\nis to search everything reachable, and HEAD is part of that\nreachability. _Usually_ it doesn't matter because HEAD is pointing to\nanother ref, but the detached case is an exception.\n\nDoing this would bring us in line with the behavior of other parts of\nGit. E.g., f0298cf1c6 (revision walker: include a detached HEAD\nin --all, 2009-01-16).\n\nThe patch is probably this:\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 60d9ef3c7e..641ca12f91 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1650,6 +1650,7 @@ static int get_oid_with_context_1(const char *name,\n \t\t\tstruct commit_list *list = NULL;\n \n \t\t\tfor_each_ref(handle_one_ref, &list);\n+\t\t\thead_ref(handle_one_ref, &list);\n \t\t\tcommit_list_sort_by_date(&list);\n \t\t\treturn get_oid_oneline(name + 2, oid, list);\n \t\t}\n\nbut I didn't test it at all. Do you want to try adding a case for this\nto our test suite (probably in t4208) and wrapping it up with a commit\nmessage?\n\n-Peff\n"},{"id":"352024","messageId":"CAFW+GMB0x9Kimmdt_v1-eOhTUV=gzj7SyHwR2KF5ofHL0d15ug@mail.gmail.com","threadId":"48843","inReplyTo":"20180709180804.GA6134@sigill.intra.peff.net","subject":"Re: Unexpected behavior with :/<text> references","fromName":"William Chargin","fromEmail":"wchargin@gmail.com","sentAt":"2018-07-09T20:52:07Z","receivedAt":"2018-07-09T20:52:31Z","isPatch":false,"sender":{"key":"wchargin@gmail.com","avatar":"https://avatars.githubusercontent.com/u/4317806?v=4"},"body":"Yep, I agree with your analysis. I'd be happy to test and commit this,\nprobably later today.\n\nThanks for your input, and for the patch!\n\nBest,\nWC\n"}]}