Patchwork [3,of,3,evolve-ext-V2] inhibit: Add -D option to the bookmark command

login
register
mail settings
Submitter Laurent Charignon
Date April 4, 2015, 12:26 a.m.
Message ID <b8af092c9ef9c1f89191.1428107189@lcharignon-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/8495/
State Accepted
Headers show

Comments

Laurent Charignon - April 4, 2015, 12:26 a.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1427836666 25200
#      Tue Mar 31 14:17:46 2015 -0700
# Node ID b8af092c9ef9c1f89191f38dd0fa3723ab90e557
# Parent  8065190d4c129e5be0ebc062d1305efdae0d8ecb
inhibit: Add -D option to the bookmark command

The -D option for bookmark is similar to the -B option for strip.
It deletes the bookmark and prunes the changes underneath it that are
not reachable.
Pierre-Yves David - April 4, 2015, 12:31 a.m.
On 04/03/2015 05:26 PM, Laurent Charignon wrote:
> # HG changeset patch
> # User Laurent Charignon <lcharignon@fb.com>
> # Date 1427836666 25200
> #      Tue Mar 31 14:17:46 2015 -0700
> # Node ID b8af092c9ef9c1f89191f38dd0fa3723ab90e557
> # Parent  8065190d4c129e5be0ebc062d1305efdae0d8ecb
> inhibit: Add -D option to the bookmark command
>
> The -D option for bookmark is similar to the -B option for strip.
> It deletes the bookmark and prunes the changes underneath it that are
> not reachable.

Pushed to evolve main, thanks

>
> diff --git a/hgext/inhibit.py b/hgext/inhibit.py
> --- a/hgext/inhibit.py
> +++ b/hgext/inhibit.py
> @@ -30,6 +30,7 @@
>   from mercurial import error
>   from mercurial import commands
>   from mercurial import bookmarks
> +from mercurial.i18n import _
>
>   cmdtable = {}
>   command = cmdutil.command(cmdtable)
> @@ -73,6 +74,29 @@
>       _inhibitmarkers(repo, bkmstorenodes)
>       return orig(bkmstoreinst, *args, **kwargs)
>
> +def _bookmark(orig, ui, repo, *bookmarks, **opts):
> +    """ Add a -D option to the bookmark command, map it to prune -B """
> +    def getdefaultopts(module, command):
> +        """ Get default options of a command from a module """
> +        cmds = [v for k,v in module.cmdtable.items() if command in k]
> +        assert len(cmds) == 1, "Ambiguous command"
> +        # Options of the first command that matched
> +        cmdopts = cmds[0][1]
> +        optsdict = {}
> +        for d in cmdopts:
> +            optsdict[d[1]] = d[2]
> +        return optsdict
> +
> +    haspruneopt = opts.get('prune', False)
> +
> +    if not haspruneopt:
> +        return orig(ui, repo, *bookmarks, **opts)
> +    # Call prune -B
> +    evolve = extensions.find('evolve')
> +    optsdict = getdefaultopts(evolve, 'prune|obsolete')
> +    optsdict['bookmark'] = bookmarks[0]
> +    evolve.cmdprune(ui, repo, **optsdict)
> +
>   # obsolescence inhibitor
>   ########################
>
> @@ -182,6 +206,11 @@
>       # wrap both to add inhibition markers.
>       extensions.wrapfunction(bookmarks.bmstore, 'recordchange', _bookmarkchanged)
>       extensions.wrapfunction(bookmarks.bmstore, 'write', _bookmarkchanged)
> +    # Add bookmark -D option
> +    entry = extensions.wrapcommand(commands.table, 'bookmark', _bookmark)
> +    entry[1].append(('D','prune',None,
> +                    _('delete the bookmark and prune the commits underneath')))
> +
>
>
>   def gethashsymbols(tree):
> diff --git a/tests/test-inhibit.t b/tests/test-inhibit.t
> --- a/tests/test-inhibit.t
> +++ b/tests/test-inhibit.t
> @@ -261,9 +261,32 @@
>     |/
>     o  0:54ccbc537fc2 add cA
>
> -  $ hg bookmark -d book1
> -  $ hg prune --hidden 1::
> -  3 changesets pruned
> +
> +Removing a bookmark with bookmark -D should prune the changes underneath
> +that are not reachable from another bookmark or head
> +
> +  $ hg bookmark -r 1 book2
> +  $ hg bookmark -D book1
> +  bookmark 'book1' deleted
> +  1 changesets pruned
> +  $ hg log -G
> +  @  9:55c73a90e4b4 add cJ
> +  |
> +  | o  7:18214586bf78 add cJ
> +  |/
> +  o  6:cf5c4f4554ce add cH
> +  |
> +  o  5:5419eb264a33 add cG
> +  |
> +  o  4:98065434e5c6 add cE
> +  |
> +  | o  1:02bcbc3f6e56 add cB
> +  |/
> +  o  0:54ccbc537fc2 add cA
> +
> +  $ hg bookmark -D book2
> +  bookmark 'book2' deleted
> +  1 changesets pruned
>     $ hg log -G
>     @  9:55c73a90e4b4 add cJ
>     |
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/hgext/inhibit.py b/hgext/inhibit.py
--- a/hgext/inhibit.py
+++ b/hgext/inhibit.py
@@ -30,6 +30,7 @@ 
 from mercurial import error
 from mercurial import commands
 from mercurial import bookmarks
