blob: 01e73747d02f384c5e31b846340a4b586c84aab3 [file] [log] [blame]
Carlos Rica62e09ce2007-07-20 01:42:28 +02001/*
2 * Builtin "git tag"
3 *
4 * Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com>,
5 * Carlos Rica <jasampler@gmail.com>
6 * Based on git-tag.sh and mktag.c by Linus Torvalds.
7 */
8
9#include "cache.h"
10#include "builtin.h"
11#include "refs.h"
12#include "tag.h"
13#include "run-command.h"
Carlos Rica39686582007-11-09 14:42:56 +010014#include "parse-options.h"
Carlos Rica62e09ce2007-07-20 01:42:28 +020015
Carlos Rica39686582007-11-09 14:42:56 +010016static const char * const git_tag_usage[] = {
Stephan Beyer1b1dd232008-07-13 15:36:15 +020017 "git tag [-a|-s|-u <key-id>] [-f] [-m <msg>|-F <file>] <tagname> [<head>]",
18 "git tag -d <tagname>...",
19 "git tag -l [-n[<num>]] [<pattern>]",
20 "git tag -v <tagname>...",
Carlos Rica39686582007-11-09 14:42:56 +010021 NULL
22};
Carlos Rica62e09ce2007-07-20 01:42:28 +020023
24static char signingkey[1000];
25
Carlos Rica62e09ce2007-07-20 01:42:28 +020026struct tag_filter {
27 const char *pattern;
28 int lines;
Jake Goulding32c35cf2009-01-26 09:13:25 -050029 struct commit_list *with_commit;
Carlos Rica62e09ce2007-07-20 01:42:28 +020030};
31
32#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"
33
34static int show_reference(const char *refname, const unsigned char *sha1,
35 int flag, void *cb_data)
36{
37 struct tag_filter *filter = cb_data;
38
39 if (!fnmatch(filter->pattern, refname, 0)) {
40 int i;
41 unsigned long size;
42 enum object_type type;
43 char *buf, *sp, *eol;
44 size_t len;
45
Jake Goulding32c35cf2009-01-26 09:13:25 -050046 if (filter->with_commit) {
47 struct commit *commit;
48
49 commit = lookup_commit_reference_gently(sha1, 1);
50 if (!commit)
51 return 0;
52 if (!is_descendant_of(commit, filter->with_commit))
53 return 0;
54 }
55
Carlos Rica62e09ce2007-07-20 01:42:28 +020056 if (!filter->lines) {
57 printf("%s\n", refname);
58 return 0;
59 }
60 printf("%-15s ", refname);
61
Mike Hommeye1f14cc2007-11-03 14:08:05 +010062 buf = read_sha1_file(sha1, &type, &size);
63 if (!buf || !size)
Carlos Rica62e09ce2007-07-20 01:42:28 +020064 return 0;
Mike Hommeye1f14cc2007-11-03 14:08:05 +010065
66 /* skip header */
67 sp = strstr(buf, "\n\n");
68 if (!sp) {
Carlos Ricae317cfa2007-07-21 14:13:12 +020069 free(buf);
70 return 0;
71 }
Carlos Rica62e09ce2007-07-20 01:42:28 +020072 /* only take up to "lines" lines, and strip the signature */
Carlos Ricae317cfa2007-07-21 14:13:12 +020073 for (i = 0, sp += 2;
74 i < filter->lines && sp < buf + size &&
Carlos Rica62e09ce2007-07-20 01:42:28 +020075 prefixcmp(sp, PGP_SIGNATURE "\n");
76 i++) {
77 if (i)
78 printf("\n ");
79 eol = memchr(sp, '\n', size - (sp - buf));
80 len = eol ? eol - sp : size - (sp - buf);
81 fwrite(sp, len, 1, stdout);
82 if (!eol)
83 break;
84 sp = eol + 1;
85 }
86 putchar('\n');
87 free(buf);
88 }
89
90 return 0;
91}
92
Jake Goulding32c35cf2009-01-26 09:13:25 -050093static int list_tags(const char *pattern, int lines,
94 struct commit_list *with_commit)
Carlos Rica62e09ce2007-07-20 01:42:28 +020095{
96 struct tag_filter filter;
Carlos Rica62e09ce2007-07-20 01:42:28 +020097
98 if (pattern == NULL)
Carlos Rica18e32b52007-09-01 07:10:09 +020099 pattern = "*";
Carlos Rica62e09ce2007-07-20 01:42:28 +0200100
Carlos Rica18e32b52007-09-01 07:10:09 +0200101 filter.pattern = pattern;
Carlos Rica62e09ce2007-07-20 01:42:28 +0200102 filter.lines = lines;
Jake Goulding32c35cf2009-01-26 09:13:25 -0500103 filter.with_commit = with_commit;
Carlos Rica62e09ce2007-07-20 01:42:28 +0200104
105 for_each_tag_ref(show_reference, (void *) &filter);
106
Carlos Rica62e09ce2007-07-20 01:42:28 +0200107 return 0;
108}
109
Carlos Ricae317cfa2007-07-21 14:13:12 +0200110typedef int (*each_tag_name_fn)(const char *name, const char *ref,
Carlos Rica62e09ce2007-07-20 01:42:28 +0200111 const unsigned char *sha1);
112
Carlos Ricae317cfa2007-07-21 14:13:12 +0200113static int for_each_tag_name(const char **argv, each_tag_name_fn fn)
Carlos Rica62e09ce2007-07-20 01:42:28 +0200114{
115 const char **p;
116 char ref[PATH_MAX];
117 int had_error = 0;
118 unsigned char sha1[20];
119
120 for (p = argv; *p; p++) {
121 if (snprintf(ref, sizeof(ref), "refs/tags/%s", *p)
122 >= sizeof(ref)) {
123 error("tag name too long: %.*s...", 50, *p);
124 had_error = 1;
125 continue;
126 }
127 if (!resolve_ref(ref, sha1, 1, NULL)) {
128 error("tag '%s' not found.", *p);
129 had_error = 1;
130 continue;
131 }
132 if (fn(*p, ref, sha1))
133 had_error = 1;
134 }
135 return had_error;
136}
137
138static int delete_tag(const char *name, const char *ref,
139 const unsigned char *sha1)
140{
Miklos Vajnaeca35a22008-10-26 03:33:56 +0100141 if (delete_ref(ref, sha1, 0))
Carlos Rica62e09ce2007-07-20 01:42:28 +0200142 return 1;
143 printf("Deleted tag '%s'\n", name);
144 return 0;
145}
146
147static int verify_tag(const char *name, const char *ref,
148 const unsigned char *sha1)
149{
150 const char *argv_verify_tag[] = {"git-verify-tag",
151 "-v", "SHA1_HEX", NULL};
152 argv_verify_tag[2] = sha1_to_hex(sha1);
153
154 if (run_command_v_opt(argv_verify_tag, 0))
155 return error("could not verify the tag '%s'", name);
156 return 0;
157}
158
Pierre Habouzitfd17f5b2007-09-10 12:35:09 +0200159static int do_sign(struct strbuf *buffer)
Carlos Rica62e09ce2007-07-20 01:42:28 +0200160{
161 struct child_process gpg;
162 const char *args[4];
163 char *bracket;
164 int len;
Johannes Schindelinc4adea82008-07-11 18:55:57 +0200165 int i, j;
Carlos Rica62e09ce2007-07-20 01:42:28 +0200166
167 if (!*signingkey) {
Junio C Hamano774751a2007-12-08 17:32:08 -0800168 if (strlcpy(signingkey, git_committer_info(IDENT_ERROR_ON_NO_NAME),
Carlos Ricae317cfa2007-07-21 14:13:12 +0200169 sizeof(signingkey)) > sizeof(signingkey) - 1)
Carlos Rica62e09ce2007-07-20 01:42:28 +0200170 return error("committer info too long.");
171 bracket = strchr(signingkey, '>');
172 if (bracket)
173 bracket[1] = '\0';
174 }
175
Carlos Ricaaba91192007-09-09 02:39:29 +0200176 /* When the username signingkey is bad, program could be terminated
177 * because gpg exits without reading and then write gets SIGPIPE. */
178 signal(SIGPIPE, SIG_IGN);
179
Carlos Rica62e09ce2007-07-20 01:42:28 +0200180 memset(&gpg, 0, sizeof(gpg));
181 gpg.argv = args;
182 gpg.in = -1;
183 gpg.out = -1;
184 args[0] = "gpg";
185 args[1] = "-bsau";
186 args[2] = signingkey;
187 args[3] = NULL;
188
189 if (start_command(&gpg))
190 return error("could not run gpg.");
191
Pierre Habouzitfd17f5b2007-09-10 12:35:09 +0200192 if (write_in_full(gpg.in, buffer->buf, buffer->len) != buffer->len) {
Carlos Ricaaba91192007-09-09 02:39:29 +0200193 close(gpg.in);
Johannes Sixte72ae282008-02-16 18:36:38 +0100194 close(gpg.out);
Carlos Ricaaba91192007-09-09 02:39:29 +0200195 finish_command(&gpg);
196 return error("gpg did not accept the tag data");
197 }
Carlos Rica62e09ce2007-07-20 01:42:28 +0200198 close(gpg.in);
Pierre Habouzitfd17f5b2007-09-10 12:35:09 +0200199 len = strbuf_read(buffer, gpg.out, 1024);
Johannes Sixte72ae282008-02-16 18:36:38 +0100200 close(gpg.out);
Carlos Rica62e09ce2007-07-20 01:42:28 +0200201
Carlos Ricaaba91192007-09-09 02:39:29 +0200202 if (finish_command(&gpg) || !len || len < 0)
203 return error("gpg failed to sign the tag");
Carlos Rica62e09ce2007-07-20 01:42:28 +0200204
Johannes Schindelinc4adea82008-07-11 18:55:57 +0200205 /* Strip CR from the line endings, in case we are on Windows. */
206 for (i = j = 0; i < buffer->len; i++)
207 if (buffer->buf[i] != '\r') {
208 if (i != j)
209 buffer->buf[j] = buffer->buf[i];
210 j++;
211 }
212 strbuf_setlen(buffer, j);
213
Pierre Habouzitfd17f5b2007-09-10 12:35:09 +0200214 return 0;
Carlos Rica62e09ce2007-07-20 01:42:28 +0200215}
216
217static const char tag_template[] =
218 "\n"
219 "#\n"
220 "# Write a tag message\n"
221 "#\n";
222
Linus Torvaldsbe15f502007-12-10 20:08:06 -0800223static void set_signingkey(const char *value)
224{
225 if (strlcpy(signingkey, value, sizeof(signingkey)) >= sizeof(signingkey))
226 die("signing key value too long (%.10s...)", value);
227}
228
Johannes Schindelinef90d6d2008-05-14 18:46:53 +0100229static int git_tag_config(const char *var, const char *value, void *cb)
Carlos Rica62e09ce2007-07-20 01:42:28 +0200230{
231 if (!strcmp(var, "user.signingkey")) {
232 if (!value)
Christian Couderc96a6d32008-07-06 06:10:04 +0200233 return config_error_nonbool(var);
Linus Torvaldsbe15f502007-12-10 20:08:06 -0800234 set_signingkey(value);
Carlos Rica62e09ce2007-07-20 01:42:28 +0200235 return 0;
236 }
237
Johannes Schindelinef90d6d2008-05-14 18:46:53 +0100238 return git_default_config(var, value, cb);
Carlos Rica62e09ce2007-07-20 01:42:28 +0200239}
240
Mike Hommeybab81182007-11-04 01:11:14 +0100241static void write_tag_body(int fd, const unsigned char *sha1)
242{
243 unsigned long size;
244 enum object_type type;
245 char *buf, *sp, *eob;
246 size_t len;
247
248 buf = read_sha1_file(sha1, &type, &size);
249 if (!buf)
250 return;
251 /* skip header */
252 sp = strstr(buf, "\n\n");
253
254 if (!sp || !size || type != OBJ_TAG) {
255 free(buf);
256 return;
257 }
258 sp += 2; /* skip the 2 LFs */
259 eob = strstr(sp, "\n" PGP_SIGNATURE "\n");
260 if (eob)
261 len = eob - sp;
262 else
263 len = buf + size - sp;
264 write_or_die(fd, sp, len);
265
266 free(buf);
267}
268
Jeff King3927bbe2008-12-06 14:40:34 -0500269static int build_tag_object(struct strbuf *buf, int sign, unsigned char *result)
270{
271 if (sign && do_sign(buf) < 0)
272 return error("unable to sign the tag");
273 if (write_sha1_file(buf->buf, buf->len, tag_type, result) < 0)
274 return error("unable to write tag file");
275 return 0;
276}
277
Carlos Rica62e09ce2007-07-20 01:42:28 +0200278static void create_tag(const unsigned char *object, const char *tag,
Pierre Habouzitfd17f5b2007-09-10 12:35:09 +0200279 struct strbuf *buf, int message, int sign,
Junio C Hamanobd46c9a2007-11-22 23:16:51 -0800280 unsigned char *prev, unsigned char *result)
Carlos Rica62e09ce2007-07-20 01:42:28 +0200281{
282 enum object_type type;
Pierre Habouzitfd17f5b2007-09-10 12:35:09 +0200283 char header_buf[1024];
284 int header_len;
Jeff King3927bbe2008-12-06 14:40:34 -0500285 char *path = NULL;
Carlos Rica62e09ce2007-07-20 01:42:28 +0200286
287 type = sha1_object_info(object, NULL);
Carlos Ricae317cfa2007-07-21 14:13:12 +0200288 if (type <= OBJ_NONE)
Carlos Rica62e09ce2007-07-20 01:42:28 +0200289 die("bad object type.");
290
291 header_len = snprintf(header_buf, sizeof(header_buf),
292 "object %s\n"
293 "type %s\n"
294 "tag %s\n"
295 "tagger %s\n\n",
296 sha1_to_hex(object),
297 typename(type),
298 tag,
Junio C Hamano774751a2007-12-08 17:32:08 -0800299 git_committer_info(IDENT_ERROR_ON_NO_NAME));
Carlos Rica62e09ce2007-07-20 01:42:28 +0200300
Carlos Ricae317cfa2007-07-21 14:13:12 +0200301 if (header_len > sizeof(header_buf) - 1)
Carlos Rica62e09ce2007-07-20 01:42:28 +0200302 die("tag header too big.");
303
304 if (!message) {
Carlos Rica62e09ce2007-07-20 01:42:28 +0200305 int fd;
306
307 /* write the template message before editing: */
Alex Riesena4f34cb2008-10-27 11:22:09 +0100308 path = git_pathdup("TAG_EDITMSG");
Carlos Rica62e09ce2007-07-20 01:42:28 +0200309 fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
310 if (fd < 0)
311 die("could not create file '%s': %s",
312 path, strerror(errno));
Mike Hommeybab81182007-11-04 01:11:14 +0100313
314 if (!is_null_sha1(prev))
315 write_tag_body(fd, prev);
316 else
317 write_or_die(fd, tag_template, strlen(tag_template));
Carlos Rica62e09ce2007-07-20 01:42:28 +0200318 close(fd);
319
Stephan Beyer71982032008-07-25 18:28:42 +0200320 if (launch_editor(path, buf, NULL)) {
321 fprintf(stderr,
322 "Please supply the message using either -m or -F option.\n");
323 exit(1);
324 }
Carlos Rica62e09ce2007-07-20 01:42:28 +0200325 }
Carlos Rica62e09ce2007-07-20 01:42:28 +0200326
Kristian Høgsberg6d69b6f2007-09-17 20:06:45 -0400327 stripspace(buf, 1);
Carlos Rica62e09ce2007-07-20 01:42:28 +0200328
Pierre Habouzitfd17f5b2007-09-10 12:35:09 +0200329 if (!message && !buf->len)
Carlos Rica62e09ce2007-07-20 01:42:28 +0200330 die("no tag message?");
331
Pierre Habouzitfd17f5b2007-09-10 12:35:09 +0200332 strbuf_insert(buf, 0, header_buf, header_len);
Carlos Rica62e09ce2007-07-20 01:42:28 +0200333
Jeff King3927bbe2008-12-06 14:40:34 -0500334 if (build_tag_object(buf, sign, result) < 0) {
335 if (path)
336 fprintf(stderr, "The tag message has been left in %s\n",
337 path);
338 exit(128);
339 }
340 if (path) {
341 unlink(path);
342 free(path);
343 }
Carlos Rica62e09ce2007-07-20 01:42:28 +0200344}
345
Junio C Hamanobd46c9a2007-11-22 23:16:51 -0800346struct msg_arg {
347 int given;
348 struct strbuf buf;
349};
350
351static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
352{
353 struct msg_arg *msg = opt->value;
354
355 if (!arg)
356 return -1;
357 if (msg->buf.len)
358 strbuf_addstr(&(msg->buf), "\n\n");
359 strbuf_addstr(&(msg->buf), arg);
360 msg->given = 1;
361 return 0;
362}
363
Carlos Rica62e09ce2007-07-20 01:42:28 +0200364int cmd_tag(int argc, const char **argv, const char *prefix)
365{
Brandon Caseyf285a2d2008-10-09 14:12:12 -0500366 struct strbuf buf = STRBUF_INIT;
Carlos Rica62e09ce2007-07-20 01:42:28 +0200367 unsigned char object[20], prev[20];
Carlos Rica62e09ce2007-07-20 01:42:28 +0200368 char ref[PATH_MAX];
369 const char *object_ref, *tag;
Carlos Rica62e09ce2007-07-20 01:42:28 +0200370 struct ref_lock *lock;
371
Samuel Tardieu6fa83422008-11-05 00:20:31 +0100372 int annotate = 0, sign = 0, force = 0, lines = -1,
Pierre Habouzit78d776a2007-12-21 11:50:58 +0100373 list = 0, delete = 0, verify = 0;
Junio C Hamanodbd0f5c2008-08-06 11:43:47 -0700374 const char *msgfile = NULL, *keyid = NULL;
Junio C Hamanobd46c9a2007-11-22 23:16:51 -0800375 struct msg_arg msg = { 0, STRBUF_INIT };
Jake Goulding32c35cf2009-01-26 09:13:25 -0500376 struct commit_list *with_commit = NULL;
Carlos Rica39686582007-11-09 14:42:56 +0100377 struct option options[] = {
Pierre Habouzit78d776a2007-12-21 11:50:58 +0100378 OPT_BOOLEAN('l', NULL, &list, "list tag names"),
Carlos Rica39686582007-11-09 14:42:56 +0100379 { OPTION_INTEGER, 'n', NULL, &lines, NULL,
380 "print n lines of each tag message",
381 PARSE_OPT_OPTARG, NULL, 1 },
382 OPT_BOOLEAN('d', NULL, &delete, "delete tags"),
383 OPT_BOOLEAN('v', NULL, &verify, "verify tags"),
384
385 OPT_GROUP("Tag creation options"),
386 OPT_BOOLEAN('a', NULL, &annotate,
387 "annotated tag, needs a message"),
Junio C Hamanobd46c9a2007-11-22 23:16:51 -0800388 OPT_CALLBACK('m', NULL, &msg, "msg",
389 "message for the tag", parse_msg_arg),
Carlos Rica39686582007-11-09 14:42:56 +0100390 OPT_STRING('F', NULL, &msgfile, "file", "message in a file"),
391 OPT_BOOLEAN('s', NULL, &sign, "annotated and GPG-signed tag"),
392 OPT_STRING('u', NULL, &keyid, "key-id",
393 "use another key to sign the tag"),
394 OPT_BOOLEAN('f', NULL, &force, "replace the tag if exists"),
Jake Goulding32c35cf2009-01-26 09:13:25 -0500395
396 OPT_GROUP("Tag listing options"),
397 {
398 OPTION_CALLBACK, 0, "contains", &with_commit, "commit",
399 "print only tags that contain the commit",
400 PARSE_OPT_LASTARG_DEFAULT,
401 parse_opt_with_commit, (intptr_t)"HEAD",
402 },
Carlos Rica39686582007-11-09 14:42:56 +0100403 OPT_END()
404 };
405
Johannes Schindelinef90d6d2008-05-14 18:46:53 +0100406 git_config(git_tag_config, NULL);
Carlos Rica39686582007-11-09 14:42:56 +0100407
408 argc = parse_options(argc, argv, options, git_tag_usage, 0);
Junio C Hamanodbd0f5c2008-08-06 11:43:47 -0700409 msgfile = parse_options_fix_filename(prefix, msgfile);
Carlos Rica39686582007-11-09 14:42:56 +0100410
Linus Torvaldsbe15f502007-12-10 20:08:06 -0800411 if (keyid) {
412 sign = 1;
413 set_signingkey(keyid);
414 }
Junio C Hamanoc1a41b92007-11-25 15:21:42 -0800415 if (sign)
416 annotate = 1;
Samuel Tardieu6fa83422008-11-05 00:20:31 +0100417 if (argc == 0 && !(delete || verify))
418 list = 1;
Junio C Hamanoc1a41b92007-11-25 15:21:42 -0800419
Samuel Tardieu6fa83422008-11-05 00:20:31 +0100420 if ((annotate || msg.given || msgfile || force) &&
421 (list || delete || verify))
422 usage_with_options(git_tag_usage, options);
423
424 if (list + delete + verify > 1)
425 usage_with_options(git_tag_usage, options);
Carlos Rica39686582007-11-09 14:42:56 +0100426 if (list)
Jake Goulding32c35cf2009-01-26 09:13:25 -0500427 return list_tags(argv[0], lines == -1 ? 0 : lines,
428 with_commit);
Samuel Tardieu6fa83422008-11-05 00:20:31 +0100429 if (lines != -1)
430 die("-n option is only allowed with -l.");
Jake Goulding32c35cf2009-01-26 09:13:25 -0500431 if (with_commit)
432 die("--contains option is only allowed with -l.");
Carlos Rica39686582007-11-09 14:42:56 +0100433 if (delete)
434 return for_each_tag_name(argv, delete_tag);
435 if (verify)
436 return for_each_tag_name(argv, verify_tag);
437
Junio C Hamanobd46c9a2007-11-22 23:16:51 -0800438 if (msg.given || msgfile) {
439 if (msg.given && msgfile)
Carlos Rica39686582007-11-09 14:42:56 +0100440 die("only one -F or -m option is allowed.");
441 annotate = 1;
Junio C Hamanobd46c9a2007-11-22 23:16:51 -0800442 if (msg.given)
443 strbuf_addbuf(&buf, &(msg.buf));
Carlos Rica39686582007-11-09 14:42:56 +0100444 else {
445 if (!strcmp(msgfile, "-")) {
Pierre Habouzit387e7e12007-09-27 15:25:55 +0200446 if (strbuf_read(&buf, 0, 1024) < 0)
Carlos Rica39686582007-11-09 14:42:56 +0100447 die("cannot read %s", msgfile);
Pierre Habouzit387e7e12007-09-27 15:25:55 +0200448 } else {
Carlos Rica39686582007-11-09 14:42:56 +0100449 if (strbuf_read_file(&buf, msgfile, 1024) < 0)
Pierre Habouzit387e7e12007-09-27 15:25:55 +0200450 die("could not open or read '%s': %s",
Carlos Rica39686582007-11-09 14:42:56 +0100451 msgfile, strerror(errno));
Carlos Rica62e09ce2007-07-20 01:42:28 +0200452 }
Carlos Rica62e09ce2007-07-20 01:42:28 +0200453 }
Carlos Rica62e09ce2007-07-20 01:42:28 +0200454 }
455
Carlos Rica39686582007-11-09 14:42:56 +0100456 tag = argv[0];
Carlos Rica62e09ce2007-07-20 01:42:28 +0200457
Carlos Rica39686582007-11-09 14:42:56 +0100458 object_ref = argc == 2 ? argv[1] : "HEAD";
459 if (argc > 2)
Carlos Rica62e09ce2007-07-20 01:42:28 +0200460 die("too many params");
461
462 if (get_sha1(object_ref, object))
463 die("Failed to resolve '%s' as a valid ref.", object_ref);
464
Carlos Ricae317cfa2007-07-21 14:13:12 +0200465 if (snprintf(ref, sizeof(ref), "refs/tags/%s", tag) > sizeof(ref) - 1)
Carlos Rica62e09ce2007-07-20 01:42:28 +0200466 die("tag name too long: %.*s...", 50, tag);
467 if (check_ref_format(ref))
468 die("'%s' is not a valid tag name.", tag);
469
470 if (!resolve_ref(ref, prev, 1, NULL))
471 hashclr(prev);
472 else if (!force)
473 die("tag '%s' already exists", tag);
474
475 if (annotate)
Junio C Hamanobd46c9a2007-11-22 23:16:51 -0800476 create_tag(object, tag, &buf, msg.given || msgfile,
477 sign, prev, object);
Carlos Rica62e09ce2007-07-20 01:42:28 +0200478
479 lock = lock_any_ref_for_update(ref, prev, 0);
480 if (!lock)
481 die("%s: cannot lock the ref", ref);
482 if (write_ref_sha1(lock, object, NULL) < 0)
483 die("%s: cannot update the ref", ref);
484
Pierre Habouzitfd17f5b2007-09-10 12:35:09 +0200485 strbuf_release(&buf);
Carlos Rica62e09ce2007-07-20 01:42:28 +0200486 return 0;
487}