cat-file: print tags raw for "cat-file -p"

When "cat-file -p" prints commits, it shows them in their raw format, since git's format is already human-readable. For tags, however, we print the whole thing raw except for one thing: we convert the timestamp on the tagger line into a human-readable date. This dates all the way back to a0f15fa (Pretty-print tagger dates, 2006-03-01). At that time there was no other way to pretty-print a tag. These days, however, neither of those matters much. The normal way to pretty-print a tag is with "git show", which is much more flexible than "cat-file -p". Commit a0f15fa also built "verify-tag --verbose" (and subsequently "tag -v") around the "cat-file -p" output. However, that behavior was lost in commit 62e09ce (Make git tag a builtin, 2007-07-20), and we went back to printing the raw tag contents. Nobody seems to have noticed the bug since then (and it is arguably a saner behavior anyway, as it shows the actual bytes for which we verified the signature). Let's drop the tagger-date formatting for "cat-file -p". It makes us more consistent with cat-file's commit pretty-printer, and as a bonus, we can drop the hand-rolled tag parsing code in cat-file (which happened to behave inconsistently with the tag pretty-printing code elsewhere). This is a change of output format, so it's possible that some callers could considered this a regression. However, the original behavior was arguably a bug (due to the inconsistency with commits), likely nobody was relying on it (even we do not use it ourselves these days), and anyone relying on the "-p" pretty-printer should be able to expect a change in the output format (i.e., while "cat-file" is plumbing, the output format of "-p" was never guaranteed to be stable). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Apr 17, 2013 at 17:00 UTC 9cfa5126a0bdb47bc9c6d5feb76bb0fbfd40785b
2 files changed +1 -75
builtin/cat-file.c
-71
@@ -16,73 +16,6 @@
16 #define BATCH 1
17 #define BATCH_CHECK 2
18
19 -static void pprint_tag(const unsigned char *sha1, const char *buf, unsigned long size)
20 -{
21 - /* the parser in tag.c is useless here. */
22 - const char *endp = buf + size;
23 - const char *cp = buf;
24 -
25 - while (cp < endp) {
26 - char c = *cp++;
27 - if (c != '\n')
28 - continue;
29 - if (7 <= endp - cp && !memcmp("tagger ", cp, 7)) {
30 - const char *tagger = cp;
31 -
32 - /* Found the tagger line. Copy out the contents
33 - * of the buffer so far.
34 - */
35 - write_or_die(1, buf, cp - buf);
36 -
37 - /*
38 - * Do something intelligent, like pretty-printing
39 - * the date.
40 - */
41 - while (cp < endp) {
42 - if (*cp++ == '\n') {
43 - /* tagger to cp is a line
44 - * that has ident and time.
45 - */
46 - const char *sp = tagger;
47 - char *ep;
48 - unsigned long date;
49 - long tz;
50 - while (sp < cp && *sp != '>')
51 - sp++;
52 - if (sp == cp) {
53 - /* give up */
54 - write_or_die(1, tagger,
55 - cp - tagger);
56 - break;
57 - }
58 - while (sp < cp &&
59 - !('0' <= *sp && *sp <= '9'))
60 - sp++;
61 - write_or_die(1, tagger, sp - tagger);
62 - date = strtoul(sp, &ep, 10);
63 - tz = strtol(ep, NULL, 10);
64 - sp = show_date(date, tz, 0);
65 - write_or_die(1, sp, strlen(sp));
66 - xwrite(1, "\n", 1);
67 - break;
68 - }
69 - }
70 - break;
71 - }
72 - if (cp < endp && *cp == '\n')
73 - /* end of header */
74 - break;
75 - }
76 - /* At this point, we have copied out the header up to the end of
77 - * the tagger line and cp points at one past \n. It could be the
78 - * next header line after the tagger line, or it could be another
79 - * \n that marks the end of the headers. We need to copy out the
80 - * remainder as is.
81 - */
82 - if (cp < endp)
83 - write_or_die(1, cp, endp - cp);
84 -}
85 -
19 static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
20 {
21 unsigned char sha1[20];
@@ -133,10 +66,6 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
66 buf = read_sha1_file(sha1, &type, &size);
67 if (!buf)
68 die("Cannot read object %s", obj_name);
136 - if (type == OBJ_TAG) {
137 - pprint_tag(sha1, buf, size);
138 - return 0;
139 - }
69
70 /* otherwise just spit out the data */
71 break;
t/t1006-cat-file.sh
+1 -4
@@ -134,15 +134,12 @@ tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
134 tag_description="This is a tag"
135 tag_content="$tag_header_without_timestamp 0000000000 +0000
136
137 -$tag_description"
138 -tag_pretty_content="$tag_header_without_timestamp Thu Jan 1 00:00:00 1970 +0000
139 -
137 $tag_description"
138
139 tag_sha1=$(echo_without_newline "$tag_content" | git mktag)
140 tag_size=$(strlen "$tag_content")
141
145 -run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_pretty_content" 1
142 +run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content" 1
143
144 test_expect_success \
145 "Reach a blob from a tag pointing to it" \