cherry: support --abbrev option
Switch to parse-options API while we're at it. Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
0d0925c5e2
commit
28a53178fc
@ -1264,8 +1264,11 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char cherry_usage[] =
|
static const char * const cherry_usage[] = {
|
||||||
"git cherry [-v] [<upstream> [<head> [<limit>]]]";
|
"git cherry [-v] [<upstream> [<head> [<limit>]]]",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
int cmd_cherry(int argc, const char **argv, const char *prefix)
|
int cmd_cherry(int argc, const char **argv, const char *prefix)
|
||||||
{
|
{
|
||||||
struct rev_info revs;
|
struct rev_info revs;
|
||||||
@ -1276,26 +1279,25 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
|
|||||||
const char *upstream;
|
const char *upstream;
|
||||||
const char *head = "HEAD";
|
const char *head = "HEAD";
|
||||||
const char *limit = NULL;
|
const char *limit = NULL;
|
||||||
int verbose = 0;
|
int verbose = 0, abbrev = 0;
|
||||||
|
|
||||||
if (argc > 1 && !strcmp(argv[1], "-v")) {
|
struct option options[] = {
|
||||||
verbose = 1;
|
OPT__ABBREV(&abbrev),
|
||||||
argc--;
|
OPT__VERBOSE(&verbose),
|
||||||
argv++;
|
OPT_END()
|
||||||
}
|
};
|
||||||
|
|
||||||
if (argc > 1 && !strcmp(argv[1], "-h"))
|
argc = parse_options(argc, argv, prefix, options, cherry_usage, 0);
|
||||||
usage(cherry_usage);
|
|
||||||
|
|
||||||
switch (argc) {
|
switch (argc) {
|
||||||
case 4:
|
|
||||||
limit = argv[3];
|
|
||||||
/* FALLTHROUGH */
|
|
||||||
case 3:
|
case 3:
|
||||||
head = argv[2];
|
limit = argv[2];
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
case 2:
|
case 2:
|
||||||
upstream = argv[1];
|
head = argv[1];
|
||||||
|
/* FALLTHROUGH */
|
||||||
|
case 1:
|
||||||
|
upstream = argv[0];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
current_branch = branch_get(NULL);
|
current_branch = branch_get(NULL);
|
||||||
@ -1305,7 +1307,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
|
|||||||
fprintf(stderr, "Could not find a tracked"
|
fprintf(stderr, "Could not find a tracked"
|
||||||
" remote branch, please"
|
" remote branch, please"
|
||||||
" specify <upstream> manually.\n");
|
" specify <upstream> manually.\n");
|
||||||
usage(cherry_usage);
|
usage_with_options(cherry_usage, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
upstream = current_branch->merge[0]->dst;
|
upstream = current_branch->merge[0]->dst;
|
||||||
@ -1358,12 +1360,13 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
|
|||||||
pretty_print_commit(CMIT_FMT_ONELINE, commit,
|
pretty_print_commit(CMIT_FMT_ONELINE, commit,
|
||||||
&buf, &ctx);
|
&buf, &ctx);
|
||||||
printf("%c %s %s\n", sign,
|
printf("%c %s %s\n", sign,
|
||||||
sha1_to_hex(commit->object.sha1), buf.buf);
|
find_unique_abbrev(commit->object.sha1, abbrev),
|
||||||
|
buf.buf);
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("%c %s\n", sign,
|
printf("%c %s\n", sign,
|
||||||
sha1_to_hex(commit->object.sha1));
|
find_unique_abbrev(commit->object.sha1, abbrev));
|
||||||
}
|
}
|
||||||
|
|
||||||
list = list->next;
|
list = list->next;
|
||||||
|
Loading…
Reference in New Issue
Block a user