{"thread":{"id":"46318","subject":"name-rev: anchor pattern without --exclude?","startedAt":"2017-07-06T16:53:40Z","lastAt":"2017-07-06T18:26:35Z","messageCount":5,"participants":["Kyle Meyer","Junio C Hamano","Bryan Turner"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"323901","messageId":"87k23ltsl6.fsf@kyleam.com","threadId":"46318","inReplyTo":null,"subject":"name-rev: anchor pattern without --exclude?","fromName":"Kyle Meyer","fromEmail":"kyle@kyleam.com","sentAt":"2017-07-06T16:53:25Z","receivedAt":"2017-07-06T16:53:40Z","isPatch":false,"sender":{"key":"kyle@kyleam.com","avatar":"https://avatars.githubusercontent.com/u/1297788?v=4"},"body":"Hello,\n\nI'm trying to restrict name-rev's output to a ref whose name begins with\nthe supplied pattern [*].  Looking at \"man git-name-rev\",\nbuiltin/name-rev.c, and wildmatch.c, I don't see a way to accomplish\nthis with \"--refs=<pattern>\".\n\nSay, for example, that I want to limit name-rev's output to a ref in the\n\"refs/heads/\" namespace.\n\n    * cc8f7dc (master) c\n    * ad6d6f0 b\n    | * 49a2156 (refs/wip/wtree/refs/heads/master) d\n    |/  \n    * b91f97a a\n\n    --------------------------------------------------\n\n    $ git name-rev b91f97a\n    b91f97a wip/wtree/refs/heads/master~1\n\n    $ git name-rev --refs=\"refs/heads/*\" b91f97a\n    b91f97a wip/wtree/refs/heads/master~1\n\n    $ git name-rev --refs=\"^refs/heads/*\" b91f97a\n    b91f97a undefined\n\nStarting with v2.13.0, I can get my desired output using the --exclude\noption.\n\n    $ git name-rev --refs=\"refs/heads/*\" --exclude=\"*/refs/heads/*\" b91f97a\n    b91f97a master~2\n\nBut, unfortunately, I'm trying to find a solution that works with\nearlier Git versions (back to v1.9.4).\n\nAm I overlooking a way to do this without the --exclude option?\n\n\n[*] A bit more information on why I'm trying to do this: In Magit, we\n    have a work-in-progress feature that takes \"snapshots\" of changes\n    before they are committed.  These snapshots are stored as\n    \"refs/wip/{wtree,index}/<full refname>\".\n\n    We want to use name-rev to map a commit to a name in \"refs/heads/\",\n    ignoring these snapshot refs.\n\n-- \nKyle\n"},{"id":"323903","messageId":"xmqqfue9fqfe.fsf@gitster.mtv.corp.google.com","threadId":"46318","inReplyTo":"87k23ltsl6.fsf@kyleam.com","subject":"Re: name-rev: anchor pattern without --exclude?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-07-06T17:03:49Z","receivedAt":"2017-07-06T17:04:04Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Kyle Meyer <kyle@kyleam.com> writes:\n\n> [*] A bit more information on why I'm trying to do this: In Magit, we\n>     have a work-in-progress feature that takes \"snapshots\" of changes\n>     before they are committed.  These snapshots are stored as\n>     \"refs/wip/{wtree,index}/<full refname>\".\n>\n>     We want to use name-rev to map a commit to a name in \"refs/heads/\",\n>     ignoring these snapshot refs.\n\nWhat is the <full refname> in the above supposed to represent?  When\na user sees two refs \"refs/wip/{wtree,index}/<full refname>\", does\nit mean: \"These two represent a snapshot for changes while the user\nwas working on this branch\"?\n\nIsn't name-rev a wrong tool to find that information?  What is the\nanswer desired by your application when two or more branches point\nat the same commit you are interested in?  Pick one at random?  An\nerror saying it cannot decide where to place the snapshot?\n\nI am wondering if you are looking for \"symbolic-ref HEAD\".\n\n"},{"id":"323904","messageId":"87h8yptr7t.fsf@kyleam.com","threadId":"46318","inReplyTo":"xmqqfue9fqfe.fsf@gitster.mtv.corp.google.com","subject":"Re: name-rev: anchor pattern without --exclude?","fromName":"Kyle Meyer","fromEmail":"kyle@kyleam.com","sentAt":"2017-07-06T17:23:02Z","receivedAt":"2017-07-06T17:23:17Z","isPatch":false,"sender":{"key":"kyle@kyleam.com","avatar":"https://avatars.githubusercontent.com/u/1297788?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Kyle Meyer <kyle@kyleam.com> writes:\n>\n>> [*] A bit more information on why I'm trying to do this: In Magit, we\n>>     have a work-in-progress feature that takes \"snapshots\" of changes\n>>     before they are committed.  These snapshots are stored as\n>>     \"refs/wip/{wtree,index}/<full refname>\".\n>>\n>>     We want to use name-rev to map a commit to a name in \"refs/heads/\",\n>>     ignoring these snapshot refs.\n>\n> What is the <full refname> in the above supposed to represent?\n\nIt's the current branch, as returned by \"git symbolic-ref HEAD\".\n\n> When a user sees two refs \"refs/wip/{wtree,index}/<full refname>\",\n> does it mean: \"These two represent a snapshot for changes while the\n> user was working on this branch\"?\n\nYes.\n\n> Isn't name-rev a wrong tool to find that information?\n\nSorry for the confusion.  We're using \"symbolic-ref HEAD\" to get the\nabove information.  I was just trying to explain why we're dealing with\nref names that contain a \"refs/heads\" substring (like\nrefs/wip/wtree/refs/heads/master in the example I gave).\n\n> What is the answer desired by your application when two or more\n> branches point at the same commit you are interested in?  Pick one at\n> random?  An error saying it cannot decide where to place the snapshot?\n\nOur use of name-rev is just to get a friendly name for a hash.  If two\nbranches point to the same commit, we're fine with whatever decision\n\"git name-rev\" makes; we just want to limit it to refs in the\n\"refs/heads/\" namespace.\n\n-- \nKyle\n"},{"id":"323907","messageId":"CAGyf7-HiwR+CDtDCvQ7q9Dd_TYfvN0133UOYTO65F=4qOHqy9w@mail.gmail.com","threadId":"46318","inReplyTo":"87h8yptr7t.fsf@kyleam.com","subject":"Re: name-rev: anchor pattern without --exclude?","fromName":"Bryan Turner","fromEmail":"bturner@atlassian.com","sentAt":"2017-07-06T18:02:05Z","receivedAt":"2017-07-06T18:02:12Z","isPatch":false,"sender":{"key":"bturner@atlassian.com","avatar":"https://gravatar.com/avatar/16bcf3167981c1ef7c804e502642366d888a35b0d0b0a4ca01fdc442aa1acb1e?d=mp&s=160"},"body":"On Thu, Jul 6, 2017 at 10:23 AM, Kyle Meyer <kyle@kyleam.com> wrote:\n> Junio C Hamano <gitster@pobox.com> writes:\n>> Kyle Meyer <kyle@kyleam.com> writes:\n>\n>> What is the answer desired by your application when two or more\n>> branches point at the same commit you are interested in?  Pick one at\n>> random?  An error saying it cannot decide where to place the snapshot?\n>\n> Our use of name-rev is just to get a friendly name for a hash.  If two\n> branches point to the same commit, we're fine with whatever decision\n> \"git name-rev\" makes; we just want to limit it to refs in the\n> \"refs/heads/\" namespace.\n\nIf you don't need the ancestor traversals \"git name-rev\" provides,\n\"git for-each-ref --count 1 --format \"%(refname:short)\" --points-at\n<hash> refs/heads/\" might work. That only goes back to Git 2.7.0,\nthough; still quite a ways off your 1.9 target. (\"git branch\n--points-at\" does the same thing, I should add, and only for branches,\nbut you can't directly limit its output like you can with\n\"for-each-ref\".. Perhaps that doesn't matter for your use case.) If\nyou want names like \"master~2\", from your example, though,\n\"--points-at\" won't do what you need.\n\nBryan\n\n>\n> --\n> Kyle\n"},{"id":"323910","messageId":"87eftttoaa.fsf@kyleam.com","threadId":"46318","inReplyTo":"CAGyf7-HiwR+CDtDCvQ7q9Dd_TYfvN0133UOYTO65F=4qOHqy9w@mail.gmail.com","subject":"Re: name-rev: anchor pattern without --exclude?","fromName":"Kyle Meyer","fromEmail":"kyle@kyleam.com","sentAt":"2017-07-06T18:26:21Z","receivedAt":"2017-07-06T18:26:35Z","isPatch":false,"sender":{"key":"kyle@kyleam.com","avatar":"https://avatars.githubusercontent.com/u/1297788?v=4"},"body":"Bryan Turner <bturner@atlassian.com> writes:\n\n[...]\n\n> If you don't need the ancestor traversals \"git name-rev\" provides,\n> \"git for-each-ref --count 1 --format \"%(refname:short)\" --points-at\n> <hash> refs/heads/\" might work. That only goes back to Git 2.7.0,\n> though; still quite a ways off your 1.9 target. (\"git branch\n> --points-at\" does the same thing, I should add, and only for branches,\n> but you can't directly limit its output like you can with\n> \"for-each-ref\".. Perhaps that doesn't matter for your use case.) If\n> you want names like \"master~2\", from your example, though,\n> \"--points-at\" won't do what you need.\n\nThanks for the suggestion.  Unfortunately, I do want to consider names\nlike \"master~2\".  I was just hoping that I had overlooked another way to\nachieve the\n\n    git name-rev --refs=\"refs/heads/*\" --exclude=\"*/refs/heads/*\" <commit>\n\nexample I gave in my initial post.\n\n-- \nKyle\n"}]}