Subject: Re: [PATCH v2] rev-parse --namespace

From: Johannes Sixt <[email-masked]>
Date: Wed, 20 Jan 2010 08:29:03 +0100

I've implemented --remotes=foo on top of your patch because I needed it,
and --namespace=remotes/foo was too much to type. Are you interested in
integrating this in your series in some way?

I only needed the --remotes=foo part; the --branches=foo is only
"because we can". Note that 'foo' is always a complete path component,
because it is the name of a remote (the trailing slash is implied), e.g.,
'--remotes=origin'.

--- 8< ---
From: Johannes Sixt <[email-masked]>
Subject: [PATCH] revision options --remotes=prefix and --branches=prefix

Signed-off-by: Johannes Sixt <[email-masked]>
---
 builtin-rev-parse.c |    2 ++
 revision.c          |   23 +++++++++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index 34af347..08b0555 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -42,6 +42,7 @@ static int is_rev_argument(const char *arg)
 		"--bisect",
 		"--dense",
 		"--branches",
+		"--branches=",
 		"--header",
 		"--max-age=",
 		"--max-count=",
@@ -52,6 +53,7 @@ static int is_rev_argument(const char *arg)
 		"--parents",
 		"--pretty",
 		"--remotes",
+		"--remotes=",
 		"--namespace=",
 		"--sparse",
 		"--tags",
diff --git a/revision.c b/revision.c
index ec63fa0..68e251b 100644
--- a/revision.c
+++ b/revision.c
@@ -714,6 +714,21 @@ static void handle_refs(struct rev_info *revs, unsigned flags,
 	for_each(handle_one_ref, &cb);
 }

+static void handle_ref_subset(struct rev_info *revs, unsigned flags,
+			      const char *prefix, const char *postfix)
+{
+	struct strbuf name = STRBUF_INIT;
+	struct all_refs_cb cb;
+
+	strbuf_addstr(&name, prefix);
+	strbuf_addstr(&name, postfix);
+	if (name.buf[name.len - 1] != '/')
+		strbuf_addch(&name, '/');
+	init_all_refs_cb(&cb, revs, flags);
+	for_each_ref_in(name.buf, handle_one_ref, &cb);
+	strbuf_release(&name);
+}
+
 static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data)
 {
 	struct all_refs_cb *cb = cb_data;
@@ -1344,6 +1359,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
 				handle_refs(revs, flags, for_each_branch_ref);
 				continue;
 			}
+			if (!prefixcmp(arg, "--branches=")) {
+				handle_ref_subset(revs, flags, "refs/heads/", arg + 11);
+				continue;
+			}
 			if (!strcmp(arg, "--bisect")) {
 				handle_refs(revs, flags, for_each_bad_bisect_ref);
 				handle_refs(revs, flags ^ UNINTERESTING, for_each_good_bisect_ref);
@@ -1358,6 +1377,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
 				handle_refs(revs, flags, for_each_remote_ref);
 				continue;
 			}
+			if (!prefixcmp(arg, "--remotes=")) {
+				handle_ref_subset(revs, flags, "refs/remotes/", arg + 10);
+				continue;
+			}
 			if (!prefixcmp(arg, "--namespace=")) {
 				struct all_refs_cb cb;

-- 
1.6.6.1301.g354d