{"thread":{"id":"6930","subject":"[PATCH] object name: introduce ':::<oneline prefix>' notation","startedAt":"2007-02-23T18:32:08Z","lastAt":"2007-02-24T02:15:33Z","messageCount":15,"participants":["Johannes Schindelin","Jeff King","Junio C Hamano","Nicolas Pitre"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"35340","messageId":"Pine.LNX.4.63.0702231930290.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6930","inReplyTo":null,"subject":"[PATCH] object name: introduce ':::<oneline prefix>' notation","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-23T18:32:08Z","receivedAt":"2007-02-23T18:32:08Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nTo name a commit, you can now say\n\n\tgit rev-parse ':::Initial revision of \"git\"'\n\nand it will return the hash of the first youngest commit whose\ncommit message (the oneline) begins with the given prefix.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tI often do \"git log --grep=bla\" to find a certain commit, then \n\tgrab my mouse, mark the commit hash, and paste it into the command \n\tline I really want to run on that commit.\n\n\tThis allows me to throw away my mouse.\n\n sha1_name.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 50 insertions(+), 0 deletions(-)\n\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 2793de9..004c4e3 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -578,6 +578,54 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1)\n \treturn get_short_sha1(name, len, sha1, 0);\n }\n \n+static int handle_one_ref(const char *path,\n+\t\tconst unsigned char *sha1, int flag, void *cb_data)\n+{\n+\tstruct commit_list **list = cb_data;\n+\tstruct object *object = parse_object(sha1);\n+\tif (!object)\n+\t\treturn 0;\n+\tif (object->type == OBJ_TAG)\n+\t\tobject = deref_tag(object, path, strlen(path));\n+\tif (object->type != OBJ_COMMIT)\n+\t\treturn 0;\n+\tinsert_by_date((struct commit *)object, list);\n+\treturn 0;\n+}\n+\n+/*\n+ * This interprets names like ':::Initial revision of \"git\"' by searching\n+ * through history and returning the first commit whose message starts\n+ * with the given string.\n+ */\n+\n+#define ONELINE_SEEN (1u<<20)\n+int get_sha1_oneline(const char *prefix, unsigned char *sha1)\n+{\n+\tstruct commit_list *list = NULL, *backup = NULL, *l;\n+\tstruct commit *commit;\n+\n+\tif (!save_commit_buffer)\n+\t\treturn error(\"Could not expand oneline-name.\");\n+\tfor_each_ref(handle_one_ref, &list);\n+\tfor (l = list; l; l = l->next)\n+\t\tcommit_list_insert(l->item, &backup);\n+\twhile ((commit = pop_most_recent_commit(&list, ONELINE_SEEN))) {\n+\t\tchar *p;\n+\t\tparse_object(commit->object.sha1);\n+\t\tif (!commit->buffer || !(p = strstr(commit->buffer, \"\\n\\n\")))\n+\t\t\tcontinue;\n+\t\tif (!prefixcmp(p + 2, prefix)) {\n+\t\t\thashcpy(sha1, commit->object.sha1);\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\tfree_commit_list(list);\n+\tfor (l = backup; l; l = l->next)\n+\t\tclear_commit_marks(l->item, ONELINE_SEEN);\n+\treturn commit == NULL;\n+}\n+\n /*\n  * This is like \"get_sha1_basic()\", except it allows \"sha1 expressions\",\n  * notably \"xyz^\" for \"parent of xyz\"\n@@ -601,6 +649,8 @@ int get_sha1(const char *name, unsigned char *sha1)\n \t\tint stage = 0;\n \t\tstruct cache_entry *ce = NULL;\n \t\tint pos;\n+\t\tif (namelen > 3 && !prefixcmp(name + 1, \"::\"))\n+\t\t\treturn get_sha1_oneline(name + 3, sha1);\n \t\tif (namelen < 3 ||\n \t\t    name[2] != ':' ||\n \t\t    name[1] < '0' || '3' < name[1])\n-- \n1.5.0.1.2246.geaab8-dirty\n"},{"id":"35352","messageId":"Pine.LNX.4.63.0702232347310.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6930","inReplyTo":"Pine.LNX.4.63.0702231930290.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] object name: introduce ':::<oneline prefix>' notation","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-23T22:48:38Z","receivedAt":"2007-02-23T22:48:38Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 23 Feb 2007, Johannes Schindelin wrote:\n\n> To name a commit, you can now say\n> \n> \tgit rev-parse ':::Initial revision of \"git\"'\n\nAlex Riesen and Shawn Pearce suggested \":/\" instead of \":::\", to reflect \nthe searching nature (\"/\" is the key to search in \"less\" output).\n\nComments?\n\nCiao,\nDscho\n"},{"id":"35356","messageId":"20070224011214.GA8369@coredump.intra.peff.net","threadId":"6930","inReplyTo":"Pine.LNX.4.63.0702232347310.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] object name: introduce ':::<oneline prefix>' notation","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-02-24T01:12:15Z","receivedAt":"2007-02-24T01:12:15Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Feb 23, 2007 at 11:48:38PM +0100, Johannes Schindelin wrote:\n\n> > To name a commit, you can now say\n> > \n> > \tgit rev-parse ':::Initial revision of \"git\"'\n> \n> Alex Riesen and Shawn Pearce suggested \":/\" instead of \":::\", to reflect \n> the searching nature (\"/\" is the key to search in \"less\" output).\n\nIs there a particular argument for using a special syntax in the commit\nargument? Why not just add a '--grep' or similar option to indicate that\nwe will be grepping the commits logs?\n\n-Peff\n"},{"id":"35357","messageId":"7vzm741hfx.fsf@assigned-by-dhcp.cox.net","threadId":"6930","inReplyTo":"Pine.LNX.4.63.0702232347310.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] object name: introduce ':::<oneline prefix>' notation","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-24T01:18:42Z","receivedAt":"2007-02-24T01:18:42Z","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> On Fri, 23 Feb 2007, Johannes Schindelin wrote:\n>\n>> To name a commit, you can now say\n>> \n>> \tgit rev-parse ':::Initial revision of \"git\"'\n>\n> Alex Riesen and Shawn Pearce suggested \":/\" instead of \":::\", to reflect \n> the searching nature (\"/\" is the key to search in \"less\" output).\n>\n> Comments?\n\nSounds good.  \"git show :/path\" does not currently mean \"find\n/path in the index\", so I do not see offhand it would interfere\nwith anything.\n\nHowever, it would be worthwhile to plant an escape hatch for\nfuture extension.  Using short-and-sweet \":/\" for the most\ncommon case such as exact prefix match would be fine, but we\nmight want to say:\n\n\t':/!' syntax is reserved for future extension and does\n\tnot look for a string that begins with \"!\".\n\tone extension \"do not do anything special\" is defined\n\tand is spelled as \"!!\" - so if you want to look for a\n\tcommit that begins with \"!something\", please spell it\n\tas ':/!!something'\n\nor something like that.\n\nObvious extension possibilities include:\n\n\t\":/!(r=regexp)\"\n        \":/!(a=author)\"\n\t\":/!(d=2001-09-17)\"\n\t\":/!(p=Documentation/)\"\n\nor various combination of them e.g.\n\n\t\":!(p=Documentation/)!(a=Johannes)Update command list\"\n\nto look for a commit by Johannes that touches Documentation/\narea and oneline begins with \"Update command list\".\n\nBy the way, where do you start digging from?  From all refs?\n"},{"id":"35359","messageId":"Pine.LNX.4.63.0702240220300.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6930","inReplyTo":"20070224011214.GA8369@coredump.intra.peff.net","subject":"Re: [PATCH] object name: introduce ':::<oneline prefix>' notation","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-24T01:21:22Z","receivedAt":"2007-02-24T01:21:22Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 23 Feb 2007, Jeff King wrote:\n\n> On Fri, Feb 23, 2007 at 11:48:38PM +0100, Johannes Schindelin wrote:\n> \n> > > To name a commit, you can now say\n> > > \n> > > \tgit rev-parse ':::Initial revision of \"git\"'\n> > \n> > Alex Riesen and Shawn Pearce suggested \":/\" instead of \":::\", to \n> > reflect the searching nature (\"/\" is the key to search in \"less\" \n> > output).\n> \n> Is there a particular argument for using a special syntax in the commit \n> argument? Why not just add a '--grep' or similar option to indicate that \n> we will be grepping the commits logs?\n\n--grep works with git-log, but not with rev-parse, rev-list, show, diff, \netc.\n\nCiao,\nDscho\n"},{"id":"35362","messageId":"20070224013015.GA9021@coredump.intra.peff.net","threadId":"6930","inReplyTo":"Pine.LNX.4.63.0702240220300.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] object name: introduce ':::<oneline prefix>' notation","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-02-24T01:30:15Z","receivedAt":"2007-02-24T01:30:15Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"I said:\n\n> > > Alex Riesen and Shawn Pearce suggested \":/\" instead of \":::\", to \n> > argument? Why not just add a '--grep' or similar option to indicate that \n\nHmm, I completely misread your patch comments in the first place, so\nforget my suggestion; it obviously needs to be a per-committish\nindicator, not a per-command flag.\n\nI think :/ is slightly easier on the eyes than :::. Plus it opens the\ndoor for :? to find the oldest such match (though I'm not sure if it\nwould be by topology or date).\n\nOf course it's starting to look a bit like line noise...maybe we just\nneed :-/ and :-).\n\n-Peff\n"},{"id":"35364","messageId":"Pine.LNX.4.63.0702240229540.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6930","inReplyTo":"7vzm741hfx.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] object name: introduce ':::<oneline prefix>' notation","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-24T01:35:25Z","receivedAt":"2007-02-24T01:35:25Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 23 Feb 2007, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > On Fri, 23 Feb 2007, Johannes Schindelin wrote:\n> >\n> >> To name a commit, you can now say\n> >> \n> >> \tgit rev-parse ':::Initial revision of \"git\"'\n> >\n> > Alex Riesen and Shawn Pearce suggested \":/\" instead of \":::\", to reflect \n> > the searching nature (\"/\" is the key to search in \"less\" output).\n> >\n> > Comments?\n> \n> Sounds good.  \"git show :/path\" does not currently mean \"find /path in \n> the index\", so I do not see offhand it would interfere with anything.\n\nThat's also what Shawn said.\n\n> However, it would be worthwhile to plant an escape hatch for future \n> extension.  Using short-and-sweet \":/\" for the most common case such as \n> exact prefix match would be fine, but we might want to say:\n> \n> \t':/!' syntax is reserved for future extension and does\n> \tnot look for a string that begins with \"!\".\n\nOkay. Will rework.\n\n> Obvious extension possibilities include:\n> \n> \t\":/!(r=regexp)\"\n>         \":/!(a=author)\"\n> \t\":/!(d=2001-09-17)\"\n> \t\":/!(p=Documentation/)\"\n> \n> or various combination of them e.g.\n> \n> \t\":!(p=Documentation/)!(a=Johannes)Update command list\"\n\nThey are much harder to implement. So I'll leave that to others :-)\n\n> By the way, where do you start digging from?  From all refs?\n\nYes, all refs. In order of the date.\n\nCiao,\nDscho\n"},{"id":"35365","messageId":"7vk5y81g4t.fsf@assigned-by-dhcp.cox.net","threadId":"6930","inReplyTo":"Pine.LNX.4.63.0702240229540.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] object name: introduce ':::<oneline prefix>' notation","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-24T01:46:58Z","receivedAt":"2007-02-24T01:46:58Z","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>> By the way, where do you start digging from?  From all refs?\n>\n> Yes, all refs. In order of the date.\n\nThen, another possibly useful extension is \"start from this ref\"\n(you can give multiple and if no such refs are given keep the\ncurrent \"from all refs\" behaviour).\n"},{"id":"35367","messageId":"Pine.LNX.4.63.0702240248210.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6930","inReplyTo":"20070224013015.GA9021@coredump.intra.peff.net","subject":"Re: [PATCH] object name: introduce ':::<oneline prefix>' notation","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-24T01:49:31Z","receivedAt":"2007-02-24T01:49:31Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 23 Feb 2007, Jeff King wrote:\n\n> I think :/ is slightly easier on the eyes than :::. Plus it opens the \n> door for :? to find the oldest such match (though I'm not sure if it \n> would be by topology or date).\n\nBy topology makes no sense with more than one root.\n\n> Of course it's starting to look a bit like line noise...maybe we just \n> need :-/ and :-).\n\nThat was also a suggestion in IRC :-)\n\nCiao,\nDscho\n"},{"id":"35368","messageId":"alpine.LRH.0.82.0702232049590.29426@xanadu.home","threadId":"6930","inReplyTo":"20070224013015.GA9021@coredump.intra.peff.net","subject":"Re: [PATCH] object name: introduce ':::<oneline prefix>' notation","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-02-24T01:53:38Z","receivedAt":"2007-02-24T01:53:38Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"On Fri, 23 Feb 2007, Jeff King wrote:\n\n> I think :/ is slightly easier on the eyes than :::. Plus it opens the\n> door for :? to find the oldest such match (though I'm not sure if it\n> would be by topology or date).\n> \n> Of course it's starting to look a bit like line noise...maybe we just\n> need :-/ and :-).\n\nLOL!  ;-D\n\nI was looking at that :/!!P=(blah) and my yuck-o-meter was going up \nquickly.  But I'd use :-) anytime!\n\n\nNicolas\n"},{"id":"35370","messageId":"alpine.LRH.0.82.0702232055060.29426@xanadu.home","threadId":"6930","inReplyTo":"7vk5y81g4t.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] object name: introduce ':::<oneline prefix>' notation","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-02-24T01:56:52Z","receivedAt":"2007-02-24T01:56:52Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"On Fri, 23 Feb 2007, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> >> By the way, where do you start digging from?  From all refs?\n> >\n> > Yes, all refs. In order of the date.\n> \n> Then, another possibly useful extension is \"start from this ref\"\n> (you can give multiple and if no such refs are given keep the\n> current \"from all refs\" behaviour).\n\nCan we generalize the syntax a bit more instead?\n\nWhat about HEAD:/blah ?\n\n\nNicolas\n"},{"id":"35371","messageId":"20070224015731.GA10198@coredump.intra.peff.net","threadId":"6930","inReplyTo":"Pine.LNX.4.63.0702240248210.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] object name: introduce ':::<oneline prefix>' notation","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-02-24T01:57:31Z","receivedAt":"2007-02-24T01:57:31Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Feb 24, 2007 at 02:49:31AM +0100, Johannes Schindelin wrote:\n\n> > door for :? to find the oldest such match (though I'm not sure if it \n> > would be by topology or date).\n> By topology makes no sense with more than one root.\n\nAgreed, but by date might not make sense if you have clock skew. I had\nassumed your patch for \"youngest\" was by distance to ref, but I suppose\nthat doesn't make sense if you are looking over a set of possibly\nunconnected refs. So I think trusting the clock may be the only\nsensible thing.\n\n-Peff\n"},{"id":"35372","messageId":"Pine.LNX.4.63.0702240310220.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6930","inReplyTo":"alpine.LRH.0.82.0702232055060.29426@xanadu.home","subject":"Re: [PATCH] object name: introduce ':::<oneline prefix>' notation","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-24T02:10:39Z","receivedAt":"2007-02-24T02:10:39Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 23 Feb 2007, Nicolas Pitre wrote:\n\n> On Fri, 23 Feb 2007, Junio C Hamano wrote:\n> \n> > Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> > \n> > >> By the way, where do you start digging from?  From all refs?\n> > >\n> > > Yes, all refs. In order of the date.\n> > \n> > Then, another possibly useful extension is \"start from this ref\"\n> > (you can give multiple and if no such refs are given keep the\n> > current \"from all refs\" behaviour).\n> \n> Can we generalize the syntax a bit more instead?\n> \n> What about HEAD:/blah ?\n\nI'd expect this to do the same as HEAD:blah\n\nCiao,\nDscho\n"},{"id":"35374","messageId":"Pine.LNX.4.63.0702240311240.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6930","inReplyTo":"20070224015731.GA10198@coredump.intra.peff.net","subject":"Re: [PATCH] object name: introduce ':::<oneline prefix>' notation","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-24T02:14:11Z","receivedAt":"2007-02-24T02:14:11Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 23 Feb 2007, Jeff King wrote:\n\n> On Sat, Feb 24, 2007 at 02:49:31AM +0100, Johannes Schindelin wrote:\n> \n> > > door for :? to find the oldest such match (though I'm not sure if it \n> > > would be by topology or date).\n> >\n> > By topology makes no sense with more than one root.\n> \n> Agreed, but by date might not make sense if you have clock skew. I had \n> assumed your patch for \"youngest\" was by distance to ref, but I suppose \n> that doesn't make sense if you are looking over a set of possibly \n> unconnected refs. So I think trusting the clock may be the only sensible \n> thing.\n\nGiven that most commits _will_ have a unique oneline, I think it does not \nmatter that much. After all, the principal use case I see for it is \nfinding a commit, given a shortlog, or a mail subject, or even a sentence \nmuttered over the phone.\n\nCiao,\nDscho\n"},{"id":"35377","messageId":"20070224021533.GA10715@coredump.intra.peff.net","threadId":"6930","inReplyTo":"Pine.LNX.4.63.0702240311240.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] object name: introduce ':::<oneline prefix>' notation","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-02-24T02:15:33Z","receivedAt":"2007-02-24T02:15:33Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Feb 24, 2007 at 03:14:11AM +0100, Johannes Schindelin wrote:\n\n> Given that most commits _will_ have a unique oneline, I think it does not \n> matter that much. After all, the principal use case I see for it is \n> finding a commit, given a shortlog, or a mail subject, or even a sentence \n> muttered over the phone.\n\nFair enough. If you have something ambiguous, looking through 'git log'\noutput is probably more sane anyway. Color me convinced.\n\n-Peff\n"}]}