# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1513662635 -19800 # Node ID b378a3d840ab4f34278b4dc1f1a9c12796d70045 # Parent 8bb90cc4668e188950e6f8c7ea2a9471c814725f commands: use the new API to access hidden changesets in various commands In previous patches, we have added an internal API to unhide hidden changesets. This patch makes the following command use that api in nowarn mode i.e. there will be no warning while accessing hidden changesets. cat, diff, export, files, heads, identify, log, manifest, parents, status This patch also adds test demonstarting the behaviour. .. feature:: Accessing hidden changesets Set config option 'experimental.directaccess = True' to access hidden changesets from read only commands. Differential Revision: https://phab.mercurial-scm.org/D1735 diff -r 8bb90cc4668e -r b378a3d840ab mercurial/commands.py --- a/mercurial/commands.py Fri Dec 15 04:31:29 2017 +0530 +++ b/mercurial/commands.py Tue Dec 19 11:20:35 2017 +0530 @@ -1279,7 +1279,9 @@ Returns 0 on success. """ opts = pycompat.byteskwargs(opts) - ctx = scmutil.revsingle(repo, opts.get('rev')) + rev = opts.get('rev') + repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') + ctx = scmutil.revsingle(repo, rev) m = scmutil.match(ctx, (file1,) + pats, opts) fntemplate = opts.pop('output', '') if cmdutil.isstdiofilename(fntemplate): @@ -1840,9 +1842,11 @@ msg = _('cannot specify --rev and --change at the same time') raise error.Abort(msg) elif change: + repo = scmutil.unhidehashlikerevs(repo, [change], 'nowarn') node2 = scmutil.revsingle(repo, change, None).node() node1 = repo[node2].p1().node() else: + repo = scmutil.unhidehashlikerevs(repo, revs, 'nowarn') node1, node2 = scmutil.revpair(repo, revs) if reverse: @@ -1926,6 +1930,7 @@ 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")) @@ -1989,7 +1994,9 @@ """ opts = pycompat.byteskwargs(opts) - ctx = scmutil.revsingle(repo, opts.get('rev'), None) + rev = opts.get('rev') + repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') + ctx = scmutil.revsingle(repo, rev, None) end = '\n' if opts.get('print0'): @@ -2586,8 +2593,10 @@ opts = pycompat.byteskwargs(opts) start = None - if 'rev' in opts: - start = scmutil.revsingle(repo, opts['rev'], None).node() + rev = opts.get('rev') + if rev: + repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') + start = scmutil.revsingle(repo, rev, None).node() if opts.get('topo'): heads = [repo[h] for h in repo.heads(start)] @@ -2770,6 +2779,7 @@ fm.data(node=hex(remoterev)) fm.data(bookmarks=fm.formatlist(bms, name='bookmark')) else: + repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') ctx = scmutil.revsingle(repo, rev, None) if ctx.rev() is None: @@ -3395,6 +3405,7 @@ raise error.Abort(_('graph not supported with line range patterns')) return cmdutil.graphlog(ui, repo, pats, opts) + repo = scmutil.unhidehashlikerevs(repo, opts.get('rev'), 'nowarn') revs, expr, filematcher = cmdutil.getlogrevs(repo, pats, opts) hunksfilter = None @@ -3502,6 +3513,7 @@ char = {'l': '@', 'x': '*', '': ''} mode = {'l': '644', 'x': '755', '': '644'} + repo = scmutil.unhidehashlikerevs(repo, [node], 'nowarn') ctx = scmutil.revsingle(repo, node) mf = ctx.manifest() ui.pager('manifest') @@ -3689,7 +3701,9 @@ """ opts = pycompat.byteskwargs(opts) - ctx = scmutil.revsingle(repo, opts.get('rev'), None) + rev = opts.get('rev') + repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') + ctx = scmutil.revsingle(repo, rev, None) if file_: m = scmutil.match(ctx, (file_,), opts) @@ -4841,9 +4855,11 @@ msg = _('cannot use --terse with --rev') raise error.Abort(msg) elif change: + repo = scmutil.unhidehashlikerevs(repo, [change], 'nowarn') node2 = scmutil.revsingle(repo, change, None).node() node1 = repo[node2].p1().node() else: + repo = scmutil.unhidehashlikerevs(repo, revs, 'nowarn') node1, node2 = scmutil.revpair(repo, revs) if pats or ui.configbool('commands', 'status.relative'): diff -r 8bb90cc4668e -r b378a3d840ab tests/test-directaccess.t --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-directaccess.t Tue Dec 19 11:20:35 2017 +0530 @@ -0,0 +1,156 @@ +Tests for access level on hidden commits by various commands on based of their +type. + +Setting the required config to start this + + $ cat >> $HGRCPATH < [experimental] + > evolution=createmarkers, allowunstable + > directaccess=True + > directaccess.revnums=True + > [extensions] + > amend = + > EOF + + $ hg init repo + $ cd repo + $ for ch in a b c; do touch $ch; echo "foo" >> $ch; hg ci -Aqm "Added "$ch; done + + $ hg log -G -T '{rev}:{node} {desc}' --hidden + @ 2:28ad74487de9599d00d81085be739c61fc340652 Added c + | + o 1:29becc82797a4bc11ec8880b58eaecd2ab3e7760 Added b + | + o 0:18d04c59bb5d2d4090ad9a5b59bd6274adb63add Added a + + $ echo "bar" >> c + $ hg amend + + $ hg log -G -T '{rev}:{node} {desc}' --hidden + @ 3:2443a0e664694756d8b435d06b6ad84f941b6fc0 Added c + | + | x 2:28ad74487de9599d00d81085be739c61fc340652 Added c + |/ + o 1:29becc82797a4bc11ec8880b58eaecd2ab3e7760 Added b + | + o 0:18d04c59bb5d2d4090ad9a5b59bd6274adb63add Added a + +Testing read only commands on the hidden revision + +Testing with rev number + + $ hg exp 2 --config experimental.directaccess.revnums=False + abort: hidden revision '2'! + (use --hidden to access hidden revisions) + [255] + + $ hg exp 2 + # HG changeset patch + # User test + # Date 0 0 + # Thu Jan 01 00:00:00 1970 +0000 + # Node ID 28ad74487de9599d00d81085be739c61fc340652 + # Parent 29becc82797a4bc11ec8880b58eaecd2ab3e7760 + Added c + + diff -r 29becc82797a -r 28ad74487de9 c + --- /dev/null Thu Jan 01 00:00:00 1970 +0000 + +++ b/c Thu Jan 01 00:00:00 1970 +0000 + @@ -0,0 +1,1 @@ + +foo + + $ hg log -r 2 + changeset: 2:28ad74487de9 + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + obsolete: rewritten using amend as 3:2443a0e66469 + summary: Added c + + $ hg identify -r 2 + 28ad74487de9 + + $ hg status --change 2 + A c + + $ hg status --change 2 --config experimental.directaccess.revnums=False + abort: hidden revision '2'! + (use --hidden to access hidden revisions) + [255] + + $ hg diff -c 2 + diff -r 29becc82797a -r 28ad74487de9 c + --- /dev/null Thu Jan 01 00:00:00 1970 +0000 + +++ b/c Thu Jan 01 00:00:00 1970 +0000 + @@ -0,0 +1,1 @@ + +foo + +Testing with hash + +`hg export` + + $ hg exp 28ad74 + # HG changeset patch + # User test + # Date 0 0 + # Thu Jan 01 00:00:00 1970 +0000 + # Node ID 28ad74487de9599d00d81085be739c61fc340652 + # Parent 29becc82797a4bc11ec8880b58eaecd2ab3e7760 + Added c + + diff -r 29becc82797a -r 28ad74487de9 c + --- /dev/null Thu Jan 01 00:00:00 1970 +0000 + +++ b/c Thu Jan 01 00:00:00 1970 +0000 + @@ -0,0 +1,1 @@ + +foo + +`hg log` + + $ hg log -r 28ad74 + changeset: 2:28ad74487de9 + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + obsolete: rewritten using amend as 3:2443a0e66469 + summary: Added c + +`hg cat` + + $ hg cat -r 28ad74 c + foo + +`hg diff` + + $ hg diff -c 28ad74 + diff -r 29becc82797a -r 28ad74487de9 c + --- /dev/null Thu Jan 01 00:00:00 1970 +0000 + +++ b/c Thu Jan 01 00:00:00 1970 +0000 + @@ -0,0 +1,1 @@ + +foo + +`hg files` + + $ hg files -r 28ad74 + a + b + c + +`hg identify` + + $ hg identify -r 28ad74 + 28ad74487de9 + +`hg status` + + $ hg status --change 28ad74 + A c + +Commands with undefined cmdtype should not work right now + + $ hg phase -r 28ad74 + abort: hidden revision '28ad74'! + (use --hidden to access hidden revisions) + [255] + + $ hg phase -r 2 + abort: hidden revision '2'! + (use --hidden to access hidden revisions) + [255]