3 #include "object-store.h"
8 #include "gpg-interface.h"
11 const char *tag_type
= "tag";
13 static int run_gpg_verify(const char *buf
, unsigned long size
, unsigned flags
)
15 struct signature_check sigc
;
16 struct strbuf payload
= STRBUF_INIT
;
17 struct strbuf signature
= STRBUF_INIT
;
20 memset(&sigc
, 0, sizeof(sigc
));
22 if (!parse_signature(buf
, size
, &payload
, &signature
)) {
23 if (flags
& GPG_VERIFY_VERBOSE
)
24 write_in_full(1, buf
, size
);
25 return error("no signature found");
28 sigc
.payload_type
= SIGNATURE_PAYLOAD_TAG
;
29 sigc
.payload
= strbuf_detach(&payload
, &sigc
.payload_len
);
30 ret
= check_signature(&sigc
, signature
.buf
, signature
.len
);
32 if (!(flags
& GPG_VERIFY_OMIT_STATUS
))
33 print_signature_buffer(&sigc
, flags
);
35 signature_check_clear(&sigc
);
36 strbuf_release(&payload
);
37 strbuf_release(&signature
);
41 int gpg_verify_tag(const struct object_id
*oid
, const char *name_to_report
,
44 enum object_type type
;
49 type
= oid_object_info(the_repository
, oid
, NULL
);
51 return error("%s: cannot verify a non-tag object of type %s.",
54 find_unique_abbrev(oid
, DEFAULT_ABBREV
),
57 buf
= read_object_file(oid
, &type
, &size
);
59 return error("%s: unable to read file.",
62 find_unique_abbrev(oid
, DEFAULT_ABBREV
));
64 ret
= run_gpg_verify(buf
, size
, flags
);
70 struct object
*deref_tag(struct repository
*r
, struct object
*o
, const char *warn
, int warnlen
)
72 struct object_id
*last_oid
= NULL
;
73 while (o
&& o
->type
== OBJ_TAG
)
74 if (((struct tag
*)o
)->tagged
) {
75 last_oid
= &((struct tag
*)o
)->tagged
->oid
;
76 o
= parse_object(r
, last_oid
);
82 if (last_oid
&& is_promisor_object(last_oid
))
85 warnlen
= strlen(warn
);
86 error("missing object referenced by '%.*s'", warnlen
, warn
);
91 struct object
*deref_tag_noverify(struct object
*o
)
93 while (o
&& o
->type
== OBJ_TAG
) {
94 o
= parse_object(the_repository
, &o
->oid
);
95 if (o
&& o
->type
== OBJ_TAG
&& ((struct tag
*)o
)->tagged
)
96 o
= ((struct tag
*)o
)->tagged
;
103 struct tag
*lookup_tag(struct repository
*r
, const struct object_id
*oid
)
105 struct object
*obj
= lookup_object(r
, oid
);
107 return create_object(r
, oid
, alloc_tag_node(r
));
108 return object_as_type(obj
, OBJ_TAG
, 0);
111 static timestamp_t
parse_tag_date(const char *buf
, const char *tail
)
115 while (buf
< tail
&& *buf
++ != '>')
120 while (buf
< tail
&& *buf
++ != '\n')
124 /* dateptr < buf && buf[-1] == '\n', so parsing will stop at buf-1 */
125 return parse_timestamp(dateptr
, NULL
, 10);
128 void release_tag_memory(struct tag
*t
)
132 t
->object
.parsed
= 0;
136 int parse_tag_buffer(struct repository
*r
, struct tag
*item
, const void *data
, unsigned long size
)
138 struct object_id oid
;
140 const char *bufptr
= data
;
141 const char *tail
= bufptr
+ size
;
144 if (item
->object
.parsed
)
149 * Presumably left over from a previous failed parse;
150 * clear it out in preparation for re-parsing (we'll probably
151 * hit the same error, which lets us tell our current caller
152 * about the problem).
154 FREE_AND_NULL(item
->tag
);
157 if (size
< the_hash_algo
->hexsz
+ 24)
159 if (memcmp("object ", bufptr
, 7) || parse_oid_hex(bufptr
+ 7, &oid
, &bufptr
) || *bufptr
++ != '\n')
162 if (!starts_with(bufptr
, "type "))
165 nl
= memchr(bufptr
, '\n', tail
- bufptr
);
166 if (!nl
|| sizeof(type
) <= (nl
- bufptr
))
168 memcpy(type
, bufptr
, nl
- bufptr
);
169 type
[nl
- bufptr
] = '\0';
172 if (!strcmp(type
, blob_type
)) {
173 item
->tagged
= (struct object
*)lookup_blob(r
, &oid
);
174 } else if (!strcmp(type
, tree_type
)) {
175 item
->tagged
= (struct object
*)lookup_tree(r
, &oid
);
176 } else if (!strcmp(type
, commit_type
)) {
177 item
->tagged
= (struct object
*)lookup_commit(r
, &oid
);
178 } else if (!strcmp(type
, tag_type
)) {
179 item
->tagged
= (struct object
*)lookup_tag(r
, &oid
);
181 return error("unknown tag type '%s' in %s",
182 type
, oid_to_hex(&item
->object
.oid
));
186 return error("bad tag pointer to %s in %s",
188 oid_to_hex(&item
->object
.oid
));
190 if (bufptr
+ 4 < tail
&& starts_with(bufptr
, "tag "))
195 nl
= memchr(bufptr
, '\n', tail
- bufptr
);
198 item
->tag
= xmemdupz(bufptr
, nl
- bufptr
);
201 if (bufptr
+ 7 < tail
&& starts_with(bufptr
, "tagger "))
202 item
->date
= parse_tag_date(bufptr
, tail
);
206 item
->object
.parsed
= 1;
210 int parse_tag(struct tag
*item
)
212 enum object_type type
;
217 if (item
->object
.parsed
)
219 data
= read_object_file(&item
->object
.oid
, &type
, &size
);
221 return error("Could not read %s",
222 oid_to_hex(&item
->object
.oid
));
223 if (type
!= OBJ_TAG
) {
225 return error("Object %s not a tag",
226 oid_to_hex(&item
->object
.oid
));
228 ret
= parse_tag_buffer(the_repository
, item
, data
, size
);
233 struct object_id
*get_tagged_oid(struct tag
*tag
)
237 return &tag
->tagged
->oid
;