3 #include "object-store.h"
8 #include "gpg-interface.h"
10 const char *tag_type
= "tag";
12 static int run_gpg_verify(const char *buf
, unsigned long size
, unsigned flags
)
14 struct signature_check sigc
;
18 memset(&sigc
, 0, sizeof(sigc
));
20 payload_size
= parse_signature(buf
, size
);
22 if (size
== payload_size
) {
23 if (flags
& GPG_VERIFY_VERBOSE
)
24 write_in_full(1, buf
, payload_size
);
25 return error("no signature found");
28 ret
= check_signature(buf
, payload_size
, buf
+ payload_size
,
29 size
- payload_size
, &sigc
);
31 if (!(flags
& GPG_VERIFY_OMIT_STATUS
))
32 print_signature_buffer(&sigc
, flags
);
34 signature_check_clear(&sigc
);
38 int gpg_verify_tag(const struct object_id
*oid
, const char *name_to_report
,
41 enum object_type type
;
46 type
= oid_object_info(the_repository
, oid
, NULL
);
48 return error("%s: cannot verify a non-tag object of type %s.",
51 find_unique_abbrev(oid
, DEFAULT_ABBREV
),
54 buf
= read_object_file(oid
, &type
, &size
);
56 return error("%s: unable to read file.",
59 find_unique_abbrev(oid
, DEFAULT_ABBREV
));
61 ret
= run_gpg_verify(buf
, size
, flags
);
67 struct object
*deref_tag_the_repository(struct object
*o
, const char *warn
, int warnlen
)
69 while (o
&& o
->type
== OBJ_TAG
)
70 if (((struct tag
*)o
)->tagged
)
71 o
= parse_object(the_repository
,
72 &((struct tag
*)o
)->tagged
->oid
);
77 warnlen
= strlen(warn
);
78 error("missing object referenced by '%.*s'", warnlen
, warn
);
83 struct object
*deref_tag_noverify(struct object
*o
)
85 while (o
&& o
->type
== OBJ_TAG
) {
86 o
= parse_object(the_repository
, &o
->oid
);
87 if (o
&& o
->type
== OBJ_TAG
&& ((struct tag
*)o
)->tagged
)
88 o
= ((struct tag
*)o
)->tagged
;
95 struct tag
*lookup_tag(struct repository
*r
, const struct object_id
*oid
)
97 struct object
*obj
= lookup_object(r
, oid
->hash
);
99 return create_object(r
, oid
->hash
,
101 return object_as_type(r
, obj
, OBJ_TAG
, 0);
104 static timestamp_t
parse_tag_date(const char *buf
, const char *tail
)
108 while (buf
< tail
&& *buf
++ != '>')
113 while (buf
< tail
&& *buf
++ != '\n')
117 /* dateptr < buf && buf[-1] == '\n', so parsing will stop at buf-1 */
118 return parse_timestamp(dateptr
, NULL
, 10);
121 void release_tag_memory(struct tag
*t
)
125 t
->object
.parsed
= 0;
129 int parse_tag_buffer(struct repository
*r
, struct tag
*item
, const void *data
, unsigned long size
)
131 struct object_id oid
;
133 const char *bufptr
= data
;
134 const char *tail
= bufptr
+ size
;
137 if (item
->object
.parsed
)
139 item
->object
.parsed
= 1;
141 if (size
< GIT_SHA1_HEXSZ
+ 24)
143 if (memcmp("object ", bufptr
, 7) || parse_oid_hex(bufptr
+ 7, &oid
, &bufptr
) || *bufptr
++ != '\n')
146 if (!starts_with(bufptr
, "type "))
149 nl
= memchr(bufptr
, '\n', tail
- bufptr
);
150 if (!nl
|| sizeof(type
) <= (nl
- bufptr
))
152 memcpy(type
, bufptr
, nl
- bufptr
);
153 type
[nl
- bufptr
] = '\0';
156 if (!strcmp(type
, blob_type
)) {
157 item
->tagged
= (struct object
*)lookup_blob(r
, &oid
);
158 } else if (!strcmp(type
, tree_type
)) {
159 item
->tagged
= (struct object
*)lookup_tree(r
, &oid
);
160 } else if (!strcmp(type
, commit_type
)) {
161 item
->tagged
= (struct object
*)lookup_commit(r
, &oid
);
162 } else if (!strcmp(type
, tag_type
)) {
163 item
->tagged
= (struct object
*)lookup_tag(r
, &oid
);
165 error("Unknown type %s", type
);
169 if (bufptr
+ 4 < tail
&& starts_with(bufptr
, "tag "))
174 nl
= memchr(bufptr
, '\n', tail
- bufptr
);
177 item
->tag
= xmemdupz(bufptr
, nl
- bufptr
);
180 if (bufptr
+ 7 < tail
&& starts_with(bufptr
, "tagger "))
181 item
->date
= parse_tag_date(bufptr
, tail
);
188 int parse_tag(struct tag
*item
)
190 enum object_type type
;
195 if (item
->object
.parsed
)
197 data
= read_object_file(&item
->object
.oid
, &type
, &size
);
199 return error("Could not read %s",
200 oid_to_hex(&item
->object
.oid
));
201 if (type
!= OBJ_TAG
) {
203 return error("Object %s not a tag",
204 oid_to_hex(&item
->object
.oid
));
206 ret
= parse_tag_buffer(the_repository
, item
, data
, size
);