Mercurial > hg
view contrib/simplemerge @ 42377:0546ead39a7e stable
manifest: avoid corruption by dropping removed files with pure (issue5801)
Previously, removed files would simply be marked by overwriting the first byte
with NUL and dropping their entry in `self.position`. But no effort was made to
ignore them when compacting the dictionary into text form. This allowed them to
slip into the manifest revision, since the code seems to be trying to minimize
the string operations by copying as large a chunk as possible. As part of this,
compact() walks the existing text based on entries in the `positions` list, and
consumed everything up to the next position entry. This typically resulted in
a ValueError complaining about unsorted manifest entries.
Sometimes it seems that files do get dropped in large repos- it seems to
correspond to there being a new entry that would take the same slot. A much
more trivial problem is that if the only changes were removals, `_compact()`
didn't even run because `__delitem__` doesn't add anything to `self.extradata`.
Now there's an explicit variable to flag this, both to allow `_compact()` to
run, and to avoid searching the manifest in cases where there are no removals.
In practice, this behavior was mostly obscured by the check in fastdelta() which
takes a different path that explicitly drops removed files if there are fewer
than 1000 changes. However, timeless has a repo where after rebasing tens of
commits, a totally different path[1] is taken that bypasses the change count
check and hits this problem.
[1] https://www.mercurial-scm.org/repo/hg/file/2338bdea4474/mercurial/manifest.py#l1511
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 23 May 2019 21:54:24 -0400 |
parents | d6b7c4e77bb4 |
children | 3c2799cbace4 |
line wrap: on
line source
#!/usr/bin/env python from __future__ import absolute_import import getopt import sys import hgdemandimport hgdemandimport.enable() from mercurial.i18n import _ from mercurial import ( context, error, fancyopts, pycompat, simplemerge, ui as uimod, ) from mercurial.utils import ( procutil, ) options = [(b'L', b'label', [], _(b'labels to use on conflict markers')), (b'a', b'text', None, _(b'treat all files as text')), (b'p', b'print', None, _(b'print results instead of overwriting LOCAL')), (b'', b'no-minimal', None, _(b'no effect (DEPRECATED)')), (b'h', b'help', None, _(b'display help and exit')), (b'q', b'quiet', None, _(b'suppress output'))] usage = _(b'''simplemerge [OPTS] LOCAL BASE OTHER Simple three-way file merge utility with a minimal feature set. Apply to LOCAL the changes necessary to go from BASE to OTHER. By default, LOCAL is overwritten with the results of this operation. ''') class ParseError(Exception): """Exception raised on errors in parsing the command line.""" def showhelp(): pycompat.stdout.write(usage) pycompat.stdout.write(b'\noptions:\n') out_opts = [] for shortopt, longopt, default, desc in options: out_opts.append((b'%2s%s' % (shortopt and b'-%s' % shortopt, longopt and b' --%s' % longopt), b'%s' % desc)) opts_len = max([len(opt[0]) for opt in out_opts]) for first, second in out_opts: pycompat.stdout.write(b' %-*s %s\n' % (opts_len, first, second)) try: for fp in (sys.stdin, pycompat.stdout, sys.stderr): procutil.setbinary(fp) opts = {} try: bargv = [a.encode('utf8') for a in sys.argv[1:]] args = fancyopts.fancyopts(bargv, options, opts) except getopt.GetoptError as e: raise ParseError(e) if opts[b'help']: showhelp() sys.exit(0) if len(args) != 3: raise ParseError(_(b'wrong number of arguments').decode('utf8')) local, base, other = args sys.exit(simplemerge.simplemerge(uimod.ui.load(), context.arbitraryfilectx(local), context.arbitraryfilectx(base), context.arbitraryfilectx(other), **pycompat.strkwargs(opts))) except ParseError as e: if pycompat.ispy3: e = str(e).encode('utf8') pycompat.stdout.write(b"%s: %s\n" % (sys.argv[0].encode('utf8'), e)) showhelp() sys.exit(1) except error.Abort as e: pycompat.stderr.write(b"abort: %s\n" % e) sys.exit(255) except KeyboardInterrupt: sys.exit(255)