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
;
19 memset(&sigc
, 0, sizeof(sigc
));
21 payload_size
= parse_signature(buf
, size
);
23 if (size
== payload_size
) {
24 if (flags
& GPG_VERIFY_VERBOSE
)
25 write_in_full(1, buf
, payload_size
);
26 return error("no signature found");
29 ret
= check_signature(buf
, payload_size
, buf
+ payload_size
,
30 size
- payload_size
, &sigc
);
32 if (!(flags
& GPG_VERIFY_OMIT_STATUS
))
33 print_signature_buffer(&sigc
, flags
);
35 signature_check_clear(&sigc
);
39 int gpg_verify_tag(const struct object_id
*oid
, const char *name_to_report
,
42 enum object_type type
;
47 type
= oid_object_info(the_repository
, oid
, NULL
);
49 return error("%s: cannot verify a non-tag object of type %s.",
52 find_unique_abbrev(oid
, DEFAULT_ABBREV
),
55 buf
= read_object_file(oid
, &type
, &size
);
57 return error("%s: unable to read file.",
60 find_unique_abbrev(oid
, DEFAULT_ABBREV
));
62 ret
= run_gpg_verify(buf
, size
, flags
);
68 struct object
*deref_tag(struct repository
*r
, struct object
*o
, const char *warn
, int warnlen
)
70 struct object_id
*last_oid
= NULL
;
71 while (o
&& o
->type
== OBJ_TAG
)
72 if (((struct tag
*)o
)->tagged
) {
73 last_oid
= &((struct tag
*)o
)->tagged
->oid
;
74 o
= parse_object(r
, last_oid
);
80 if (last_oid
&& is_promisor_object(last_oid
))
83 warnlen
= strlen(warn
);
84 error("missing object referenced by '%.*s'", warnlen
, warn
);
89 struct object
*deref_tag_noverify(struct object
*o
)
91 while (o
&& o
->type
== OBJ_TAG
) {
92 o
= parse_object(the_repository
, &o
->oid
);
93 if (o
&& o
->type
== OBJ_TAG
&& ((struct tag
*)o
)->tagged
)
94 o
= ((struct tag
*)o
)->tagged
;
101 struct tag
*lookup_tag(struct repository
*r
, const struct object_id
*oid
)
103 struct object
*obj
= lookup_object(r
, oid
->hash
);
105 return create_object(r
, oid
->hash
,
107 return object_as_type(r
, obj
, OBJ_TAG
, 0);
110 static timestamp_t
parse_tag_date(const char *buf
, const char *tail
)
114 while (buf
< tail
&& *buf
++ != '>')
119 while (buf
< tail
&& *buf
++ != '\n')
123 /* dateptr < buf && buf[-1] == '\n', so parsing will stop at buf-1 */
124 return parse_timestamp(dateptr
, NULL
, 10);
127 void release_tag_memory(struct tag
*t
)
131 t
->object
.parsed
= 0;
135 int parse_tag_buffer(struct repository
*r
, struct tag
*item
, const void *data
, unsigned long size
)
137 struct object_id oid
;
139 const char *bufptr
= data
;
140 const char *tail
= bufptr
+ size
;
143 if (item
->object
.parsed
)
145 item
->object
.parsed
= 1;
147 if (size
< GIT_SHA1_HEXSZ
+ 24)
149 if (memcmp("object ", bufptr
, 7) || parse_oid_hex(bufptr
+ 7, &oid
, &bufptr
) || *bufptr
++ != '\n')
152 if (!starts_with(bufptr
, "type "))
155 nl
= memchr(bufptr
, '\n', tail
- bufptr
);
156 if (!nl
|| sizeof(type
) <= (nl
- bufptr
))
158 memcpy(type
, bufptr
, nl
- bufptr
);
159 type
[nl
- bufptr
] = '\0';
162 if (!strcmp(type
, blob_type
)) {
163 item
->tagged
= (struct object
*)lookup_blob(r
, &oid
);
164 } else if (!strcmp(type
, tree_type
)) {
165 item
->tagged
= (struct object
*)lookup_tree(r
, &oid
);
166 } else if (!strcmp(type
, commit_type
)) {
167 item
->tagged
= (struct object
*)lookup_commit(r
, &oid
);
168 } else if (!strcmp(type
, tag_type
)) {
169 item
->tagged
= (struct object
*)lookup_tag(r
, &oid
);
171 error("Unknown type %s", type
);
175 if (bufptr
+ 4 < tail
&& starts_with(bufptr
, "tag "))
180 nl
= memchr(bufptr
, '\n', tail
- bufptr
);
183 item
->tag
= xmemdupz(bufptr
, nl
- bufptr
);
186 if (bufptr
+ 7 < tail
&& starts_with(bufptr
, "tagger "))
187 item
->date
= parse_tag_date(bufptr
, tail
);
194 int parse_tag(struct tag
*item
)
196 enum object_type type
;
201 if (item
->object
.parsed
)
203 data
= read_object_file(&item
->object
.oid
, &type
, &size
);
205 return error("Could not read %s",
206 oid_to_hex(&item
->object
.oid
));
207 if (type
!= OBJ_TAG
) {
209 return error("Object %s not a tag",
210 oid_to_hex(&item
->object
.oid
));
212 ret
= parse_tag_buffer(the_repository
, item
, data
, size
);