Patchwork [V2] shelve: copy bookmarks and restore them after a commit

login
register
mail settings
Submitter David Soria Parra
Date Oct. 3, 2013, 5:44 p.m.
Message ID <9b35c4b4c9af14da5ca5.1380822278@achird.localdomain>
Download mbox | patch
Permalink /patch/2729/
State Accepted
Commit 5836edcbdc2e4c5bd97a50db512191b98c2d69d8
Headers show

Comments

David Soria Parra - Oct. 3, 2013, 5:44 p.m.
# HG changeset patch
# User David Soria Parra <dsp@experimentalworks.net>
# Date 1380822085 -7200
#      Thu Oct 03 19:41:25 2013 +0200
# Node ID 9b35c4b4c9af14da5ca5c5afb171dbea51da3be1
# Parent  a69a77a80900eabe1257c935818d0910217e9702
shelve: copy bookmarks and restore them after a commit

cmdutil.commit() will advance the bookmarks. Therefore we have to restore
them afterwards. We have to use update() to ensure we preserve the bmstore
object.
Augie Fackler - Oct. 7, 2013, 9:14 p.m.
On Thu, Oct 03, 2013 at 07:44:38PM +0200, David Soria Parra wrote:
> # HG changeset patch
> # User David Soria Parra <dsp@experimentalworks.net>
> # Date 1380822085 -7200
> #      Thu Oct 03 19:41:25 2013 +0200
> # Node ID 9b35c4b4c9af14da5ca5c5afb171dbea51da3be1
> # Parent  a69a77a80900eabe1257c935818d0910217e9702
> shelve: copy bookmarks and restore them after a commit

queued, thanks

>
> cmdutil.commit() will advance the bookmarks. Therefore we have to restore
> them afterwards. We have to use update() to ensure we preserve the bmstore
> object.
>
> diff --git a/hgext/shelve.py b/hgext/shelve.py
> --- a/hgext/shelve.py
> +++ b/hgext/shelve.py
> @@ -172,11 +172,12 @@
>
>      name = opts['name']
>
> -    wlock = lock = tr = None
> +    wlock = lock = tr = bms = None
>      try:
>          wlock = repo.wlock()
>          lock = repo.lock()
>
> +        bms = repo._bookmarks.copy()
>          # use an uncommited transaction to generate the bundle to avoid
>          # pull races. ensure we don't print the abort message to stderr.
>          tr = repo.transaction('commit', report=lambda x: None)
> @@ -224,11 +225,16 @@
>                         fp=shelvedfile(repo, name, 'patch').opener('wb'),
>                         opts=mdiff.diffopts(git=True))
>
> +
>          if ui.formatted():
>              desc = util.ellipsis(desc, ui.termwidth())
>          ui.status(_('shelved as %s\n') % name)
>          hg.update(repo, parent.node())
>      finally:
> +        if bms:
> +            # restore old bookmarks
> +            repo._bookmarks.update(bms)
> +            repo._bookmarks.write()
>          if tr:
>              tr.abort()
>          lockmod.release(lock, wlock)
> diff --git a/tests/test-shelve.t b/tests/test-shelve.t
> --- a/tests/test-shelve.t
> +++ b/tests/test-shelve.t
> @@ -418,3 +418,23 @@
>    default         (*)    create conflict (glob)
>    $ hg shelve --cleanup
>    $ hg shelve --list
> +
> +test bookmarks
> +
> +  $ hg bookmark test
> +  $ hg bookmark
> +   * test                      5:01ba9745dc5a
> +  $ hg shelve
> +  shelved as test
> +  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
> +  $ hg bookmark
> +   * test                      5:01ba9745dc5a
> +  $ hg unshelve
> +  unshelving change 'test'
> +  adding changesets
> +  adding manifests
> +  adding file changes
> +  added 1 changesets with 1 changes to 7 files
> +  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
> +  $ hg bookmark
> +   * test                      5:01ba9745dc5a
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -172,11 +172,12 @@ 
 
     name = opts['name']
 
-    wlock = lock = tr = None
+    wlock = lock = tr = bms = None
     try:
         wlock = repo.wlock()
         lock = repo.lock()
 
+        bms = repo._bookmarks.copy()
         # use an uncommited transaction to generate the bundle to avoid
         # pull races. ensure we don't print the abort message to stderr.
         tr = repo.transaction('commit', report=lambda x: None)
@@ -224,11 +225,16 @@ 
                        fp=shelvedfile(repo, name, 'patch').opener('wb'),
                        opts=mdiff.diffopts(git=True))
 
+
         if ui.formatted():
             desc = util.ellipsis(desc, ui.termwidth())
         ui.status(_('shelved as %s\n') % name)
         hg.update(repo, parent.node())
     finally:
+        if bms:
+            # restore old bookmarks
+            repo._bookmarks.update(bms)
+            repo._bookmarks.write()
         if tr:
             tr.abort()
         lockmod.release(lock, wlock)
diff --git a/tests/test-shelve.t b/tests/test-shelve.t
--- a/tests/test-shelve.t
+++ b/tests/test-shelve.t
@@ -418,3 +418,23 @@ 
   default         (*)    create conflict (glob)
   $ hg shelve --cleanup
   $ hg shelve --list
+
+test bookmarks
+
+  $ hg bookmark test
+  $ hg bookmark
+   * test                      5:01ba9745dc5a
+  $ hg shelve
+  shelved as test
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg bookmark
+   * test                      5:01ba9745dc5a
+  $ hg unshelve
+  unshelving change 'test'
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 7 files
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg bookmark
+   * test                      5:01ba9745dc5a