File: diff.txt

package info (click to toggle)
git-cola 4.17.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 6,928 kB
  • sloc: python: 38,433; sh: 298; makefile: 223; xml: 110; tcl: 62
file content (57 lines) | stat: -rw-r--r-- 2,548 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@@ -6,10 +6,21 @@ from cola import gitcmds
 from cola import gitcfg
 
 
+class DiffSource(object):
+    def get(self, head, amending, filename, cached, reverse):
+        return gitcmds.diff_helper(head=head,
+                                   amending=amending,
+                                   filename=filename,
+                                   with_diff_header=True,
+                                   cached=cached,
+                                   reverse=reverse)
+
+
 class DiffParser(object):
     """Handles parsing diff for use by the interactive index editor."""
     def __init__(self, model, filename='',
-                 cached=True, reverse=False):
+                 cached=True, reverse=False,
+                 diff_source=None):
 
         self._header_re = re.compile('^@@ -(\d+),(\d+) \+(\d+),(\d+) @@.*')
         self._header_start_re = re.compile('^@@ -(\d+) \+(\d+),(\d+) @@.*')
@@ -29,13 +40,11 @@ class DiffParser(object):
         self.diff_sel = []
         self.selected = []
         self.filename = filename
+        self.diff_source = diff_source or DiffSource()
 
-        (header, diff) = gitcmds.diff_helper(head=self.head,
-                                             amending=self.amending,
-                                             filename=filename,
-                                             with_diff_header=True,
-                                             cached=cached,
-                                             reverse=cached or reverse)
+        (header, diff) = self.diff_source.get(self.head, self.amending,
+                                              filename, cached,
+                                              cached or reverse)
         self.model = model
         self.diff = diff
         self.header = header
@@ -43,11 +52,10 @@ class DiffParser(object):
 
         # Always index into the non-reversed diff
         self.fwd_header, self.fwd_diff = \
-            gitcmds.diff_helper(head=self.head,
-                                amending=self.amending,
-                                filename=filename,
-                                with_diff_header=True,
-                                cached=cached)
+                self.diff_source.get(self.head,
+                                     self.amending,
+                                     filename,
+                                     cached, False)
 
     def write_diff(self,filename,which,selected=False,noop=False):
         """Writes a new diff corresponding to the user's selection."""