{"thread":{"id":"1605","subject":"[PATCH] Add a new extended SHA1 syntax <name>:<num>","startedAt":"2005-08-21T09:43:54Z","lastAt":"2005-08-21T18:41:02Z","messageCount":4,"participants":["Junio C Hamano","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"7605","messageId":"7vll2viq05.fsf@assigned-by-dhcp.cox.net","threadId":"1605","inReplyTo":null,"subject":"[PATCH] Add a new extended SHA1 syntax <name>:<num>","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-08-21T09:43:54Z","receivedAt":"2005-08-21T09:43:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The new notation is a short-hand for <name> followed by <num>\ncaret ('^') characters.  E.g. \"master:4\" is the fourth\ngeneration ancestor of the current \"master\" branch head,\nfollowing the first parents; same as \"master^^^^\" but a bit more\nreadable.\n\nThis will be used in the updated \"git show-branch\" command.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n\n sha1_name.c |   41 +++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 41 insertions(+), 0 deletions(-)\n\n3a371474bc20e192b0e9d3b48fb7c84ca107b818\ndiff --git a/sha1_name.c b/sha1_name.c\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -191,9 +191,29 @@ static int get_parent(const char *name, \n \treturn -1;\n }\n \n+static int get_nth_ancestor(const char *name, int len,\n+\t\t\t    unsigned char *result, int generation)\n+{\n+\tunsigned char sha1[20];\n+\tint ret = get_sha1_1(name, len, sha1);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\twhile (generation--) {\n+\t\tstruct commit *commit = lookup_commit_reference(sha1);\n+\n+\t\tif (!commit || parse_commit(commit) || !commit->parents)\n+\t\t\treturn -1;\n+\t\tmemcpy(sha1, commit->parents->item->object.sha1, 20);\n+\t}\n+\tmemcpy(result, sha1, 20);\n+\treturn 0;\n+}\n+\n static int get_sha1_1(const char *name, int len, unsigned char *sha1)\n {\n \tint parent, ret;\n+\tconst char *cp;\n \n \t/* foo^[0-9] or foo^ (== foo^1); we do not do more than 9 parents. */\n \tif (len > 2 && name[len-2] == '^' &&\n@@ -210,6 +230,27 @@ static int get_sha1_1(const char *name, \n \tif (parent >= 0)\n \t\treturn get_parent(name, len, sha1, parent);\n \n+\t/* name:3 is name^^^,\n+\t * name:12 is name^^^^^^^^^^^^, and\n+\t * name: is name\n+\t */\n+\tparent = 0;\n+\tfor (cp = name + len - 1; name <= cp; cp--) {\n+\t\tint ch = *cp;\n+\t\tif ('0' <= ch && ch <= '9')\n+\t\t\tcontinue;\n+\t\tif (ch != ':')\n+\t\t\tparent = -1;\n+\t\tbreak;\n+\t}\n+\tif (!parent && *cp == ':') {\n+\t\tint len1 = cp - name;\n+\t\tcp++;\n+\t\twhile (cp < name + len)\n+\t\t\tparent = parent * 10 + *cp++ - '0';\n+\t\treturn get_nth_ancestor(name, len1, sha1, parent);\n+\t}\n+\n \tret = get_sha1_basic(name, len, sha1);\n \tif (!ret)\n \t\treturn 0;\n"},{"id":"7611","messageId":"Pine.LNX.4.63.0508212025350.15353@wgmdd8.biozentrum.uni-wuerzburg.de","threadId":"1605","inReplyTo":"7vll2viq05.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Add a new extended SHA1 syntax <name>:<num>","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-08-21T18:26:35Z","receivedAt":"2005-08-21T18:26:35Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 21 Aug 2005, Junio C Hamano wrote:\n\n> The new notation is a short-hand for <name> followed by <num>\n> caret ('^') characters.  E.g. \"master:4\" is the fourth\n> generation ancestor of the current \"master\" branch head,\n> following the first parents; same as \"master^^^^\" but a bit more\n> readable.\n\nThis might confuse some people with the <src>:<dest> notation of the \nrenaming fetch...\n\nCiao,\nDscho\n"},{"id":"7610","messageId":"7vr7cngmq4.fsf@assigned-by-dhcp.cox.net","threadId":"1605","inReplyTo":"Pine.LNX.4.63.0508212025350.15353@wgmdd8.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Add a new extended SHA1 syntax <name>:<num>","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-08-21T18:37:39Z","receivedAt":"2005-08-21T18:37:39Z","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> This might confuse some people with the <src>:<dest> notation of the \n> renaming fetch...\n\nTrue.  How about using a tilde '~'?\n"},{"id":"7613","messageId":"Pine.LNX.4.63.0508212040470.15825@wgmdd8.biozentrum.uni-wuerzburg.de","threadId":"1605","inReplyTo":"7vr7cngmq4.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Add a new extended SHA1 syntax <name>:<num>","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-08-21T18:41:02Z","receivedAt":"2005-08-21T18:41:02Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 21 Aug 2005, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > This might confuse some people with the <src>:<dest> notation of the \n> > renaming fetch...\n> \n> True.  How about using a tilde '~'?\n\nI like it.\n\nCiao,\nDscho\n"}]}