+from mercurial.i18n import _
 
 cmdtable = {}
 command = cmdutil.command(cmdtable)
@@ -73,6 +74,29 @@ 
     _inhibitmarkers(repo, bkmstorenodes)
     return orig(bkmstoreinst, *args, **kwargs)
 
+def _bookmark(orig, ui, repo, *bookmarks, **opts):
+    """ Add a -D option to the bookmark command, map it to prune -B """
+    def getdefaultopts(module, command):
+        """ Get default options of a command from a module """
+        cmds = [v for k,v in module.cmdtable.items() if command in k]
+        assert len(cmds) == 1, "Ambiguous command"
+        # Options of the first command that matched
+        cmdopts = cmds[0][1]
+        optsdict = {}
+        for d in cmdopts:
+            optsdict[d[1]] = d[2]
+        return optsdict
+
+    haspruneopt = opts.get('prune', False)
+
+    if not haspruneopt:
+        return orig(ui, repo, *bookmarks, **opts)
+    # Call prune -B
+    evolve = extensions.find('evolve')
+    optsdict = getdefaultopts(evolve, 'prune|obsolete')
+    optsdict['bookmark'] = bookmarks[0]
+    evolve.cmdprune(ui, repo, **optsdict)
+
 # obsolescence inhibitor
 ########################
 
@@ -182,6 +206,11 @@ 
     # wrap both to add inhibition markers.
     extensions.wrapfunction(bookmarks.bmstore, 'recordchange', _bookmarkchanged)
     extensions.wrapfunction(bookmarks.bmstore, 'write', _bookmarkchanged)
+    # Add bookmark -D option
+    entry = extensions.wrapcommand(commands.table, 'bookmark', _bookmark)
+    entry[1].append(('D','prune',None,
+                    _('delete the bookmark and prune the commits underneath')))
+
 
 
 def gethashsymbols(tree):
diff --git a/tests/test-inhibit.t b/tests/test-inhibit.t
--- a/tests/test-inhibit.t
+++ b/tests/test-inhibit.t
@@ -261,9 +261,32 @@ 
   |/
   o  0:54ccbc537fc2 add cA
   
-  $ hg bookmark -d book1
-  $ hg prune --hidden 1::
-  3 changesets pruned
+
+Removing a bookmark with bookmark -D should prune the changes underneath
+that are not reachable from another bookmark or head
+
+  $ hg bookmark -r 1 book2
+  $ hg bookmark -D book1
+  bookmark 'book1' deleted
+  1 changesets pruned
+  $ hg log -G
+  @  9:55c73a90e4b4 add cJ
+  |
+  | o  7:18214586bf78 add cJ
+  |/
+  o  6:cf5c4f4554ce add cH
+  |
+  o  5:5419eb264a33 add cG
+  |
+  o  4:98065434e5c6 add cE
+  |
+  | o  1:02bcbc3f6e56 add cB
+  |/
+  o  0:54ccbc537fc2 add cA
+  
+  $ hg bookmark -D book2
+  bookmark 'book2' deleted
+  1 changesets pruned
   $ hg log -G
   @  9:55c73a90e4b4 add cJ
   |