changeset 1101:843f409526fb

compat: pass memctx to memfilectx constructor on hg 4.5+
author Tony Tung <tonytung@merly.org>
date Mon, 05 Feb 2018 23:21:35 -0800
parents 6dc827703bfb
children 93cb29247d61
files hggit/git_handler.py
diffstat 1 files changed, 16 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/git_handler.py	Fri Feb 02 10:06:57 2018 -0600
+++ b/hggit/git_handler.py	Mon Feb 05 23:21:35 2018 -0800
@@ -985,16 +985,22 @@
                 if copied:
                     copied_path = copied[0]
 
-            try:
-                return context.memfilectx(self.repo, f, data,
-                                          islink='l' in e,
-                                          isexec='x' in e,
-                                          copied=copied_path)
-            except TypeError:
-                return context.memfilectx(f, data,
-                                          islink='l' in e,
-                                          isexec='x' in e,
-                                          copied=copied_path)
+            # 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
 
         p1, p2 = (nullid, nullid)
         octopus = False