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

Re: [Bug] for-each-ref: %(object) and %(type) unimplemented

From
Jeff King <peff@peff.net>
Date
Jun 25, 2008, 16:08 UTC
Message-ID
<20080625160814.GA3321@sigill.intra.peff.net>
In-Reply-To
<48625DAD.5040404@gmail.com>
On Wed, Jun 25, 2008 at 05:01:01PM +0200, Lea Wiemann wrote:
Show 11 quoted lines
> Try the following on a repository with tag objects in it:
>
> git for-each-ref --format='%(object)'
> git for-each-ref --format='%(type)'
>
> Each command prints only newlines.  The %(type) and %(object) options are 
> not rejected with an error message (like "%(doesnotexist)"), but they 
> don't seem to be implemented.  "%(tag)" works though.
>
> Anyone care to implement the missing options?  Or should they rather be  
> removed from the documentation?

Looks like they were part of the original set of atoms, but they just never ended up implemented. Clearly nobody has actually cared in the intervening time, but it is easy enough to add them. See below.

Since you seem to be testing for-each-ref, maybe it would make sense to put together a test script that exercises each of the atoms?

-- >8 -- for-each-ref: implement missing tag values

The "type" and "object" fields for tags were accepted as valid atoms, but never implemented. Consequently, they simply returned the empty string, even for valid tags.

Noticed by Lea Wiemann.
Signed-off-by: Jeff King <peff@peff.net>
---
 builtin-for-each-ref.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index 07d9c57..fef93d7 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -234,6 +234,13 @@ static void grab_tag_values(struct atom_value *val, int deref, struct object *ob
 			name++;
 		if (!strcmp(name, "tag"))
 			v->s = tag->tag;
+		else if (!strcmp(name, "type") && tag->tagged)
+			v->s = typename(tag->tagged->type);
+		else if (!strcmp(name, "object") && tag->tagged) {
+			char *s = xmalloc(41);
+			strcpy(s, sha1_to_hex(tag->tagged->sha1));
+			v->s = s;
+		}
 	}
 }
 
-- 
1.5.6.129.g8dea5.dirty
Previous: Lea WiemannNext: Jeff King
Message 2 of 11 in “[Bug] for-each-ref: %(object) and %(type) unimplemented”
  1. Lea WiemannJun 25, 2008
  2. Jeff KingJun 25, 2008
  3. Jeff KingJun 25, 2008
  4. Mikael MagnussonJun 25, 2008
  5. Junio C HamanoJun 25, 2008
  6. Mikael MagnussonJun 25, 2008
  7. Jeff KingJun 26, 2008
  8. 1/2 improve for-each-ref test scriptJeff King, Jun 26, 2008
  9. 2/2 for-each-ref: implement missing tag valuesJeff King, Jun 26, 2008
  10. Jeff KingJun 26, 2008
  11. Junio C HamanoJun 26, 2008

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.