Patchwork bookmark: add an --active flag to display the active bookmark

login
register
mail settings
Submitter Boris Feld
Date Aug. 17, 2018, 4:25 p.m.
Message ID <743d3dfd61a275c393a1.1534523123@FB-lair>
Download mbox | patch
Permalink /patch/33816/
State Accepted
Headers show

Comments

Boris Feld - Aug. 17, 2018, 4:25 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1534432767 -7200
#      Thu Aug 16 17:19:27 2018 +0200
# Node ID 743d3dfd61a275c393a19121de3cc24e70555c5c
# Parent  46da52f4b820f2668b120fcf93f09fb730065da6
# EXP-Topic active-bookmark
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 743d3dfd61a2
bookmark: add an --active flag to display the active bookmark

There is currently no official simple way to retrieve the current bookmark. In
particular for automation.

We add a `--active` flag to the `hg bookmarks` command. When set, the command
display the current bookmark name if any or return 1.

For now, this flag is read-only. However sensible combinations exist with
`--delete`, `--rename` and `--rev` and can be implemented later.
Augie Fackler - Aug. 20, 2018, 6:55 p.m.
(+TheMystic)

On Fri, Aug 17, 2018 at 06:25:23PM +0200, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1534432767 -7200
> #      Thu Aug 16 17:19:27 2018 +0200
> # Node ID 743d3dfd61a275c393a19121de3cc24e70555c5c
> # Parent  46da52f4b820f2668b120fcf93f09fb730065da6
> # EXP-Topic active-bookmark
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 743d3dfd61a2
> bookmark: add an --active flag to display the active bookmark

I'm +0 on this, I guess. Kevin?
Yuya Nishihara - Aug. 25, 2018, 9:12 a.m.
On Fri, 17 Aug 2018 18:25:23 +0200, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1534432767 -7200
> #      Thu Aug 16 17:19:27 2018 +0200
> # Node ID 743d3dfd61a275c393a19121de3cc24e70555c5c
> # Parent  46da52f4b820f2668b120fcf93f09fb730065da6
> # EXP-Topic active-bookmark
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 743d3dfd61a2
> bookmark: add an --active flag to display the active bookmark

Queued, thanks.

> We add a `--active` flag to the `hg bookmarks` command. When set, the command
> display the current bookmark name if any or return 1.

> For now, this flag is read-only. However sensible combinations exist with
> `--delete`, `--rename` and `--rev` and can be implemented later.

Do you mean --active == --no-inactive?

> +    if delete and active:
> +        raise error.Abort(_("--delete is incompatible with --active"))
> +    if rev and active:
> +        raise error.Abort(_("--rev is incompatible with --active"))
> +    if rename and active:
> +        raise error.Abort(_("--rename is incompatible with --active"))
> +    if names and active:
> +        raise error.Abort(_("NAMES is incompatible with --active"))
> +    if inactive and active:
> +        raise error.Abort(_("--delete is incompatible with --active"))

s/--delete/--inactive/

> +    elif active:
> +        book = repo._activebookmark
> +        if book is None:
> +            return 1
> +        ui.write("%s\n" % book, label=bookmarks.activebookmarklabel)

Can you update this to support -T ?
Boris Feld - Aug. 27, 2018, 9:20 a.m.
On 25/08/2018 11:12, Yuya Nishihara wrote:
> On Fri, 17 Aug 2018 18:25:23 +0200, Boris Feld wrote:
>> # HG changeset patch
>> # User Boris Feld <boris.feld@octobus.net>
>> # Date 1534432767 -7200
>> #      Thu Aug 16 17:19:27 2018 +0200
>> # Node ID 743d3dfd61a275c393a19121de3cc24e70555c5c
>> # Parent  46da52f4b820f2668b120fcf93f09fb730065da6
>> # EXP-Topic active-bookmark
>> # Available At https://bitbucket.org/octobus/mercurial-devel/
>> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 743d3dfd61a2
>> bookmark: add an --active flag to display the active bookmark
> Queued, thanks.
>
>> We add a `--active` flag to the `hg bookmarks` command. When set, the command
>> display the current bookmark name if any or return 1.
>> For now, this flag is read-only. However sensible combinations exist with
>> `--delete`, `--rename` and `--rev` and can be implemented later.
> Do you mean --active == --no-inactive?

I mean:

  `hg bookmarks --active --delete`: delete the active bookmark

  `hg bookmarks --active --rev 42`: move active bookmark to revision 42

  `hg bookmarks --active --rename foo`: rename the active bookmark
>
>> +    if delete and active:
>> +        raise error.Abort(_("--delete is incompatible with --active"))
>> +    if rev and active:
>> +        raise error.Abort(_("--rev is incompatible with --active"))
>> +    if rename and active:
>> +        raise error.Abort(_("--rename is incompatible with --active"))
>> +    if names and active:
>> +        raise error.Abort(_("NAMES is incompatible with --active"))
>> +    if inactive and active:
>> +        raise error.Abort(_("--delete is incompatible with --active"))
> s/--delete/--inactive/
Good catch, thank you for the fix
>
>> +    elif active:
>> +        book = repo._activebookmark
>> +        if book is None:
>> +            return 1
>> +        ui.write("%s\n" % book, label=bookmarks.activebookmarklabel)
> Can you update this to support -T ?
I'm not sure of how to do that. Can you point me toward an example?
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Yuya Nishihara - Aug. 27, 2018, 12:29 p.m.
On Mon, 27 Aug 2018 11:20:39 +0200, Boris FELD wrote:
> 
> On 25/08/2018 11:12, Yuya Nishihara wrote:
> > On Fri, 17 Aug 2018 18:25:23 +0200, Boris Feld wrote:
> >> # HG changeset patch
> >> # User Boris Feld <boris.feld@octobus.net>
> >> # Date 1534432767 -7200
> >> #      Thu Aug 16 17:19:27 2018 +0200
> >> # Node ID 743d3dfd61a275c393a19121de3cc24e70555c5c
> >> # Parent  46da52f4b820f2668b120fcf93f09fb730065da6
> >> # EXP-Topic active-bookmark
> >> # Available At https://bitbucket.org/octobus/mercurial-devel/
> >> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 743d3dfd61a2
> >> bookmark: add an --active flag to display the active bookmark
> > Queued, thanks.
> >
> >> We add a `--active` flag to the `hg bookmarks` command. When set, the command
> >> display the current bookmark name if any or return 1.
> >> For now, this flag is read-only. However sensible combinations exist with
> >> `--delete`, `--rename` and `--rev` and can be implemented later.
> > Do you mean --active == --no-inactive?
> 
> I mean:
> 
>   `hg bookmarks --active --delete`: delete the active bookmark

