Selaa lähdekoodia

Factor out common code

Steven Myint 12 vuotta sitten
vanhempi
commit
41c1e5bc2b
1 muutettua tiedostoa jossa 17 lisäystä ja 6 poistoa
  1. 17
    6
      src/cdiff.py

+ 17
- 6
src/cdiff.py Näytä tiedosto

40
     'lightcyan'     : '\x1b[1;36m',
40
     'lightcyan'     : '\x1b[1;36m',
41
 }
41
 }
42
 
42
 
43
+
44
+# Keys for checking and values for diffing.
45
+REVISION_CONTROL = (
46
+    (['git', 'rev-parse'], ['git', 'diff']),
47
+    (['svn', 'info'], ['svn', 'diff']),
48
+    (['hg', 'summary'], ['hg', 'diff'])
49
+)
50
+
51
+
43
 def ansi_code(color):
52
 def ansi_code(color):
44
     return COLORS.get(color, '')
53
     return COLORS.get(color, '')
45
 
54
 
481
         return False
490
         return False
482
 
491
 
483
 
492
 
493
+def command_pipe(arguments):
494
+    """Return stdout pipe after starting subprocess."""
495
+    return subprocess.Popen(arguments, stdout=subprocess.PIPE).stdout
496
+
497
+
484
 def revision_control_diff(path):
498
 def revision_control_diff(path):
485
     """Return diff from revision control system."""
499
     """Return diff from revision control system."""
486
-    if check_command_status(['git', 'rev-parse']):
487
-        return subprocess.Popen(['git', 'diff'], stdout=subprocess.PIPE).stdout
488
-    elif check_command_status(['svn', 'info']):
489
-        return subprocess.Popen(['svn', 'diff'], stdout=subprocess.PIPE).stdout
490
-    elif check_command_status(['hg', 'summary']):
491
-        return subprocess.Popen(['hg', 'diff'], stdout=subprocess.PIPE).stdout
500
+    for check, diff in REVISION_CONTROL:
501
+        if check_command_status(check):
502
+            return command_pipe(diff)
492
 
503
 
493
 
504
 
494
 def decode(line):
505
 def decode(line):