@@ -207,6 +207,21 @@ def rev_parse(arg, abbrev=None):
207
207
raise Failure ('%r is not a valid commit!' % (arg ,))
208
208
209
209
210
+ def describe (arg , contains = False ):
211
+ cmd = ['git' , 'describe' ]
212
+ if contains :
213
+ cmd += ['--contains' ]
214
+ cmd += [arg ]
215
+
216
+ process = subprocess .Popen (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
217
+ out , err = process .communicate ()
218
+ retcode = process .poll ()
219
+ if retcode :
220
+ return None
221
+ else :
222
+ return _decode_output (out ).strip ()
223
+
224
+
210
225
def rev_list (* args ):
211
226
"""Iterate over (commit, [parent,...]) for the selected commits.
212
227
@@ -365,15 +380,26 @@ def get_full_name(branch):
365
380
return branch
366
381
367
382
368
- FIRST_FORMAT = '%(refname)-38s %(sha1 )s'
369
- OTHER_FORMAT = FIRST_FORMAT % dict (refname = '' , sha1 = 'via %(sha1 )s' )
383
+ FIRST_FORMAT = '%(refname)-38s %(name )s'
384
+ OTHER_FORMAT = FIRST_FORMAT % dict (refname = '' , name = 'via %(name )s' )
370
385
371
- COMMIT_FORMAT = '%(sha1 )s'
372
- BRANCH_FORMAT = '%(sha1 )s^1..%(sha1 )s'
386
+ COMMIT_FORMAT = '%(name )s'
387
+ BRANCH_FORMAT = '%(name )s^1..%(name )s'
373
388
374
389
WARN_FORMAT = '%(refname)-38s %(msg)s'
375
390
376
391
392
+ def name_commit (sha1 , options ):
393
+ if options .describe :
394
+ return describe (sha1 ) or sha1
395
+ elif options .describe_contains :
396
+ return describe (sha1 , contains = True ) or sha1
397
+ elif options .abbrev is not None :
398
+ return rev_parse (sha1 , abbrev = options .abbrev )
399
+ else :
400
+ return sha1
401
+
402
+
377
403
def main (args ):
378
404
parser = argparse .ArgumentParser (
379
405
prog = 'git when-merged' ,
@@ -439,7 +465,8 @@ def main(args):
439
465
'--visualize.'
440
466
),
441
467
)
442
- parser .add_argument (
468
+ group = parser .add_mutually_exclusive_group ()
469
+ group .add_argument (
443
470
'--abbrev' , metavar = 'N' ,
444
471
action = 'store' , type = int , default = default_abbrev ,
445
472
help = (
@@ -448,10 +475,24 @@ def main(args):
448
475
'See also whenmerged.abbrev below under CONFIGURATION.'
449
476
),
450
477
)
451
- parser .add_argument (
478
+ group .add_argument (
452
479
'--no-abbrev' , dest = 'abbrev' , action = 'store_const' , const = None ,
453
480
help = 'Do not abbreviate commit SHA-1s.' ,
454
481
)
482
+ group .add_argument (
483
+ '--describe' , action = 'store_true' ,
484
+ help = (
485
+ 'Describe the merge commit in terms of the most recent tag '
486
+ 'reachable from the commit (see git-describe(1))'
487
+ ),
488
+ )
489
+ group .add_argument (
490
+ '--describe-contains' , action = 'store_true' ,
491
+ help = (
492
+ 'Describe the merge commit in terms of a nearby tag '
493
+ 'that contains it (see git-describe(1))'
494
+ ),
495
+ )
455
496
parser .add_argument (
456
497
'--log' , '-l' , action = 'store_true' , default = False ,
457
498
help = (
@@ -549,15 +590,16 @@ def main(args):
549
590
first = True
550
591
try :
551
592
for sha1 in find_merge (commit , branch ):
552
- if options .abbrev is not None :
553
- sha1 = rev_parse (sha1 , abbrev = options .abbrev )
593
+ name = name_commit (sha1 )
554
594
555
595
if first :
556
596
format = first_format
557
597
else :
558
598
format = other_format
559
599
560
- sys .stdout .write (format % dict (refname = branch , sha1 = sha1 ) + '\n ' )
600
+ sys .stdout .write (
601
+ format % dict (refname = branch , sha1 = sha1 , name = name ) + '\n ' ,
602
+ )
561
603
562
604
if options .log :
563
605
cmd = ['git' , '--no-pager' , 'log' ]
0 commit comments