Why not use "--delete ." ?

>   `hg bookmarks --active --rev 42`: move active bookmark to revision 42

I think it can be read as "bookmark revision 42 as <something> and activate
it."

>   `hg bookmarks --active --rename foo`: rename the active bookmark

This seems weird since the syntax is --rename=OLD. IIRC, that's one reason
why we've added "--rename . foo".

> >> +    elif active:
> >> +        book = repo._activebookmark
> >> +        if book is None:
> >> +            return 1
> >> +        ui.write("%s\n" % book, label=bookmarks.activebookmarklabel)
> > Can you update this to support -T ?
> I'm not sure of how to do that. Can you point me toward an example?

See bookmarks._printbookmark().

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -901,6 +901,7 @@  def bisect(ui, repo, rev=None, extra=Non
     ('d', 'delete', False, _('delete a given bookmark')),
     ('m', 'rename', '', _('rename a given bookmark'), _('OLD')),
     ('i', 'inactive', False, _('mark a bookmark inactive')),
+    ('', 'active', False, _('display the active bookmark')),
     ] + formatteropts,
     _('hg bookmarks [OPTIONS]... [NAME]...'))
 def bookmark(ui, repo, *names, **opts):
@@ -927,6 +928,10 @@  def bookmark(ui, repo, *names, **opts):
     A bookmark named '@' has the special property that :hg:`clone` will
     check it out by default if it exists.
 
+    The '--active' flag will display the current bookmark or return non-zero,
+    if combined with other action, they will be performed on the active
+    bookmark.
+
     .. container:: verbose
 
       Examples:
@@ -956,6 +961,7 @@  def bookmark(ui, repo, *names, **opts):
     delete = opts.get(r'delete')
     rename = opts.get(r'rename')
     inactive = opts.get(r'inactive')
+    active = opts.get(r'active')
 
     if delete and rename:
         raise error.Abort(_("--delete and --rename are incompatible"))
@@ -963,6 +969,16 @@  def bookmark(ui, repo, *names, **opts):
         raise error.Abort(_("--rev is incompatible with --delete"))
     if rename and rev:
         raise error.Abort(_("--rev is incompatible with --rename"))
+    if delete and active:
+        raise error.Abort(_("--delete is incompatible with --active"))
+    if rev and active:
+        raise error.Abort(_("--rev is incompatible with --active"))
+    if rename and active:
+        raise error.Abort(_("--rename is incompatible with --active"))
+    if names and active:
+        raise error.Abort(_("NAMES is incompatible with --active"))
+    if inactive and active:
+        raise error.Abort(_("--delete is incompatible with --active"))
     if not names and (delete or rev):
         raise error.Abort(_("bookmark name required"))
 
@@ -987,6 +1003,11 @@  def bookmark(ui, repo, *names, **opts):
                     ui.status(_("no active bookmark\n"))
                 else:
                     bookmarks.deactivate(repo)
+    elif active:
+        book = repo._activebookmark
+        if book is None:
+            return 1
+        ui.write("%s\n" % book, label=bookmarks.activebookmarklabel)
     else: # show bookmarks
         bookmarks.printbookmarks(ui, repo, **opts)
 
diff --git a/tests/test-bookmarks-current.t b/tests/test-bookmarks-current.t
--- a/tests/test-bookmarks-current.t
+++ b/tests/test-bookmarks-current.t
@@ -222,3 +222,26 @@  test that updating to closed branch head
      Z                         0:719295282060
   $ hg parents -q
   4:8fa964221e8e
+
+Checks command to retrieve active bookmark
+------------------------------------------
+
+display how "{activebookmark}" template is unsuitable for the task
+
+  $ hg book -T '- {activebookmark}\n'
+  - 
+  - Y
+  - 
+
+  $ hg book -r . W
+  $ hg book -T '- {activebookmark}\n'
+  - Y
+  - 
+  - Y
+  - 
+
+  $ hg bookmarks --active
+  Y
+  $ hg bookmarks --inactive
+  $ hg bookmarks --active
+  [1]
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -249,7 +249,7 @@  Show all commands + options
   archive: no-decode, prefix, rev, type, subrepos, include, exclude
   backout: merge, commit, no-commit, parent, rev, edit, tool, include, exclude, message, logfile, date, user
   bisect: reset, good, bad, skip, extend, command, noupdate
-  bookmarks: force, rev, delete, rename, inactive, template
+  bookmarks: force, rev, delete, rename, inactive, active, template
   branch: force, clean, rev
   branches: active, closed, template
   bundle: force, rev, branch, base, all, type, ssh, remotecmd, insecure