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

[PATCH 4/4] for-each-ref --format='%(flag)'

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 13, 2010, 20:30 UTC
Message-ID
<1266093033-9526-5-git-send-email-gitster@pobox.com>
In-Reply-To
<1266093033-9526-1-git-send-email-gitster@pobox.com>

This expands to "symref" or "packed" or an empty string, exposing the internal "flag" the for_each_ref() callback functions are called with.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-for-each-ref.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index b9b03e1..62be1bb 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -71,6 +71,7 @@ static struct {
 	{ "contents" },
 	{ "upstream" },
 	{ "symref" },
+	{ "flag" },
 };
 
 /*
@@ -558,6 +559,13 @@ static void grab_values(struct atom_value *val, int deref, struct object *obj, v
 	}
 }
 
+static inline char *copy_advance(char *dst, const char *src)
+{
+	while (*src)
+		*dst++ = *src++;
+	return dst;
+}
+
 /*
  * Parse the object referred by ref, and grab needed value.
  */
@@ -610,6 +618,20 @@ static void populate_value(struct refinfo *ref)
 				continue;
 			refname = branch->merge[0]->dst;
 		}
+		else if (!strcmp(name, "flag")) {
+			char buf[256], *cp = buf;
+			if (ref->flag & REF_ISSYMREF)
+				cp = copy_advance(cp, ",symref");
+			if (ref->flag & REF_ISPACKED)
+				cp = copy_advance(cp, ",packed");
+			if (cp == buf)
+				v->s = "";
+			else {
+				*cp = '\0';
+				v->s = xstrdup(buf + 1);
+			}
+			continue;
+		}
 		else
 			continue;
 
-- 
1.7.0.169.g57c99
Previous: Jeff King
Message 8 of 8 in “for-each-ref --format='%(symref) %(symref:short) %(flag)'”
  1. 0/4 for-each-ref --format='%(symref) %(symref:short) %(flag)'Junio C Hamano, Feb 13, 2010
  2. 1/4 builtin-for-each-ref.c: comment fixesJunio C Hamano, Feb 13, 2010
  3. 2/4 builtin-for-each-ref.c: check if we need to peel onion while parsing the formatJunio C Hamano, Feb 13, 2010
  4. 3/4 for-each-ref --format='%(symref) %(symref:short)'Junio C Hamano, Feb 13, 2010
  5. Jeff KingFeb 14, 2010
  6. Junio C HamanoFeb 14, 2010
  7. Jeff KingFeb 15, 2010
  8. 4/4 for-each-ref --format='%(flag)'Junio C Hamano, Feb 13, 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.