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>
maint
Junio C Hamano 2014-09-11 12:19:54 -07:00
parent ce1d3a93a6
commit b64a984606
1 changed files with 23 additions and 29 deletions

View File

@ -36,9 +36,7 @@ static void hash_object(const char *path, const char *type, int write_object,
hash_fd(fd, type, write_object, vpath); hash_fd(fd, type, write_object, vpath);
} }


static int no_filters; static void hash_stdin_paths(const char *type, int write_objects, int no_filters)

static void hash_stdin_paths(const char *type, int write_objects)
{ {
struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;


@ -56,19 +54,20 @@ static void hash_stdin_paths(const char *type, int write_objects)
strbuf_release(&nbuf); strbuf_release(&nbuf);
} }


static const char * const hash_object_usage[] = { 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 [-t <type>] [-w] [--path=<file>|--no-filters] [--stdin] [--] <file>..."),
N_("git hash-object --stdin-paths < <list-of-paths>"), N_("git hash-object --stdin-paths < <list-of-paths>"),
NULL NULL
}; };

const char *type = blob_type;
static const char *type; int hashstdin = 0;
static int write_object; int stdin_paths = 0;
static int hashstdin; int write_object = 0;
static int stdin_paths; int no_filters = 0;
static const char *vpath; const char *vpath = NULL;

const struct option hash_object_options[] = {
static const struct option hash_object_options[] = {
OPT_STRING('t', NULL, &type, N_("type"), N_("object type")), 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_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_COUNTUP( 0 , "stdin", &hashstdin, N_("read the object from stdin")),
@ -76,16 +75,11 @@ static const struct option hash_object_options[] = {
OPT_BOOL( 0 , "no-filters", &no_filters, N_("store file as is without filters")), 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_STRING( 0 , "path", &vpath, N_("file"), N_("process file as it were from this path")),
OPT_END() OPT_END()
}; };

int cmd_hash_object(int argc, const char **argv, const char *prefix)
{
int i; int i;
int prefix_length = -1; int prefix_length = -1;
const char *errstr = NULL; const char *errstr = NULL;


type = blob_type;

argc = parse_options(argc, argv, NULL, hash_object_options, argc = parse_options(argc, argv, NULL, hash_object_options,
hash_object_usage, 0); hash_object_usage, 0);


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


if (stdin_paths) if (stdin_paths)
hash_stdin_paths(type, write_object); hash_stdin_paths(type, write_object, no_filters);


return 0; return 0;
} }