2007-06-25 10:26:44 +04:00
|
|
|
# repair.py - functions for repository repair for mercurial
|
|
|
|
#
|
|
|
|
# Copyright 2005, 2006 Chris Mason <mason@suse.com>
|
|
|
|
# Copyright 2007 Matt Mackall
|
|
|
|
#
|
2009-04-26 03:08:54 +04:00
|
|
|
# This software may be used and distributed according to the terms of the
|
2010-01-20 07:20:08 +03:00
|
|
|
# GNU General Public License version 2 or any later version.
|
2007-06-25 10:26:44 +04:00
|
|
|
|
2015-08-09 05:50:48 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2012-04-16 12:33:18 +04:00
|
|
|
import errno
|
2016-06-10 07:12:33 +03:00
|
|
|
import hashlib
|
2007-06-25 10:26:44 +04:00
|
|
|
|
2015-08-09 05:50:48 +03:00
|
|
|
from .i18n import _
|
2017-08-23 04:22:34 +03:00
|
|
|
from .node import (
|
|
|
|
hex,
|
|
|
|
short,
|
|
|
|
)
|
2015-08-09 05:50:48 +03:00
|
|
|
from . import (
|
|
|
|
bundle2,
|
|
|
|
changegroup,
|
2017-05-05 19:15:42 +03:00
|
|
|
discovery,
|
2015-10-08 22:55:45 +03:00
|
|
|
error,
|
2015-08-09 05:50:48 +03:00
|
|
|
exchange,
|
2016-04-12 14:06:50 +03:00
|
|
|
obsolete,
|
2017-06-27 02:11:56 +03:00
|
|
|
obsutil,
|
2018-03-21 23:36:35 +03:00
|
|
|
progress,
|
2015-08-09 05:50:48 +03:00
|
|
|
util,
|
|
|
|
)
|
|
|
|
|
flake8: enable F821 check
Summary:
This check is useful and detects real errors (ex. fbconduit). Unfortunately
`arc lint` will run it with both py2 and py3 so a lot of py2 builtins will
still be warned.
I didn't find a clean way to disable py3 check. So this diff tries to fix them.
For `xrange`, the change was done by a script:
```
import sys
import redbaron
headertypes = {'comment', 'endl', 'from_import', 'import', 'string',
'assignment', 'atomtrailers'}
xrangefix = '''try:
xrange(0)
except NameError:
xrange = range
'''
def isxrange(x):
try:
return x[0].value == 'xrange'
except Exception:
return False
def main(argv):
for i, path in enumerate(argv):
print('(%d/%d) scanning %s' % (i + 1, len(argv), path))
content = open(path).read()
try:
red = redbaron.RedBaron(content)
except Exception:
print(' warning: failed to parse')
continue
hasxrange = red.find('atomtrailersnode', value=isxrange)
hasxrangefix = 'xrange = range' in content
if hasxrangefix or not hasxrange:
print(' no need to change')
continue
# find a place to insert the compatibility statement
changed = False
for node in red:
if node.type in headertypes:
continue
# node.insert_before is an easier API, but it has bugs changing
# other "finally" and "except" positions. So do the insert
# manually.
# # node.insert_before(xrangefix)
line = node.absolute_bounding_box.top_left.line - 1
lines = content.splitlines(1)
content = ''.join(lines[:line]) + xrangefix + ''.join(lines[line:])
changed = True
break
if changed:
# "content" is faster than "red.dumps()"
open(path, 'w').write(content)
print(' updated')
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
```
For other py2 builtins that do not have a py3 equivalent, some `# noqa`
were added as a workaround for now.
Reviewed By: DurhamG
Differential Revision: D6934535
fbshipit-source-id: 546b62830af144bc8b46788d2e0fd00496838939
2018-02-10 04:31:44 +03:00
|
|
|
try:
|
|
|
|
xrange(0)
|
|
|
|
except NameError:
|
|
|
|
xrange = range
|
|
|
|
|
2017-06-01 13:08:49 +03:00
|
|
|
def _bundle(repo, bases, heads, node, suffix, compress=True, obsolescence=True):
|
2008-01-19 23:01:16 +03:00
|
|
|
"""create a bundle with the specified revisions as a backup"""
|
2015-01-16 03:51:13 +03:00
|
|
|
|
2014-03-08 20:03:28 +04:00
|
|
|
backupdir = "strip-backup"
|
|
|
|
vfs = repo.vfs
|
|
|
|
if not vfs.isdir(backupdir):
|
|
|
|
vfs.mkdir(backupdir)
|
2015-01-09 21:52:14 +03:00
|
|
|
|
|
|
|
# Include a hash of all the nodes in the filename for uniqueness
|
2015-05-24 08:34:12 +03:00
|
|
|
allcommits = repo.set('%ln::%ln', bases, heads)
|
2015-01-09 21:52:14 +03:00
|
|
|
allhashes = sorted(c.hex() for c in allcommits)
|
2017-08-23 04:22:34 +03:00
|
|
|
totalhash = hashlib.sha1(''.join(allhashes)).digest()
|
|
|
|
name = "%s/%s-%s-%s.hg" % (backupdir, short(node),
|
|
|
|
hex(totalhash[:4]), suffix)
|
2015-01-09 21:52:14 +03:00
|
|
|
|
2017-09-14 21:16:57 +03:00
|
|
|
cgversion = changegroup.localversion(repo)
|
2015-09-30 00:42:03 +03:00
|
|
|
comp = None
|
2015-09-29 23:16:51 +03:00
|
|
|
if cgversion != '01':
|
2015-04-09 23:25:48 +03:00
|
|
|
bundletype = "HG20"
|
2015-09-30 00:42:03 +03:00
|
|
|
if compress:
|
|
|
|
comp = 'BZ'
|
2015-01-16 03:51:13 +03:00
|
|
|
elif compress:
|
2010-08-12 11:53:23 +04:00
|
|
|
bundletype = "HG10BZ"
|
|
|
|
else:
|
|
|
|
bundletype = "HG10UN"
|
2017-05-05 19:15:42 +03:00
|
|
|
|
|
|
|
outgoing = discovery.outgoing(repo, missingroots=bases, missingheads=heads)
|
2017-06-15 10:15:52 +03:00
|
|
|
contentopts = {
|
|
|
|
'cg.version': cgversion,
|
|
|
|
'obsolescence': obsolescence,
|
|
|
|
'phases': True,
|
|
|
|
}
|
2017-05-05 19:15:42 +03:00
|
|
|
return bundle2.writenewbundle(repo.ui, repo, 'strip', name, bundletype,
|
|
|
|
outgoing, contentopts, vfs, compression=comp)
|
2008-01-19 23:01:16 +03:00
|
|
|
|
2008-01-19 23:01:16 +03:00
|
|
|
def _collectfiles(repo, striprev):
|
|
|
|
"""find out the filelogs affected by the strip"""
|
2009-05-17 05:38:03 +04:00
|
|
|
files = set()
|
2008-01-19 23:01:16 +03:00
|
|
|
|
2008-06-26 23:35:50 +04:00
|
|
|
for x in xrange(striprev, len(repo)):
|
2009-05-17 18:55:51 +04:00
|
|
|
files.update(repo[x].files())
|
2008-01-19 23:01:16 +03:00
|
|
|
|
2009-05-17 05:38:03 +04:00
|
|
|
return sorted(files)
|
2008-01-19 23:01:16 +03:00
|
|
|
|
2017-08-09 03:25:38 +03:00
|
|
|
def _collectrevlog(revlog, striprev):
|
|
|
|
_, brokenset = revlog.getstrippoint(striprev)
|
|
|
|
return [revlog.linkrev(r) for r in brokenset]
|
|
|
|
|
|
|
|
def _collectmanifest(repo, striprev):
|
|
|
|
return _collectrevlog(repo.manifestlog._revlog, striprev)
|
|
|
|
|
2011-03-20 02:50:22 +03:00
|
|
|
def _collectbrokencsets(repo, files, striprev):
|
|
|
|
"""return the changesets which will be broken by the truncation"""
|
2011-03-21 03:43:28 +03:00
|
|
|
s = set()
|
2008-01-19 23:01:16 +03:00
|
|
|
|
2017-08-09 03:25:38 +03:00
|
|
|
s.update(_collectmanifest(repo, striprev))
|
2008-01-19 23:01:16 +03:00
|
|
|
for fname in files:
|
2017-08-09 03:25:38 +03:00
|
|
|
s.update(_collectrevlog(repo.file(fname), striprev))
|
2011-03-21 03:43:28 +03:00
|
|
|
|
|
|
|
return s
|
2008-01-19 23:01:16 +03:00
|
|
|
|
2014-07-24 23:06:08 +04:00
|
|
|
def strip(ui, repo, nodelist, backup=True, topic='backup'):
|
2017-06-19 21:24:21 +03:00
|
|
|
# This function requires the caller to lock the repo, but it operates
|
|
|
|
# within a transaction of its own, and thus requires there to be no current
|
|
|
|
# transaction when it is called.
|
2017-06-19 23:18:00 +03:00
|
|
|
if repo.currenttransaction() is not None:
|
|
|
|
raise error.ProgrammingError('cannot strip from inside a transaction')
|
|
|
|
|
2014-07-24 23:06:08 +04:00
|
|
|
# Simple way to maintain backwards compatibility for this
|
|
|
|
# argument.
|
|
|
|
if backup in ['none', 'strip']:
|
|
|
|
backup = False
|
|
|
|
|
2012-10-08 19:12:09 +04:00
|
|
|
repo = repo.unfiltered()
|
2012-12-15 22:08:13 +04:00
|
|
|
repo.destroying()
|
2012-05-18 23:45:47 +04:00
|
|
|
|
2008-01-19 23:01:16 +03:00
|
|
|
cl = repo.changelog
|
2012-03-06 20:43:05 +04:00
|
|
|
# TODO handle undo of merge sets
|
strip: enhance repair.strip to receive a list of nodes (issue3299)
Originally, mq.strip called repair.strip a single rev at a time.
repair.strip stores in a backup bundle any revision greater than
the revision being stripped, strips, then restores the backup with
repo.addchangegroup. So, when stripping revisions on more than one
topological branch, some could end up being restored from the backup
bundle, only to be later removed by a subsequent repair.strip call.
But repo.addchangegroup calls hooks for all those restore operations.
And 1671d21e8e41 changed it to delay all hook calls until the
repository lock were released - by mq.strip, after stripping all
revisions. Thus, the hooks could be called over revisions already
removed from the repository at that point.
By generating the revision lists at once inside repo.strip, we avoid
calling addchangegroup for temporary restores. Incidentally, this
also avoids creating many backup files for a single strip command.
2012-03-13 00:02:45 +04:00
|
|
|
if isinstance(nodelist, str):
|
|
|
|
nodelist = [nodelist]
|
|
|
|
striplist = [cl.rev(node) for node in nodelist]
|
|
|
|
striprev = min(striplist)
|
2007-06-25 10:26:44 +04:00
|
|
|
|
2017-01-04 21:35:04 +03:00
|
|
|
files = _collectfiles(repo, striprev)
|
|
|
|
saverevs = _collectbrokencsets(repo, files, striprev)
|
|
|
|
|
2008-02-20 01:20:10 +03:00
|
|
|
# Some revisions with rev > striprev may not be descendants of striprev.
|
|
|
|
# We have to find these revisions and put them in a bundle, so that
|
|
|
|
# we can restore them after the truncations.
|
|
|
|
# To create the bundle we use repo.changegroupsubset which requires
|
|
|
|
# the list of heads and bases of the set of interesting revisions.
|
|
|
|
# (head = revision in the set that has no descendant in the set;
|
|
|
|
# base = revision in the set that has no ancestor in the set)
|
strip: enhance repair.strip to receive a list of nodes (issue3299)
Originally, mq.strip called repair.strip a single rev at a time.
repair.strip stores in a backup bundle any revision greater than
the revision being stripped, strips, then restores the backup with
repo.addchangegroup. So, when stripping revisions on more than one
topological branch, some could end up being restored from the backup
bundle, only to be later removed by a subsequent repair.strip call.
But repo.addchangegroup calls hooks for all those restore operations.
And 1671d21e8e41 changed it to delay all hook calls until the
repository lock were released - by mq.strip, after stripping all
revisions. Thus, the hooks could be called over revisions already
removed from the repository at that point.
By generating the revision lists at once inside repo.strip, we avoid
calling addchangegroup for temporary restores. Incidentally, this
also avoids creating many backup files for a single strip command.
2012-03-13 00:02:45 +04:00
|
|
|
tostrip = set(striplist)
|
2017-01-04 21:35:04 +03:00
|
|
|
saveheads = set(saverevs)
|
2017-01-04 21:07:12 +03:00
|
|
|
for r in cl.revs(start=striprev + 1):
|
|
|
|
if any(p in tostrip for p in cl.parentrevs(r)):
|
|
|
|
tostrip.add(r)
|
2011-03-20 02:50:22 +03:00
|
|
|
|
|
|
|
if r not in tostrip:
|
|
|
|
saverevs.add(r)
|
|
|
|
saveheads.difference_update(cl.parentrevs(r))
|
2009-05-17 05:38:03 +04:00
|
|
|
saveheads.add(r)
|
2011-03-20 02:50:22 +03:00
|
|
|
saveheads = [cl.node(r) for r in saveheads]
|
|
|
|
|
2011-10-30 21:10:09 +04:00
|
|
|
# compute base nodes
|
|
|
|
if saverevs:
|
2012-06-01 23:45:16 +04:00
|
|
|
descendants = set(cl.descendants(saverevs))
|
2011-10-30 21:10:09 +04:00
|
|
|
saverevs.difference_update(descendants)
|
|
|
|
savebases = [cl.node(r) for r in saverevs]
|
strip: enhance repair.strip to receive a list of nodes (issue3299)
Originally, mq.strip called repair.strip a single rev at a time.
repair.strip stores in a backup bundle any revision greater than
the revision being stripped, strips, then restores the backup with
repo.addchangegroup. So, when stripping revisions on more than one
topological branch, some could end up being restored from the backup
bundle, only to be later removed by a subsequent repair.strip call.
But repo.addchangegroup calls hooks for all those restore operations.
And 1671d21e8e41 changed it to delay all hook calls until the
repository lock were released - by mq.strip, after stripping all
revisions. Thus, the hooks could be called over revisions already
removed from the repository at that point.
By generating the revision lists at once inside repo.strip, we avoid
calling addchangegroup for temporary restores. Incidentally, this
also avoids creating many backup files for a single strip command.
2012-03-13 00:02:45 +04:00
|
|
|
stripbases = [cl.node(r) for r in tostrip]
|
strip: make query to get new bookmark target cheaper
The current query to get the new bookmark target for stripped revisions
involves multiple walks up the DAG, and is really expensive, taking over 2.5
seconds on a repository with over 400,000 changesets even if just one
changeset is being stripped.
A slightly simplified version of the current query is
max(heads(::<tostrip> - <tostrip>))
We make two observations here.
1. For any set s, max(heads(s)) == max(s). That is because revision numbers
define a topological order, so that the element with the highest revision
number in s will not have any children in s.
2. For any set s, max(::s - s) == max(parents(s) - s). In other words, the
ancestor of s with the highest revision number not in s is a parent of one
of the revs in s. Why? Because if it were an ancestor but not a parent of s,
it would have a descendant that would be a parent of s. This descendant
would have a higher revision number, leading to a contradiction.
Combining these two observations, we rewrite the revset query as
max(parents(<tostrip>) - <tostrip>)
The time complexity is now linear in the number of changesets being stripped.
For the above repository, the query now takes 0.1 seconds when one changeset
is stripped. This speeds up operations that use repair.strip, like the rebase
and strip commands.
2012-12-06 02:33:15 +04:00
|
|
|
|
2017-05-20 17:19:59 +03:00
|
|
|
stripobsidx = obsmarkers = ()
|
2017-06-28 14:32:36 +03:00
|
|
|
if repo.ui.configbool('devel', 'strip-obsmarkers'):
|
2017-06-27 02:11:56 +03:00
|
|
|
obsmarkers = obsutil.exclusivemarkers(repo, stripbases)
|
2017-05-20 17:19:59 +03:00
|
|
|
if obsmarkers:
|
|
|
|
stripobsidx = [i for i, m in enumerate(repo.obsstore)
|
|
|
|
if m in obsmarkers]
|
|
|
|
|
strip: make query to get new bookmark target cheaper
The current query to get the new bookmark target for stripped revisions
involves multiple walks up the DAG, and is really expensive, taking over 2.5
seconds on a repository with over 400,000 changesets even if just one
changeset is being stripped.
A slightly simplified version of the current query is
max(heads(::<tostrip> - <tostrip>))
We make two observations here.
1. For any set s, max(heads(s)) == max(s). That is because revision numbers
define a topological order, so that the element with the highest revision
number in s will not have any children in s.
2. For any set s, max(::s - s) == max(parents(s) - s). In other words, the
ancestor of s with the highest revision number not in s is a parent of one
of the revs in s. Why? Because if it were an ancestor but not a parent of s,
it would have a descendant that would be a parent of s. This descendant
would have a higher revision number, leading to a contradiction.
Combining these two observations, we rewrite the revset query as
max(parents(<tostrip>) - <tostrip>)
The time complexity is now linear in the number of changesets being stripped.
For the above repository, the query now takes 0.1 seconds when one changeset
is stripped. This speeds up operations that use repair.strip, like the rebase
and strip commands.
2012-12-06 02:33:15 +04:00
|
|
|
# For a set s, max(parents(s) - s) is the same as max(heads(::s - s)), but
|
|
|
|
# is much faster
|
|
|
|
newbmtarget = repo.revs('max(parents(%ld) - (%ld))', tostrip, tostrip)
|
2012-07-27 01:57:50 +04:00
|
|
|
if newbmtarget:
|
2014-10-07 11:09:50 +04:00
|
|
|
newbmtarget = repo[newbmtarget.first()].node()
|
2012-07-27 01:57:50 +04:00
|
|
|
else:
|
|
|
|
newbmtarget = '.'
|
2008-02-20 01:20:10 +03:00
|
|
|
|
2011-02-10 22:46:28 +03:00
|
|
|
bm = repo._bookmarks
|
|
|
|
updatebm = []
|
|
|
|
for m in bm:
|
|
|
|
rev = repo[bm[m]].rev()
|
|
|
|
if rev in tostrip:
|
|
|
|
updatebm.append(m)
|
|
|
|
|
2007-06-25 10:26:44 +04:00
|
|
|
# create a changegroup for all the branches we need to keep
|
2010-05-20 04:46:39 +04:00
|
|
|
backupfile = None
|
2014-03-08 20:03:28 +04:00
|
|
|
vfs = repo.vfs
|
2015-03-10 23:25:10 +03:00
|
|
|
node = nodelist[-1]
|
2014-07-24 23:06:08 +04:00
|
|
|
if backup:
|
2012-04-06 17:18:33 +04:00
|
|
|
backupfile = _bundle(repo, stripbases, cl.heads(), node, topic)
|
2014-03-08 20:03:28 +04:00
|
|
|
repo.ui.status(_("saved backup bundle to %s\n") %
|
|
|
|
vfs.join(backupfile))
|
|
|
|
repo.ui.log("backupbundle", "saved backup bundle to %s\n",
|
|
|
|
vfs.join(backupfile))
|
2016-09-19 19:14:35 +03:00
|
|
|
tmpbundlefile = None
|
2016-09-15 20:18:56 +03:00
|
|
|
if saveheads:
|
2016-09-19 19:14:35 +03:00
|
|
|
# do not compress temporary bundle if we remove it from disk later
|
2017-06-01 13:08:49 +03:00
|
|
|
#
|
|
|
|
# We do not include obsolescence, it might re-introduce prune markers
|
|
|
|
# we are trying to strip. This is harmless since the stripped markers
|
|
|
|
# are already backed up and we did not touched the markers for the
|
|
|
|
# saved changesets.
|
2016-09-19 19:14:35 +03:00
|
|
|
tmpbundlefile = _bundle(repo, savebases, saveheads, node, 'temp',
|
2017-06-01 13:08:49 +03:00
|
|
|
compress=False, obsolescence=False)
|
2007-06-25 10:26:44 +04:00
|
|
|
|
2009-04-16 17:34:03 +04:00
|
|
|
try:
|
2016-01-16 00:14:49 +03:00
|
|
|
with repo.transaction("strip") as tr:
|
|
|
|
offset = len(tr.entries)
|
|
|
|
|
|
|
|
tr.startgroup()
|
|
|
|
cl.strip(striprev, tr)
|
2017-08-09 03:25:38 +03:00
|
|
|
stripmanifest(repo, striprev, tr, files)
|
2017-05-08 21:35:23 +03:00
|
|
|
|
2016-01-16 00:14:49 +03:00
|
|
|
for fn in files:
|
|
|
|
repo.file(fn).strip(striprev, tr)
|
|
|
|
tr.endgroup()
|
|
|
|
|
2010-05-20 04:46:39 +04:00
|
|
|
for i in xrange(offset, len(tr.entries)):
|
|
|
|
file, troffset, ignore = tr.entries[i]
|
2016-09-22 15:52:00 +03:00
|
|
|
with repo.svfs(file, 'a', checkambig=True) as fp:
|
2018-05-19 02:37:29 +03:00
|
|
|
# Workaround ftruncate returning 1. See
|
|
|
|
# https://www.spinics.net/lists/linux-btrfs/msg78417.html
|
|
|
|
try:
|
|
|
|
fp.truncate(troffset)
|
|
|
|
except IOError as ex:
|
|
|
|
if ex.errno != 0:
|
|
|
|
raise
|
2014-03-25 02:43:15 +04:00
|
|
|
if troffset == 0:
|
|
|
|
repo.store.markremoved(file)
|
2010-05-20 04:46:39 +04:00
|
|
|
|
2017-05-20 17:19:59 +03:00
|
|
|
deleteobsmarkers(repo.obsstore, stripobsidx)
|
|
|
|
del repo.obsstore
|
|
|
|
|
2017-06-15 10:15:52 +03:00
|
|
|
repo._phasecache.filterunknown(repo)
|
2016-09-19 19:14:35 +03:00
|
|
|
if tmpbundlefile:
|
2010-05-20 22:27:28 +04:00
|
|
|
ui.note(_("adding branch\n"))
|
2016-09-19 19:14:35 +03:00
|
|
|
f = vfs.open(tmpbundlefile, "rb")
|
|
|
|
gen = exchange.readbundle(ui, f, tmpbundlefile, vfs)
|
2010-05-20 22:27:28 +04:00
|
|
|
if not repo.ui.verbose:
|
|
|
|
# silence internal shuffling chatter
|
|
|
|
repo.ui.pushbuffer()
|
2017-06-16 09:09:14 +03:00
|
|
|
tmpbundleurl = 'bundle:' + vfs.join(tmpbundlefile)
|
2017-06-23 07:27:57 +03:00
|
|
|
txnname = 'strip'
|
|
|
|
if not isinstance(gen, bundle2.unbundle20):
|
|
|
|
txnname = "strip\n%s" % util.hidepassword(tmpbundleurl)
|
|
|
|
with repo.transaction(txnname) as tr:
|
2017-06-23 01:00:19 +03:00
|
|
|
bundle2.applybundle(repo, gen, tr, source='strip',
|
2017-07-01 09:58:31 +03:00
|
|
|
url=tmpbundleurl)
|
2010-05-20 22:27:28 +04:00
|
|
|
if not repo.ui.verbose:
|
|
|
|
repo.ui.popbuffer()
|
2010-05-20 04:46:39 +04:00
|
|
|
f.close()
|
strip: invalidate phase cache after stripping changeset (issue5235)
When we remove a changeset from the changelog, the phase cache must be
invalidated, otherwise it could refer to changesets that are no longer in the
repo.
To reproduce the failure, I created an extension querying the phase cache after
the strip transaction is over.
To do that, I stripped two commits with a bookmark on one of them to force
another transaction (we open a transaction for moving bookmarks)
after the strip transaction.
Without the fix in this patch, the test leads to a stacktrace showing the issue:
repair.strip(ui, repo, revs, backup)
File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/repair.py", line 205, in strip
tr.close()
File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/transaction.py", line 44, in _active
return func(self, *args, **kwds)
File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/transaction.py", line 490, in close
self._postclosecallback[cat](self)
File "$TESTTMP/crashstrip2.py", line 4, in test
[repo.changelog.node(r) for r in repo.revs("not public()")]
File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/changelog.py", line 337, in node
return super(changelog, self).node(rev)
File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/revlog.py", line 377, in node
return self.index[rev][7]
IndexError: revlog index out of range
The situation was encountered in inhibit (evolve's repo) where we would crash
following the volatile set invalidation submitted by Augie in
cbc52a99d057d11790cf5011e877c6f698bf57bf. Before his patch the issue was masked
as we were not accessing the phasecache after stripping a revision.
This bug uncovered another but in histedit (see explanation in issue5235).
I changed the histedit test accordingly to avoid fixing two things at once.
2016-05-12 16:13:59 +03:00
|
|
|
repo._phasecache.invalidate()
|
2011-02-10 22:46:28 +03:00
|
|
|
|
2017-06-19 21:24:49 +03:00
|
|
|
with repo.transaction('repair') as tr:
|
2017-07-10 18:46:47 +03:00
|
|
|
bmchanges = [(m, repo[newbmtarget].node()) for m in updatebm]
|
|
|
|
bm.applychanges(repo, tr, bmchanges)
|
2015-12-01 03:38:29 +03:00
|
|
|
|
2012-03-06 20:43:05 +04:00
|
|
|
# remove undo files
|
2014-03-08 20:03:28 +04:00
|
|
|
for undovfs, undofile in repo.undofiles():
|
2012-03-06 20:43:05 +04:00
|
|
|
try:
|
2014-03-08 20:03:28 +04:00
|
|
|
undovfs.unlink(undofile)
|
2015-06-24 08:20:08 +03:00
|
|
|
except OSError as e:
|
2012-03-06 20:43:05 +04:00
|
|
|
if e.errno != errno.ENOENT:
|
2014-03-08 20:03:28 +04:00
|
|
|
ui.warn(_('error removing %s: %s\n') %
|
|
|
|
(undovfs.join(undofile), str(e)))
|
2012-03-06 20:43:05 +04:00
|
|
|
|
2012-05-13 15:18:06 +04:00
|
|
|
except: # re-raises
|
2010-05-20 04:46:39 +04:00
|
|
|
if backupfile:
|
2016-09-19 19:14:35 +03:00
|
|
|
ui.warn(_("strip failed, backup bundle stored in '%s'\n")
|
2014-03-08 20:03:28 +04:00
|
|
|
% vfs.join(backupfile))
|
2016-09-19 19:14:35 +03:00
|
|
|
if tmpbundlefile:
|
2016-09-19 19:14:32 +03:00
|
|
|
ui.warn(_("strip failed, unrecovered changes stored in '%s'\n")
|
2016-09-19 19:14:35 +03:00
|
|
|
% vfs.join(tmpbundlefile))
|
2016-09-19 19:14:32 +03:00
|
|
|
ui.warn(_("(fix the problem, then recover the changesets with "
|
2016-09-19 19:14:35 +03:00
|
|
|
"\"hg unbundle '%s'\")\n") % vfs.join(tmpbundlefile))
|
2009-04-16 17:34:03 +04:00
|
|
|
raise
|
2014-07-24 23:06:08 +04:00
|
|
|
else:
|
2016-09-19 19:14:35 +03:00
|
|
|
if tmpbundlefile:
|
|
|
|
# Remove temporary bundle only if there were no exceptions
|
|
|
|
vfs.unlink(tmpbundlefile)
|
2007-06-25 10:26:44 +04:00
|
|
|
|
2013-01-16 03:09:26 +04:00
|
|
|
repo.destroyed()
|
2016-11-01 01:40:30 +03:00
|
|
|
# return the backup file path (or None if 'backup' was False) so
|
|
|
|
# extensions can use it
|
|
|
|
return backupfile
|
2015-06-22 19:59:48 +03:00
|
|
|
|
2017-06-25 20:38:45 +03:00
|
|
|
def safestriproots(ui, repo, nodes):
|
|
|
|
"""return list of roots of nodes where descendants are covered by nodes"""
|
|
|
|
torev = repo.unfiltered().changelog.rev
|
|
|
|
revs = set(torev(n) for n in nodes)
|
|
|
|
# tostrip = wanted - unsafe = wanted - ancestors(orphaned)
|
|
|
|
# orphaned = affected - wanted
|
|
|
|
# affected = descendants(roots(wanted))
|
|
|
|
# wanted = revs
|
|
|
|
tostrip = set(repo.revs('%ld-(::((roots(%ld)::)-%ld))', revs, revs, revs))
|
|
|
|
notstrip = revs - tostrip
|
|
|
|
if notstrip:
|
|
|
|
nodestr = ', '.join(sorted(short(repo[n].node()) for n in notstrip))
|
|
|
|
ui.warn(_('warning: orphaned descendants detected, '
|
|
|
|
'not stripping %s\n') % nodestr)
|
|
|
|
return [c.node() for c in repo.set('roots(%ld)', tostrip)]
|
|
|
|
|
|
|
|
class stripcallback(object):
|
|
|
|
"""used as a transaction postclose callback"""
|
|
|
|
|
|
|
|
def __init__(self, ui, repo, backup, topic):
|
|
|
|
self.ui = ui
|
|
|
|
self.repo = repo
|
|
|
|
self.backup = backup
|
|
|
|
self.topic = topic or 'backup'
|
|
|
|
self.nodelist = []
|
|
|
|
|
|
|
|
def addnodes(self, nodes):
|
|
|
|
self.nodelist.extend(nodes)
|
|
|
|
|
|
|
|
def __call__(self, tr):
|
|
|
|
roots = safestriproots(self.ui, self.repo, self.nodelist)
|
|
|
|
if roots:
|
2017-06-27 07:11:02 +03:00
|
|
|
strip(self.ui, self.repo, roots, self.backup, self.topic)
|
2017-06-25 20:38:45 +03:00
|
|
|
|
|
|
|
def delayedstrip(ui, repo, nodelist, topic=None):
|
|
|
|
"""like strip, but works inside transaction and won't strip irreverent revs
|
|
|
|
|
|
|
|
nodelist must explicitly contain all descendants. Otherwise a warning will
|
|
|
|
be printed that some nodes are not stripped.
|
|
|
|
|
|
|
|
Always do a backup. The last non-None "topic" will be used as the backup
|
|
|
|
topic name. The default backup topic name is "backup".
|
|
|
|
"""
|
|
|
|
tr = repo.currenttransaction()
|
|
|
|
if not tr:
|
|
|
|
nodes = safestriproots(ui, repo, nodelist)
|
|
|
|
return strip(ui, repo, nodes, True, topic)
|
|
|
|
# transaction postclose callbacks are called in alphabet order.
|
|
|
|
# use '\xff' as prefix so we are likely to be called last.
|
|
|
|
callback = tr.getpostclose('\xffstrip')
|
|
|
|
if callback is None:
|
|
|
|
callback = stripcallback(ui, repo, True, topic)
|
|
|
|
tr.addpostclose('\xffstrip', callback)
|
|
|
|
if topic:
|
|
|
|
callback.topic = topic
|
|
|
|
callback.addnodes(nodelist)
|
|
|
|
|
2017-08-09 03:25:38 +03:00
|
|
|
def stripmanifest(repo, striprev, tr, files):
|
|
|
|
revlog = repo.manifestlog._revlog
|
|
|
|
revlog.strip(striprev, tr)
|
|
|
|
striptrees(repo, tr, striprev, files)
|
|
|
|
|
2017-05-08 21:35:23 +03:00
|
|
|
def striptrees(repo, tr, striprev, files):
|
|
|
|
if 'treemanifest' in repo.requirements: # safe but unnecessary
|
|
|
|
# otherwise
|
2017-05-16 04:55:58 +03:00
|
|
|
for unencoded, encoded, size in repo.store.datafiles():
|
|
|
|
if (unencoded.startswith('meta/') and
|
|
|
|
unencoded.endswith('00manifest.i')):
|
|
|
|
dir = unencoded[5:-12]
|
|
|
|
repo.manifestlog._revlog.dirlog(dir).strip(striprev, tr)
|
2017-05-08 21:35:23 +03:00
|
|
|
|
2015-06-22 19:59:48 +03:00
|
|
|
def rebuildfncache(ui, repo):
|
|
|
|
"""Rebuilds the fncache file from repo history.
|
|
|
|
|
|
|
|
Missing entries will be added. Extra entries will be removed.
|
|
|
|
"""
|
|
|
|
repo = repo.unfiltered()
|
|
|
|
|
|
|
|
if 'fncache' not in repo.requirements:
|
|
|
|
ui.warn(_('(not rebuilding fncache because repository does not '
|
2015-07-26 15:28:52 +03:00
|
|
|
'support fncache)\n'))
|
2015-06-22 19:59:48 +03:00
|
|
|
return
|
|
|
|
|
2016-01-16 00:14:49 +03:00
|
|
|
with repo.lock():
|
2015-06-22 19:59:48 +03:00
|
|
|
fnc = repo.store.fncache
|
|
|
|
# Trigger load of fncache.
|
|
|
|
if 'irrelevant' in fnc:
|
|
|
|
pass
|
|
|
|
|
|
|
|
oldentries = set(fnc.entries)
|
|
|
|
newentries = set()
|
|
|
|
seenfiles = set()
|
|
|
|
|
|
|
|
repolen = len(repo)
|
2018-03-21 23:36:35 +03:00
|
|
|
with progress.bar(ui, _('rebuilding'), _('changesets'),
|
|
|
|
repolen) as prog:
|
|
|
|
for rev in repo:
|
|
|
|
prog.value = rev
|
|
|
|
ctx = repo[rev]
|
|
|
|
for f in ctx.files():
|
|
|
|
# This is to minimize I/O.
|
|
|
|
if f in seenfiles:
|
|
|
|
continue
|
|
|
|
seenfiles.add(f)
|
|
|
|
|
|
|
|
i = 'data/%s.i' % f
|
|
|
|
d = 'data/%s.d' % f
|
|
|
|
|
|
|
|
if repo.store._exists(i):
|
|
|
|
newentries.add(i)
|
|
|
|
if repo.store._exists(d):
|
|
|
|
newentries.add(d)
|
2015-06-22 19:59:48 +03:00
|
|
|
|
2016-02-08 08:44:38 +03:00
|
|
|
if 'treemanifest' in repo.requirements: # safe but unnecessary otherwise
|
2016-02-04 19:34:07 +03:00
|
|
|
for dir in util.dirs(seenfiles):
|
|
|
|
i = 'meta/%s/00manifest.i' % dir
|
|
|
|
d = 'meta/%s/00manifest.d' % dir
|
|
|
|
|
|
|
|
if repo.store._exists(i):
|
|
|
|
newentries.add(i)
|
|
|
|
if repo.store._exists(d):
|
|
|
|
newentries.add(d)
|
|
|
|
|
2015-06-22 19:59:48 +03:00
|
|
|
addcount = len(newentries - oldentries)
|
|
|
|
removecount = len(oldentries - newentries)
|
|
|
|
for p in sorted(oldentries - newentries):
|
|
|
|
ui.write(_('removing %s\n') % p)
|
|
|
|
for p in sorted(newentries - oldentries):
|
|
|
|
ui.write(_('adding %s\n') % p)
|
|
|
|
|
|
|
|
if addcount or removecount:
|
|
|
|
ui.write(_('%d items added, %d removed from fncache\n') %
|
|
|
|
(addcount, removecount))
|
|
|
|
fnc.entries = newentries
|
|
|
|
fnc._dirty = True
|
|
|
|
|
2016-01-16 00:14:49 +03:00
|
|
|
with repo.transaction('fncache') as tr:
|
2015-06-22 19:59:48 +03:00
|
|
|
fnc.write(tr)
|
|
|
|
else:
|
|
|
|
ui.write(_('fncache already up to date\n'))
|
|
|
|
|
2015-10-10 00:48:59 +03:00
|
|
|
def stripbmrevset(repo, mark):
|
|
|
|
"""
|
|
|
|
The revset to strip when strip is called with -B mark
|
|
|
|
|
|
|
|
Needs to live here so extensions can use it and wrap it even when strip is
|
|
|
|
not enabled or not present on a box.
|
|
|
|
"""
|
|
|
|
return repo.revs("ancestors(bookmark(%s)) - "
|
|
|
|
"ancestors(head() and not bookmark(%s)) - "
|
|
|
|
"ancestors(bookmark() and not bookmark(%s))",
|
|
|
|
mark, mark, mark)
|
2016-04-12 14:06:50 +03:00
|
|
|
|
|
|
|
def deleteobsmarkers(obsstore, indices):
|
|
|
|
"""Delete some obsmarkers from obsstore and return how many were deleted
|
|
|
|
|
|
|
|
'indices' is a list of ints which are the indices
|
|
|
|
of the markers to be deleted.
|
|
|
|
|
|
|
|
Every invocation of this function completely rewrites the obsstore file,
|
|
|
|
skipping the markers we want to be removed. The new temporary file is
|
|
|
|
created, remaining markers are written there and on .close() this file
|
|
|
|
gets atomically renamed to obsstore, thus guaranteeing consistency."""
|
|
|
|
if not indices:
|
|
|
|
# we don't want to rewrite the obsstore with the same content
|
|
|
|
return
|
|
|
|
|
|
|
|
left = []
|
|
|
|
current = obsstore._all
|
|
|
|
n = 0
|
|
|
|
for i, m in enumerate(current):
|
|
|
|
if i in indices:
|
|
|
|
n += 1
|
|
|
|
continue
|
|
|
|
left.append(m)
|
|
|
|
|
|
|
|
newobsstorefile = obsstore.svfs('obsstore', 'w', atomictemp=True)
|
|
|
|
for bytes in obsolete.encodemarkers(left, True, obsstore._version):
|
|
|
|
newobsstorefile.write(bytes)
|
|
|
|
newobsstorefile.close()
|
|
|
|
return n
|