Commits

Steve Streeting committed b99088e

Make hgattic compatible with Mercurial 1.9 (and beyond, hopefully)

  • Participants
  • Parent commits 3ba1e5f

Comments (0)

Files changed (1)

         """initializes everything, this was copied from mq"""
         self.basepath = path
         self.path = patchdir or os.path.join(path, 'attic')
-        self.opener = util.opener(self.path)
+        try:
+            # since version 1.9 scmutil.opener is the right function
+            from mercurial import scmutil
+            self.opener = scmutil.opener(self.path)
+        except ImportError:
+            # we are at an older version, fall back
+            self.opener = util.opener(self.path)
         self.ui = ui
         self.applied = ''
         self.appliedfile = '.applied'
                 adopts['reverse'] = True
             return orig(*adargs, **adopts)
 
-        epo = extensions.wrapfunction(patch, 'externalpatch', epwrapper)
+        # Mercurial 1.9 deprecates external patching, will be removed in future
+        if getattr(patch, "externalpatch", None):
+            epo = extensions.wrapfunction(patch, 'externalpatch', epwrapper)
+        elif getattr(patch, "_externalpatch", None):
+            epo = extensions.wrapfunction(patch, '_externalpatch', epwrapper)
+        else:
+            epo = None;
         ado = extensions.wrapfunction(patch, 'applydiff', adwrapper)
         files, success = {}, True
         try:
                     self.ui.warn('patch failed, unable to continue (try -v)\n')
                 success = False
         finally:
-            patch.externalpatch = epo
+            if epo:
+                if getattr(patch, "externalpatch", None):
+                    patch.externalpatch = epo
+                else:
+                    patch._externalpatch = epo
             patch.applydiff = ado
         return success