Pārlūkot izejas kodu

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

Matthew Wang 12 gadus atpakaļ
vecāks
revīzija
185b587209
3 mainītis faili ar 29 papildinājumiem un 8 dzēšanām
  1. 7
    0
      README.rst
  2. 22
    7
      cdiff.py
  3. 0
    1
      setup.py

+ 7
- 0
README.rst Parādīt failu

72
     cdiff -s                    # view side by side
72
     cdiff -s                    # view side by side
73
     cdiff -s -w 90              # use text width 90 other than default 80
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
 Pipe in a diff:
82
 Pipe in a diff:
76
 
83
 
77
 .. code:: sh
84
 .. code:: sh

+ 22
- 7
cdiff.py Parādīt failu

25
     raise SystemExit("*** Requires python >= 2.5.0")
25
     raise SystemExit("*** Requires python >= 2.5.0")
26
 IS_PY3 = sys.hexversion >= 0x03000000
26
 IS_PY3 = sys.hexversion >= 0x03000000
27
 
27
 
28
-import os
29
 import re
28
 import re
30
 import subprocess
29
 import subprocess
31
 import errno
30
 import errno
53
 
52
 
54
 # Keys for checking and values for diffing.
53
 # Keys for checking and values for diffing.
55
 REVISION_CONTROL = (
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
 
554
 
556
 def revision_control_diff():
555
 def revision_control_diff():
557
     """Return diff from revision control system."""
556
     """Return diff from revision control system."""
558
-    for check, diff in REVISION_CONTROL:
557
+    for check, diff, _ in REVISION_CONTROL:
559
         if check_command_status(check):
558
         if check_command_status(check):
560
             return subprocess.Popen(diff, stdout=subprocess.PIPE).stdout
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
 def decode(line):
569
 def decode(line):
564
     """Decode UTF-8 if necessary."""
570
     """Decode UTF-8 if necessary."""
565
     try:
571
     try:
571
 def main():
577
 def main():
572
     import optparse
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
     usage = """
582
     usage = """
577
   %prog [options]
583
   %prog [options]
586
             help='show in side-by-side mode')
592
             help='show in side-by-side mode')
587
     parser.add_option('-w', '--width', type='int', default=80, metavar='N',
593
     parser.add_option('-w', '--width', type='int', default=80, metavar='N',
588
             help='set text width (side-by-side mode only), default is 80')
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
     opts, args = parser.parse_args()
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
         parser.print_help()
607
         parser.print_help()
593
         return 1
608
         return 1
594
     elif len(args) == 2:
609
     elif len(args) == 2:

+ 0
- 1
setup.py Parādīt failu

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