changeset 981:0b957c2d151a

util: add method for writing bookmarks
author Sean Farley <sean@farley.io>
date Fri, 08 Jan 2016 13:58:47 -0800
parents a3da45923700
children 7a767993352b
files hggit/util.py
diffstat 1 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/util.py
+++ b/hggit/util.py
@@ -9,6 +9,7 @@
 
 from dulwich import errors
 from mercurial import (
+    lock as lockmod,
     util as hgutil,
 )
 
@@ -92,3 +93,19 @@
         if re.match(fqdn_re, giturl):
             return True
     return False
+
+def recordbookmarks(repo, bms, name='git_handler'):
+    """abstract writing bookmarks for backwards compatibility"""
+    tr = lock = wlock = None
+    try:
+        wlock = repo.wlock()
+        lock = repo.lock()
+        tr = repo.transaction(name)
+        if hgutil.safehasattr(bms, 'recordchange'):
+            # recordchange was added in mercurial 3.2
+            bms.recordchange(tr)
+        else:
+            bms.write()
+        tr.close()
+    finally:
+        lockmod.release(tr, lock, wlock)