{"thread":{"id":"23802","subject":"[RFC PATCH] Make :/ accept a regex rather than a fixed pattern","startedAt":"2010-05-13T22:08:42Z","lastAt":"2010-06-18T17:03:21Z","messageCount":2,"participants":["Linus Torvalds","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"141619","messageId":"alpine.LFD.2.00.1005131457350.3711@i5.linux-foundation.org","threadId":"23802","inReplyTo":null,"subject":"[RFC PATCH] Make :/ accept a regex rather than a fixed pattern","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2010-05-13T22:08:42Z","receivedAt":"2010-05-13T22:08:42Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nFrom: Linus Torvalds <torvalds@linux-foundation.org>\nDate: Fri, 23 Apr 2010 08:20:20 -0700\nSubject: [PATCH] Make :/ accept a regex rather than a fixed pattern\n\nThis also makes it trigger anywhere in the commit message, rather than\njust at the beginning. Which tends to be a lot more useful.\n\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n---\n\nI'm re-sending, because after having this in my tree for several weeks \nnow, I actually end up still using it. \n\nI agree that it's still not a wonderful thing, and it's entirely possible \nthat we should strive to use just HEAD in :/ commit finding rather than \nall refs we can find, but for at least the kernel, I don't care (since my \ntree tends to have just one main branch anyway, apart from some random \ntesting stuff I keep around).\n\nBut even if we want to limit it to HEAD, that would be a separate patch.\n\nI've personally used it for things like\n\n\tgit show :/mqueue\t# did I apply that 'mqueue' patch?\n\tgit show :/akpm\t\t# what was the last patch I got from Andrew?\n\nand while in all cases I could admittedly have done exactly the same thing \nwith something like \"git log -p -1 --grep=mqueue\" instead, I've used it as \na nice shortcut.\n\nOf course, I'm still not convinced that :/ was a good feature to begin \nwith. If we had a short form of \"--grep\" (\"-/\"?), I would probably happily \nhave written \"git log -/akpm\" instead. \n\nSo take this patch with a large pinch of salt. It's just not very \nimportant.\n\n sha1_name.c |   12 +++++++++---\n 1 files changed, 9 insertions(+), 3 deletions(-)\n\ndiff --git a/sha1_name.c b/sha1_name.c\nindex bf92417..8cf635a 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -679,8 +679,8 @@ static int handle_one_ref(const char *path,\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+ * through history and returning the first commit whose message matches\n+ * the given regular expression.\n  *\n  * For future extension, ':/!' is reserved. If you want to match a message\n  * beginning with a '!', you have to repeat the exclamation mark.\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-- \n1.7.1.83.g9d02\n"},{"id":"143910","messageId":"7vhbl0xoh2.fsf@alter.siamese.dyndns.org","threadId":"23802","inReplyTo":"alpine.LFD.2.00.1005131457350.3711@i5.linux-foundation.org","subject":"Re: [RFC PATCH] Make :/ accept a regex rather than a fixed pattern","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-06-18T17:03:21Z","receivedAt":"2010-06-18T17:03:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Torvalds <torvalds@linux-foundation.org> writes:\n\n> From: Linus Torvalds <torvalds@linux-foundation.org>\n> Date: Fri, 23 Apr 2010 08:20:20 -0700\n> Subject: [PATCH] Make :/ accept a regex rather than a fixed pattern\n>\n> This also makes it trigger anywhere in the commit message, rather than\n> just at the beginning. Which tends to be a lot more useful.\n>\n> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n> ---\n>\n> I'm re-sending, because after having this in my tree for several weeks \n> now, I actually end up still using it. \n>\n> I agree that it's still not a wonderful thing, and it's entirely possible \n> that we should strive to use just HEAD in :/ commit finding rather than \n> all refs we can find, but for at least the kernel, I don't care (since my \n> tree tends to have just one main branch anyway, apart from some random \n> testing stuff I keep around).\n>\n> But even if we want to limit it to HEAD, that would be a separate patch.\n>\n> I've personally used it for things like\n>\n> \tgit show :/mqueue\t# did I apply that 'mqueue' patch?\n> \tgit show :/akpm\t\t# what was the last patch I got from Andrew?\n>\n> and while in all cases I could admittedly have done exactly the same thing \n> with something like \"git log -p -1 --grep=mqueue\" instead, I've used it as \n> a nice shortcut.\n\nI already took this but I actually started hating it.  As I have\nmerge.summary on,\n\n    git show ':/diff: add configuration option'\n\nalmost never hits the commit I am looking for---instead it ends up finding\na merge that merges it.\n\nI however suspect that I would hate it much less after retraining my\nfingers to anchor the pattern at the beginning of the line.  But not\nyet...\n"}]}