All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Vlasov <vsu@altlinux.ru>
To: Junio C Hamano <junkio@cox.net>
Cc: Marco Costalba <mcostalba@gmail.com>,
	catalin.marinas@gmail.com, git@vger.kernel.org,
	Sergey Vlasov <vsu@altlinux.ru>
Subject: [PATCH] revision traversal: Add --refs=<pattern> option
Date: Mon, 27 Nov 2006 18:09:11 +0300	[thread overview]
Message-ID: <11646401513369-git-send-email-vsu@altlinux.ru> (raw)
In-Reply-To: <7vzmadl5b0.fsf@assigned-by-dhcp.cox.net>

Add the --refs=<pattern> option, which can be used to select a
subset of refs matching the specified glob pattern.

Signed-off-by: Sergey Vlasov <vsu@altlinux.ru>
---

 If --all-branches is too specific for the mentioned use case,
 what about adding a more general glob pattern match?

 Documentation/git-rev-list.txt |    9 +++++++++
 revision.c                     |   21 ++++++++++++++++++---
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt
index ec43c0b..d5f99ef 100644
--- a/Documentation/git-rev-list.txt
+++ b/Documentation/git-rev-list.txt
@@ -17,6 +17,7 @@ SYNOPSIS
 	     [ \--remove-empty ]
 	     [ \--not ]
 	     [ \--all ]
+	     [ \--refs=<pattern> ]
 	     [ \--stdin ]
 	     [ \--topo-order ]
 	     [ \--parents ]
@@ -179,6 +180,14 @@ limiting may be applied.
 	Pretend as if all the refs in `$GIT_DIR/refs/` are listed on the
 	command line as '<commit>'.
 
+--refs='pattern'::
+
+	Pretend as if all the refs in `$GIT_DIR/refs/` matching the
+	specified glob pattern are listed on the command line as
+	'<commit>'.  The initial `refs/` part is skipped when matching,
+	but the subsequent `heads/`, `tags/` or `remotes/` part is
+	included in the text to match.
+
 --stdin::
 
 	In addition to the '<commit>' listed on the command
diff --git a/revision.c b/revision.c
index 993bb66..240ff59 100644
--- a/revision.c
+++ b/revision.c
@@ -7,6 +7,7 @@
 #include "refs.h"
 #include "revision.h"
 #include <regex.h>
+#include <fnmatch.h>
 #include "grep.h"
 
 static char *path_name(struct name_path *path, const char *name)
@@ -464,18 +465,28 @@ static void limit_list(struct rev_info *
 
 static int all_flags;
 static struct rev_info *all_revs;
+static const char *all_pattern;
 
 static int handle_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
 {
-	struct object *object = get_reference(all_revs, path, sha1, all_flags);
+	struct object *object;
+
+	if (all_pattern) {
+		if (strncmp(path, "refs/", 5))
+			return 0;
+		if (fnmatch(all_pattern, path + 5, 0))
+			return 0;
+	}
+	object = get_reference(all_revs, path, sha1, all_flags);
 	add_pending_object(all_revs, object, "");
 	return 0;
 }
 
-static void handle_all(struct rev_info *revs, unsigned flags)
+static void handle_all(struct rev_info *revs, unsigned flags, const char *pattern)
 {
 	all_revs = revs;
 	all_flags = flags;
+	all_pattern = pattern;
 	for_each_ref(handle_one_ref, NULL);
 }
 
@@ -800,7 +811,11 @@ int setup_revisions(int argc, const char
 				continue;
 			}
 			if (!strcmp(arg, "--all")) {
-				handle_all(revs, flags);
+				handle_all(revs, flags, NULL);
+				continue;
+			}
+			if (!strncmp(arg, "--refs=", 7)) {
+				handle_all(revs, flags, arg + 7);
 				continue;
 			}
 			if (!strcmp(arg, "--not")) {
-- 
1.4.4.1.gb0b0

  reply	other threads:[~2006-11-27 15:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-26 16:27 Possible BUG with git-rev-list --all in a StGit repository Marco Costalba
2006-11-26 20:16 ` Junio C Hamano
2006-11-27  6:31   ` Marco Costalba
2006-11-27  6:38     ` Marco Costalba
2006-11-27  7:25       ` Junio C Hamano
2006-11-27 15:09         ` Sergey Vlasov [this message]
2006-11-27 23:59           ` [PATCH] revision traversal: Add --refs=<pattern> option Junio C Hamano
2006-11-28  7:57         ` Possible BUG with git-rev-list --all in a StGit repository Marco Costalba
2006-11-28  8:41           ` Junio C Hamano
2006-11-28 12:11             ` Marco Costalba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11646401513369-git-send-email-vsu@altlinux.ru \
    --to=vsu@altlinux.ru \
    --cc=catalin.marinas@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=mcostalba@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.