git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Johannes Sixt <j.sixt@viscovery.net>
Date
Jan 20, 2010, 07:29 UTC
Message-ID
<4B56B0BF.6020102@viscovery.net>
In-Reply-To
<1263798952-27624-1-git-send-email-ilari.liusvaara@elisanet.fi>

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 <j6t@kdbg.org>
Subject: [PATCH] revision options --remotes=prefix and --branches=prefix
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 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
Previous: Junio C Hamano
Message 14 of 14 in “rev-parse --namespace”
  1. rev-parse --namespaceIlari Liusvaara, Jan 18, 2010
  2. Junio C HamanoJan 18, 2010
  3. rev-parse --namespaceIlari Liusvaara, Jan 18, 2010
  4. Jeff KingJan 19, 2010
  5. Fix errors in t6018Ilari Liusvaara, Jan 19, 2010
  6. Junio C HamanoJan 19, 2010
  7. Thomas RastJan 19, 2010
  8. Ilari LiusvaaraJan 19, 2010
  9. Junio C HamanoJan 19, 2010
  10. Ilari LiusvaaraJan 19, 2010
  11. Thomas RastJan 19, 2010
  12. Ilari LiusvaaraJan 19, 2010
  13. Junio C HamanoJan 19, 2010
  14. Johannes SixtJan 20, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.