Patchwork D1735: commands: use the new API to access hidden changesets in various commands

login
register
mail settings
Submitter phabricator
Date Dec. 26, 2017, 2:12 p.m.
Message ID <32607c657c12503214ae492a89f43b1b@localhost.localdomain>
Download mbox | patch
Permalink /patch/26445/
State Not Applicable
Headers show

Comments

phabricator - Dec. 26, 2017, 2:12 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGb378a3d840ab: commands: use the new API to access hidden changesets in various commands (authored by pulkit, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1735?vs=4554&id=4620

REVISION DETAIL
  https://phab.mercurial-scm.org/D1735

AFFECTED FILES
  mercurial/commands.py
  tests/test-directaccess.t

CHANGE DETAILS




To: pulkit, #hg-reviewers, yuja
Cc: yuja, mercurial-devel

Patch

diff --git a/tests/test-directaccess.t b/tests/test-directaccess.t
new file mode 100644
--- /dev/null
+++ b/tests/test-directaccess.t
@@ -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 <<EOF
+  > [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]
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -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'):