17
int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
18
{
19
int i;
20
- const char *format = "%(objectname) %(objecttype)\t%(refname)";
20
struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
22
- int maxcount = 0, quote_style = 0, icase = 0;
21
+ int maxcount = 0, icase = 0;
22
struct ref_array array;
23
struct ref_filter filter;
24
+ struct ref_format format = REF_FORMAT_INIT;
25
26
struct option opts[] = {
27
- OPT_BIT('s', "shell", "e_style,
27
+ OPT_BIT('s', "shell", &format.quote_style,
28
N_("quote placeholders suitably for shells"), QUOTE_SHELL),
29
- OPT_BIT('p', "perl", "e_style,
29
+ OPT_BIT('p', "perl", &format.quote_style,
30
N_("quote placeholders suitably for perl"), QUOTE_PERL),
31
- OPT_BIT(0 , "python", "e_style,
31
+ OPT_BIT(0 , "python", &format.quote_style,
32
N_("quote placeholders suitably for python"), QUOTE_PYTHON),
33
- OPT_BIT(0 , "tcl", "e_style,
33
+ OPT_BIT(0 , "tcl", &format.quote_style,
34
N_("quote placeholders suitably for Tcl"), QUOTE_TCL),
35
36
OPT_GROUP(""),
37
OPT_INTEGER( 0 , "count", &maxcount, N_("show only <n> matched refs")),
38
- OPT_STRING( 0 , "format", &format, N_("format"), N_("format to use for the output")),
38
+ OPT_STRING( 0 , "format", &format.format, N_("format"), N_("format to use for the output")),
39
OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
40
N_("field name to sort on"), &parse_opt_ref_sorting),
41
OPT_CALLBACK(0, "points-at", &filter.points_at,
52
memset(&array, 0, sizeof(array));
53
memset(&filter, 0, sizeof(filter));
54
55
+ format.format = "%(objectname) %(objecttype)\t%(refname)";
56
+
57
parse_options(argc, argv, prefix, opts, for_each_ref_usage, 0);
58
if (maxcount < 0) {
59
error("invalid --count argument: `%d'", maxcount);
60
usage_with_options(for_each_ref_usage, opts);
61
}
60
- if (HAS_MULTI_BITS(quote_style)) {
62
+ if (HAS_MULTI_BITS(format.quote_style)) {
63
error("more than one quoting style?");
64
usage_with_options(for_each_ref_usage, opts);
65
}
64
- if (verify_ref_format(format))
66
+ if (verify_ref_format(&format))
67
usage_with_options(for_each_ref_usage, opts);
68
69
if (!sorting)
82
if (!maxcount || array.nr < maxcount)
83
maxcount = array.nr;
84
for (i = 0; i < maxcount; i++)
83
- show_ref_array_item(array.items[i], format, quote_style);
85
+ show_ref_array_item(array.items[i], &format);
86
ref_array_clear(&array);
87
return 0;
88
}