changeset 6879:5f1af779bddf

hg: prepare for Mercurial 4.2 or later where tagging moved from localrepo to the tags module
author Mads Kiilerich <mads@kiilerich.com>
date Thu, 14 Sep 2017 02:08:06 +0200
parents 1ba4fee6b27c
children 86bd75e0347c
files kallithea/lib/vcs/backends/hg/repository.py kallithea/lib/vcs/utils/hgcompat.py
diffstat 2 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/vcs/backends/hg/repository.py	Thu Sep 14 02:08:06 2017 +0200
+++ b/kallithea/lib/vcs/backends/hg/repository.py	Thu Sep 14 02:08:06 2017 +0200
@@ -31,7 +31,7 @@
 from kallithea.lib.vcs.utils.hgcompat import (
     ui, nullid, match, patch, diffopts, clone, get_contact,
     localrepository, RepoLookupError, Abort, RepoError, hex, scmutil, hg_url,
-    httpbasicauthhandler, httpdigestauthhandler, peer, httppeer, sshpeer
+    httpbasicauthhandler, httpdigestauthhandler, peer, httppeer, sshpeer, tag
 )
 
 from .changeset import MercurialChangeset
@@ -175,8 +175,7 @@
             date = datetime.datetime.now().strftime('%a, %d %b %Y %H:%M:%S')
 
         try:
-            self._repo.tag(name, changeset._ctx.node(), message, local, user,
-                date)
+            tag(self._repo, name, changeset._ctx.node(), message, local, user, date)
         except Abort as e:
             raise RepositoryError(e.message)
 
@@ -206,7 +205,7 @@
         local = False
 
         try:
-            self._repo.tag(name, nullid, message, local, user, date)
+            tag(self._repo, name, nullid, message, local, user, date)
             self.tags = self._get_tags()
         except Abort as e:
             raise RepositoryError(e.message)
--- a/kallithea/lib/vcs/utils/hgcompat.py	Thu Sep 14 02:08:06 2017 +0200
+++ b/kallithea/lib/vcs/utils/hgcompat.py	Thu Sep 14 02:08:06 2017 +0200
@@ -12,6 +12,7 @@
 from mercurial import unionrepo
 from mercurial import scmutil
 from mercurial import config
+from mercurial import tags as tagsmod
 from mercurial.commands import clone, nullid, pull
 from mercurial.context import memctx, memfilectx
 from mercurial.error import RepoError, RepoLookupError, Abort
@@ -47,3 +48,11 @@
 localrepository._lfstatuswriters = [lambda *msg, **opts: None]
 # 3.5 7699d3212994 added the invariant that repo.lfstatus must exist before hitting overridearchive
 localrepository.lfstatus = False
+
+# Mercurial 4.2 moved tag from localrepo to the tags module
+def tag(repo, *args):
+    try:
+        tag_f  = tagsmod.tag
+    except AttributeError:
+        return repo.tag(*args)
+    tag_f(repo, *args)