Merge branch 'jk/cleanup-callback-parameters'
Code clean-up. * jk/cleanup-callback-parameters: attr: drop DEBUG_ATTR code commit: avoid writing to global in option callback multi-pack-index: avoid writing to global in option callback test-submodule: inline resolve_relative_url() function
This commit is contained in:
commit
86cc5ee3b7
41
attr.c
41
attr.c
@ -23,10 +23,6 @@ static const char git_attr__unknown[] = "(builtin)unknown";
|
|||||||
#define ATTR__UNSET NULL
|
#define ATTR__UNSET NULL
|
||||||
#define ATTR__UNKNOWN git_attr__unknown
|
#define ATTR__UNKNOWN git_attr__unknown
|
||||||
|
|
||||||
#ifndef DEBUG_ATTR
|
|
||||||
#define DEBUG_ATTR 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct git_attr {
|
struct git_attr {
|
||||||
int attr_nr; /* unique attribute number */
|
int attr_nr; /* unique attribute number */
|
||||||
char name[FLEX_ARRAY]; /* attribute name */
|
char name[FLEX_ARRAY]; /* attribute name */
|
||||||
@ -807,33 +803,6 @@ static struct attr_stack *read_attr(struct index_state *istate,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG_ATTR
|
|
||||||
static void debug_info(const char *what, struct attr_stack *elem)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: %s\n", what, elem->origin ? elem->origin : "()");
|
|
||||||
}
|
|
||||||
static void debug_set(const char *what, const char *match, struct git_attr *attr, const void *v)
|
|
||||||
{
|
|
||||||
const char *value = v;
|
|
||||||
|
|
||||||
if (ATTR_TRUE(value))
|
|
||||||
value = "set";
|
|
||||||
else if (ATTR_FALSE(value))
|
|
||||||
value = "unset";
|
|
||||||
else if (ATTR_UNSET(value))
|
|
||||||
value = "unspecified";
|
|
||||||
|
|
||||||
fprintf(stderr, "%s: %s => %s (%s)\n",
|
|
||||||
what, attr->name, (char *) value, match);
|
|
||||||
}
|
|
||||||
#define debug_push(a) debug_info("push", (a))
|
|
||||||
#define debug_pop(a) debug_info("pop", (a))
|
|
||||||
#else
|
|
||||||
#define debug_push(a) do { ; } while (0)
|
|
||||||
#define debug_pop(a) do { ; } while (0)
|
|
||||||
#define debug_set(a,b,c,d) do { ; } while (0)
|
|
||||||
#endif /* DEBUG_ATTR */
|
|
||||||
|
|
||||||
static const char *git_etc_gitattributes(void)
|
static const char *git_etc_gitattributes(void)
|
||||||
{
|
{
|
||||||
static const char *system_wide;
|
static const char *system_wide;
|
||||||
@ -954,7 +923,6 @@ static void prepare_attr_stack(struct index_state *istate,
|
|||||||
(!namelen || path[namelen] == '/'))
|
(!namelen || path[namelen] == '/'))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
debug_pop(elem);
|
|
||||||
*stack = elem->prev;
|
*stack = elem->prev;
|
||||||
attr_stack_free(elem);
|
attr_stack_free(elem);
|
||||||
}
|
}
|
||||||
@ -1028,7 +996,7 @@ static int path_matches(const char *pathname, int pathlen,
|
|||||||
|
|
||||||
static int macroexpand_one(struct all_attrs_item *all_attrs, int nr, int rem);
|
static int macroexpand_one(struct all_attrs_item *all_attrs, int nr, int rem);
|
||||||
|
|
||||||
static int fill_one(const char *what, struct all_attrs_item *all_attrs,
|
static int fill_one(struct all_attrs_item *all_attrs,
|
||||||
const struct match_attr *a, int rem)
|
const struct match_attr *a, int rem)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -1039,9 +1007,6 @@ static int fill_one(const char *what, struct all_attrs_item *all_attrs,
|
|||||||
const char *v = a->state[i].setto;
|
const char *v = a->state[i].setto;
|
||||||
|
|
||||||
if (*n == ATTR__UNKNOWN) {
|
if (*n == ATTR__UNKNOWN) {
|
||||||
debug_set(what,
|
|
||||||
a->is_macro ? a->u.attr->name : a->u.pat.pattern,
|
|
||||||
attr, v);
|
|
||||||
*n = v;
|
*n = v;
|
||||||
rem--;
|
rem--;
|
||||||
rem = macroexpand_one(all_attrs, attr->attr_nr, rem);
|
rem = macroexpand_one(all_attrs, attr->attr_nr, rem);
|
||||||
@ -1064,7 +1029,7 @@ static int fill(const char *path, int pathlen, int basename_offset,
|
|||||||
continue;
|
continue;
|
||||||
if (path_matches(path, pathlen, basename_offset,
|
if (path_matches(path, pathlen, basename_offset,
|
||||||
&a->u.pat, base, stack->originlen))
|
&a->u.pat, base, stack->originlen))
|
||||||
rem = fill_one("fill", all_attrs, a, rem);
|
rem = fill_one(all_attrs, a, rem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1076,7 +1041,7 @@ static int macroexpand_one(struct all_attrs_item *all_attrs, int nr, int rem)
|
|||||||
const struct all_attrs_item *item = &all_attrs[nr];
|
const struct all_attrs_item *item = &all_attrs[nr];
|
||||||
|
|
||||||
if (item->macro && item->value == ATTR__TRUE)
|
if (item->macro && item->value == ATTR__TRUE)
|
||||||
return fill_one("expand", all_attrs, item->macro, rem);
|
return fill_one(all_attrs, item->macro, rem);
|
||||||
else
|
else
|
||||||
return rem;
|
return rem;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ static int opt_pass_trailer(const struct option *opt, const char *arg, int unset
|
|||||||
{
|
{
|
||||||
BUG_ON_OPT_NEG(unset);
|
BUG_ON_OPT_NEG(unset);
|
||||||
|
|
||||||
strvec_pushl(&trailer_args, "--trailer", arg, NULL);
|
strvec_pushl(opt->value, "--trailer", arg, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1633,7 +1633,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
|
|||||||
OPT_STRING(0, "fixup", &fixup_message, N_("[(amend|reword):]commit"), N_("use autosquash formatted message to fixup or amend/reword specified commit")),
|
OPT_STRING(0, "fixup", &fixup_message, N_("[(amend|reword):]commit"), N_("use autosquash formatted message to fixup or amend/reword specified commit")),
|
||||||
OPT_STRING(0, "squash", &squash_message, N_("commit"), N_("use autosquash formatted message to squash specified commit")),
|
OPT_STRING(0, "squash", &squash_message, N_("commit"), N_("use autosquash formatted message to squash specified commit")),
|
||||||
OPT_BOOL(0, "reset-author", &renew_authorship, N_("the commit is authored by me now (used with -C/-c/--amend)")),
|
OPT_BOOL(0, "reset-author", &renew_authorship, N_("the commit is authored by me now (used with -C/-c/--amend)")),
|
||||||
OPT_CALLBACK_F(0, "trailer", NULL, N_("trailer"), N_("add custom trailer(s)"), PARSE_OPT_NONEG, opt_pass_trailer),
|
OPT_CALLBACK_F(0, "trailer", &trailer_args, N_("trailer"), N_("add custom trailer(s)"), PARSE_OPT_NONEG, opt_pass_trailer),
|
||||||
OPT_BOOL('s', "signoff", &signoff, N_("add a Signed-off-by trailer")),
|
OPT_BOOL('s', "signoff", &signoff, N_("add a Signed-off-by trailer")),
|
||||||
OPT_FILENAME('t', "template", &template_file, N_("use specified template file")),
|
OPT_FILENAME('t', "template", &template_file, N_("use specified template file")),
|
||||||
OPT_BOOL('e', "edit", &edit_flag, N_("force edit of commit")),
|
OPT_BOOL('e', "edit", &edit_flag, N_("force edit of commit")),
|
||||||
|
@ -56,11 +56,12 @@ static struct opts_multi_pack_index {
|
|||||||
static int parse_object_dir(const struct option *opt, const char *arg,
|
static int parse_object_dir(const struct option *opt, const char *arg,
|
||||||
int unset)
|
int unset)
|
||||||
{
|
{
|
||||||
free(opts.object_dir);
|
char **value = opt->value;
|
||||||
|
free(*value);
|
||||||
if (unset)
|
if (unset)
|
||||||
opts.object_dir = xstrdup(get_object_directory());
|
*value = xstrdup(get_object_directory());
|
||||||
else
|
else
|
||||||
opts.object_dir = real_pathdup(arg, 1);
|
*value = real_pathdup(arg, 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,10 +85,17 @@ static int cmd__submodule_is_active(int argc, const char **argv)
|
|||||||
return !is_submodule_active(the_repository, argv[0]);
|
return !is_submodule_active(the_repository, argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int resolve_relative_url(int argc, const char **argv)
|
static int cmd__submodule_resolve_relative_url(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
char *remoteurl, *res;
|
char *remoteurl, *res;
|
||||||
const char *up_path, *url;
|
const char *up_path, *url;
|
||||||
|
struct option options[] = {
|
||||||
|
OPT_END()
|
||||||
|
};
|
||||||
|
argc = parse_options(argc, argv, "test-tools", options,
|
||||||
|
submodule_resolve_relative_url_usage, 0);
|
||||||
|
if (argc != 3)
|
||||||
|
usage_with_options(submodule_resolve_relative_url_usage, options);
|
||||||
|
|
||||||
up_path = argv[0];
|
up_path = argv[0];
|
||||||
remoteurl = xstrdup(argv[1]);
|
remoteurl = xstrdup(argv[1]);
|
||||||
@ -104,19 +111,6 @@ static int resolve_relative_url(int argc, const char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmd__submodule_resolve_relative_url(int argc, const char **argv)
|
|
||||||
{
|
|
||||||
struct option options[] = {
|
|
||||||
OPT_END()
|
|
||||||
};
|
|
||||||
argc = parse_options(argc, argv, "test-tools", options,
|
|
||||||
submodule_resolve_relative_url_usage, 0);
|
|
||||||
if (argc != 3)
|
|
||||||
usage_with_options(submodule_resolve_relative_url_usage, options);
|
|
||||||
|
|
||||||
return resolve_relative_url(argc, argv);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct test_cmd cmds[] = {
|
static struct test_cmd cmds[] = {
|
||||||
{ "check-name", cmd__submodule_check_name },
|
{ "check-name", cmd__submodule_check_name },
|
||||||
{ "is-active", cmd__submodule_is_active },
|
{ "is-active", cmd__submodule_is_active },
|
||||||
|
Loading…
Reference in New Issue
Block a user