Skip to content

Commit 1f49b51

Browse files
committed
Merge branch 'jk/cleanup-callback-parameters' into maint-2.38
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
2 parents 28f9cd0 + 69c5f17 commit 1f49b51

File tree

4 files changed

+17
-57
lines changed

4 files changed

+17
-57
lines changed

attr.c

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ static const char git_attr__unknown[] = "(builtin)unknown";
2323
#define ATTR__UNSET NULL
2424
#define ATTR__UNKNOWN git_attr__unknown
2525

26-
#ifndef DEBUG_ATTR
27-
#define DEBUG_ATTR 0
28-
#endif
29-
3026
struct git_attr {
3127
int attr_nr; /* unique attribute number */
3228
char name[FLEX_ARRAY]; /* attribute name */
@@ -807,33 +803,6 @@ static struct attr_stack *read_attr(struct index_state *istate,
807803
return res;
808804
}
809805

810-
#if DEBUG_ATTR
811-
static void debug_info(const char *what, struct attr_stack *elem)
812-
{
813-
fprintf(stderr, "%s: %s\n", what, elem->origin ? elem->origin : "()");
814-
}
815-
static void debug_set(const char *what, const char *match, struct git_attr *attr, const void *v)
816-
{
817-
const char *value = v;
818-
819-
if (ATTR_TRUE(value))
820-
value = "set";
821-
else if (ATTR_FALSE(value))
822-
value = "unset";
823-
else if (ATTR_UNSET(value))
824-
value = "unspecified";
825-
826-
fprintf(stderr, "%s: %s => %s (%s)\n",
827-
what, attr->name, (char *) value, match);
828-
}
829-
#define debug_push(a) debug_info("push", (a))
830-
#define debug_pop(a) debug_info("pop", (a))
831-
#else
832-
#define debug_push(a) do { ; } while (0)
833-
#define debug_pop(a) do { ; } while (0)
834-
#define debug_set(a,b,c,d) do { ; } while (0)
835-
#endif /* DEBUG_ATTR */
836-
837806
static const char *git_etc_gitattributes(void)
838807
{
839808
static const char *system_wide;
@@ -954,7 +923,6 @@ static void prepare_attr_stack(struct index_state *istate,
954923
(!namelen || path[namelen] == '/'))
955924
break;
956925

957-
debug_pop(elem);
958926
*stack = elem->prev;
959927
attr_stack_free(elem);
960928
}
@@ -1028,7 +996,7 @@ static int path_matches(const char *pathname, int pathlen,
1028996

1029997
static int macroexpand_one(struct all_attrs_item *all_attrs, int nr, int rem);
1030998

1031-
static int fill_one(const char *what, struct all_attrs_item *all_attrs,
999+
static int fill_one(struct all_attrs_item *all_attrs,
10321000
const struct match_attr *a, int rem)
10331001
{
10341002
int i;
@@ -1039,9 +1007,6 @@ static int fill_one(const char *what, struct all_attrs_item *all_attrs,
10391007
const char *v = a->state[i].setto;
10401008

10411009
if (*n == ATTR__UNKNOWN) {
1042-
debug_set(what,
1043-
a->is_macro ? a->u.attr->name : a->u.pat.pattern,
1044-
attr, v);
10451010
*n = v;
10461011
rem--;
10471012
rem = macroexpand_one(all_attrs, attr->attr_nr, rem);
@@ -1064,7 +1029,7 @@ static int fill(const char *path, int pathlen, int basename_offset,
10641029
continue;
10651030
if (path_matches(path, pathlen, basename_offset,
10661031
&a->u.pat, base, stack->originlen))
1067-
rem = fill_one("fill", all_attrs, a, rem);
1032+
rem = fill_one(all_attrs, a, rem);
10681033
}
10691034
}
10701035

@@ -1076,7 +1041,7 @@ static int macroexpand_one(struct all_attrs_item *all_attrs, int nr, int rem)
10761041
const struct all_attrs_item *item = &all_attrs[nr];
10771042

10781043
if (item->macro && item->value == ATTR__TRUE)
1079-
return fill_one("expand", all_attrs, item->macro, rem);
1044+
return fill_one(all_attrs, item->macro, rem);
10801045
else
10811046
return rem;
10821047
}

builtin/commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static int opt_pass_trailer(const struct option *opt, const char *arg, int unset
139139
{
140140
BUG_ON_OPT_NEG(unset);
141141

142-
strvec_pushl(&trailer_args, "--trailer", arg, NULL);
142+
strvec_pushl(opt->value, "--trailer", arg, NULL);
143143
return 0;
144144
}
145145

@@ -1633,7 +1633,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16331633
OPT_STRING(0, "fixup", &fixup_message, N_("[(amend|reword):]commit"), N_("use autosquash formatted message to fixup or amend/reword specified commit")),
16341634
OPT_STRING(0, "squash", &squash_message, N_("commit"), N_("use autosquash formatted message to squash specified commit")),
16351635
OPT_BOOL(0, "reset-author", &renew_authorship, N_("the commit is authored by me now (used with -C/-c/--amend)")),
1636-
OPT_CALLBACK_F(0, "trailer", NULL, N_("trailer"), N_("add custom trailer(s)"), PARSE_OPT_NONEG, opt_pass_trailer),
1636+
OPT_CALLBACK_F(0, "trailer", &trailer_args, N_("trailer"), N_("add custom trailer(s)"), PARSE_OPT_NONEG, opt_pass_trailer),
16371637
OPT_BOOL('s', "signoff", &signoff, N_("add a Signed-off-by trailer")),
16381638
OPT_FILENAME('t', "template", &template_file, N_("use specified template file")),
16391639
OPT_BOOL('e', "edit", &edit_flag, N_("force edit of commit")),

builtin/multi-pack-index.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ static struct opts_multi_pack_index {
5656
static int parse_object_dir(const struct option *opt, const char *arg,
5757
int unset)
5858
{
59-
free(opts.object_dir);
59+
char **value = opt->value;
60+
free(*value);
6061
if (unset)
61-
opts.object_dir = xstrdup(get_object_directory());
62+
*value = xstrdup(get_object_directory());
6263
else
63-
opts.object_dir = real_pathdup(arg, 1);
64+
*value = real_pathdup(arg, 1);
6465
return 0;
6566
}
6667

t/helper/test-submodule.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,17 @@ static int cmd__submodule_is_active(int argc, const char **argv)
8585
return !is_submodule_active(the_repository, argv[0]);
8686
}
8787

88-
static int resolve_relative_url(int argc, const char **argv)
88+
static int cmd__submodule_resolve_relative_url(int argc, const char **argv)
8989
{
9090
char *remoteurl, *res;
9191
const char *up_path, *url;
92+
struct option options[] = {
93+
OPT_END()
94+
};
95+
argc = parse_options(argc, argv, "test-tools", options,
96+
submodule_resolve_relative_url_usage, 0);
97+
if (argc != 3)
98+
usage_with_options(submodule_resolve_relative_url_usage, options);
9299

93100
up_path = argv[0];
94101
remoteurl = xstrdup(argv[1]);
@@ -104,19 +111,6 @@ static int resolve_relative_url(int argc, const char **argv)
104111
return 0;
105112
}
106113

107-
static int cmd__submodule_resolve_relative_url(int argc, const char **argv)
108-
{
109-
struct option options[] = {
110-
OPT_END()
111-
};
112-
argc = parse_options(argc, argv, "test-tools", options,
113-
submodule_resolve_relative_url_usage, 0);
114-
if (argc != 3)
115-
usage_with_options(submodule_resolve_relative_url_usage, options);
116-
117-
return resolve_relative_url(argc, argv);
118-
}
119-
120114
static struct test_cmd cmds[] = {
121115
{ "check-name", cmd__submodule_check_name },
122116
{ "is-active", cmd__submodule_is_active },

0 commit comments

Comments
 (0)