comparison mercurial/scmutil.py @ 35496:8bb90cc4668e

scmutil: add utility fn to return repo object with user passed revs unhidden There has been a need for accessing hidden changesets by default without passing --hidden. This is currently done using the directaccess extension but is bit hacky. This patch adds a utility function to return a repo object having user passed revisions unhidden. This functionality will live behind a config option and won't be the default behaviour. There is also a config option added by this patch which tells whether we want to unhide only those revisions whose hashes are passed or should we consider revisions numbers also. Differential Revision: https://phab.mercurial-scm.org/D1733
author Pulkit Goyal <7895pulkit@gmail.com>
date Fri, 15 Dec 2017 04:31:29 +0530
parents b1959391a088
children b55a142f00c5
comparison
equal deleted inserted replaced
35495:07fdac1d5c66 35496:8bb90cc4668e
1303 def wrapconvertsink(sink): 1303 def wrapconvertsink(sink):
1304 """Allow extensions to wrap the sink returned by convcmd.convertsink() 1304 """Allow extensions to wrap the sink returned by convcmd.convertsink()
1305 before it is used, whether or not the convert extension was formally loaded. 1305 before it is used, whether or not the convert extension was formally loaded.
1306 """ 1306 """
1307 return sink 1307 return sink
1308
1309 def unhidehashlikerevs(repo, specs, hiddentype):
1310 """parse the user specs and unhide changesets whose hash or revision number
1311 is passed.
1312
1313 hiddentype can be: 1) 'warn': warn while unhiding changesets
1314 2) 'nowarn': don't warn while unhiding changesets
1315
1316 returns a repo object with the required changesets unhidden
1317 """
1318 if not repo.filtername or not repo.ui.configbool('experimental',
1319 'directaccess'):
1320 return repo
1321
1322 if not repo.filtername.startswith('visible'):
1323 return repo
1324
1325 symbols = set()
1326 for spec in specs:
1327 try:
1328 tree = revsetlang.parse(spec)
1329 except error.ParseError: # will be reported by scmutil.revrange()
1330 continue
1331
1332 symbols.update(revsetlang.gethashlikesymbols(tree))
1333
1334 if not symbols:
1335 return repo
1336
1337 revs = _getrevsfromsymbols(repo, symbols)
1338
1339 if not revs:
1340 return repo
1341
1342 if hiddentype == 'warn':
1343 unfi = repo.unfiltered()
1344 revstr = ", ".join([pycompat.bytestr(unfi[l]) for l in revs])
1345 repo.ui.warn(_("warning: accessing hidden changesets for write "
1346 "operation: %s\n") % revstr)
1347
1348 return repo.filtered('visible-hidden', revs)
1349
1350 def _getrevsfromsymbols(repo, symbols):
1351 """parse the list of symbols and returns a set of revision numbers of hidden
1352 changesets present in symbols"""
1353 revs = set()
1354 unfi = repo.unfiltered()
1355 unficl = unfi.changelog
1356 cl = repo.changelog
1357 tiprev = len(unficl)
1358 pmatch = unficl._partialmatch
1359 allowrevnums = repo.ui.configbool('experimental', 'directaccess.revnums')
1360 for s in symbols:
1361 try:
1362 n = int(s)
1363 if n <= tiprev:
1364 if not allowrevnums:
1365 continue
1366 else:
1367 if n not in cl:
1368 revs.add(n)
1369 continue
1370 except ValueError:
1371 pass
1372
1373 try:
1374 s = pmatch(s)
1375 except error.LookupError:
1376 s = None
1377
1378 if s is not None:
1379 rev = unficl.rev(s)
1380 if rev not in cl:
1381 revs.add(rev)
1382
1383 return revs