hide: add -B option to the hide command

Summary:
Add support for `hg hide -B bookmarkname`.  This hides all commits that are
uniquely reachable by the provided bookmarks.  This means if a bookmark is at
the head of a stack, `hg hide -B bookmark` will hide the stack.

Reviewed By: quark-zju

Differential Revision: D15562715

fbshipit-source-id: 9fdb3383b534faea982396a4f4782c03e4910dc3
This commit is contained in:
Mark Thomas 2019-06-03 08:42:57 -07:00 committed by Facebook Github Bot
parent 30549a98dd
commit 48e3c2e21f
2 changed files with 78 additions and 16 deletions

View File

@ -22,7 +22,7 @@ from edenscm.mercurial import (
scmutil,
visibility,
)
from edenscm.mercurial.i18n import _
from edenscm.mercurial.i18n import _, _n
from edenscm.mercurial.node import short
@ -38,8 +38,9 @@ command = registrar.command(cmdtable)
"c",
"cleanup",
None,
_("cleanup obsolete commits (eg. marked as landed, amended, etc.)"),
_("clean up obsolete commits (e.g. marked as landed, amended, etc.)"),
),
("B", "bookmark", [], _("hide commits only reachable from a bookmark")),
],
_("[OPTION]... [-r] REV..."),
)
@ -66,13 +67,38 @@ def hide(ui, repo, *revs, **opts):
revs = ["draft() & ::(head() & obsolete()) - ::(not obsolete())"]
else:
revs = list(revs) + opts.pop("rev", [])
revs = set(scmutil.revrange(repo, revs))
hidectxs = list(repo.set("(%ld)::", revs))
if not hidectxs:
raise error.Abort(_("nothing to hide"))
with repo.wlock(), repo.lock(), repo.transaction("hide") as tr:
revs = repo.revs("(%ld)::", scmutil.revrange(repo, revs))
bookmarks = set(opts.get("bookmark", ()))
if bookmarks:
revs += bookmarksmod.reachablerevs(repo, bookmarks)
if not revs:
# No revs are reachable exclusively from these bookmarks, just
# delete the bookmarks.
if not ui.quiet:
for bookmark in sorted(bookmarks):
ui.status(
_("removing bookmark '%s' (was at: %s)\n")
% (bookmark, short(repo._bookmarks[bookmark]))
)
bookmarksmod.delete(repo, tr, bookmarks)
ui.status(
_n(
"%i bookmark removed\n",
"%i bookmarks removed\n",
len(bookmarks),
)
% len(bookmarks)
)
return 0
if not revs:
raise error.Abort(_("nothing to hide"))
hidectxs = [repo[r] for r in revs]
# revs to be hidden
for ctx in hidectxs:
if not ctx.mutable():
@ -107,19 +133,19 @@ def hide(ui, repo, *revs, **opts):
# remove bookmarks pointing to hidden changesets
hnodes = [r.node() for r in hidectxs]
bmchanges = []
for book, node in sorted(bookmarksmod.listbinbookmarks(repo)):
deletebookmarks = set(bookmarks)
for bookmark, node in sorted(bookmarksmod.listbinbookmarks(repo)):
if node in hnodes:
bmchanges.append((book, None))
deletebookmarks.add(bookmark)
if deletebookmarks:
for bookmark in sorted(deletebookmarks):
if not ui.quiet:
ui.status(
_('removing bookmark "%s (was at: %s)"\n') % (book, short(node))
_('removing bookmark "%s (was at: %s)"\n')
% (bookmark, short(repo._bookmarks[bookmark]))
)
repo._bookmarks.applychanges(repo, tr, bmchanges)
if len(bmchanges) > 0:
ui.status(_("%i bookmarks removed\n") % len(bmchanges))
bookmarksmod.delete(repo, tr, deletebookmarks)
ui.status(_("%i bookmarks removed\n") % len(deletebookmarks))
hintutil.trigger("undo")

View File

@ -166,3 +166,39 @@ hg hide --cleanup tests
|
o 0 A
Hiding the head bookmark of a stack hides the stack.
$ hg book -r 3 somebookmark
$ hg hide -B somebookmark
hiding commit be0ef73c17ad "D"
1 changesets hidden
removing bookmark "somebookmark (was at: be0ef73c17ad)"
1 bookmarks removed
hint[undo]: you can undo this using the `hg undo` command
hint[hint-ack]: use 'hg hint --ack undo' to silence these hints
$ hg log -G -T '{rev} {desc} {bookmarks}\n'
o 7 F
|
@ 6 E2
|
o 2 C
|
o 1 B
|
o 0 A
Hiding a bookmark in the middle of a stack just deletes the bookmark.
$ hg book -r 2 stackmidbookmark
$ hg hide -B stackmidbookmark
removing bookmark 'stackmidbookmark' (was at: 26805aba1e60)
1 bookmark removed
$ hg log -G -T '{rev} {desc} {bookmarks}\n'
o 7 F
|
@ 6 E2
|
o 2 C
|
o 1 B
|
o 0 A