[PATCH v2] export: add -B option to select a bookmark

David Demelier markand at malikania.fr
Tue May 15 07:32:30 EDT 2018


# HG changeset patch
# User David Demelier <markand at malikania.fr>
# Date 1526295193 -7200
#      Mon May 14 12:53:13 2018 +0200
# Node ID c3d248600824a3478b1c3aede2fe78916f9d7de5
# 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.

diff -r 8ba0344f9fb1 -r c3d248600824 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,9 @@
                               root=opts.get('root'))
 
 @command('^export',
-    [('o', 'output', '',
+    [('B', 'bookmark', '',
+     _('export 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 +1941,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,11 +1972,26 @@
     Returns 0 on success.
     """
     opts = pycompat.byteskwargs(opts)
-    changesets += tuple(opts.get('rev', []))
-    if not changesets:
-        changesets = ['.']
-    repo = scmutil.unhidehashlikerevs(repo, changesets, 'nowarn')
-    revs = scmutil.revrange(repo, changesets)
+    rev = opts.get('rev')
+    bookmark = opts.get('bookmark')
+
+    if bookmark and rev:
+        raise error.Abort(_("-r and -B are mutually exclusive"))
+
+    if bookmark:
+        if bookmark not in repo._bookmarks:
+            raise error.Abort(_("bookmark '%s' not found") % bookmark)
+
+        revs = repair.stripbmrevset(repo, bookmark)
+    else:
+        changesets += tuple(opts.get('rev', []))
+
+        if not changesets:
+            changesets = ['.']
+
+        repo = scmutil.unhidehashlikerevs(repo, changesets, 'nowarn')
+        revs = scmutil.revrange(repo, changesets)
+
     if not revs:
         raise error.Abort(_("export requires at least one changeset"))
     if len(revs) > 1:
diff -r 8ba0344f9fb1 -r c3d248600824 tests/test-completion.t
--- a/tests/test-completion.t	Fri May 11 22:07:43 2018 -0400
+++ b/tests/test-completion.t	Mon May 14 12:53:13 2018 +0200
@@ -231,7 +231,7 @@
   clone: noupdate, updaterev, rev, branch, pull, uncompressed, stream, ssh, remotecmd, insecure
   commit: addremove, close-branch, amend, secret, edit, interactive, include, exclude, message, logfile, date, user, subrepos
   diff: rev, change, text, git, binary, nodates, noprefix, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, ignore-space-at-eol, unified, stat, root, include, exclude, subrepos
-  export: output, switch-parent, rev, text, git, binary, nodates, template
+  export: bookmark, output, switch-parent, rev, text, git, binary, nodates, template
   forget: interactive, include, exclude, dry-run
   init: ssh, remotecmd, insecure
   log: follow, follow-first, date, copies, keyword, rev, line-range, removed, only-merges, user, only-branch, branch, prune, patch, git, limit, no-merges, stat, graph, style, template, include, exclude
diff -r 8ba0344f9fb1 -r c3d248600824 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


More information about the Mercurial-devel mailing list