7 const char *tag_type
= "tag";
9 static int run_gpg_verify(const char *buf
, unsigned long size
, unsigned flags
)
11 struct signature_check sigc
;
15 memset(&sigc
, 0, sizeof(sigc
));
17 payload_size
= parse_signature(buf
, size
);
19 if (size
== payload_size
) {
20 if (flags
& GPG_VERIFY_VERBOSE
)
21 write_in_full(1, buf
, payload_size
);
22 return error("no signature found");
25 ret
= check_signature(buf
, payload_size
, buf
+ payload_size
,
26 size
- payload_size
, &sigc
);
27 print_signature_buffer(&sigc
, flags
);
29 signature_check_clear(&sigc
);
33 int gpg_verify_tag(const unsigned char *sha1
, const char *name_to_report
,
36 enum object_type type
;
41 type
= sha1_object_info(sha1
, NULL
);
43 return error("%s: cannot verify a non-tag object of type %s.",
46 find_unique_abbrev(sha1
, DEFAULT_ABBREV
),
49 buf
= read_sha1_file(sha1
, &type
, &size
);
51 return error("%s: unable to read file.",
54 find_unique_abbrev(sha1
, DEFAULT_ABBREV
));
56 ret
= run_gpg_verify(buf
, size
, flags
);
62 struct object
*deref_tag(struct object
*o
, const char *warn
, int warnlen
)
64 while (o
&& o
->type
== OBJ_TAG
)
65 if (((struct tag
*)o
)->tagged
)
66 o
= parse_object(((struct tag
*)o
)->tagged
->oid
.hash
);
71 warnlen
= strlen(warn
);
72 error("missing object referenced by '%.*s'", warnlen
, warn
);
77 struct object
*deref_tag_noverify(struct object
*o
)
79 while (o
&& o
->type
== OBJ_TAG
) {
80 o
= parse_object(o
->oid
.hash
);
81 if (o
&& o
->type
== OBJ_TAG
&& ((struct tag
*)o
)->tagged
)
82 o
= ((struct tag
*)o
)->tagged
;
89 struct tag
*lookup_tag(const unsigned char *sha1
)
91 struct object
*obj
= lookup_object(sha1
);
93 return create_object(sha1
, alloc_tag_node());
94 return object_as_type(obj
, OBJ_TAG
, 0);
97 static unsigned long parse_tag_date(const char *buf
, const char *tail
)
101 while (buf
< tail
&& *buf
++ != '>')
106 while (buf
< tail
&& *buf
++ != '\n')
110 /* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */
111 return strtoul(dateptr
, NULL
, 10);
114 int parse_tag_buffer(struct tag
*item
, const void *data
, unsigned long size
)
116 unsigned char sha1
[20];
118 const char *bufptr
= data
;
119 const char *tail
= bufptr
+ size
;
122 if (item
->object
.parsed
)
124 item
->object
.parsed
= 1;
128 if (memcmp("object ", bufptr
, 7) || get_sha1_hex(bufptr
+ 7, sha1
) || bufptr
[47] != '\n')
130 bufptr
+= 48; /* "object " + sha1 + "\n" */
132 if (!starts_with(bufptr
, "type "))
135 nl
= memchr(bufptr
, '\n', tail
- bufptr
);
136 if (!nl
|| sizeof(type
) <= (nl
- bufptr
))
138 memcpy(type
, bufptr
, nl
- bufptr
);
139 type
[nl
- bufptr
] = '\0';
142 if (!strcmp(type
, blob_type
)) {
143 item
->tagged
= &lookup_blob(sha1
)->object
;
144 } else if (!strcmp(type
, tree_type
)) {
145 item
->tagged
= &lookup_tree(sha1
)->object
;
146 } else if (!strcmp(type
, commit_type
)) {
147 item
->tagged
= &lookup_commit(sha1
)->object
;
148 } else if (!strcmp(type
, tag_type
)) {
149 item
->tagged
= &lookup_tag(sha1
)->object
;
151 error("Unknown type %s", type
);
155 if (bufptr
+ 4 < tail
&& starts_with(bufptr
, "tag "))
160 nl
= memchr(bufptr
, '\n', tail
- bufptr
);
163 item
->tag
= xmemdupz(bufptr
, nl
- bufptr
);
166 if (bufptr
+ 7 < tail
&& starts_with(bufptr
, "tagger "))
167 item
->date
= parse_tag_date(bufptr
, tail
);
174 int parse_tag(struct tag
*item
)
176 enum object_type type
;
181 if (item
->object
.parsed
)
183 data
= read_sha1_file(item
->object
.oid
.hash
, &type
, &size
);
185 return error("Could not read %s",
186 oid_to_hex(&item
->object
.oid
));
187 if (type
!= OBJ_TAG
) {
189 return error("Object %s not a tag",
190 oid_to_hex(&item
->object
.oid
));
192 ret
= parse_tag_buffer(item
, data
, size
);