parse-opt: migrate git-merge-base.
Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
parent
c8ef0383ac
commit
e5d1a4df56
@ -1,6 +1,7 @@
|
|||||||
#include "builtin.h"
|
#include "builtin.h"
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "commit.h"
|
#include "commit.h"
|
||||||
|
#include "parse-options.h"
|
||||||
|
|
||||||
static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
|
static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
|
||||||
{
|
{
|
||||||
@ -21,8 +22,10 @@ static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char merge_base_usage[] =
|
static const char * const merge_base_usage[] = {
|
||||||
"git merge-base [--all] <commit-id> <commit-id>...";
|
"git merge-base [--all] <commit-id> <commit-id>...",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
static struct commit *get_commit_reference(const char *arg)
|
static struct commit *get_commit_reference(const char *arg)
|
||||||
{
|
{
|
||||||
@ -44,25 +47,17 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)
|
|||||||
int rev_nr = 0;
|
int rev_nr = 0;
|
||||||
int show_all = 0;
|
int show_all = 0;
|
||||||
|
|
||||||
|
struct option options[] = {
|
||||||
|
OPT_BOOLEAN('a', "all", &show_all, "outputs all common ancestors"),
|
||||||
|
OPT_END()
|
||||||
|
};
|
||||||
|
|
||||||
git_config(git_default_config, NULL);
|
git_config(git_default_config, NULL);
|
||||||
|
argc = parse_options(argc, argv, options, merge_base_usage, 0);
|
||||||
while (1 < argc && argv[1][0] == '-') {
|
if (argc < 2)
|
||||||
const char *arg = argv[1];
|
usage_with_options(merge_base_usage, options);
|
||||||
if (!strcmp(arg, "-a") || !strcmp(arg, "--all"))
|
rev = xmalloc(argc * sizeof(*rev));
|
||||||
show_all = 1;
|
while (argc-- > 0)
|
||||||
else
|
rev[rev_nr++] = get_commit_reference(*argv++);
|
||||||
usage(merge_base_usage);
|
|
||||||
argc--; argv++;
|
|
||||||
}
|
|
||||||
if (argc < 3)
|
|
||||||
usage(merge_base_usage);
|
|
||||||
|
|
||||||
rev = xmalloc((argc - 1) * sizeof(*rev));
|
|
||||||
|
|
||||||
do {
|
|
||||||
rev[rev_nr++] = get_commit_reference(argv[1]);
|
|
||||||
argc--; argv++;
|
|
||||||
} while (argc > 1);
|
|
||||||
|
|
||||||
return show_merge_base(rev, rev_nr, show_all);
|
return show_merge_base(rev, rev_nr, show_all);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user