Browse Source

Add "--log" option

This will use the patch log from git, svn, or hg.
Steven Myint 12 years ago
parent
commit
93d2bf08bf
1 changed files with 22 additions and 6 deletions
  1. 22
    6
      cdiff.py

+ 22
- 6
cdiff.py View File

@@ -52,9 +52,9 @@ COLORS = {
52 52
 
53 53
 # Keys for checking and values for diffing.
54 54
 REVISION_CONTROL = (
55
-    (['git', 'rev-parse'], ['git', 'diff']),
56
-    (['svn', 'info'], ['svn', 'diff']),
57
-    (['hg', 'summary'], ['hg', 'diff'])
55
+    (['git', 'rev-parse'], ['git', 'diff'], ['git', 'log', '--patch']),
56
+    (['svn', 'info'],      ['svn', 'diff'], ['svn', 'log', '--diff']),
57
+    (['hg',  'summary'],   ['hg',  'diff'], ['hg',  'log', '--patch'])
58 58
 )
59 59
 
60 60
 
@@ -516,11 +516,18 @@ def check_command_status(arguments):
516 516
 
517 517
 def revision_control_diff():
518 518
     """Return diff from revision control system."""
519
-    for check, diff in REVISION_CONTROL:
519
+    for check, diff, _ in REVISION_CONTROL:
520 520
         if check_command_status(check):
521 521
             return subprocess.Popen(diff, stdout=subprocess.PIPE).stdout
522 522
 
523 523
 
524
+def revision_control_log():
525
+    """Return log from revision control system."""
526
+    for check, _, log in REVISION_CONTROL:
527
+        if check_command_status(check):
528
+            return subprocess.Popen(log, stdout=subprocess.PIPE).stdout
529
+
530
+
524 531
 def decode(line):
525 532
     """Decode UTF-8 if necessary."""
526 533
     try:
@@ -532,7 +539,7 @@ def decode(line):
532 539
 def main():
533 540
     import optparse
534 541
 
535
-    supported_vcs = [check[0] for check, _ in REVISION_CONTROL]
542
+    supported_vcs = [check[0][0] for check in REVISION_CONTROL]
536 543
 
537 544
     usage = """
538 545
   %prog [options]
@@ -547,9 +554,18 @@ def main():
547 554
             help='show in side-by-side mode')
548 555
     parser.add_option('-w', '--width', type='int', default=80, metavar='N',
549 556
             help='set text width (side-by-side mode only), default is 80')
557
+    parser.add_option('-l', '--log', action='store_true',
558
+                      help='show log from revision control (git, svn, hg)')
550 559
     opts, args = parser.parse_args()
551 560
 
552
-    if len(args) > 2:
561
+    if opts.log:
562
+        diff_hdl = revision_control_log()
563
+        if not diff_hdl:
564
+            sys.stderr.write(('*** Not in a supported workspace, supported '
565
+                              'are: %s\n\n') % ', '.join(supported_vcs))
566
+            parser.print_help()
567
+            return 1
568
+    elif len(args) > 2:
553 569
         parser.print_help()
554 570
         return 1
555 571
     elif len(args) == 2: