diff options
author | Junio C Hamano <gitster@pobox.com> | 2014-09-11 12:19:54 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-09-11 12:23:42 -0700 |
commit | b64a98460682366d7533ea251d26026b85bb39cb (patch) | |
tree | b3589cb7300f06cebb502dd14f32101fed5a28b7 /builtin/hash-object.c | |
parent | Update draft release notes to 2.2 (diff) | |
download | tgif-b64a98460682366d7533ea251d26026b85bb39cb.tar.xz |
hash-object: reduce file-scope statics
Most of the knobs that affect helper functions called from
cmd_hash_object() were passed to them as parameters already, and the
only effect of having them as file-scope statics was to make the
reader wonder if the parameters are hiding the file-scope global
values by accident. Adjust their initialisation and make them
function-local variables.
The only exception was no_filters hash_stdin_paths() peeked from the
file-scope global, which was converted to a parameter to the helper
function.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/hash-object.c')
-rw-r--r-- | builtin/hash-object.c | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/builtin/hash-object.c b/builtin/hash-object.c index d7fcf4c13c..40008e256f 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -36,9 +36,7 @@ static void hash_object(const char *path, const char *type, int write_object, hash_fd(fd, type, write_object, vpath); } -static int no_filters; - -static void hash_stdin_paths(const char *type, int write_objects) +static void hash_stdin_paths(const char *type, int write_objects, int no_filters) { struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT; @@ -50,42 +48,38 @@ static void hash_stdin_paths(const char *type, int write_objects) strbuf_swap(&buf, &nbuf); } hash_object(buf.buf, type, write_objects, - no_filters ? NULL : buf.buf); + no_filters ? NULL : buf.buf); } strbuf_release(&buf); strbuf_release(&nbuf); } -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 < <list-of-paths>"), - NULL -}; - -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, N_("type"), N_("object type")), - OPT_BOOL('w', NULL, &write_object, N_("write the object into the object database")), - OPT_COUNTUP( 0 , "stdin", &hashstdin, N_("read the object from stdin")), - OPT_BOOL( 0 , "stdin-paths", &stdin_paths, N_("read file names from stdin")), - OPT_BOOL( 0 , "no-filters", &no_filters, N_("store file as is without filters")), - OPT_STRING( 0 , "path", &vpath, N_("file"), N_("process file as it were from this path")), - OPT_END() -}; - 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 < <list-of-paths>"), + NULL + }; + const char *type = blob_type; + int hashstdin = 0; + int stdin_paths = 0; + int write_object = 0; + int no_filters = 0; + const char *vpath = NULL; + const struct option hash_object_options[] = { + OPT_STRING('t', NULL, &type, N_("type"), N_("object type")), + OPT_BOOL('w', NULL, &write_object, N_("write the object into the object database")), + OPT_COUNTUP( 0 , "stdin", &hashstdin, N_("read the object from stdin")), + OPT_BOOL( 0 , "stdin-paths", &stdin_paths, N_("read file names from stdin")), + OPT_BOOL( 0 , "no-filters", &no_filters, N_("store file as is without filters")), + OPT_STRING( 0 , "path", &vpath, N_("file"), N_("process file as it were from this path")), + OPT_END() + }; int i; int prefix_length = -1; const char *errstr = NULL; - type = blob_type; - argc = parse_options(argc, argv, NULL, hash_object_options, hash_object_usage, 0); @@ -131,7 +125,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix) } if (stdin_paths) - hash_stdin_paths(type, write_object); + hash_stdin_paths(type, write_object, no_filters); return 0; } |