Pretty-print tagger dates.
We can show commit objects with human readable dates using various --pretty options, but there was no way to do so with tags. This introduces two such ways: $ git-cat-file -p v1.2.3 shows the tag object with tagger dates in human readable format. $ git-verify-tag --verbose v1.2.3 uses it to show the contents of the tag object as well as doing GPG verification. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Mar 1, 2006 at 16:43 UTC
a0f15fa502d4451a1d0041a431f43ff5519536dd
2 files changed
+125
-15
cat-file.c
+105
-14
@@ -4,6 +4,92 @@
4
* Copyright (C) Linus Torvalds, 2005
5
*/
6
#include "cache.h"
7
+#include "exec_cmd.h"
8
+
9
+static void flush_buffer(const char *buf, unsigned long size)
10
+{
11
+ while (size > 0) {
12
+ long ret = xwrite(1, buf, size);
13
+ if (ret < 0) {
14
+ /* Ignore epipe */
15
+ if (errno == EPIPE)
16
+ break;
17
+ die("git-cat-file: %s", strerror(errno));
18
+ } else if (!ret) {
19
+ die("git-cat-file: disk full?");
20
+ }
21
+ size -= ret;
22
+ buf += ret;
23
+ }
24
+}
25
+
26
+static int pprint_tag(const unsigned char *sha1, const char *buf, unsigned long size)
27
+{
28
+ /* the parser in tag.c is useless here. */
29
+ const char *endp = buf + size;
30
+ const char *cp = buf;
31
+
32
+ while (cp < endp) {
33
+ char c = *cp++;
34
+ if (c != '\n')
35
+ continue;
36
+ if (7 <= endp - cp && !memcmp("tagger ", cp, 7)) {
37
+ const char *tagger = cp;
38
+
39
+ /* Found the tagger line. Copy out the contents
40
+ * of the buffer so far.
41
+ */
42
+ flush_buffer(buf, cp - buf);
43
+
44
+ /*
45
+ * Do something intelligent, like pretty-printing
46
+ * the date.
47
+ */
48
+ while (cp < endp) {
49
+ if (*cp++ == '\n') {
50
+ /* tagger to cp is a line
51
+ * that has ident and time.
52
+ */
53
+ const char *sp = tagger;
54
+ char *ep;
55
+ unsigned long date;
56
+ long tz;
57
+ while (sp < cp && *sp != '>')
58
+ sp++;
59
+ if (sp == cp) {
60
+ /* give up */
61
+ flush_buffer(tagger,
62
+ cp - tagger);
63
+ break;
64
+ }
65
+ while (sp < cp &&
66
+ !('0' <= *sp && *sp <= '9'))
67
+ sp++;
68
+ flush_buffer(tagger, sp - tagger);
69
+ date = strtoul(sp, &ep, 10);
70
+ tz = strtol(ep, NULL, 10);
71
+ sp = show_date(date, tz);
72
+ flush_buffer(sp, strlen(sp));
73
+ xwrite(1, "\n", 1);
74
+ break;
75
+ }
76
+ }
77
+ break;
78
+ }
79
+ if (cp < endp && *cp == '\n')
80
+ /* end of header */
81
+ break;
82
+ }
83
+ /* At this point, we have copied out the header up to the end of
84
+ * the tagger line and cp points at one past \n. It could be the
85
+ * next header line after the tagger line, or it could be another
86
+ * \n that marks the end of the headers. We need to copy out the
87
+ * remainder as is.
88
+ */
89
+ if (cp < endp)
90
+ flush_buffer(cp, endp - cp);
91
+ return 0;
92
+}
93
94
int main(int argc, char **argv)
95
{
@@ -15,7 +101,7 @@ int main(int argc, char **argv)
101
102
setup_git_directory();
103
if (argc != 3 || get_sha1(argv[2], sha1))
18
- usage("git-cat-file [-t|-s|-e|<type>] <sha1>");
104
+ usage("git-cat-file [-t|-s|-e|-p|<type>] <sha1>");
105
106
opt = 0;
107
if ( argv[1][0] == '-' ) {
@@ -43,6 +129,23 @@ int main(int argc, char **argv)
129
case 'e':
130
return !has_sha1_file(sha1);
131
132
+ case 'p':
133
+ if (get_sha1(argv[2], sha1) ||
134
+ sha1_object_info(sha1, type, NULL))
135
+ die("Not a valid object name %s", argv[2]);
136
+
137
+ /* custom pretty-print here */
138
+ if (!strcmp(type, "tree"))
139
+ return execl_git_cmd("ls-tree", argv[2], NULL);
140
+
141
+ buf = read_sha1_file(sha1, type, &size);
142
+ if (!buf)
143
+ die("Cannot read object %s", argv[2]);
144
+ if (!strcmp(type, "tag"))
145
+ return pprint_tag(sha1, buf, size);
146
+
147
+ /* otherwise just spit out the data */
148
+ break;
149
case 0:
150
buf = read_object_with_reference(sha1, argv[1], &size, NULL);
151
break;
@@ -54,18 +157,6 @@ int main(int argc, char **argv)
157
if (!buf)
158
die("git-cat-file %s: bad file", argv[2]);
159
57
- while (size > 0) {
58
- long ret = xwrite(1, buf, size);
59
- if (ret < 0) {
60
- /* Ignore epipe */
61
- if (errno == EPIPE)
62
- break;
63
- die("git-cat-file: %s", strerror(errno));
64
- } else if (!ret) {
65
- die("git-cat-file: disk full?");
66
- }
67
- size -= ret;
68
- buf += ret;
69
- }
160
+ flush_buffer(buf, size);
161
return 0;
162
}
git-verify-tag.sh
+20
-1
@@ -4,9 +4,21 @@ USAGE='<tag>'
4
SUBDIRECTORY_OK='Yes'
5
. git-sh-setup
6
7
+verbose=
8
+while case $# in 0) break;; esac
9
+do
10
+ case "$1" in
11
+ -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
12
+ verbose=t ;;
13
+ *)
14
+ break ;;
15
+ esac
16
+ shift
17
+done
18
+
19
if [ "$#" != "1" ]
20
then
9
- usage
21
+ usage
22
fi
23
24
type="$(git-cat-file -t "$1" 2>/dev/null)" ||
@@ -15,6 +27,13 @@ type="$(git-cat-file -t "$1" 2>/dev/null)" ||
27
test "$type" = tag ||
28
die "$1: cannot verify a non-tag object of type $type."
29
30
+case "$verbose" in
31
+t)
32
+ git-cat-file -p "$1" |
33
+ sed -n -e '/^-----BEGIN PGP SIGNATURE-----/q' -e p
34
+ ;;
35
+esac
36
+
37
git-cat-file tag "$1" >"$GIT_DIR/.tmp-vtag" || exit 1
38
cat "$GIT_DIR/.tmp-vtag" |
39
sed '/-----BEGIN PGP/Q' |