Patchwork [3,of,4] bookmarks: use changectx instead of remembering hex of hidden revision

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 9, 2019, 4:51 a.m.
Message ID <3e4a888ce13ae2737ef1.1573275099@mimosa>
Download mbox | patch
Permalink /patch/43018/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 9, 2019, 4:51 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1573271040 -32400
#      Sat Nov 09 12:44:00 2019 +0900
# Node ID 3e4a888ce13ae2737ef1facc3d1b00ed6f295e1a
# Parent  2562eaf1bb72faf1b2383ef651f63be39b875e4f
bookmarks: use changectx instead of remembering hex of hidden revision

It should be better to not depend on the ctx variable which was assigned
conditionally.

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -953,16 +953,13 @@  def addbookmarks(repo, tr, names, rev=No
     cur = repo[b'.'].node()
     newact = None
     changes = []
-    hiddenrev = None
 
-    tgt = cur
     # unhide revs if any
     if rev:
         repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
-        ctx = scmutil.revsingle(repo, rev)
-        if ctx.hidden():
-            hiddenrev = ctx.hex()[:12]
-        tgt = ctx.node()
+
+    ctx = scmutil.revsingle(repo, rev)
+    tgt = ctx.node()
 
     for mark in names:
         mark = checkformat(repo, mark)
@@ -979,11 +976,11 @@  def addbookmarks(repo, tr, names, rev=No
     if not changes:
         return
 
-    if hiddenrev:
-        repo.ui.warn(_(b"bookmarking hidden changeset %s\n") % hiddenrev)
+    if ctx.hidden():
+        repo.ui.warn(_(b"bookmarking hidden changeset %s\n") % ctx.hex()[:12])
 
         if ctx.obsolete():
-            msg = obsutil._getfilteredreason(repo, b"%s" % hiddenrev, ctx)
+            msg = obsutil._getfilteredreason(repo, ctx.hex()[:12], ctx)
             repo.ui.warn(b"(%s)\n" % msg)
 
     marks.applychanges(repo, tr, changes)