{"thread":{"id":"23348","subject":"[RFD} Use regex's in :/ revision naming machinery","startedAt":"2010-04-05T23:00:59Z","lastAt":"2010-04-07T01:04:19Z","messageCount":8,"participants":["Linus Torvalds","Junio C Hamano","Jeff King","Johannes Sixt","Nazri Ramliy"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"138682","messageId":"alpine.LFD.2.00.1004051551180.21411@i5.linux-foundation.org","threadId":"23348","inReplyTo":null,"subject":"[RFD} Use regex's in :/ revision naming machinery","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2010-04-05T23:00:59Z","receivedAt":"2010-04-05T23:00:59Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nSo this is very much debatable, but I'm including a patch for the \ndiscussion to start.\n\nI never use ':/', and part of it is that it's so horribly cumbersome. I'd \n_like_ to use it to do things like \n\n\tgitk :/slabh..\n\nwhich would (right now) show what happened since I merged the 'slabh' \nbranch. But that doesn't work, I would need to write it as\n\n\tgitk :/\"Merge branch 'slabh'\"..\n\nat which point it really isn't all that useful any more - in order to \nfigure out the string I need to use, I had to look up the commit, so the \nwhole :/ format was useless. I might as well just have used the SHA1 value \ninstead.\n\nThe thing is, I'm not quite sure _who_ uses :/ as things are now, so maybe \nthere is some reason for that incredibly annoying interface.\n\nBut with this trivial (LARGELY UNTESTED!) patch, I get the behaviour _I_ \nwant, and I can do my simpler version instead.\n\nIt also allows me to do silly things like this:\n\n\tgit show :/'Signed-off-by: Linus'\n\nwhich shows the last commit that was signed off by me. Is that really \nuseful? Not bloody likely. But it shows how much more flexible the whole \nnotion of \"let's grep the commit message\" is than having to match exactly \nthe beginning of it.\n\n\t\tLinus\n\nPS. Do note the \"largely untested\" part. I think this patch is kind of \ncool, but it might be totally broken. I did run the test-suite on it, and \nit still says \"failed  0\", but that's probably more indicative of limited \ntest coverage of :/ than anything else.\n\n---\n sha1_name.c |    8 +++++++-\n 1 files changed, 7 insertions(+), 1 deletions(-)\n\ndiff --git a/sha1_name.c b/sha1_name.c\nindex bf92417..7570f1a 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -692,12 +692,17 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)\n \tstruct commit_list *list = NULL, *backup = NULL, *l;\n \tint retval = -1;\n \tchar *temp_commit_buffer = NULL;\n+\tregex_t regex;\n \n \tif (prefix[0] == '!') {\n \t\tif (prefix[1] != '!')\n \t\t\tdie (\"Invalid search pattern: %s\", prefix);\n \t\tprefix++;\n \t}\n+\n+\tif (regcomp(&regex, prefix, REG_EXTENDED))\n+\t\tdie(\"Invalid search pattern: %s\", prefix);\n+\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@@ -721,12 +726,13 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)\n \t\t}\n \t\tif (!(p = strstr(p, \"\\n\\n\")))\n \t\t\tcontinue;\n-\t\tif (!prefixcmp(p + 2, prefix)) {\n+\t\tif (!regexec(&regex, p + 2, 0, NULL, 0)) {\n \t\t\thashcpy(sha1, commit->object.sha1);\n \t\t\tretval = 0;\n \t\t\tbreak;\n \t\t}\n \t}\n+\tregfree(&regex);\n \tfree(temp_commit_buffer);\n \tfree_commit_list(list);\n \tfor (l = backup; l; l = l->next)\n"},{"id":"138692","messageId":"7vr5mtl55q.fsf@alter.siamese.dyndns.org","threadId":"23348","inReplyTo":"alpine.LFD.2.00.1004051551180.21411@i5.linux-foundation.org","subject":"Re: [RFD} Use regex's in :/ revision naming machinery","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-04-06T01:51:29Z","receivedAt":"2010-04-06T01:51:29Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Torvalds <torvalds@linux-foundation.org> writes:\n\n> So this is very much debatable, but I'm including a patch for the \n> discussion to start.\n>\n> I never use ':/', and part of it is that it's so horribly cumbersome. I'd \n> _like_ to use it to do things like \n>\n> \tgitk :/slabh..\n>\n> which would (right now) show what happened since I merged the 'slabh' \n> branch. But that doesn't work, I would need to write it as\n>\n> \tgitk :/\"Merge branch 'slabh'\"..\n\nA related but a larger issue is that I suspect this \"two-dot\" would not\nwork, as the syntax looks for \"Merge branch 'slabh'..\" (two-dot taken\nliterally).\n\nI also happen to think that the current ':/' is more or less useless\nbecause you cannot tell it to start digging from only these branches, and\nit becomes dice-throwing which commit it would find.\n\nCompared to these, I don't think anybody has much against using regex.  I\npersonally am all for it, but I am not sure how much regex makes it more\nuseful.\n"},{"id":"138693","messageId":"7vmxxhl4dy.fsf@alter.siamese.dyndns.org","threadId":"23348","inReplyTo":"7vr5mtl55q.fsf@alter.siamese.dyndns.org","subject":"Re: [RFD} Use regex's in :/ revision naming machinery","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-04-06T02:08:09Z","receivedAt":"2010-04-06T02:08:09Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> A related but a larger issue is that I suspect this \"two-dot\" would not\n> work, as the syntax looks for \"Merge branch 'slabh'..\" (two-dot taken\n> literally).\n\nHeh, what do I know.  This does seem to work.  Sorry for the noise.\n"},{"id":"138694","messageId":"alpine.LFD.2.00.1004051911190.11318@i5.linux-foundation.org","threadId":"23348","inReplyTo":"7vr5mtl55q.fsf@alter.siamese.dyndns.org","subject":"Re: [RFD} Use regex's in :/ revision naming machinery","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2010-04-06T02:15:05Z","receivedAt":"2010-04-06T02:15:05Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Mon, 5 Apr 2010, Junio C Hamano wrote:\n> \n> A related but a larger issue is that I suspect this \"two-dot\" would not\n> work, as the syntax looks for \"Merge branch 'slabh'..\" (two-dot taken\n> literally).\n\nThat part works. We do the dot-dot handling first. But:\n\n> I also happen to think that the current ':/' is more or less useless\n> because you cannot tell it to start digging from only these branches, and\n> it becomes dice-throwing which commit it would find.\n\nI do agree that :/ would be much better if it just started from HEAD, \nrather than from any branch. It doesn't matter too much for me, but that's \nbecause for the kernel I tend to have just one branch (with random \noccasional topic-branches, but since I do merging rather than real \ndevelopment, that's the rare case)\n\n> Compared to these, I don't think anybody has much against using regex.  I\n> personally am all for it, but I am not sure how much regex makes it more\n> useful.\n\nI have to admit that I never use it. The reason I did that silly patch is \nthat today I thought that I _could_ use it, but then my naive\n\n\tgitk :/slabh..\n\nthing didn't work, and I wondered why.\n\nWould I actually use it more regularly if it was a regex? And if it had \nsaner semantics wrt branches? I dunno. Maybe my try at using it today was \nthe last time I'd ever try to use it again, regardless.\n\n\t\t\tLinus\n"},{"id":"138704","messageId":"20100406043133.GA3901@coredump.intra.peff.net","threadId":"23348","inReplyTo":"alpine.LFD.2.00.1004051551180.21411@i5.linux-foundation.org","subject":"Re: [RFD} Use regex's in :/ revision naming machinery","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-04-06T04:31:34Z","receivedAt":"2010-04-06T04:31:34Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Apr 05, 2010 at 04:00:59PM -0700, Linus Torvalds wrote:\n\n> So this is very much debatable, but I'm including a patch for the \n> discussion to start.\n\nFWIW, this came up quite a while ago and people generally seemed to\nthink it was a good idea, but the patch from Dscho (cc'd) never made it\nupstream.\n\nThe old thread is here:\n\n  http://article.gmane.org/gmane.comp.version-control.git/50010\n\nPersonally, I think regex matching makes :/ a bit more usable, though\nsince that thread I have found I don't use :/ all that often (instead\nneeding to pick through the results of --grep looking for the commit in\nquestion, at which point I just cut-and-paste the commit sha1). I agree\nas was suggested elsewhere in the thread that searching from HEAD would\nhelp.\n\n-Peff\n"},{"id":"138721","messageId":"4BBAE904.6010105@viscovery.net","threadId":"23348","inReplyTo":"alpine.LFD.2.00.1004051551180.21411@i5.linux-foundation.org","subject":"Re: [RFD} Use regex's in :/ revision naming machinery","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2010-04-06T07:55:48Z","receivedAt":"2010-04-06T07:55:48Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 4/6/2010 1:00, schrieb Linus Torvalds:\n> I never use ':/', and part of it is that it's so horribly cumbersome. I'd \n> _like_ to use it to do things like \n> \n> \tgitk :/slabh..\n\nRhethoric question: Do you mean history _starting_ at the commit that\ncontains \"slabh\" or _ending_ at the commit that contains \"slabh\" followed\nby two arbitrary characters?\n\nIf :/ is pattern-ized in some way, then IMO pattern matching syntax would\nbe more use-friendly than (extended) regular expresssions, particluarly\nalso because the single-character wildcard would be ? and avoid the\notherwise overloaded dot.\n\n-- Hannes\n"},{"id":"138753","messageId":"alpine.LFD.2.00.1004060713200.3487@i5.linux-foundation.org","threadId":"23348","inReplyTo":"4BBAE904.6010105@viscovery.net","subject":"Re: [RFD} Use regex's in :/ revision naming machinery","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2010-04-06T14:19:31Z","receivedAt":"2010-04-06T14:19:31Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Tue, 6 Apr 2010, Johannes Sixt wrote:\n>\n> Am 4/6/2010 1:00, schrieb Linus Torvalds:\n> > I never use ':/', and part of it is that it's so horribly cumbersome. I'd \n> > _like_ to use it to do things like \n> > \n> > \tgitk :/slabh..\n> \n> Rhethoric question: Do you mean history _starting_ at the commit that\n> contains \"slabh\" or _ending_ at the commit that contains \"slabh\" followed\n> by two arbitrary characters?\n\nEnding in the commit that contains \"slabh\".\n\nThe last two dots are removed by the revision handling machinery, _before_ \nwe even see the ':/' thing. See 'handle_revision_arg()', and notice how it \nsearches for \"..\" and then does \"*dotdot = 0\".\n\nSo the regex is 'slabh'.\n\n> If :/ is pattern-ized in some way, then IMO pattern matching syntax would\n> be more use-friendly than (extended) regular expresssions, particluarly\n> also because the single-character wildcard would be ? and avoid the\n> otherwise overloaded dot.\n\nI do agree that regex'es might contain the invalid sequence \"..\", but it's \nfairly unusual, and you can work around it, ie you can do\n\n\tgitk :/'slabh(.)(.)of'..\n\nwhich now that I write it out admittedly looks like you are searching for \ntitties, but hey, sex sells, so we can call it a _feature_.\n\n\t\t\tLinus\n"},{"id":"138793","messageId":"q2p544dda351004061804vf56aa87bo86da6480efdfa4c6@mail.gmail.com","threadId":"23348","inReplyTo":"alpine.LFD.2.00.1004060713200.3487@i5.linux-foundation.org","subject":"Re: [RFD} Use regex's in :/ revision naming machinery","fromName":"Nazri Ramliy","fromEmail":"ayiehere@gmail.com","sentAt":"2010-04-07T01:04:19Z","receivedAt":"2010-04-07T01:04:19Z","isPatch":false,"sender":{"key":"ayiehere@gmail.com","avatar":"https://avatars.githubusercontent.com/u/164756?v=4"},"body":"On Tue, Apr 6, 2010 at 10:19 PM, Linus Torvalds\n<torvalds@linux-foundation.org> wrote:\n>        gitk :/'slabh(.)(.)of'..\n>\n> which now that I write it out admittedly looks like you are searching for\n> titties, but hey, sex sells, so we can call it a _feature_.\n\nI knew it! You've had this planned out since the early beginnings!\n\nThere's a reason why you chose the name 'blob', no?\n\ngit grep blob|sed -e 's/blo/boo/g'|less\n\nHidden features?\n\nWarning: Don't try this at home. You may never read the source the\nsame way again!\n\nnazri (I'll go back to my cave)\n"}]}