Patchwork [STABLE] share: wrap bmstore._writerepo for transaction sensitivity (issue4940)

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Nov. 12, 2015, 5:39 p.m.
Message ID <b9f3b6dcb38fed138a60.1447349979@juju>
Download mbox | patch
Permalink /patch/11375/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - Nov. 12, 2015, 5:39 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1447349790 -32400
#      Fri Nov 13 02:36:30 2015 +0900
# Branch stable
# Node ID b9f3b6dcb38fed138a6038c6c79792152a7b27fa
# Parent  a45821a808ab3588d5d6f34418749e04dca938fb
share: wrap bmstore._writerepo for transaction sensitivity (issue4940)

46dec89fe888 made 'bmstore.write()' transaction sensitive, to restore
original bookmarks correctly at failure of a transaction.

For example, shelve and unshelve imply steps below:

  before 46dec89fe888:
    1. move active bookmark forward at internal rebasing
    2. 'bmstore.write()' writes updated ones into .hg/bookmarks
    3. rollback transaction to remove internal commits
    4. restore updated bookmarks manually

  after 46dec89fe888:
    1. move active bookmark forward at internal rebasing
    2. 'bmstore.write()' doesn't write updated ones into .hg/bookmarks
       (these are written into .hg/bookmarks.pending, if external hook
       is spawn)
    3. rollback transaction to remove internal commits
    4. .hg/bookmarks should be clean, because it isn't changed while
       transaction running: see (2) above

But if shelve or unshelve is executed in the repository created with
"shared bookmarks" ("hg share -B"), this doesn't work as expected,
because:

  - share extension makes 'bmstore.write()' write updated bookmarks
    into .hg/bookmarks of shared source repository regardless of
    transaction activity, and

  - intentional transaction failure at the end of shelve/unshelve
    doesn't restore already updated .hg/bookmarks of shared source

This patch makes share extension wrap 'bmstore._writerepo()' instead
of 'bmstore.write()', because the former is used to actually write
bookmark changes out.
Matt Mackall - Nov. 12, 2015, 8:21 p.m.
On Fri, 2015-11-13 at 02:39 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1447349790 -32400
> #      Fri Nov 13 02:36:30 2015 +0900
> # Branch stable
> # Node ID b9f3b6dcb38fed138a6038c6c79792152a7b27fa
> # Parent  a45821a808ab3588d5d6f34418749e04dca938fb
> share: wrap bmstore._writerepo for transaction sensitivity
> (issue4940)

Thanks, queued for stable.

-- 
Mathematics is the supreme nostalgia of our time.

Patch

diff --git a/hgext/share.py b/hgext/share.py
--- a/hgext/share.py
+++ b/hgext/share.py
@@ -123,7 +123,7 @@  def clone(orig, ui, source, *args, **opt
 def extsetup(ui):
     extensions.wrapfunction(bookmarks.bmstore, 'getbkfile', getbkfile)
     extensions.wrapfunction(bookmarks.bmstore, 'recordchange', recordchange)
-    extensions.wrapfunction(bookmarks.bmstore, 'write', write)
+    extensions.wrapfunction(bookmarks.bmstore, '_writerepo', writerepo)
     extensions.wrapcommand(commands.table, 'clone', clone)
 
 def _hassharedbookmarks(repo):
@@ -166,10 +166,11 @@  def recordchange(orig, self, tr):
             category = 'share-bookmarks'
             tr.addpostclose(category, lambda tr: self._writerepo(srcrepo))
 
-def write(orig, self):
+def writerepo(orig, self, repo):
     # First write local bookmarks file in case we ever unshare
-    orig(self)
+    orig(self, repo)
+
     if _hassharedbookmarks(self._repo):
         srcrepo = _getsrcrepo(self._repo)
         if srcrepo is not None:
-            self._writerepo(srcrepo)
+            orig(self, srcrepo)
diff --git a/tests/test-shelve.t b/tests/test-shelve.t
--- a/tests/test-shelve.t
+++ b/tests/test-shelve.t
@@ -1174,3 +1174,42 @@  Try again but with a corrupted shelve st
   rebase aborted
   $ hg up -C .
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ cd ..
+
+Keep active bookmark while (un)shelving even on shared repo (issue4940)
+-----------------------------------------------------------------------
+
+  $ cat <<EOF >> $HGRCPATH
+  > [extensions]
+  > share =
+  > EOF
+
+  $ hg bookmarks -R repo
+     test                      4:33f7f61e6c5e
+  $ hg share -B repo share
+  updating working directory
+  6 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd share
+
+  $ hg bookmarks
+     test                      4:33f7f61e6c5e
+  $ hg bookmarks foo
+  $ hg bookmarks
+   * foo                       5:703117a2acfb
+     test                      4:33f7f61e6c5e
+  $ echo x >> x
+  $ hg shelve
+  shelved as foo
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg bookmarks
+   * foo                       5:703117a2acfb
+     test                      4:33f7f61e6c5e
+
+  $ hg unshelve
+  unshelving change 'foo'
+  $ hg bookmarks
+   * foo                       5:703117a2acfb
+     test                      4:33f7f61e6c5e
+
+  $ cd ..