git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Interpret :/<pattern> as a regular expression
@ 2007-06-13  0:50 Johannes Schindelin
  2007-06-13  1:21 ` Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Johannes Schindelin @ 2007-06-13  0:50 UTC (permalink / raw)
  To: git


Earlier, Git interpreted the pattern as a strict prefix, which made
the operator unsuited in many cases.

Now, the pattern is interpreted as a regular expression (which does not 
change the behaviour too much, since few onelines contain special regex 
characters), so that you can say

	git diff :/.*^Signed-off-by:.Zack.Brown

to see the diff against the most recent reachable commit which was
signed off by Zack, whose Kernel Cousin I miss very much.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---

	For fun, you can see which committer signed himself off:

		git show :/.*^Signed-off:

	*grin*

 sha1_name.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/sha1_name.c b/sha1_name.c
index d9188ed..f1ba194 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -611,6 +611,8 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
 {
 	struct commit_list *list = NULL, *backup = NULL, *l;
 	int retval = -1;
+	regex_t regexp;
+	regmatch_t regmatch[1];
 
 	if (prefix[0] == '!') {
 		if (prefix[1] != '!')
@@ -622,6 +624,8 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
 	for_each_ref(handle_one_ref, &list);
 	for (l = list; l; l = l->next)
 		commit_list_insert(l->item, &backup);
+	if (regcomp(&regexp, prefix, REG_EXTENDED))
+		return error("invalid regexp: %s", prefix);
 	while (list) {
 		char *p;
 		struct commit *commit;
@@ -630,7 +634,9 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
 		parse_object(commit->object.sha1);
 		if (!commit->buffer || !(p = strstr(commit->buffer, "\n\n")))
 			continue;
-		if (!prefixcmp(p + 2, prefix)) {
+		if (!regexec(&regexp, p + 2, 1, regmatch, 0) &&
+				printf("match: %d\n", regmatch[0].rm_so) &&
+				regmatch[0].rm_so == 0) {
 			hashcpy(sha1, commit->object.sha1);
 			retval = 0;
 			break;
@@ -639,6 +645,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
 	free_commit_list(list);
 	for (l = backup; l; l = l->next)
 		clear_commit_marks(l->item, ONELINE_SEEN);
+	regfree(&regexp);
 	return retval;
 }
 
-- 
1.5.2.1.2827.gba84a8-dirty

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2007-06-14  9:08 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-13  0:50 [PATCH] Interpret :/<pattern> as a regular expression Johannes Schindelin
2007-06-13  1:21 ` Junio C Hamano
2007-06-13 13:13   ` Johannes Schindelin
2007-06-13  4:52 ` Junio C Hamano
2007-06-13 11:10   ` Johannes Schindelin
2007-06-13 11:17   ` (unknown) Johannes Schindelin
2007-06-13 12:11     ` [PATCH] Interpret :/<pattern> as a regular expression Johannes Schindelin
2007-06-13 18:41 ` Jeff King
2007-06-13 18:54   ` Johannes Schindelin
2007-06-13 20:00     ` Jeff King
2007-06-13 22:20       ` Johannes Schindelin
2007-06-14  7:48         ` Sam Vilain
2007-06-14  8:09           ` Johannes Schindelin
2007-06-14  9:07             ` Sam Vilain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).