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