Skip to content

Commit b64a984

Browse files
committed
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 <[email protected]>
1 parent ce1d3a9 commit b64a984

File tree

1 file changed

+23
-29
lines changed

1 file changed

+23
-29
lines changed

builtin/hash-object.c

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ static void hash_object(const char *path, const char *type, int write_object,
3636
hash_fd(fd, type, write_object, vpath);
3737
}
3838

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)
4240
{
4341
struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
4442

@@ -50,42 +48,38 @@ static void hash_stdin_paths(const char *type, int write_objects)
5048
strbuf_swap(&buf, &nbuf);
5149
}
5250
hash_object(buf.buf, type, write_objects,
53-
no_filters ? NULL : buf.buf);
51+
no_filters ? NULL : buf.buf);
5452
}
5553
strbuf_release(&buf);
5654
strbuf_release(&nbuf);
5755
}
5856

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-
8157
int cmd_hash_object(int argc, const char **argv, const char *prefix)
8258
{
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+
};
8379
int i;
8480
int prefix_length = -1;
8581
const char *errstr = NULL;
8682

87-
type = blob_type;
88-
8983
argc = parse_options(argc, argv, NULL, hash_object_options,
9084
hash_object_usage, 0);
9185

@@ -131,7 +125,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)
131125
}
132126

133127
if (stdin_paths)
134-
hash_stdin_paths(type, write_object);
128+
hash_stdin_paths(type, write_object, no_filters);
135129

136130
return 0;
137131
}

0 commit comments

Comments
 (0)