git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [RFD} Use regex's in :/ revision naming machinery
@ 2010-04-06  7:02 Yann Dirson
  0 siblings, 0 replies; 9+ messages in thread
From: Yann Dirson @ 2010-04-06  7:02 UTC (permalink / raw)
  To: git; +Cc: ydirson

Let's step in as a user of the feature :)

I started to use :/ very recently, and found it very convenient for my
particular use.  I'm running a script which takes a treeish as
argument, which I regularly run on a dev branch on which I am editing
the commits regularly - that is, the commit message rarely change, but
the sha1's do.  Then once I have a working :/ expr, I can just reuse
the line from shell history, saving typing.

Also, for composing the :/ expression, I make use of "git slog|head"
(slog being an alias of mostly "git log --pretty=oneline"), which helps
figuring out a prefix string that does not require too much
keystrokes.  There again, it is a gain compared to grabbing the mouse
to cut+paste a sha1.

Junio wrote:
>I also happen to think that the current ':/' is more or less useless
>because you cannot tell it to start digging from only these branches,
>and it becomes dice-throwing which commit it would find.

Now what I found really strange, is that the ":" in :/ would not act as
it does in the [<treeish>]:<file> syntax.  Allowing to use
[<treeish>]:/<regexp> would not only make it more useful, but also more
consistent with that other syntax.


>A related but a larger issue is that I suspect this "two-dot" would not
>work, as the syntax looks for "Merge branch 'slabh'.." (two-dot taken
>literally).

Right there is a problem here - even if it works when you mean ".." as
the range separator, it makes it hard to specify a ".." search pattern.

What about using ":/pattern/" as a syntax instead ?  That would also be
close to other familiar stuff - although it would now require quoting
a "/" to include it in the search pattern...

Another issue would be to (de)activate regexp processing (as compared
to just substring or leading-substring behaviour).  Maybe we could use
sed-like trailing modifiers for this - eg. if regexp is made the
default, ":/obj.c/f" would not match "object".  This would also give us
provision to add classical pattern modifiers like /i, and at 1st sight
would still be unambiguous wrt the .. separator.

Does that make sense ?
-- 
Yann

^ permalink raw reply	[flat|nested] 9+ messages in thread
* [RFD} Use regex's in :/ revision naming machinery
@ 2010-04-05 23:00 Linus Torvalds
  2010-04-06  1:51 ` Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Linus Torvalds @ 2010-04-05 23:00 UTC (permalink / raw)
  To: Git Mailing List, Junio C Hamano


So this is very much debatable, but I'm including a patch for the 
discussion to start.

I never use ':/', and part of it is that it's so horribly cumbersome. I'd 
_like_ to use it to do things like 

	gitk :/slabh..

which would (right now) show what happened since I merged the 'slabh' 
branch. But that doesn't work, I would need to write it as

	gitk :/"Merge branch 'slabh'"..

at which point it really isn't all that useful any more - in order to 
figure out the string I need to use, I had to look up the commit, so the 
whole :/ format was useless. I might as well just have used the SHA1 value 
instead.

The thing is, I'm not quite sure _who_ uses :/ as things are now, so maybe 
there is some reason for that incredibly annoying interface.

But with this trivial (LARGELY UNTESTED!) patch, I get the behaviour _I_ 
want, and I can do my simpler version instead.

It also allows me to do silly things like this:

	git show :/'Signed-off-by: Linus'

which shows the last commit that was signed off by me. Is that really 
useful? Not bloody likely. But it shows how much more flexible the whole 
notion of "let's grep the commit message" is than having to match exactly 
the beginning of it.

		Linus

PS. Do note the "largely untested" part. I think this patch is kind of 
cool, but it might be totally broken. I did run the test-suite on it, and 
it still says "failed  0", but that's probably more indicative of limited 
test coverage of :/ than anything else.

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

diff --git a/sha1_name.c b/sha1_name.c
index bf92417..7570f1a 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -692,12 +692,17 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
 	struct commit_list *list = NULL, *backup = NULL, *l;
 	int retval = -1;
 	char *temp_commit_buffer = NULL;
+	regex_t regex;
 
 	if (prefix[0] == '!') {
 		if (prefix[1] != '!')
 			die ("Invalid search pattern: %s", prefix);
 		prefix++;
 	}
+
+	if (regcomp(&regex, prefix, REG_EXTENDED))
+		die("Invalid search pattern: %s", prefix);
+
 	for_each_ref(handle_one_ref, &list);
 	for (l = list; l; l = l->next)
 		commit_list_insert(l->item, &backup);
@@ -721,12 +726,13 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
 		}
 		if (!(p = strstr(p, "\n\n")))
 			continue;
-		if (!prefixcmp(p + 2, prefix)) {
+		if (!regexec(&regex, p + 2, 0, NULL, 0)) {
 			hashcpy(sha1, commit->object.sha1);
 			retval = 0;
 			break;
 		}
 	}
+	regfree(&regex);
 	free(temp_commit_buffer);
 	free_commit_list(list);
 	for (l = backup; l; l = l->next)

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

end of thread, other threads:[~2010-04-07  1:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-06  7:02 [RFD} Use regex's in :/ revision naming machinery Yann Dirson
  -- strict thread matches above, loose matches on Subject: below --
2010-04-05 23:00 Linus Torvalds
2010-04-06  1:51 ` Junio C Hamano
2010-04-06  2:08   ` Junio C Hamano
2010-04-06  2:15   ` Linus Torvalds
2010-04-06  4:31 ` Jeff King
2010-04-06  7:55 ` Johannes Sixt
2010-04-06 14:19   ` Linus Torvalds
2010-04-07  1:04     ` Nazri Ramliy

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).