@matheusbsbs / matheus-bagliano / commits / bab8118aff
Fork 0

Reuse previous annotation when overwriting a tag

When forcing to overwrite an annotated tag, there are good chances one wants to keep the old annotation, or modify it, not start from scratch. This is obviously only triggered for annotated tagging (-a or -s). Signed-off-by: Mike Hommey <mh@glandium.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Mike Hommey committed Nov 4, 2007 at 01:11 UTC bab8118aff7581364eb5c74472fe7ab4f45f4a12
1 file changed +35 -3
builtin-tag.c
+35 -3
@@ -247,9 +247,37 @@ static int git_tag_config(const char *var, const char *value)
247 return git_default_config(var, value);
248 }
249
250 +static void write_tag_body(int fd, const unsigned char *sha1)
251 +{
252 + unsigned long size;
253 + enum object_type type;
254 + char *buf, *sp, *eob;
255 + size_t len;
256 +
257 + buf = read_sha1_file(sha1, &type, &size);
258 + if (!buf)
259 + return;
260 + /* skip header */
261 + sp = strstr(buf, "\n\n");
262 +
263 + if (!sp || !size || type != OBJ_TAG) {
264 + free(buf);
265 + return;
266 + }
267 + sp += 2; /* skip the 2 LFs */
268 + eob = strstr(sp, "\n" PGP_SIGNATURE "\n");
269 + if (eob)
270 + len = eob - sp;
271 + else
272 + len = buf + size - sp;
273 + write_or_die(fd, sp, len);
274 +
275 + free(buf);
276 +}
277 +
278 static void create_tag(const unsigned char *object, const char *tag,
279 struct strbuf *buf, int message, int sign,
252 - unsigned char *result)
280 + unsigned char *prev, unsigned char *result)
281 {
282 enum object_type type;
283 char header_buf[1024];
@@ -282,7 +310,11 @@ static void create_tag(const unsigned char *object, const char *tag,
310 if (fd < 0)
311 die("could not create file '%s': %s",
312 path, strerror(errno));
285 - write_or_die(fd, tag_template, strlen(tag_template));
313 +
314 + if (!is_null_sha1(prev))
315 + write_tag_body(fd, prev);
316 + else
317 + write_or_die(fd, tag_template, strlen(tag_template));
318 close(fd);
319
320 launch_editor(path, buf);
@@ -419,7 +451,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
451 die("tag '%s' already exists", tag);
452
453 if (annotate)
422 - create_tag(object, tag, &buf, message, sign, object);
454 + create_tag(object, tag, &buf, message, sign, prev, object);
455
456 lock = lock_any_ref_for_update(ref, prev, 0);
457 if (!lock)