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 _
|
|
|
|
from .node import short
|
|
|
|
from . import (
|
|
|
|
bundle2,
|
|
|
|
changegroup,
|
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,
|
2015-08-09 05:50:48 +03:00
|
|
|
util,
|
|
|
|
)
|
|
|
|
|
2011-10-30 21:10:09 +04:00
|
|
|
def _bundle(repo, bases, heads, node, suffix, compress=True):
|
2008-01-19 23:01:16 +03:00
|
|
|
"""create a bundle with the specified revisions as a backup"""
|
2016-01-20 02:38:24 +03:00
|
|
|
cgversion = changegroup.safeversion(repo)
|
2015-01-16 03:51:13 +03:00
|
|
|
|
|
|
|
cg = changegroup.changegroupsubset(repo, bases, heads, 'strip',
|
|
|
|
version=cgversion)
|
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)
|
2016-06-10 07:12:33 +03:00
|
|
|
totalhash = hashlib.sha1(''.join(allhashes)).hexdigest()
|
2015-01-09 21:52:14 +03:00
|
|
|
name = "%s/%s-%s-%s.hg" % (backupdir, short(node), totalhash[:8], suffix)
|
|
|
|
|
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"
|
2016-03-29 00:41:29 +03:00
|
|
|
return bundle2.writebundle(repo.ui, cg, name, bundletype, vfs,
|
2015-09-30 00:42:03 +03:00
|
|
|
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
|
|
|
|
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()
|
2011-03-20 02:50:22 +03:00
|
|
|
def collectone(revlog):
|
2013-11-12 04:42:49 +04:00
|
|
|
_, brokenset = revlog.getstrippoint(striprev)
|
|
|
|
s.update([revlog.linkrev(r) for r in brokenset])
|
2008-01-19 23:01:16 +03:00
|
|
|
|
2016-11-10 13:13:19 +03:00
|
|
|
collectone(repo.manifestlog._revlog)
|
2008-01-19 23:01:16 +03:00
|
|
|
for fname in files:
|
2011-03-21 03:43:28 +03:00
|
|
|
collectone(repo.file(fname))
|
|
|
|
|
|
|
|
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'):
|
2015-12-29 21:21:39 +03:00
|
|
|
# This function operates within a transaction of its own, but does
|
|
|
|
# not take any lock on the repo.
|
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
|
|
|
|
|
|
|
# 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
|
|
|
|
tmpbundlefile = _bundle(repo, savebases, saveheads, node, 'temp',
|
2014-07-24 23:06:08 +04:00
|
|
|
compress=False)
|
2007-06-25 10:26:44 +04:00
|
|
|
|
2016-11-10 13:13:19 +03:00
|
|
|
mfst = repo.manifestlog._revlog
|
2009-04-16 17:34:03 +04:00
|
|
|
|
2015-05-24 07:18:47 +03:00
|
|
|
curtr = repo.currenttransaction()
|
|
|
|
if curtr is not None:
|
|
|
|
del curtr # avoid carrying reference to transaction for nothing
|
2017-03-27 02:53:28 +03:00
|
|
|
raise error.ProgrammingError('cannot strip from inside a transaction')
|
2015-05-24 07:18:47 +03: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)
|
|
|
|
mfst.strip(striprev, tr)
|
2016-06-30 23:06:19 +03:00
|
|
|
if 'treemanifest' in repo.requirements: # safe but unnecessary
|
|
|
|
# otherwise
|
|
|
|
for unencoded, encoded, size in repo.store.datafiles():
|
|
|
|
if (unencoded.startswith('meta/') and
|
|
|
|
unencoded.endswith('00manifest.i')):
|
|
|
|
dir = unencoded[5:-12]
|
2016-11-10 13:13:19 +03:00
|
|
|
repo.manifestlog._revlog.dirlog(dir).strip(striprev, tr)
|
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:
|
|
|
|
fp.truncate(troffset)
|
2014-03-25 02:43:15 +04:00
|
|
|
if troffset == 0:
|
|
|
|
repo.store.markremoved(file)
|
2010-05-20 04:46:39 +04:00
|
|
|
|
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()
|
2015-01-16 03:51:13 +03:00
|
|
|
if isinstance(gen, bundle2.unbundle20):
|
2016-01-16 00:14:49 +03:00
|
|
|
with repo.transaction('strip') as tr:
|
|
|
|
tr.hookargs = {'source': 'strip',
|
2016-09-19 19:14:35 +03:00
|
|
|
'url': 'bundle:' + vfs.join(tmpbundlefile)}
|
2015-10-20 17:01:33 +03:00
|
|
|
bundle2.applybundle(repo, gen, tr, source='strip',
|
2016-09-19 19:14:35 +03:00
|
|
|
url='bundle:' + vfs.join(tmpbundlefile))
|
2015-01-16 03:51:13 +03:00
|
|
|
else:
|
2016-09-19 19:14:35 +03:00
|
|
|
gen.apply(repo, 'strip', 'bundle:' + vfs.join(tmpbundlefile),
|
|
|
|
True)
|
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
|
|
|
|
2015-12-01 03:38:29 +03:00
|
|
|
for m in updatebm:
|
|
|
|
bm[m] = repo[newbmtarget].node()
|
2017-03-24 06:47:23 +03:00
|
|
|
|
|
|
|
with repo.lock():
|
|
|
|
with repo.transaction('repair') as tr:
|
|
|
|
bm.recordchange(tr)
|
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
|
|
|
|
|
|
|
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)
|
|
|
|
for rev in repo:
|
2016-03-11 15:44:40 +03:00
|
|
|
ui.progress(_('rebuilding'), rev, total=repolen,
|
|
|
|
unit=_('changesets'))
|
2015-06-22 19:59:48 +03:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2016-03-11 15:39:29 +03:00
|
|
|
ui.progress(_('rebuilding'), None)
|
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
|