2
#include "commit.h"
3
#include "config.h"
4
#include "environment.h"
5
+#include "for-each-ref.h"
6
#include "gettext.h"
7
#include "object.h"
8
#include "parse-options.h"
10
#include "strbuf.h"
11
#include "strvec.h"
12
12
-#define COMMON_USAGE_FOR_EACH_REF \
13
- "[--count=<count>] [--shell|--perl|--python|--tcl]\n" \
14
- " [(--sort=<key>)...] [--format=<format>]\n" \
15
- " [--include-root-refs] [--points-at=<object>]\n" \
16
- " [--merged[=<object>]] [--no-merged[=<object>]]\n" \
17
- " [--contains[=<object>]] [--no-contains[=<object>]]\n" \
18
- " [(--exclude=<pattern>)...] [--start-after=<marker>]\n" \
19
- " [ --stdin | <pattern>... ]"
20
-
21
-static char const * const for_each_ref_usage[] = {
22
- "git for-each-ref " COMMON_USAGE_FOR_EACH_REF,
23
- NULL
24
-};
25
-
26
-int cmd_for_each_ref(int argc,
27
- const char **argv,
28
- const char *prefix,
29
- struct repository *repo)
13
+int for_each_ref_core(int argc, const char **argv, const char *prefix, struct repository *repo, const char *const *usage)
14
{
15
struct ref_sorting *sorting;
16
struct string_list sorting_options = STRING_LIST_INIT_DUP;
59
/* Set default (refname) sorting */
60
string_list_append(&sorting_options, "refname");
61
78
- parse_options(argc, argv, prefix, opts, for_each_ref_usage, 0);
62
+ parse_options(argc, argv, prefix, opts, usage, 0);
63
if (format.array_opts.max_count < 0) {
64
error("invalid --count argument: `%d'", format.array_opts.max_count);
81
- usage_with_options(for_each_ref_usage, opts);
65
+ usage_with_options(usage, opts);
66
}
67
if (HAS_MULTI_BITS(format.quote_style)) {
68
error("more than one quoting style?");
85
- usage_with_options(for_each_ref_usage, opts);
69
+ usage_with_options(usage, opts);
70
}
71
if (verify_ref_format(&format))
88
- usage_with_options(for_each_ref_usage, opts);
72
+ usage_with_options(usage, opts);
73
74
if (filter.start_after && sorting_options.nr > 1)
75
die(_("cannot use --start-after with custom sort options"));
109
strvec_clear(&vec);
110
return 0;
111
}
112
+
113
+int cmd_for_each_ref(int argc,
114
+ const char **argv,
115
+ const char *prefix,
116
+ struct repository *repo)
117
+{
118
+ static char const * const for_each_ref_usage[] = {
119
+ N_("git for-each-ref " COMMON_USAGE_FOR_EACH_REF),
120
+ NULL
121
+ };
122
+
123
+ return for_each_ref_core(argc, argv, prefix, repo, for_each_ref_usage);
124
+}