Patchwork D1733: scmutil: add utility fn to return repo object with user passed revs unhidden

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

Comments

phabricator - Dec. 26, 2017, 2:11 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG8bb90cc4668e: scmutil: add utility fn to return repo object with user passed revs unhidden (authored by pulkit, committed by ).

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D1733?vs=4585&id=4619#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1733?vs=4585&id=4619

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

AFFECTED FILES
  mercurial/configitems.py
  mercurial/scmutil.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -1305,3 +1305,79 @@ 
     before it is used, whether or not the convert extension was formally loaded.
     """
     return sink
+
+def unhidehashlikerevs(repo, specs, hiddentype):
+    """parse the user specs and unhide changesets whose hash or revision number
+    is passed.
+
+    hiddentype can be: 1) 'warn': warn while unhiding changesets
+                       2) 'nowarn': don't warn while unhiding changesets
+
+    returns a repo object with the required changesets unhidden
+    """
+    if not repo.filtername or not repo.ui.configbool('experimental',
+                                                     'directaccess'):
+        return repo
+
+    if not repo.filtername.startswith('visible'):
+        return repo
+
+    symbols = set()
+    for spec in specs:
+        try:
+            tree = revsetlang.parse(spec)
+        except error.ParseError: # will be reported by scmutil.revrange()
+            continue
+
+        symbols.update(revsetlang.gethashlikesymbols(tree))
+
+    if not symbols:
+        return repo
+
+    revs = _getrevsfromsymbols(repo, symbols)
+
+    if not revs:
+        return repo
+
+    if hiddentype == 'warn':
+        unfi = repo.unfiltered()
+        revstr = ", ".join([pycompat.bytestr(unfi[l]) for l in revs])
+        repo.ui.warn(_("warning: accessing hidden changesets for write "
+                       "operation: %s\n") % revstr)
+
+    return repo.filtered('visible-hidden', revs)
+
+def _getrevsfromsymbols(repo, symbols):
+    """parse the list of symbols and returns a set of revision numbers of hidden
+    changesets present in symbols"""
+    revs = set()
+    unfi = repo.unfiltered()
+    unficl = unfi.changelog
+    cl = repo.changelog
+    tiprev = len(unficl)
+    pmatch = unficl._partialmatch
+    allowrevnums = repo.ui.configbool('experimental', 'directaccess.revnums')
+    for s in symbols:
+        try:
+            n = int(s)
+            if n <= tiprev:
+                if not allowrevnums:
+                    continue
+                else:
+                    if n not in cl:
+                        revs.add(n)
+                    continue
+        except ValueError:
+            pass
+
+        try:
+            s = pmatch(s)
+        except error.LookupError:
+            s = None
+
+        if s is not None:
+            rev = unficl.rev(s)
+            if rev not in cl:
+                revs.add(rev)
+
+    return revs
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -452,6 +452,12 @@ 
 coreconfigitem('experimental', 'crecordtest',
     default=None,
 )
+coreconfigitem('experimental', 'directaccess',
+    default=False,
+)
+coreconfigitem('experimental', 'directaccess.revnums',
+    default=False,
+)
 coreconfigitem('experimental', 'editortmpinhg',
     default=False,
 )