@matheusbsbs / matheus-bagliano / commits / e451d06bf3
Fork 0

tag.c: Parse tagger date (if present)

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shawn O. Pearce committed Apr 12, 2010 at 16:25 UTC e451d06bf39df35d1106ad9bde5e38505533d805
2 files changed +23
tag.c
+22
@@ -36,6 +36,23 @@ struct tag *lookup_tag(const unsigned char *sha1)
36 return (struct tag *) obj;
37 }
38
39 +static unsigned long parse_tag_date(const char *buf, const char *tail)
40 +{
41 + const char *dateptr;
42 +
43 + while (buf < tail && *buf++ != '>')
44 + /* nada */;
45 + if (buf >= tail)
46 + return 0;
47 + dateptr = buf;
48 + while (buf < tail && *buf++ != '\n')
49 + /* nada */;
50 + if (buf >= tail)
51 + return 0;
52 + /* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */
53 + return strtoul(dateptr, NULL, 10);
54 +}
55 +
56 int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
57 {
58 unsigned char sha1[20];
@@ -86,6 +103,11 @@ int parse_tag_buffer(struct tag *item, void *data, unsigned long size)
103 item->tag = xmemdupz(bufptr, nl - bufptr);
104 bufptr = nl + 1;
105
106 + if (!prefixcmp(bufptr, "tagger "))
107 + item->date = parse_tag_date(bufptr, tail);
108 + else
109 + item->date = 0;
110 +
111 return 0;
112 }
113
tag.h
+1
@@ -9,6 +9,7 @@ struct tag {
9 struct object object;
10 struct object *tagged;
11 char *tag;
12 + unsigned long date;
13 };
14
15 extern struct tag *lookup_tag(const unsigned char *sha1);