Selaa lähdekoodia

Merge branch 'log' of https://github.com/myint/cdiff

Matthew Wang 11 vuotta sitten
vanhempi
commit
185b587209
3 muutettua tiedostoa jossa 29 lisäystä ja 8 poistoa
  1. 7
    0
      README.rst
  2. 22
    7
      cdiff.py
  3. 0
    1
      setup.py

+ 7
- 0
README.rst Näytä tiedosto

@@ -72,6 +72,13 @@ Read diff from local modification in a *svn*, *git*, or *hg* workspace:
72 72
     cdiff -s                    # view side by side
73 73
     cdiff -s -w 90              # use text width 90 other than default 80
74 74
 
75
+Read the log (e.g. ``git log -p``) in a svn, git, or hg workspace:
76
+
77
+.. code:: sh
78
+
79
+    cd proj-workspace
80
+    cdiff -l
81
+
75 82
 Pipe in a diff:
76 83
 
77 84
 .. code:: sh

+ 22
- 7
cdiff.py Näytä tiedosto

@@ -25,7 +25,6 @@ if sys.hexversion < 0x02050000:
25 25
     raise SystemExit("*** Requires python >= 2.5.0")
26 26
 IS_PY3 = sys.hexversion >= 0x03000000
27 27
 
28
-import os
29 28
 import re
30 29
 import subprocess
31 30
 import errno
@@ -53,9 +52,9 @@ COLORS = {
53 52
 
54 53
 # Keys for checking and values for diffing.
55 54
 REVISION_CONTROL = (
56
-    (['git', 'rev-parse'], ['git', 'diff']),
57
-    (['svn', 'info'], ['svn', 'diff']),
58
-    (['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'])
59 58
 )
60 59
 
61 60
 
@@ -555,11 +554,18 @@ def check_command_status(arguments):
555 554
 
556 555
 def revision_control_diff():
557 556
     """Return diff from revision control system."""
558
-    for check, diff in REVISION_CONTROL:
557
+    for check, diff, _ in REVISION_CONTROL:
559 558
         if check_command_status(check):
560 559
             return subprocess.Popen(diff, stdout=subprocess.PIPE).stdout
561 560
 
562 561
 
562
+def revision_control_log():
563
+    """Return log from revision control system."""
564
+    for check, _, log in REVISION_CONTROL:
565
+        if check_command_status(check):
566
+            return subprocess.Popen(log, stdout=subprocess.PIPE).stdout
567
+
568
+
563 569
 def decode(line):
564 570
     """Decode UTF-8 if necessary."""
565 571
     try:
@@ -571,7 +577,7 @@ def decode(line):
571 577
 def main():
572 578
     import optparse
573 579
 
574
-    supported_vcs = [check[0] for check, _ in REVISION_CONTROL]
580
+    supported_vcs = [check[0][0] for check in REVISION_CONTROL]
575 581
 
576 582
     usage = """
577 583
   %prog [options]
@@ -586,9 +592,18 @@ def main():
586 592
             help='show in side-by-side mode')
587 593
     parser.add_option('-w', '--width', type='int', default=80, metavar='N',
588 594
             help='set text width (side-by-side mode only), default is 80')
595
+    parser.add_option('-l', '--log', action='store_true',
596
+                      help='show log from revision control (git, svn, hg)')
589 597
     opts, args = parser.parse_args()
590 598
 
591
-    if len(args) > 2:
599
+    if opts.log:
600
+        diff_hdl = revision_control_log()
601
+        if not diff_hdl:
602
+            sys.stderr.write(('*** Not in a supported workspace, supported '
603
+                              'are: %s\n\n') % ', '.join(supported_vcs))
604
+            parser.print_help()
605
+            return 1
606
+    elif len(args) > 2:
592 607
         parser.print_help()
593 608
         return 1
594 609
     elif len(args) == 2:

+ 0
- 1
setup.py Näytä tiedosto

@@ -3,7 +3,6 @@
3 3
 
4 4
 from __future__ import with_statement
5 5
 from distutils.core import setup
6
-import os
7 6
 from cdiff import META_INFO as _meta
8 7
 
9 8
 import sys