changeset 1139:8e03a8ba04af

compat: find the right method to set active bookmark once
author Kevin Bullock <kbullock@ringworld.org>
date Wed, 07 Feb 2018 22:30:17 -0600
parents c693541ee210
children 583ac3ddd54b
files hggit/compat.py hggit/git_handler.py
diffstat 2 files changed, 9 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/compat.py	Wed Feb 07 22:18:35 2018 -0600
+++ b/hggit/compat.py	Wed Feb 07 22:30:17 2018 -0600
@@ -1,4 +1,5 @@
 from mercurial import (
+    bookmarks,
     context,
     url,
     util as hgutil,
@@ -68,6 +69,12 @@
         # compat with hg < 3.9
         return url.passwordmgr(ui)
 
+# bookmarks.setcurrent was renamed to activate in hg 3.5
+if hgutil.safehasattr(bookmarks, 'activate'):
+    activatebookmark = bookmarks.activate
+else:
+    activatebookmark = bookmarks.setcurrent
+
 
 try:
     import dulwich.client
--- a/hggit/git_handler.py	Wed Feb 07 22:18:35 2018 -0600
+++ b/hggit/git_handler.py	Wed Feb 07 22:30:17 2018 -0600
@@ -18,7 +18,6 @@
 from mercurial.i18n import _
 from mercurial.node import hex, bin, nullid
 from mercurial import (
-    bookmarks,
     commands,
     context,
     encoding,
@@ -324,11 +323,7 @@
                     bms = [rhead + suffix]
 
                 if bms:
-                    # COMPAT: hg 3.5 - bookmarks.setcurrent renamed to activate
-                    try:
-                        bookmarks.activate(self.repo, bms[0])
-                    except AttributeError:
-                        bookmarks.setcurrent(self.repo, bms[0])
+                    compat.activatebookmark(self.repo, bms[0])
 
         self.save_map(self.map_file)
 
@@ -1156,11 +1151,7 @@
                     tip = hex(tip)
                     commands.bookmark(self.ui, self.repo, 'master',
                                       rev=tip, force=True)
-                    # COMPAT: hg 3.5 - bookmarks.setcurrent renamed to activate
-                    try:
-                        bookmarks.activate(self.repo, 'master')
-                    except AttributeError:
-                        bookmarks.setcurrent(self.repo, 'master')
+                    compat.activatebookmark(self.repo, 'master')
                     new_refs['refs/heads/master'] = self.map_git_get(tip)
 
         # mapped nodes might be hidden