Patchwork export: add -B option to select a bookmark

login
register
mail settings
Submitter David Demelier
Date May 14, 2018, 11:01 a.m.
Message ID <870851c118b003e60a57.1526295686@x1>
Download mbox | patch
Permalink /patch/31584/
State Superseded
Headers show

Comments

David Demelier - May 14, 2018, 11:01 a.m.
# HG changeset patch
# User David Demelier <markand@malikania.fr>
# Date 1526295193 -7200
#      Mon May 14 12:53:13 2018 +0200
# Node ID 870851c118b003e60a574670fc603b4780609c3b
# Parent  8ba0344f9fb145f5b9b909f1211defc9e0793f68
export: add -B option to select a bookmark

Just like `hg email -B`, `hg strip -B`, supports -B in export to select a list
of changesets reachable from a bookmark.
Yuya Nishihara - May 14, 2018, 12:16 p.m.
On Mon, 14 May 2018 13:01:26 +0200, David Demelier wrote:
> # HG changeset patch
> # User David Demelier <markand@malikania.fr>
> # Date 1526295193 -7200
> #      Mon May 14 12:53:13 2018 +0200
> # Node ID 870851c118b003e60a574670fc603b4780609c3b
> # Parent  8ba0344f9fb145f5b9b909f1211defc9e0793f68
> export: add -B option to select a bookmark

Nice.

> +    [('B', 'bookmark', '', _('send changes only reachable by given bookmark')),

Nit: s/send/export/

>      opts = pycompat.byteskwargs(opts)
> -    changesets += tuple(opts.get('rev', []))
> +    rev = opts.get('rev')
> +    bookmark = opts.get('bookmark')
> +
> +    if bookmark and rev:
> +        raise error.Abort(_("-r and -B are mutually exclusive"))
> +    if rev:
> +        changesets += tuple(opts.get('rev', []))
> +    elif bookmark:
> +        if bookmark not in repo._bookmarks:
> +            raise error.Abort(_("bookmark '%s' not found") % bookmark)
> +        changesets += tuple(repair.stripbmrevset(repo, bookmark))
> +
>      if not changesets:
>          changesets = ['.']
>      repo = scmutil.unhidehashlikerevs(repo, changesets, 'nowarn')

Here changesets is a list of revset expressions, but stripbmrevset() returns
a list of integer revisions. So this should be something like:

  if bookmark:
      revs = repair.stripbmrevset(repo, bookmark)
  else:
      if not changesets:
          ...
      revs = scmutil.revrange(...)

FWIW, stripbmrevset() will have to be moved somewhere. Maybe scmutil?
David Demelier - May 22, 2018, 7:30 a.m.
On Mon, 2018-05-14 at 21:16 +0900, Yuya Nishihara wrote:
> FWIW, stripbmrevset() will have to be moved somewhere. Maybe scmutil?

Yes when we will find an appropriate name. Anyone has idea?

Few ideas:

scmutil.brevset
scmutil.bmrevset
scmutil.bookmarkrevset

Regards,
Yuya Nishihara - May 22, 2018, noon
On Tue, 22 May 2018 09:30:39 +0200, David Demelier wrote:
> On Mon, 2018-05-14 at 21:16 +0900, Yuya Nishihara wrote:
> > FWIW, stripbmrevset() will have to be moved somewhere. Maybe scmutil?
> 
> Yes when we will find an appropriate name. Anyone has idea?
> 
> Few ideas:
> 
> scmutil.brevset
> scmutil.bmrevset
> scmutil.bookmarkrevset

My two cents. s/revset/revs/ since no input nor output is a revset query,
and we generally call an evaluated list/set of revisions as revs.

Patch

diff -r 8ba0344f9fb1 -r 870851c118b0 mercurial/commands.py
--- a/mercurial/commands.py	Fri May 11 22:07:43 2018 -0400
+++ b/mercurial/commands.py	Mon May 14 12:53:13 2018 +0200
@@ -50,6 +50,7 @@ 
     pycompat,
     rcutil,
     registrar,
+    repair,
     revsetlang,
     rewriteutil,
     scmutil,
@@ -1895,7 +1896,8 @@ 
                               root=opts.get('root'))
 
 @command('^export',
-    [('o', 'output', '',
+    [('B', 'bookmark', '', _('send changes only reachable by given bookmark')),
+    ('o', 'output', '',
      _('print output to file with formatted name'), _('FORMAT')),
     ('', 'switch-parent', None, _('diff against the second parent')),
     ('r', 'rev', [], _('revisions to export'), _('REV')),
@@ -1938,6 +1940,9 @@ 
     of files it detects as binary. With -a, export will generate a
     diff anyway, probably with undesirable results.
 
+    With -B/--bookmark changesets reachable by the given bookmark are
+    selected.
+
     Use the -g/--git option to generate diffs in the git extended diff
     format. See :hg:`help diffs` for more information.
 
@@ -1966,7 +1971,18 @@ 
     Returns 0 on success.
     """
     opts = pycompat.byteskwargs(opts)
-    changesets += tuple(opts.get('rev', []))
+    rev = opts.get('rev')
+    bookmark = opts.get('bookmark')
+
+    if bookmark and rev:
+        raise error.Abort(_("-r and -B are mutually exclusive"))
+    if rev:
+        changesets += tuple(opts.get('rev', []))
+    elif bookmark:
+        if bookmark not in repo._bookmarks:
+            raise error.Abort(_("bookmark '%s' not found") % bookmark)
+        changesets += tuple(repair.stripbmrevset(repo, bookmark))
+
     if not changesets:
         changesets = ['.']
     repo = scmutil.unhidehashlikerevs(repo, changesets, 'nowarn')
diff -r 8ba0344f9fb1 -r 870851c118b0 tests/test-export.t
--- a/tests/test-export.t	Fri May 11 22:07:43 2018 -0400
+++ b/tests/test-export.t	Mon May 14 12:53:13 2018 +0200
@@ -101,6 +101,44 @@ 
   $ grep HG foo-foo_3.patch | wc -l
   \s*1 (re)
 
+Using bookmarks:
+
+  $ hg book -f -r 9 @
+  $ hg book -f -r 11 test
+  $ hg export -B test
+  # HG changeset patch
+  # User test
+  # Date 0 0
+  #      Thu Jan 01 00:00:00 1970 +0000
+  # Node ID 5f17a83f5fbd9414006a5e563eab4c8a00729efd
+  # Parent  747d3c68f8ec44bb35816bfcd59aeb50b9654c2f
+  foo-10
+  
+  diff -r 747d3c68f8ec -r 5f17a83f5fbd foo
+  --- a/foo	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
+  @@ -8,3 +8,4 @@
+   foo-7
+   foo-8
+   foo-9
+  +foo-10
+  # HG changeset patch
+  # User test
+  # Date 0 0
+  #      Thu Jan 01 00:00:00 1970 +0000
+  # Node ID f3acbafac161ec68f1598af38f794f28847ca5d3
+  # Parent  5f17a83f5fbd9414006a5e563eab4c8a00729efd
+  foo-11
+  
+  diff -r 5f17a83f5fbd -r f3acbafac161 foo
+  --- a/foo	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
+  @@ -9,3 +9,4 @@
+   foo-8
+   foo-9
+   foo-10
+  +foo-11
+
 Exporting 4 changesets to a file:
 
   $ hg export -o export_internal 1 2 3 4