changeset 1104:e326b349eba6

compat: extract function for memfilectx signature variants
author Kevin Bullock <kbullock@ringworld.org>
date Tue, 06 Feb 2018 08:45:48 -0600
parents 89303af1c4aa
children bb255eaf3d14
files hggit/compat.py hggit/git_handler.py
diffstat 2 files changed, 25 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/compat.py	Tue Feb 06 08:37:11 2018 -0600
+++ b/hggit/compat.py	Tue Feb 06 08:45:48 2018 -0600
@@ -1,4 +1,5 @@
 from mercurial import (
+    context,
     url,
     util as hgutil,
 )
@@ -96,6 +97,26 @@
         return refs, set(server_capabilities)
 
 
+def memfilectx(repo, changectx, path, data, islink=False,
+               isexec=False, copied=None):
+    # Different versions of mercurial have different parameters to
+    # memfilectx.  Try them from newest to oldest.
+    args_to_try = (
+        (repo, changectx, path, data),  # hg 4.5+
+        (repo, path, data),             # hg 3.1 - 4.5
+        (path, data),                   # hg < 3.1
+    )
+    for args in args_to_try:
+        try:
+            return context.memfilectx(*args,
+                                      islink=islink,
+                                      isexec=isexec,
+                                      copied=copied)
+        except TypeError as ex:
+            last_ex = ex
+    raise last_ex
+
+
 CONFIG_DEFAULTS = {
     'git': {
         'authors': None,
--- a/hggit/git_handler.py	Tue Feb 06 08:37:11 2018 -0600
+++ b/hggit/git_handler.py	Tue Feb 06 08:45:48 2018 -0600
@@ -985,22 +985,10 @@
                 if copied:
                     copied_path = copied[0]
 
-            # Different versions of mercurial have different parameters to
-            # memfilectx.  Try them from newest to oldest.
-            args_to_try = (
-                (self.repo, memctx, f, data),   # hg 4.5+
-                (self.repo, f, data),           # hg 3.1 - 4.5
-                (f, data),                      # hg < 3.1
-            )
-            for args in args_to_try:
-                try:
-                    return context.memfilectx(*args,
-                                              islink='l' in e,
-                                              isexec='x' in e,
-                                              copied=copied_path)
-                except TypeError as ex:
-                    last_ex = ex
-            raise last_ex
+            return compat.memfilectx(self.repo, memctx, f, data,
+                                     islink='l' in e,
+                                     isexec='x' in e,
+                                     copied=copied_path)
 
         p1, p2 = (nullid, nullid)
         octopus = False