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>

Junio C Hamano committed Sep 11, 2014 at 12:19 UTC b64a98460682366d7533ea251d26026b85bb39cb
1 file changed +23 -29
builtin/hash-object.c
+23 -29
@@ -36,9 +36,7 @@ static void hash_object(const char *path, const char *type, int write_object,
36 hash_fd(fd, type, write_object, vpath);
37 }
38
39 -static int no_filters;
40 -
41 -static void hash_stdin_paths(const char *type, int write_objects)
39 +static void hash_stdin_paths(const char *type, int write_objects, int no_filters)
40 {
41 struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
42
@@ -50,42 +48,38 @@ static void hash_stdin_paths(const char *type, int write_objects)
48 strbuf_swap(&buf, &nbuf);
49 }
50 hash_object(buf.buf, type, write_objects,
53 - no_filters ? NULL : buf.buf);
51 + no_filters ? NULL : buf.buf);
52 }
53 strbuf_release(&buf);
54 strbuf_release(&nbuf);
55 }
56
59 -static const char * const hash_object_usage[] = {
60 - N_("git hash-object [-t <type>] [-w] [--path=<file>|--no-filters] [--stdin] [--] <file>..."),
61 - N_("git hash-object --stdin-paths < <list-of-paths>"),
62 - NULL
63 -};
64 -
65 -static const char *type;
66 -static int write_object;
67 -static int hashstdin;
68 -static int stdin_paths;
69 -static const char *vpath;
70 -
71 -static const struct option hash_object_options[] = {
72 - OPT_STRING('t', NULL, &type, N_("type"), N_("object type")),
73 - OPT_BOOL('w', NULL, &write_object, N_("write the object into the object database")),
74 - OPT_COUNTUP( 0 , "stdin", &hashstdin, N_("read the object from stdin")),
75 - OPT_BOOL( 0 , "stdin-paths", &stdin_paths, N_("read file names from stdin")),
76 - OPT_BOOL( 0 , "no-filters", &no_filters, N_("store file as is without filters")),
77 - OPT_STRING( 0 , "path", &vpath, N_("file"), N_("process file as it were from this path")),
78 - OPT_END()
79 -};
80 -
57 int cmd_hash_object(int argc, const char **argv, const char *prefix)
58 {
59 + static const char * const hash_object_usage[] = {
60 + N_("git hash-object [-t <type>] [-w] [--path=<file>|--no-filters] [--stdin] [--] <file>..."),
61 + N_("git hash-object --stdin-paths < <list-of-paths>"),
62 + NULL
63 + };
64 + const char *type = blob_type;
65 + int hashstdin = 0;
66 + int stdin_paths = 0;
67 + int write_object = 0;
68 + int no_filters = 0;
69 + const char *vpath = NULL;
70 + const struct option hash_object_options[] = {
71 + OPT_STRING('t', NULL, &type, N_("type"), N_("object type")),
72 + OPT_BOOL('w', NULL, &write_object, N_("write the object into the object database")),
73 + OPT_COUNTUP( 0 , "stdin", &hashstdin, N_("read the object from stdin")),
74 + OPT_BOOL( 0 , "stdin-paths", &stdin_paths, N_("read file names from stdin")),
75 + OPT_BOOL( 0 , "no-filters", &no_filters, N_("store file as is without filters")),
76 + OPT_STRING( 0 , "path", &vpath, N_("file"), N_("process file as it were from this path")),
77 + OPT_END()
78 + };
79 int i;
80 int prefix_length = -1;
81 const char *errstr = NULL;
82
87 - type = blob_type;
88 -
83 argc = parse_options(argc, argv, NULL, hash_object_options,
84 hash_object_usage, 0);
85
@@ -131,7 +125,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
125 }
126
127 if (stdin_paths)
134 - hash_stdin_paths(type, write_object);
128 + hash_stdin_paths(type, write_object, no_filters);
129
130 return 0;
131 }