compat: add compat layer for date related functions
authorBoris Feld <boris.feld@octobus.net>
Sat, 03 Mar 2018 23:17:26 -0500
changeset 3514 498f782ccb4b
parent 3513 b1cc19e5ef24
child 3515 d5a824a5853f
compat: add compat layer for date related functions
hgext3rd/evolve/cmdrewrite.py
hgext3rd/evolve/compat.py
hgext3rd/evolve/legacy.py
--- a/hgext3rd/evolve/cmdrewrite.py	Sat Mar 03 22:25:24 2018 -0500
+++ b/hgext3rd/evolve/cmdrewrite.py	Sat Mar 03 23:17:26 2018 -0500
@@ -74,7 +74,7 @@
     """
     # N.B. this is extremely similar to setupheaderopts() in mq.py
     if not opts.get('date') and opts.get('current_date'):
-        opts['date'] = '%d %d' % util.makedate()
+        opts['date'] = '%d %d' % compat.makedate()
     if not opts.get('user') and opts.get('current_user'):
         opts['user'] = ui.username()
 
@@ -771,7 +771,7 @@
     date = opts.get('date')
     user = opts.get('user')
     if date:
-        metadata['date'] = '%i %i' % util.parsedate(date)
+        metadata['date'] = '%i %i' % compat.parsedate(date)
     if user:
         metadata['user'] = user
     return metadata
--- a/hgext3rd/evolve/compat.py	Sat Mar 03 22:25:24 2018 -0500
+++ b/hgext3rd/evolve/compat.py	Sat Mar 03 23:17:26 2018 -0500
@@ -254,3 +254,14 @@
         args.append(False)
 
     return mdiff.unidiff(*args)
+
+# date related
+
+try:
+    import mercurial.utils.dateutil
+    makedate = mercurial.utils.dateutil.makedate
+    parsedate = mercurial.utils.dateutil.parsedate
+except ImportError as e:
+    import mercurial.util
+    makedate = mercurial.util.makedate
+    parsedate = mercurial.util.parsedate
--- a/hgext3rd/evolve/legacy.py	Sat Mar 03 22:25:24 2018 -0500
+++ b/hgext3rd/evolve/legacy.py	Sat Mar 03 23:17:26 2018 -0500
@@ -30,6 +30,12 @@
 from mercurial import registrar
 from mercurial import util
 
+try:
+    from mercurial.utils.dateutil import makedate
+except ImportError as e:
+    # compat with hg < 4.6
+    from mercurial.util import makedate
+
 if util.safehasattr(registrar, 'command'):
     commandfunc = registrar.command
 else: # compat with hg < 4.3
@@ -105,7 +111,7 @@
                         prec = bin(objhex)
                         sucs = (suc == nullid) and [] or [suc]
                         meta = {
-                            'date': '%i %i' % util.makedate(),
+                            'date': '%i %i' % makedate(),
                             'user': ui.username(),
                             }
                         try: