diff --git a/builtin-tag.c b/builtin-tag.c
index 82ebda11b02b2fd1fad3e3687832bb222e84f500..4aca3dc79b2a3d28f158ff61c01363244bfd7637 100644 (file)
--- a/builtin-tag.c
+++ b/builtin-tag.c
const char *editor, *terminal;
struct child_process child;
const char *args[3];
const char *editor, *terminal;
struct child_process child;
const char *args[3];
- int fd;
editor = getenv("GIT_EDITOR");
if (!editor && editor_program)
editor = getenv("GIT_EDITOR");
if (!editor && editor_program)
if (run_command(&child))
die("There was a problem with the editor %s.", editor);
if (run_command(&child))
die("There was a problem with the editor %s.", editor);
- fd = open(path, O_RDONLY);
- if (fd < 0)
- die("could not open '%s': %s", path, strerror(errno));
- if (strbuf_read(buffer, fd, 0) < 0) {
- die("could not read message file '%s': %s", path, strerror(errno));
- }
- close(fd);
+ if (strbuf_read_file(buffer, path, 0) < 0)
+ die("could not read message file '%s': %s",
+ path, strerror(errno));
}
struct tag_filter {
}
struct tag_filter {
}
printf("%-15s ", refname);
}
printf("%-15s ", refname);
- sp = buf = read_sha1_file(sha1, &type, &size);
- if (!buf)
+ buf = read_sha1_file(sha1, &type, &size);
+ if (!buf || !size)
return 0;
return 0;
- if (!size) {
+
+ /* skip header */
+ sp = strstr(buf, "\n\n");
+ if (!sp) {
free(buf);
return 0;
}
free(buf);
return 0;
}
- /* skip header */
- while (sp + 1 < buf + size &&
- !(sp[0] == '\n' && sp[1] == '\n'))
- sp++;
/* only take up to "lines" lines, and strip the signature */
for (i = 0, sp += 2;
i < filter->lines && sp < buf + size &&
/* only take up to "lines" lines, and strip the signature */
for (i = 0, sp += 2;
i < filter->lines && sp < buf + size &&
free(path);
}
free(path);
}
- strbuf_setlen(buf, stripspace(buf->buf, buf->len, 1));
+ stripspace(buf, 1);
if (!message && !buf->len)
die("no tag message?");
if (!message && !buf->len)
die("no tag message?");
- /* insert the header and add the '\n' if needed: */
- if (buf->len)
- strbuf_addch(buf, '\n');
strbuf_insert(buf, 0, header_buf, header_len);
if (sign && do_sign(buf) < 0)
strbuf_insert(buf, 0, header_buf, header_len);
if (sign && do_sign(buf) < 0)
continue;
}
if (!strcmp(arg, "-F")) {
continue;
}
if (!strcmp(arg, "-F")) {
- int fd;
-
annotate = 1;
i++;
if (i == argc)
annotate = 1;
i++;
if (i == argc)
if (message)
die("only one -F or -m option is allowed.");
if (message)
die("only one -F or -m option is allowed.");
- if (!strcmp(argv[i], "-"))
- fd = 0;
- else {
- fd = open(argv[i], O_RDONLY);
- if (fd < 0)
- die("could not open '%s': %s",
+ if (!strcmp(argv[i], "-")) {
+ if (strbuf_read(&buf, 0, 1024) < 0)
+ die("cannot read %s", argv[i]);
+ } else {
+ if (strbuf_read_file(&buf, argv[i], 1024) < 0)
+ die("could not open or read '%s': %s",
argv[i], strerror(errno));
}
argv[i], strerror(errno));
}
- if (strbuf_read(&buf, fd, 1024) < 0) {
- die("cannot read %s", argv[i]);
- }
message = 1;
continue;
}
message = 1;
continue;
}