Skip to content

Commit 28a5317

Browse files
kusmagitster
authored andcommitted
cherry: support --abbrev option
Switch to parse-options API while we're at it. Signed-off-by: Erik Faye-Lund <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d0925c commit 28a5317

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

builtin/log.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,8 +1264,11 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
12641264
return -1;
12651265
}
12661266

1267-
static const char cherry_usage[] =
1268-
"git cherry [-v] [<upstream> [<head> [<limit>]]]";
1267+
static const char * const cherry_usage[] = {
1268+
"git cherry [-v] [<upstream> [<head> [<limit>]]]",
1269+
NULL
1270+
};
1271+
12691272
int cmd_cherry(int argc, const char **argv, const char *prefix)
12701273
{
12711274
struct rev_info revs;
@@ -1276,26 +1279,25 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
12761279
const char *upstream;
12771280
const char *head = "HEAD";
12781281
const char *limit = NULL;
1279-
int verbose = 0;
1282+
int verbose = 0, abbrev = 0;
12801283

1281-
if (argc > 1 && !strcmp(argv[1], "-v")) {
1282-
verbose = 1;
1283-
argc--;
1284-
argv++;
1285-
}
1284+
struct option options[] = {
1285+
OPT__ABBREV(&abbrev),
1286+
OPT__VERBOSE(&verbose),
1287+
OPT_END()
1288+
};
12861289

1287-
if (argc > 1 && !strcmp(argv[1], "-h"))
1288-
usage(cherry_usage);
1290+
argc = parse_options(argc, argv, prefix, options, cherry_usage, 0);
12891291

12901292
switch (argc) {
1291-
case 4:
1292-
limit = argv[3];
1293-
/* FALLTHROUGH */
12941293
case 3:
1295-
head = argv[2];
1294+
limit = argv[2];
12961295
/* FALLTHROUGH */
12971296
case 2:
1298-
upstream = argv[1];
1297+
head = argv[1];
1298+
/* FALLTHROUGH */
1299+
case 1:
1300+
upstream = argv[0];
12991301
break;
13001302
default:
13011303
current_branch = branch_get(NULL);
@@ -1305,7 +1307,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
13051307
fprintf(stderr, "Could not find a tracked"
13061308
" remote branch, please"
13071309
" specify <upstream> manually.\n");
1308-
usage(cherry_usage);
1310+
usage_with_options(cherry_usage, options);
13091311
}
13101312

13111313
upstream = current_branch->merge[0]->dst;
@@ -1358,12 +1360,13 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
13581360
pretty_print_commit(CMIT_FMT_ONELINE, commit,
13591361
&buf, &ctx);
13601362
printf("%c %s %s\n", sign,
1361-
sha1_to_hex(commit->object.sha1), buf.buf);
1363+
find_unique_abbrev(commit->object.sha1, abbrev),
1364+
buf.buf);
13621365
strbuf_release(&buf);
13631366
}
13641367
else {
13651368
printf("%c %s\n", sign,
1366-
sha1_to_hex(commit->object.sha1));
1369+
find_unique_abbrev(commit->object.sha1, abbrev));
13671370
}
13681371

13691372
list = list->next;

0 commit comments

Comments
 (0)