diff options
Diffstat (limited to 'builtin/hash-object.c')
-rw-r--r-- | builtin/hash-object.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/builtin/hash-object.c b/builtin/hash-object.c index 640ef4d..82ca6d2 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -5,12 +5,18 @@ * Copyright (C) Junio C Hamano, 2005 */ #include "builtin.h" +#include "abspath.h" #include "config.h" -#include "object-store.h" +#include "gettext.h" +#include "hex.h" +#include "object-file.h" +#include "object-store-ll.h" #include "blob.h" #include "quote.h" #include "parse-options.h" -#include "exec-cmd.h" +#include "setup.h" +#include "strbuf.h" +#include "write-or-die.h" /* * This is to create corrupt objects for debugging and as such it @@ -25,8 +31,9 @@ static int hash_literally(struct object_id *oid, int fd, const char *type, unsig if (strbuf_read(&buf, fd, 4096) < 0) ret = -1; else - ret = hash_object_file_literally(buf.buf, buf.len, type, oid, + ret = write_object_file_literally(buf.buf, buf.len, type, oid, flags); + close(fd); strbuf_release(&buf); return ret; } @@ -53,9 +60,7 @@ static void hash_object(const char *path, const char *type, const char *vpath, unsigned flags, int literally) { int fd; - fd = open(path, O_RDONLY); - if (fd < 0) - die_errno("Cannot open '%s'", path); + fd = xopen(path, O_RDONLY); hash_fd(fd, type, vpath, flags, literally); } @@ -82,8 +87,9 @@ static void hash_stdin_paths(const char *type, int no_filters, unsigned flags, int cmd_hash_object(int argc, const char **argv, const char *prefix) { static const char * const hash_object_usage[] = { - N_("git hash-object [-t <type>] [-w] [--path=<file> | --no-filters] [--stdin] [--] <file>..."), - N_("git hash-object --stdin-paths"), + N_("git hash-object [-t <type>] [-w] [--path=<file> | --no-filters]\n" + " [--stdin [--literally]] [--] <file>..."), + N_("git hash-object [-t <type>] [-w] --stdin-paths [--no-filters]"), NULL }; const char *type = blob_type; @@ -94,6 +100,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix) int nongit = 0; unsigned flags = HASH_FORMAT_CHECK; const char *vpath = NULL; + char *vpath_free = NULL; const struct option hash_object_options[] = { OPT_STRING('t', NULL, &type, N_("type"), N_("object type")), OPT_BIT('w', NULL, &flags, N_("write the object into the object database"), @@ -116,8 +123,10 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix) else prefix = setup_git_directory_gently(&nongit); - if (vpath && prefix) - vpath = xstrdup(prefix_filename(prefix, vpath)); + if (vpath && prefix) { + vpath_free = prefix_filename(prefix, vpath); + vpath = vpath_free; + } git_config(git_default_config, NULL); @@ -158,5 +167,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix) if (stdin_paths) hash_stdin_paths(type, no_filters, flags, literally); + free(vpath_free); + return 0; } |