|
28 | 28 | #include "ref-filter.h"
|
29 | 29 | #include "date.h"
|
30 | 30 | #include "write-or-die.h"
|
| 31 | +#include "object-file-convert.h" |
31 | 32 |
|
32 | 33 | static const char * const git_tag_usage[] = {
|
33 | 34 | N_("git tag [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>] [-e]\n"
|
@@ -174,9 +175,43 @@ static int verify_tag(const char *name, const char *ref UNUSED,
|
174 | 175 | return 0;
|
175 | 176 | }
|
176 | 177 |
|
177 |
| -static int do_sign(struct strbuf *buffer) |
| 178 | +static int do_sign(struct strbuf *buffer, struct object_id **compat_oid, |
| 179 | + struct object_id *compat_oid_buf) |
178 | 180 | {
|
179 |
| - return sign_buffer(buffer, buffer, get_signing_key()); |
| 181 | + const struct git_hash_algo *compat = the_repository->compat_hash_algo; |
| 182 | + struct strbuf sig = STRBUF_INIT, compat_sig = STRBUF_INIT; |
| 183 | + struct strbuf compat_buf = STRBUF_INIT; |
| 184 | + const char *keyid = get_signing_key(); |
| 185 | + int ret = -1; |
| 186 | + |
| 187 | + if (sign_buffer(buffer, &sig, keyid)) |
| 188 | + return -1; |
| 189 | + |
| 190 | + if (compat) { |
| 191 | + const struct git_hash_algo *algo = the_repository->hash_algo; |
| 192 | + |
| 193 | + if (convert_object_file(&compat_buf, algo, compat, |
| 194 | + buffer->buf, buffer->len, OBJ_TAG, 1)) |
| 195 | + goto out; |
| 196 | + if (sign_buffer(&compat_buf, &compat_sig, keyid)) |
| 197 | + goto out; |
| 198 | + add_header_signature(&compat_buf, &sig, algo); |
| 199 | + strbuf_addbuf(&compat_buf, &compat_sig); |
| 200 | + hash_object_file(compat, compat_buf.buf, compat_buf.len, |
| 201 | + OBJ_TAG, compat_oid_buf); |
| 202 | + *compat_oid = compat_oid_buf; |
| 203 | + } |
| 204 | + |
| 205 | + if (compat_sig.len) |
| 206 | + add_header_signature(buffer, &compat_sig, compat); |
| 207 | + |
| 208 | + strbuf_addbuf(buffer, &sig); |
| 209 | + ret = 0; |
| 210 | +out: |
| 211 | + strbuf_release(&sig); |
| 212 | + strbuf_release(&compat_sig); |
| 213 | + strbuf_release(&compat_buf); |
| 214 | + return ret; |
180 | 215 | }
|
181 | 216 |
|
182 | 217 | static const char tag_template[] =
|
@@ -249,9 +284,11 @@ static void write_tag_body(int fd, const struct object_id *oid)
|
249 | 284 |
|
250 | 285 | static int build_tag_object(struct strbuf *buf, int sign, struct object_id *result)
|
251 | 286 | {
|
252 |
| - if (sign && do_sign(buf) < 0) |
| 287 | + struct object_id *compat_oid = NULL, compat_oid_buf; |
| 288 | + if (sign && do_sign(buf, &compat_oid, &compat_oid_buf) < 0) |
253 | 289 | return error(_("unable to sign the tag"));
|
254 |
| - if (write_object_file(buf->buf, buf->len, OBJ_TAG, result) < 0) |
| 290 | + if (write_object_file_flags(buf->buf, buf->len, OBJ_TAG, result, |
| 291 | + compat_oid, 0) < 0) |
255 | 292 | return error(_("unable to write tag file"));
|
256 | 293 | return 0;
|
257 | 294 | }
|
|
0 commit comments