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>
Erik Faye-Lund committed
Mar 20, 2010 at 19:55 UTC
28a53178fcd3c9a6576b20040982ca0b9e972f42
1 file changed
+21
-18
builtin/log.c
+21
-18
@@ -1264,8 +1264,11 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
1264
return -1;
1265
}
1266
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
+
1272
int cmd_cherry(int argc, const char **argv, const char *prefix)
1273
{
1274
struct rev_info revs;
@@ -1276,26 +1279,25 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
1279
const char *upstream;
1280
const char *head = "HEAD";
1281
const char *limit = NULL;
1279
- int verbose = 0;
1282
+ int verbose = 0, abbrev = 0;
1283
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
+ };
1289
1287
- if (argc > 1 && !strcmp(argv[1], "-h"))
1288
- usage(cherry_usage);
1290
+ argc = parse_options(argc, argv, prefix, options, cherry_usage, 0);
1291
1292
switch (argc) {
1291
- case 4:
1292
- limit = argv[3];
1293
- /* FALLTHROUGH */
1293
case 3:
1295
- head = argv[2];
1294
+ limit = argv[2];
1295
/* FALLTHROUGH */
1296
case 2:
1298
- upstream = argv[1];
1297
+ head = argv[1];
1298
+ /* FALLTHROUGH */
1299
+ case 1:
1300
+ upstream = argv[0];
1301
break;
1302
default:
1303
current_branch = branch_get(NULL);
@@ -1305,7 +1307,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
1307
fprintf(stderr, "Could not find a tracked"
1308
" remote branch, please"
1309
" specify <upstream> manually.\n");
1308
- usage(cherry_usage);
1310
+ usage_with_options(cherry_usage, options);
1311
}
1312
1313
upstream = current_branch->merge[0]->dst;
@@ -1358,12 +1360,13 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
1360
pretty_print_commit(CMIT_FMT_ONELINE, commit,
1361
&buf, &ctx);
1362
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);
1365
strbuf_release(&buf);
1366
}
1367
else {
1368
printf("%c %s\n", sign,
1366
- sha1_to_hex(commit->object.sha1));
1369
+ find_unique_abbrev(commit->object.sha1, abbrev));
1370
}
1371
1372
list = list->next;