Commits

Alain Leufroy committed 9799d0a

[obsolete] add supprt for futur Hg 2.2

  • Participants
  • Parent commits 83b7e2c
  • Branches default

Comments (0)

Files changed (1)

File hgext/obsolete.py

     opull = repo.pull
     opush = repo.push
     o_rollback = repo._rollback
-    o_writejournal = repo._writejournal
     ocancopy = repo.cancopy
 
+    # /!\ api change in  Hg 2.2 (97efd26eb9576f39590812ea9) /!\
+    if util.safehasattr(repo, '_journalfiles'): # Hg 2.2
+        o_journalfiles = repo._journalfiles
+    else:  # XXX remove this bloc while breaking support to Hg 2.1
+        o_writejournal = repo._writejournal
+
+
     class obsoletingrepo(repo.__class__):
 
         ### Public method
             obs = set()
             nm = self.changelog.nodemap
             for obj in self._obsobjrels:
-                rev = nm.get(obj, None)
+                try: # /!\api change in Hg 2.2 (e8d37b78acfb22ae2c1fb126c2)/!\
+                    rev = nm.get(obj)
+                except TypeError:  #XXX to remove while breaking Hg 2.1 support
+                    rev = nm.get(obj, None)
                 if rev is not None:
                     obs.add(rev)
             return obs
             return result
 
 
-
         ### rollback support
 
-        def _writejournal(self, desc):
-            """wrapped version of _writejournal that save obsolete data"""
-            entries = list(o_writejournal(desc))
-            filename = 'obsolete-relations'
-            filepath = self.join(filename)
-            if  os.path.exists(filepath):
-                journalname = 'journal.' + filename
-                journalpath = self.join(journalname)
-                util.copyfile(filepath, journalpath)
-                entries.append(journalpath)
-            return tuple(entries)
+        # /!\ api change in  Hg 2.2 (97efd26eb9576f39590812ea9) /!\
+        if util.safehasattr(repo, '_journalfiles'): # Hg 2.2
+            def _journalfiles(self):
+                return o_journalfiles() + ('journal.obsolete-relations',) 
+        else: # XXX remove this bloc while breaking support to Hg 2.1
+             def _writejournal(self, desc):
+                """wrapped version of _writejournal that save obsolete data"""
+                entries = list(o_writejournal(desc))
+                filename = 'obsolete-relations'
+                filepath = self.join(filename)
+                if  os.path.exists(filepath):
+                    journalname = 'journal.' + filename
+                    journalpath = self.join(journalname)
+                    util.copyfile(filepath, journalpath)
+                    entries.append(journalpath)
+                return tuple(entries)
 
         def _rollback(self, dryrun=False, **kwargs):
             """wrapped version of _rollback that restore obsolete data"""