diff kallithea/lib/diffs.py @ 6938:6fde53180c50

diffs: wrap vcs repo get_diff Refactor to get a single place for diff error handling outside the vcs lib.
author Mads Kiilerich <mads@kiilerich.com>
date Sun, 22 Oct 2017 00:42:12 +0200
parents 9cdb81c7b855
children 07f026cdf7ac
line wrap: on
line diff
--- a/kallithea/lib/diffs.py	Sun Oct 22 00:42:12 2017 +0200
+++ b/kallithea/lib/diffs.py	Sun Oct 22 00:42:12 2017 +0200
@@ -248,10 +248,19 @@
     old_raw_id = getattr(filenode_old.changeset, 'raw_id', repo.EMPTY_CHANGESET)
     new_raw_id = getattr(filenode_new.changeset, 'raw_id', repo.EMPTY_CHANGESET)
 
-    vcs_gitdiff = repo.get_diff(old_raw_id, new_raw_id, filenode_new.path,
-                                ignore_whitespace, context)
+    vcs_gitdiff = get_diff(repo, old_raw_id, new_raw_id, filenode_new.path,
+                           ignore_whitespace, context)
     return vcs_gitdiff
 
+
+def get_diff(scm_instance, rev1, rev2, path=None, ignore_whitespace=False, context=3):
+    """
+    A thin wrapper around vcs lib get_diff.
+    """
+    return scm_instance.get_diff(rev1, rev2, path=path,
+                                 ignore_whitespace=ignore_whitespace, context=context)
+
+
 NEW_FILENODE = 1
 DEL_FILENODE = 2
 MOD_FILENODE = 3