1. Marcin Kuzminski
  2. vcs

Commits

Lukasz Balcerzak  committed ab53600 Merge

Merge branch 'master' of github.com:codeinn/vcs

  • Participants
  • Parent commits 40f5322, 1afab74
  • Branches default

Comments (0)

Files changed (3)

File vcs/backends/git.py

View file
                 "stderr:\n%s" % (cmd, se))
         return so, se
 
-    def _get_diff(self, rev1, rev2, path=None, ignore_whitespace=False):
+    def _get_diff(self, rev1, rev2, path=None, ignore_whitespace=False,
+                  context=3):
         rev1 = self._get_revision(rev1)
         rev2 = self._get_revision(rev2)
-        
+        context = context or 3
+
         if ignore_whitespace:
-            cmd = 'diff -w %s %s' % (rev1, rev2)
+            cmd = 'diff -U%s -w %s %s' % (context, rev1, rev2)
         else:
-            cmd = 'diff %s %s' % (rev1, rev2)
+            cmd = 'diff -U%s %s %s' % (context, rev1, rev2)
         if path:
             cmd += ' -- "%s"' % path
         so, se = self.run_git_command(cmd)

File vcs/backends/hg.py

View file
 
         return map(lambda x: hex(x[7]), self._repo.changelog.index)[:-1]
 
-    def _get_diff(self, rev1, rev2, path=None, ignore_whitespace=False):
+    def _get_diff(self, rev1, rev2, path=None, ignore_whitespace=False,
+                  context=3):
         file_filter = match(self.path, '', [path])
         return patch.diff(self._repo, rev1, rev2, match=file_filter,
                           opts=diffopts(git=True,
-                                        ignorews=ignore_whitespace))
+                                        ignorews=ignore_whitespace,
+                                        context=context))
 
     def _check_url(self, url):
         """

File vcs/tests/test_git.py

View file
     def test_get_diff_runs_git_command_with_hashes(self):
         self.repo.run_git_command = mock.Mock(return_value=['', ''])
         self.repo._get_diff(0, 1)
-        self.repo.run_git_command.assert_called_once_with('diff %s %s' %
-            (self.repo._get_revision(0), self.repo._get_revision(1)))
+        self.repo.run_git_command.assert_called_once_with('diff -U%s %s %s' %
+            (3, self.repo._get_revision(0), self.repo._get_revision(1)))
 
     def test_get_diff_runs_git_command_with_str_hashes(self):
         self.repo.run_git_command = mock.Mock(return_value=['', ''])
         self.repo._get_diff('0' * 40, 1)
-        self.repo.run_git_command.assert_called_once_with('diff %s %s' %
-            (self.repo._get_revision(0), self.repo._get_revision(1)))
+        self.repo.run_git_command.assert_called_once_with('diff -U%s %s %s' %
+            (3, self.repo._get_revision(0), self.repo._get_revision(1)))
 
     def test_get_diff_runs_git_command_with_path_if_its_given(self):
         self.repo.run_git_command = mock.Mock(return_value=['', ''])
         self.repo._get_diff(0, 1, 'foo')
-        self.repo.run_git_command.assert_called_once_with('diff %s %s -- "foo"'
-            % (self.repo._get_revision(0), self.repo._get_revision(1)))
+        self.repo.run_git_command.assert_called_once_with('diff -U%s %s %s -- "foo"'
+            % (3, self.repo._get_revision(0), self.repo._get_revision(1)))
 
 if __name__ == '__main__':
     unittest.main()