Patchwork [4,of,4] git: implement basic bookmark activation

login
register
mail settings
Submitter Josef 'Jeff' Sipek
Date March 26, 2020, 10:07 p.m.
Message ID <5a77ab1704526629c316.1585260427@meili>
Download mbox | patch
Permalink /patch/45918/
State New
Headers show

Comments

Josef 'Jeff' Sipek - March 26, 2020, 10:07 p.m.
# HG changeset patch
# User Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
# Date 1585259370 14400
#      Thu Mar 26 17:49:30 2020 -0400
# Node ID 5a77ab1704526629c316ebd93ca355d3439eb0b7
# Parent  917cd2c4073cf69b2c366dccbfccc3b28ff4fca2
git: implement basic bookmark activation

This is very limited, but it allows 'hg update foo' when already on foo.

The caching is based on bmstore's caching.
Augie Fackler - March 27, 2020, 3:44 a.m.
On Thu, Mar 26, 2020 at 06:07:07PM -0400, Josef 'Jeff' Sipek wrote:
> # HG changeset patch
> # User Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
> # Date 1585259370 14400
> #      Thu Mar 26 17:49:30 2020 -0400
> # Node ID 5a77ab1704526629c316ebd93ca355d3439eb0b7
> # Parent  917cd2c4073cf69b2c366dccbfccc3b28ff4fca2
> git: implement basic bookmark activation

queued, thanks (will push tomorrow unless I see test failures -
libgit2 is busted on this laptop and I'm lazy)

Patch

diff --git a/hgext/git/__init__.py b/hgext/git/__init__.py
--- a/hgext/git/__init__.py
+++ b/hgext/git/__init__.py
@@ -143,6 +143,8 @@  def _setupdothg(ui, path):
 class gitbmstore(object):
     def __init__(self, gitrepo):
         self.gitrepo = gitrepo
+        self._aclean = True
+        self._active = gitrepo.references['HEAD'] # git head, not mark
 
     def __contains__(self, name):
         return (
@@ -180,7 +182,18 @@  class gitbmstore(object):
 
     @active.setter
     def active(self, mark):
-        raise NotImplementedError
+        githead = mark is not None and (_BMS_PREFIX + mark) or None
+        if githead is not None and githead not in self.gitrepo.references:
+            raise AssertionError(b'bookmark %s does not exist!' % mark)
+
+        self._active = githead
+        self._aclean = False
+
+    def _writeactive(self):
+        if self._aclean:
+            return
+        self.gitrepo.references.create('HEAD', self._active, True)
+        self._aclean = True
 
     def names(self, node):
         r = []