X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=mktag.c;h=b05260c83fd8ef766eb2e16fa355501bf1f62fb5;hb=891e85a0c08e12d3f6174d8eb10b4ef284c4b01b;hp=38acd5a295d5f06fb2db60633e89a06ba634beb8;hpb=11bb2d4fa9ebc7481828c25752d8c23233b24c76;p=git.git diff --git a/mktag.c b/mktag.c index 38acd5a29..b05260c83 100644 --- a/mktag.c +++ b/mktag.c @@ -111,8 +111,7 @@ static int verify_tag(char *buffer, unsigned long size) int main(int argc, char **argv) { - unsigned long size = 4096; - char *buffer = xmalloc(size); + struct strbuf buf; unsigned char result_sha1[20]; if (argc != 1) @@ -120,21 +119,20 @@ int main(int argc, char **argv) setup_git_directory(); - if (read_fd(0, &buffer, &size)) { - free(buffer); + strbuf_init(&buf, 0); + if (strbuf_read(&buf, 0, 4096) < 0) { die("could not read from stdin"); } /* Verify it for some basic sanity: it needs to start with "object \ntype\ntagger " */ - if (verify_tag(buffer, size) < 0) + if (verify_tag(buf.buf, buf.len) < 0) die("invalid tag signature file"); - if (write_sha1_file(buffer, size, tag_type, result_sha1) < 0) + if (write_sha1_file(buf.buf, buf.len, tag_type, result_sha1) < 0) die("unable to write tag file"); - free(buffer); - + strbuf_release(&buf); printf("%s\n", sha1_to_hex(result_sha1)); return 0; }