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

[PATCH v2 4/5] tag.c: Parse tagger date (if present)

From
Shawn O. Pearce <spearce@spearce.org>
Date
Apr 12, 2010, 23:25 UTC
Message-ID
<1271114729-18166-4-git-send-email-spearce@spearce.org>
In-Reply-To
<20100411024008.GC23075@spearce.org>

Just like with committer dates, we parse the tagger date into the struct tag so its available for further downstream processing. However since the tagger header was not introduced until Git 0.99.1 we must consider it optional. For tags missing this header we use the default date of 0.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 tag.c |   22 ++++++++++++++++++++++
 tag.h |    1 +
 2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/tag.c b/tag.c
index ceb8655..85607c2 100644
--- a/tag.c
+++ b/tag.c
@@ -36,6 +36,23 @@ struct tag *lookup_tag(const unsigned char *sha1)
         return (struct tag *) obj;
 }
 
+static unsigned long parse_tag_date(const char *buf, const char *tail)
+{
+	const char *dateptr;
+
+	while (buf < tail && *buf++ != '>')
+		/* nada */;
+	if (buf >= tail)
+		return 0;
+	dateptr = buf;
+	while (buf < tail && *buf++ != '\n')
+		/* nada */;
+	if (buf >= tail)
+		return 0;
+	/* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */
+	return strtoul(dateptr, NULL, 10);
+}
+
 int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
 {
 	unsigned char sha1[20];
@@ -86,6 +103,11 @@ int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
 	item->tag = xmemdupz(bufptr, nl - bufptr);
 	bufptr = nl + 1;
 
+	if (!prefixcmp(bufptr, "tagger "))
+		item->date = parse_tag_date(bufptr, tail);
+	else
+		item->date = 0;
+
 	return 0;
 }
 
diff --git a/tag.h b/tag.h
index c437890..4766272 100644
--- a/tag.h
+++ b/tag.h
@@ -9,6 +9,7 @@ struct tag {
 	struct object object;
 	struct object *tagged;
 	char *tag;
+	unsigned long date;
 };
 
 extern struct tag *lookup_tag(const unsigned char *sha1);
-- 
1.7.1.rc1.246.g978a8
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 11 of 17 in “git describe bug?”
  1. Dustin SallingsApr 2, 2010
  2. Shawn O. PearceApr 2, 2010
  3. Andreas EricssonApr 6, 2010
  4. Shawn O. PearceApr 11, 2010
  5. describe: Break annotated tag ties by tagger dateShawn O. Pearce, Apr 11, 2010
  6. Junio C HamanoApr 11, 2010
  7. Shawn O. PearceApr 11, 2010
  8. 1/5 tag.c: Correct indentationShawn O. Pearce, Apr 12, 2010
  9. 2/5 tag.h: Remove unused signature fieldShawn O. Pearce, Apr 12, 2010
  10. 3/5 tag.c: Refactor parse_tag_buffer to be saner to programShawn O. Pearce, Apr 12, 2010
  11. 4/5 tag.c: Parse tagger date (if present)Shawn O. Pearce, Apr 12, 2010
  12. 5/5 describe: Break annotated tag ties by tagger dateShawn O. Pearce, Apr 12, 2010
  13. Andreas EricssonApr 13, 2010
  14. Thomas RastApr 13, 2010
  15. Shawn O. PearceApr 13, 2010
  16. Junio C HamanoApr 13, 2010
  17. Shawn O. PearceApr 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.