#include "commit.h"
#include "config.h"
#include "environment.h"
+#include "for-each-ref.h"
#include "gettext.h"
#include "object.h"
#include "parse-options.h"
#include "strbuf.h"
#include "strvec.h"
-#define COMMON_USAGE_FOR_EACH_REF \
- "[--count=<count>] [--shell|--perl|--python|--tcl]\n" \
- " [(--sort=<key>)...] [--format=<format>]\n" \
- " [--include-root-refs] [--points-at=<object>]\n" \
- " [--merged[=<object>]] [--no-merged[=<object>]]\n" \
- " [--contains[=<object>]] [--no-contains[=<object>]]\n" \
- " [(--exclude=<pattern>)...] [--start-after=<marker>]\n" \
- " [ --stdin | <pattern>... ]"
-
-static char const * const for_each_ref_usage[] = {
- "git for-each-ref " COMMON_USAGE_FOR_EACH_REF,
- NULL
-};
-
-int cmd_for_each_ref(int argc,
- const char **argv,
- const char *prefix,
- struct repository *repo)
+int for_each_ref_core(int argc, const char **argv, const char *prefix, struct repository *repo, const char *const *usage)
{
struct ref_sorting *sorting;
struct string_list sorting_options = STRING_LIST_INIT_DUP;
/* Set default (refname) sorting */
string_list_append(&sorting_options, "refname");
- parse_options(argc, argv, prefix, opts, for_each_ref_usage, 0);
+ parse_options(argc, argv, prefix, opts, usage, 0);
if (format.array_opts.max_count < 0) {
error("invalid --count argument: `%d'", format.array_opts.max_count);
- usage_with_options(for_each_ref_usage, opts);
+ usage_with_options(usage, opts);
}
if (HAS_MULTI_BITS(format.quote_style)) {
error("more than one quoting style?");
- usage_with_options(for_each_ref_usage, opts);
+ usage_with_options(usage, opts);
}
if (verify_ref_format(&format))
- usage_with_options(for_each_ref_usage, opts);
+ usage_with_options(usage, opts);
if (filter.start_after && sorting_options.nr > 1)
die(_("cannot use --start-after with custom sort options"));
strvec_clear(&vec);
return 0;
}
+
+int cmd_for_each_ref(int argc,
+ const char **argv,
+ const char *prefix,
+ struct repository *repo)
+{
+ static char const * const for_each_ref_usage[] = {
+ N_("git for-each-ref " COMMON_USAGE_FOR_EACH_REF),
+ NULL
+ };
+
+ return for_each_ref_core(argc, argv, prefix, repo, for_each_ref_usage);
+}
--- /dev/null
+#ifndef FOR_EACH_REF_H
+#define FOR_EACH_REF_H
+
+struct repository;
+
+/*
+ * Shared usage string for options common to git-for-each-ref(1)
+ * and git-refs-list(1). The command-specific part (e.g., "git refs list ")
+ * must be prepended by the caller.
+ */
+#define COMMON_USAGE_FOR_EACH_REF \
+ "[--count=<count>] [--shell|--perl|--python|--tcl]\n" \
+ " [(--sort=<key>)...] [--format=<format>]\n" \
+ " [--include-root-refs] [--points-at=<object>]\n" \
+ " [--merged[=<object>]] [--no-merged[=<object>]]\n" \
+ " [--contains[=<object>]] [--no-contains[=<object>]]\n" \
+ " [(--exclude=<pattern>)...] [--start-after=<marker>]\n" \
+ " [ --stdin | <pattern>... ]"
+
+/*
+ * The core logic for for-each-ref and its clones.
+ */
+int for_each_ref_core(int argc, const char **argv, const char *prefix,
+ struct repository *repo, const char *const *usage);
+
+#endif /* FOR_EACH_REF_H */