1. mirror
  2. mercurial-crew-stable

Commits

Patrick Mézard  committed 7412904

bookmarks: fix _bookmarks/lookup() reentrancy issue (issue2016)

_bookmarks is loaded lazily and calls super.lookup(). Unfortunately, branch and
tags caches initializations also recurse in lookup() and end up trying to
access _bookmarks again. Massive confusion ensues.

I considered fixing all branches and tags cache loading to avoid recursing in
lookup() but it would add complexity to otherwise working code provided lookups
are performed on nodes or revnums.

  • Participants
  • Parent commits ca5fd84
  • Branches stable

Comments (0)

Files changed (3)

File hgext/bookmarks.py

View file
             in the .hg/bookmarks file.
             Read the file and return a (name=>nodeid) dictionary
             '''
+            self._loadingbookmarks = True
             try:
                 bookmarks = {}
                 for line in self.opener('bookmarks'):
                     bookmarks[refspec] = super(bookmark_repo, self).lookup(sha)
             except:
                 pass
+            self._loadingbookmarks = False
             return bookmarks
 
         @util.propertycache
             return super(bookmark_repo, self).rollback(*args)
 
         def lookup(self, key):
-            if key in self._bookmarks:
-                key = self._bookmarks[key]
+            if not getattr(self, '_loadingbookmarks', False):
+                if key in self._bookmarks:
+                    key = self._bookmarks[key]
             return super(bookmark_repo, self).lookup(key)
 
         def _bookmarksupdate(self, parents, node):
         def _findtags(self):
             """Merge bookmarks with normal tags"""
             (tags, tagtypes) = super(bookmark_repo, self)._findtags()
-            tags.update(self._bookmarks)
+            if not getattr(self, '_loadingbookmarks', False):
+                tags.update(self._bookmarks)
             return (tags, tagtypes)
 
         if hasattr(repo, 'invalidate'):

File tests/test-bookmarks-strip

View file
 echo % list bookmarks
 hg book
 
+echo '% test immediate rollback and reentrancy issue'
+echo "mq=!" >> $HGRCPATH
+hg init repo
+cd repo
+echo a > a
+hg ci -Am adda
+echo b > b
+hg ci -Am addb
+hg bookmarks markb
+hg rollback
+hg bookmarks
+hg bookmarks markb
+hg bookmarks
+cd ..
+

File tests/test-bookmarks-strip.out

View file
 % list bookmarks
  * test                      1:9f1b7e78eff8
  * test2                     1:9f1b7e78eff8
+% test immediate rollback and reentrancy issue
+adding a
+adding b
+rolling back to revision 0 (undo commit)
+no bookmarks set
+ * markb                     0:07f494440405