From ff350ccf49a800c4c90f817d346fb1bcb96e02e7 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Sat, 10 Nov 2007 15:00:33 -0500 Subject: git-hash-object should honor config variables ... such as core.compression. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- hash-object.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'hash-object.c') diff --git a/hash-object.c b/hash-object.c index 18f5017f5..0a58f3f12 100644 --- a/hash-object.c +++ b/hash-object.c @@ -42,6 +42,8 @@ int main(int argc, char **argv) int prefix_length = -1; int no_more_flags = 0; + git_config(git_default_config); + for (i = 1 ; i < argc; i++) { if (!no_more_flags && argv[i][0] == '-') { if (!strcmp(argv[i], "-t")) { -- cgit v1.2.1 From 8a2f5e5b032ca73e19ad1425b75c63234eb166fa Mon Sep 17 00:00:00 2001 From: Gerrit Pape Date: Thu, 21 Feb 2008 10:06:47 +0000 Subject: hash-object: cleanup handling of command line options git hash-object used to process the --stdin command line argument before reading subsequent arguments. This caused 'git hash-object --stdin -w' to fail to actually write the object into the database, while '-w --stdin' properly did. Now git hash-object first reads all arguments, and then processes them. This regresses one insane use case. git hash-object used to allow multiple --stdin arguments on the command line: $ git hash-object --stdin --stdin foo ^D bar ^D Now git hash-object errors out if --stdin is given more than once. Reported by Josh Triplett through http://bugs.debian.org/464432 Signed-off-by: Gerrit Pape Signed-off-by: Junio C Hamano --- hash-object.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'hash-object.c') diff --git a/hash-object.c b/hash-object.c index 0a58f3f12..61e7160b3 100644 --- a/hash-object.c +++ b/hash-object.c @@ -41,6 +41,7 @@ int main(int argc, char **argv) const char *prefix = NULL; int prefix_length = -1; int no_more_flags = 0; + int hashstdin = 0; git_config(git_default_config); @@ -65,13 +66,20 @@ int main(int argc, char **argv) else if (!strcmp(argv[i], "--help")) usage(hash_object_usage); else if (!strcmp(argv[i], "--stdin")) { - hash_stdin(type, write_object); + if (hashstdin) + die("Multiple --stdin arguments are not supported"); + hashstdin = 1; } else usage(hash_object_usage); } else { const char *arg = argv[i]; + + if (hashstdin) { + hash_stdin(type, write_object); + hashstdin = 0; + } if (0 <= prefix_length) arg = prefix_filename(prefix, prefix_length, arg); @@ -79,5 +87,7 @@ int main(int argc, char **argv) no_more_flags = 1; } } + if (hashstdin) + hash_stdin(type, write_object); return 0; } -- cgit v1.2.1 From ef90d6d4208a5130185b04f06e5f90a5f9959fe3 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 14 May 2008 18:46:53 +0100 Subject: Provide git_config with a callback-data parameter git_config() only had a function parameter, but no callback data parameter. This assumes that all callback functions only modify global variables. With this patch, every callback gets a void * parameter, and it is hoped that this will help the libification effort. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- hash-object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hash-object.c') diff --git a/hash-object.c b/hash-object.c index 61e7160b3..3d773900f 100644 --- a/hash-object.c +++ b/hash-object.c @@ -43,7 +43,7 @@ int main(int argc, char **argv) int no_more_flags = 0; int hashstdin = 0; - git_config(git_default_config); + git_config(git_default_config, NULL); for (i = 1 ; i < argc; i++) { if (!no_more_flags && argv[i][0] == '-') { -- cgit v1.2.1 From d8ee4832509dd2d7448a49920f5cba2fc979283d Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 23 May 2008 16:19:38 +0200 Subject: git-hash-object: Add --stdin-paths option This allows multiple paths to be specified on stdin. Signed-off-by: Adam Roben Signed-off-by: Junio C Hamano --- hash-object.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'hash-object.c') diff --git a/hash-object.c b/hash-object.c index 61e7160b3..0a7ac2fe2 100644 --- a/hash-object.c +++ b/hash-object.c @@ -6,6 +6,7 @@ */ #include "cache.h" #include "blob.h" +#include "quote.h" static void hash_object(const char *path, enum object_type type, int write_object) { @@ -20,6 +21,7 @@ static void hash_object(const char *path, enum object_type type, int write_objec ? "Unable to add %s to database" : "Unable to hash %s", path); printf("%s\n", sha1_to_hex(sha1)); + maybe_flush_or_die(stdout, "hash to stdout"); } static void hash_stdin(const char *type, int write_object) @@ -30,8 +32,27 @@ static void hash_stdin(const char *type, int write_object) printf("%s\n", sha1_to_hex(sha1)); } +static void hash_stdin_paths(const char *type, int write_objects) +{ + struct strbuf buf, nbuf; + + strbuf_init(&buf, 0); + strbuf_init(&nbuf, 0); + while (strbuf_getline(&buf, stdin, '\n') != EOF) { + if (buf.buf[0] == '"') { + strbuf_reset(&nbuf); + if (unquote_c_style(&nbuf, buf.buf, NULL)) + die("line is badly quoted"); + strbuf_swap(&buf, &nbuf); + } + hash_object(buf.buf, type_from_string(type), write_objects); + } + strbuf_release(&buf); + strbuf_release(&nbuf); +} + static const char hash_object_usage[] = -"git-hash-object [-t ] [-w] [--stdin] ..."; +"git-hash-object [ [-t ] [-w] [--stdin] ... | --stdin-paths < ]"; int main(int argc, char **argv) { @@ -42,6 +63,7 @@ int main(int argc, char **argv) int prefix_length = -1; int no_more_flags = 0; int hashstdin = 0; + int stdin_paths = 0; git_config(git_default_config); @@ -65,7 +87,19 @@ int main(int argc, char **argv) } else if (!strcmp(argv[i], "--help")) usage(hash_object_usage); + else if (!strcmp(argv[i], "--stdin-paths")) { + if (hashstdin) { + error("Can't use --stdin-paths with --stdin"); + usage(hash_object_usage); + } + stdin_paths = 1; + + } else if (!strcmp(argv[i], "--stdin")) { + if (stdin_paths) { + error("Can't use %s with --stdin-paths", argv[i]); + usage(hash_object_usage); + } if (hashstdin) die("Multiple --stdin arguments are not supported"); hashstdin = 1; @@ -76,6 +110,11 @@ int main(int argc, char **argv) else { const char *arg = argv[i]; + if (stdin_paths) { + error("Can't specify files (such as \"%s\") with --stdin-paths", arg); + usage(hash_object_usage); + } + if (hashstdin) { hash_stdin(type, write_object); hashstdin = 0; @@ -87,6 +126,10 @@ int main(int argc, char **argv) no_more_flags = 1; } } + + if (stdin_paths) + hash_stdin_paths(type, write_object); + if (hashstdin) hash_stdin(type, write_object); return 0; -- cgit v1.2.1 From 1b1dd23f2d6a707b7077cdf6bc6d4055bd0bfb7d Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Sun, 13 Jul 2008 15:36:15 +0200 Subject: Make usage strings dash-less When you misuse a git command, you are shown the usage string. But this is currently shown in the dashed form. So if you just copy what you see, it will not work, when the dashed form is no longer supported. This patch makes git commands show the dash-less version. For shell scripts that do not specify OPTIONS_SPEC, git-sh-setup.sh generates a dash-less usage string now. Signed-off-by: Stephan Beyer Signed-off-by: Junio C Hamano --- hash-object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hash-object.c') diff --git a/hash-object.c b/hash-object.c index 48d522368..46c06a955 100644 --- a/hash-object.c +++ b/hash-object.c @@ -52,7 +52,7 @@ static void hash_stdin_paths(const char *type, int write_objects) } static const char hash_object_usage[] = -"git-hash-object [ [-t ] [-w] [--stdin] ... | --stdin-paths < ]"; +"git hash-object [ [-t ] [-w] [--stdin] ... | --stdin-paths < ]"; int main(int argc, char **argv) { -- cgit v1.2.1 From 43df4f86e035056605ceb757029181d7ddee1e7e Mon Sep 17 00:00:00 2001 From: Dmitry Potapov Date: Sun, 3 Aug 2008 08:39:16 +0400 Subject: teach index_fd to work with pipes index_fd can now work with file descriptors that are not normal files but any readable file. If the given file descriptor is a regular file then mmap() is used; for other files, strbuf_read is used. The path parameter, which has been used as hint for filters, can be NULL now to indicate that the file should be hashed literally without any filter. The index_pipe function is removed as redundant. Signed-off-by: Dmitry Potapov Signed-off-by: Junio C Hamano --- hash-object.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'hash-object.c') diff --git a/hash-object.c b/hash-object.c index 46c06a955..7acfae15d 100644 --- a/hash-object.c +++ b/hash-object.c @@ -8,15 +8,12 @@ #include "blob.h" #include "quote.h" -static void hash_object(const char *path, enum object_type type, int write_object) +static void hash_fd(int fd, const char *type, int write_object, const char *path) { - int fd; struct stat st; unsigned char sha1[20]; - fd = open(path, O_RDONLY); - if (fd < 0 || - fstat(fd, &st) < 0 || - index_fd(sha1, fd, &st, write_object, type, path)) + if (fstat(fd, &st) < 0 || + index_fd(sha1, fd, &st, write_object, type_from_string(type), path)) die(write_object ? "Unable to add %s to database" : "Unable to hash %s", path); @@ -24,12 +21,13 @@ static void hash_object(const char *path, enum object_type type, int write_objec maybe_flush_or_die(stdout, "hash to stdout"); } -static void hash_stdin(const char *type, int write_object) +static void hash_object(const char *path, const char *type, int write_object) { - unsigned char sha1[20]; - if (index_pipe(sha1, 0, type, write_object)) - die("Unable to add stdin to database"); - printf("%s\n", sha1_to_hex(sha1)); + int fd; + fd = open(path, O_RDONLY); + if (fd < 0) + die("Cannot open %s", path); + hash_fd(fd, type, write_object, path); } static void hash_stdin_paths(const char *type, int write_objects) @@ -45,7 +43,7 @@ static void hash_stdin_paths(const char *type, int write_objects) die("line is badly quoted"); strbuf_swap(&buf, &nbuf); } - hash_object(buf.buf, type_from_string(type), write_objects); + hash_object(buf.buf, type, write_objects); } strbuf_release(&buf); strbuf_release(&nbuf); @@ -116,13 +114,13 @@ int main(int argc, char **argv) } if (hashstdin) { - hash_stdin(type, write_object); + hash_fd(0, type, write_object, NULL); hashstdin = 0; } if (0 <= prefix_length) arg = prefix_filename(prefix, prefix_length, arg); - hash_object(arg, type_from_string(type), write_object); + hash_object(arg, type, write_object); no_more_flags = 1; } } @@ -131,6 +129,6 @@ int main(int argc, char **argv) hash_stdin_paths(type, write_object); if (hashstdin) - hash_stdin(type, write_object); + hash_fd(0, type, write_object, NULL); return 0; } -- cgit v1.2.1 From 9ae8e008abf2e05dee59142fae068ae1f9004147 Mon Sep 17 00:00:00 2001 From: Dmitry Potapov Date: Sun, 3 Aug 2008 18:36:19 +0400 Subject: correct usage help string for git-hash-object The usage string is corrected to make it fit in 80 columns and to make it unequivocal about what options can be used with --stdin-paths. Signed-off-by: Dmitry Potapov Signed-off-by: Junio C Hamano --- hash-object.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'hash-object.c') diff --git a/hash-object.c b/hash-object.c index 7acfae15d..bb7c5dc6e 100644 --- a/hash-object.c +++ b/hash-object.c @@ -50,7 +50,8 @@ static void hash_stdin_paths(const char *type, int write_objects) } static const char hash_object_usage[] = -"git hash-object [ [-t ] [-w] [--stdin] ... | --stdin-paths < ]"; +"git hash-object [-t ] [-w] [--stdin] [--] ...\n" +" or: git hash-object --stdin-paths < "; int main(int argc, char **argv) { -- cgit v1.2.1 From 548601adcc638d96486e0f2a3dd399d4ca215eca Mon Sep 17 00:00:00 2001 From: Dmitry Potapov Date: Sun, 3 Aug 2008 18:36:20 +0400 Subject: use parse_options() in git hash-object Signed-off-by: Dmitry Potapov Signed-off-by: Junio C Hamano --- hash-object.c | 122 +++++++++++++++++++++++++--------------------------------- 1 file changed, 53 insertions(+), 69 deletions(-) (limited to 'hash-object.c') diff --git a/hash-object.c b/hash-object.c index bb7c5dc6e..489e8369d 100644 --- a/hash-object.c +++ b/hash-object.c @@ -7,6 +7,7 @@ #include "cache.h" #include "blob.h" #include "quote.h" +#include "parse-options.h" static void hash_fd(int fd, const char *type, int write_object, const char *path) { @@ -49,87 +50,70 @@ static void hash_stdin_paths(const char *type, int write_objects) strbuf_release(&nbuf); } -static const char hash_object_usage[] = -"git hash-object [-t ] [-w] [--stdin] [--] ...\n" -" or: git hash-object --stdin-paths < "; +static const char * const hash_object_usage[] = { + "git hash-object [-t ] [-w] [--stdin] [--] ...", + "git hash-object --stdin-paths < ", + NULL +}; -int main(int argc, char **argv) +static const char *type; +static int write_object; +static int hashstdin; +static int stdin_paths; + +static const struct option hash_object_options[] = { + OPT_STRING('t', NULL, &type, "type", "object type"), + OPT_BOOLEAN('w', NULL, &write_object, "write the object into the object database"), + OPT_BOOLEAN( 0 , "stdin", &hashstdin, "read the object from stdin"), + OPT_BOOLEAN( 0 , "stdin-paths", &stdin_paths, "read file names from stdin"), + OPT_END() +}; + +int main(int argc, const char **argv) { int i; - const char *type = blob_type; - int write_object = 0; const char *prefix = NULL; int prefix_length = -1; - int no_more_flags = 0; - int hashstdin = 0; - int stdin_paths = 0; + const char *errstr = NULL; + + type = blob_type; git_config(git_default_config, NULL); - for (i = 1 ; i < argc; i++) { - if (!no_more_flags && argv[i][0] == '-') { - if (!strcmp(argv[i], "-t")) { - if (argc <= ++i) - usage(hash_object_usage); - type = argv[i]; - } - else if (!strcmp(argv[i], "-w")) { - if (prefix_length < 0) { - prefix = setup_git_directory(); - prefix_length = - prefix ? strlen(prefix) : 0; - } - write_object = 1; - } - else if (!strcmp(argv[i], "--")) { - no_more_flags = 1; - } - else if (!strcmp(argv[i], "--help")) - usage(hash_object_usage); - else if (!strcmp(argv[i], "--stdin-paths")) { - if (hashstdin) { - error("Can't use --stdin-paths with --stdin"); - usage(hash_object_usage); - } - stdin_paths = 1; - - } - else if (!strcmp(argv[i], "--stdin")) { - if (stdin_paths) { - error("Can't use %s with --stdin-paths", argv[i]); - usage(hash_object_usage); - } - if (hashstdin) - die("Multiple --stdin arguments are not supported"); - hashstdin = 1; - } - else - usage(hash_object_usage); - } - else { - const char *arg = argv[i]; - - if (stdin_paths) { - error("Can't specify files (such as \"%s\") with --stdin-paths", arg); - usage(hash_object_usage); - } - - if (hashstdin) { - hash_fd(0, type, write_object, NULL); - hashstdin = 0; - } - if (0 <= prefix_length) - arg = prefix_filename(prefix, prefix_length, - arg); - hash_object(arg, type, write_object); - no_more_flags = 1; - } + argc = parse_options(argc, argv, hash_object_options, hash_object_usage, 0); + + if (write_object) { + prefix = setup_git_directory(); + prefix_length = prefix ? strlen(prefix) : 0; } - if (stdin_paths) - hash_stdin_paths(type, write_object); + if (stdin_paths) { + if (hashstdin) + errstr = "Can't use --stdin-paths with --stdin"; + else if (argc) + errstr = "Can't specify files with --stdin-paths"; + } + else if (hashstdin > 1) + errstr = "Multiple --stdin arguments are not supported"; + + if (errstr) { + error (errstr); + usage_with_options(hash_object_usage, hash_object_options); + } if (hashstdin) hash_fd(0, type, write_object, NULL); + + for (i = 0 ; i < argc; i++) { + const char *arg = argv[i]; + + if (0 <= prefix_length) + arg = prefix_filename(prefix, prefix_length, arg); + hash_object(arg, type, write_object); + } + + if (stdin_paths) + hash_stdin_paths(type, write_object); + return 0; } -- cgit v1.2.1 From 39702431500b76425f047209c9e9b2aae7e92b00 Mon Sep 17 00:00:00 2001 From: Dmitry Potapov Date: Sun, 3 Aug 2008 18:36:21 +0400 Subject: add --path option to git hash-object The --path option allows us to pretend as if the contents being hashed came from the specified path, and affects which input filter is used via the attributes mechanism. This is useful for hashing a temporary file whose name is different from the path that is meant to have the hashed contents. Signed-off-by: Dmitry Potapov Signed-off-by: Junio C Hamano --- hash-object.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'hash-object.c') diff --git a/hash-object.c b/hash-object.c index 489e8369d..ce04d150a 100644 --- a/hash-object.c +++ b/hash-object.c @@ -22,13 +22,14 @@ static void hash_fd(int fd, const char *type, int write_object, const char *path maybe_flush_or_die(stdout, "hash to stdout"); } -static void hash_object(const char *path, const char *type, int write_object) +static void hash_object(const char *path, const char *type, int write_object, + const char *vpath) { int fd; fd = open(path, O_RDONLY); if (fd < 0) die("Cannot open %s", path); - hash_fd(fd, type, write_object, path); + hash_fd(fd, type, write_object, vpath); } static void hash_stdin_paths(const char *type, int write_objects) @@ -44,14 +45,14 @@ static void hash_stdin_paths(const char *type, int write_objects) die("line is badly quoted"); strbuf_swap(&buf, &nbuf); } - hash_object(buf.buf, type, write_objects); + hash_object(buf.buf, type, write_objects, buf.buf); } strbuf_release(&buf); strbuf_release(&nbuf); } static const char * const hash_object_usage[] = { - "git hash-object [-t ] [-w] [--stdin] [--] ...", + "git hash-object [-t ] [-w] [--path=] [--stdin] [--] ...", "git hash-object --stdin-paths < ", NULL }; @@ -60,12 +61,14 @@ static const char *type; static int write_object; static int hashstdin; static int stdin_paths; +static const char *vpath; static const struct option hash_object_options[] = { OPT_STRING('t', NULL, &type, "type", "object type"), OPT_BOOLEAN('w', NULL, &write_object, "write the object into the object database"), OPT_BOOLEAN( 0 , "stdin", &hashstdin, "read the object from stdin"), OPT_BOOLEAN( 0 , "stdin-paths", &stdin_paths, "read file names from stdin"), + OPT_STRING( 0 , "path", &vpath, "file", "process file as it were from this path"), OPT_END() }; @@ -85,6 +88,8 @@ int main(int argc, const char **argv) if (write_object) { prefix = setup_git_directory(); prefix_length = prefix ? strlen(prefix) : 0; + if (vpath && prefix) + vpath = prefix_filename(prefix, prefix_length, vpath); } if (stdin_paths) { @@ -92,6 +97,8 @@ int main(int argc, const char **argv) errstr = "Can't use --stdin-paths with --stdin"; else if (argc) errstr = "Can't specify files with --stdin-paths"; + else if (vpath) + errstr = "Can't use --stdin-paths with --path"; } else if (hashstdin > 1) errstr = "Multiple --stdin arguments are not supported"; @@ -102,14 +109,14 @@ int main(int argc, const char **argv) } if (hashstdin) - hash_fd(0, type, write_object, NULL); + hash_fd(0, type, write_object, vpath); for (i = 0 ; i < argc; i++) { const char *arg = argv[i]; if (0 <= prefix_length) arg = prefix_filename(prefix, prefix_length, arg); - hash_object(arg, type, write_object); + hash_object(arg, type, write_object, vpath ? vpath : arg); } if (stdin_paths) -- cgit v1.2.1 From 4a3d85dcf6722b7e5d16b5b1f69b51e39ad5f1dc Mon Sep 17 00:00:00 2001 From: Dmitry Potapov Date: Sun, 3 Aug 2008 18:36:22 +0400 Subject: add --no-filters option to git hash-object The new option allows the contents to be hashed as is, ignoring any input filter that would have been chosen by the attributes mechanism. This option is incompatible with --path and --stdin-paths options. Signed-off-by: Dmitry Potapov Signed-off-by: Junio C Hamano --- hash-object.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'hash-object.c') diff --git a/hash-object.c b/hash-object.c index ce04d150a..a4d127cf7 100644 --- a/hash-object.c +++ b/hash-object.c @@ -52,7 +52,7 @@ static void hash_stdin_paths(const char *type, int write_objects) } static const char * const hash_object_usage[] = { - "git hash-object [-t ] [-w] [--path=] [--stdin] [--] ...", + "git hash-object [-t ] [-w] [--path=|--no-filters] [--stdin] [--] ...", "git hash-object --stdin-paths < ", NULL }; @@ -61,6 +61,7 @@ static const char *type; static int write_object; static int hashstdin; static int stdin_paths; +static int no_filters; static const char *vpath; static const struct option hash_object_options[] = { @@ -68,6 +69,7 @@ static const struct option hash_object_options[] = { OPT_BOOLEAN('w', NULL, &write_object, "write the object into the object database"), OPT_BOOLEAN( 0 , "stdin", &hashstdin, "read the object from stdin"), OPT_BOOLEAN( 0 , "stdin-paths", &stdin_paths, "read file names from stdin"), + OPT_BOOLEAN( 0 , "no-filters", &no_filters, "store file as is without filters"), OPT_STRING( 0 , "path", &vpath, "file", "process file as it were from this path"), OPT_END() }; @@ -99,9 +101,15 @@ int main(int argc, const char **argv) errstr = "Can't specify files with --stdin-paths"; else if (vpath) errstr = "Can't use --stdin-paths with --path"; + else if (no_filters) + errstr = "Can't use --stdin-paths with --no-filters"; + } + else { + if (hashstdin > 1) + errstr = "Multiple --stdin arguments are not supported"; + if (vpath && no_filters) + errstr = "Can't use --path with --no-filters"; } - else if (hashstdin > 1) - errstr = "Multiple --stdin arguments are not supported"; if (errstr) { error (errstr); @@ -116,7 +124,8 @@ int main(int argc, const char **argv) if (0 <= prefix_length) arg = prefix_filename(prefix, prefix_length, arg); - hash_object(arg, type, write_object, vpath ? vpath : arg); + hash_object(arg, type, write_object, + no_filters ? NULL : vpath ? vpath : arg); } if (stdin_paths) -- cgit v1.2.1 From f285a2d7ed6548666989406de8f0e7233eb84368 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 9 Oct 2008 14:12:12 -0500 Subject: Replace calls to strbuf_init(&foo, 0) with STRBUF_INIT initializer Many call sites use strbuf_init(&foo, 0) to initialize local strbuf variable "foo" which has not been accessed since its declaration. These can be replaced with a static initialization using the STRBUF_INIT macro which is just as readable, saves a function call, and takes up fewer lines. Signed-off-by: Brandon Casey Signed-off-by: Shawn O. Pearce --- hash-object.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'hash-object.c') diff --git a/hash-object.c b/hash-object.c index a4d127cf7..20937ff94 100644 --- a/hash-object.c +++ b/hash-object.c @@ -34,10 +34,8 @@ static void hash_object(const char *path, const char *type, int write_object, static void hash_stdin_paths(const char *type, int write_objects) { - struct strbuf buf, nbuf; + struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT; - strbuf_init(&buf, 0); - strbuf_init(&nbuf, 0); while (strbuf_getline(&buf, stdin, '\n') != EOF) { if (buf.buf[0] == '"') { strbuf_reset(&nbuf); -- cgit v1.2.1 From 42fc1139a07b4292d3e5251c591609126664941a Mon Sep 17 00:00:00 2001 From: Daniel Lowe Date: Mon, 10 Nov 2008 16:07:52 -0500 Subject: Fix non-literal format in printf-style calls These were found using gcc 4.3.2-1ubuntu11 with the warning: warning: format not a string literal and no format arguments Signed-off-by: Junio C Hamano --- hash-object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hash-object.c') diff --git a/hash-object.c b/hash-object.c index 20937ff94..846e91a23 100644 --- a/hash-object.c +++ b/hash-object.c @@ -110,7 +110,7 @@ int main(int argc, const char **argv) } if (errstr) { - error (errstr); + error("%s", errstr); usage_with_options(hash_object_usage, hash_object_options); } -- cgit v1.2.1 From 2fb3f6db96492b680899f9e40f434eeb4c778a84 Mon Sep 17 00:00:00 2001 From: Steffen Prohaska Date: Sun, 18 Jan 2009 13:00:12 +0100 Subject: Add calls to git_extract_argv0_path() in programs that call git_config_* Programs that use git_config need to find the global configuration. When runtime prefix computation is enabled, this requires that git_extract_argv0_path() is called early in the program's main(). This commit adds the necessary calls. Signed-off-by: Steffen Prohaska Acked-by: Johannes Sixt Signed-off-by: Junio C Hamano --- hash-object.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'hash-object.c') diff --git a/hash-object.c b/hash-object.c index 846e91a23..37e66779a 100644 --- a/hash-object.c +++ b/hash-object.c @@ -8,6 +8,7 @@ #include "blob.h" #include "quote.h" #include "parse-options.h" +#include "exec_cmd.h" static void hash_fd(int fd, const char *type, int write_object, const char *path) { @@ -81,6 +82,8 @@ int main(int argc, const char **argv) type = blob_type; + git_extract_argv0_path(argv[0]); + git_config(git_default_config, NULL); argc = parse_options(argc, argv, hash_object_options, hash_object_usage, 0); -- cgit v1.2.1 From 272459a3b809db19d15131eb5df9dfe939af9c8c Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Sat, 28 Feb 2009 12:56:49 -0700 Subject: Ensure proper setup of git_dir for git-hash-object Call setup_git_directory() before git_config() to make sure git_dir is set to the proper value. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- hash-object.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'hash-object.c') diff --git a/hash-object.c b/hash-object.c index 846e91a23..adfd5336a 100644 --- a/hash-object.c +++ b/hash-object.c @@ -81,8 +81,6 @@ int main(int argc, const char **argv) type = blob_type; - git_config(git_default_config, NULL); - argc = parse_options(argc, argv, hash_object_options, hash_object_usage, 0); if (write_object) { @@ -92,6 +90,8 @@ int main(int argc, const char **argv) vpath = prefix_filename(prefix, prefix_length, vpath); } + git_config(git_default_config, NULL); + if (stdin_paths) { if (hashstdin) errstr = "Can't use --stdin-paths with --stdin"; -- cgit v1.2.1 From 377829201783b8a648e07af6ce7d747e0f45dc19 Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Sat, 23 May 2009 11:53:12 -0700 Subject: parse-opts: prepare for OPT_FILENAME To give OPT_FILENAME the prefix, we pass the prefix to parse_options() which passes the prefix to parse_options_start() which sets the prefix member of parse_opts_ctx accordingly. If there isn't a prefix in the calling context, passing NULL will suffice. Signed-off-by: Stephen Boyd Signed-off-by: Junio C Hamano --- hash-object.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'hash-object.c') diff --git a/hash-object.c b/hash-object.c index ebb3bedb0..47cf43c3c 100644 --- a/hash-object.c +++ b/hash-object.c @@ -84,7 +84,8 @@ int main(int argc, const char **argv) git_extract_argv0_path(argv[0]); - argc = parse_options(argc, argv, hash_object_options, hash_object_usage, 0); + argc = parse_options(argc, argv, NULL, hash_object_options, + hash_object_usage, 0); if (write_object) { prefix = setup_git_directory(); -- cgit v1.2.1 From 0721c314a5c8fddc877140ab5a333c42c62f780d Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Sat, 27 Jun 2009 17:58:47 +0200 Subject: Use die_errno() instead of die() when checking syscalls Lots of die() calls did not actually report the kind of error, which can leave the user confused as to the real problem. Use die_errno() where we check a system/library call that sets errno on failure, or one of the following that wrap such calls: Function Passes on error from -------- -------------------- odb_pack_keep open read_ancestry fopen read_in_full xread strbuf_read xread strbuf_read_file open or strbuf_read_file strbuf_readlink readlink write_in_full xwrite Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- hash-object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hash-object.c') diff --git a/hash-object.c b/hash-object.c index 47cf43c3c..9455dd070 100644 --- a/hash-object.c +++ b/hash-object.c @@ -29,7 +29,7 @@ static void hash_object(const char *path, const char *type, int write_object, int fd; fd = open(path, O_RDONLY); if (fd < 0) - die("Cannot open %s", path); + die_errno("Cannot open '%s'", path); hash_fd(fd, type, write_object, vpath); } -- cgit v1.2.1