summaryrefslogtreecommitdiff
path: root/mktag.c
diff options
context:
space:
mode:
authorPierre Habouzit <madcoder@debian.org>2007-09-10 12:35:09 +0200
committerJunio C Hamano <gitster@pobox.com>2007-09-10 12:50:58 -0700
commitfd17f5b5f77716bf90098c6e49e3cf7fd9f56306 (patch)
tree7b6ed050e8283c9fe80d0c8229281de4bed4dccf /mktag.c
parent635d043f30c60f5ec8121bd94304e529f90407c7 (diff)
downloadgit-fd17f5b5f77716bf90098c6e49e3cf7fd9f56306.tar.gz
Replace all read_fd use with strbuf_read, and get rid of it.
This brings builtin-stripspace, builtin-tag and mktag to use strbufs. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'mktag.c')
-rw-r--r--mktag.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/mktag.c b/mktag.c
index 38acd5a295..7567f9ec29 100644
--- a/mktag.c
+++ b/mktag.c
@@ -1,4 +1,5 @@
#include "cache.h"
+#include "strbuf.h"
#include "tag.h"
/*
@@ -111,8 +112,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 +120,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 <sha1>\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;
}