##// END OF EJS Templates
manifest: avoid corruption by dropping removed files with pure (issue5801)...
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

File last commit:

r34648:dacfcdd8 default
r42569:0546ead3 stable
Show More
scmposix.py
85 lines | 2.4 KiB | text/x-python | PythonLexer
Gregory Szorc
scmposix: use absolute_import
r27483 from __future__ import absolute_import
Yuya Nishihara
scmutil: narrow ImportError handling in termwidth()...
r30311 import array
Yuya Nishihara
scmutil: move util.termwidth()...
r30309 import errno
import fcntl
Gregory Szorc
scmposix: use absolute_import
r27483 import os
import sys
from . import (
Pulkit Goyal
py3: make scmposix.userrcpath() return bytes...
r30276 encoding,
Pulkit Goyal
py3: use pycompat.sysargv in scmposix.systemrcpath()...
r30467 pycompat,
Yuya Nishihara
osutil: proxy through util (and platform) modules (API)...
r32203 util,
Gregory Szorc
scmposix: use absolute_import
r27483 )
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690
Yuya Nishihara
pager: use less as a fallback on Unix...
r32078 # BSD 'more' escapes ANSI color sequences by default. This can be disabled by
# $MORE variable, but there's no compatible option with Linux 'more'. Given
# OS X is widely used and most modern Unix systems would have 'less', setting
# 'less' as the default seems reasonable.
fallbackpager = 'less'
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 def _rcfiles(path):
rcs = [os.path.join(path, 'hgrc')]
rcdir = os.path.join(path, 'hgrc.d')
try:
rcs.extend([os.path.join(rcdir, f)
Yuya Nishihara
osutil: proxy through util (and platform) modules (API)...
r32203 for f, kind in util.listdir(rcdir)
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 if f.endswith(".rc")])
except OSError:
pass
return rcs
def systemrcpath():
path = []
Pulkit Goyal
py3: replace sys.platform with pycompat.sysplatform (part 1 of 2)...
r30641 if pycompat.sysplatform == 'plan9':
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 root = 'lib/mercurial'
else:
root = 'etc/mercurial'
# old mod_python does not set sys.argv
if len(getattr(sys, 'argv', [])) > 0:
Pulkit Goyal
py3: use pycompat.sysargv in scmposix.systemrcpath()...
r30467 p = os.path.dirname(os.path.dirname(pycompat.sysargv[0]))
Mads Kiilerich
config: don't read the same config file twice...
r22583 if p != '/':
path.extend(_rcfiles(os.path.join(p, root)))
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 path.extend(_rcfiles('/' + root))
return path
def userrcpath():
Pulkit Goyal
py3: replace sys.platform with pycompat.sysplatform (part 1 of 2)...
r30641 if pycompat.sysplatform == 'plan9':
Pulkit Goyal
py3: make scmposix.userrcpath() return bytes...
r30276 return [encoding.environ['home'] + '/lib/hgrc']
Jun Wu
codemod: use pycompat.isdarwin...
r34648 elif pycompat.isdarwin:
David Demelier
hg: allow usage of XDG_CONFIG_HOME/hg/hgrc...
r30941 return [os.path.expanduser('~/.hgrc')]
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 else:
David Demelier
hg: allow usage of XDG_CONFIG_HOME/hg/hgrc...
r30941 confighome = encoding.environ.get('XDG_CONFIG_HOME')
if confighome is None or not os.path.isabs(confighome):
confighome = os.path.expanduser('~/.config')
return [os.path.expanduser('~/.hgrc'),
os.path.join(confighome, 'hg', 'hgrc')]
Yuya Nishihara
scmutil: move util.termwidth()...
r30309
Yuya Nishihara
scmutil: extend termwidth() to return terminal height, renamed to termsize()...
r30314 def termsize(ui):
Yuya Nishihara
scmutil: move util.termwidth()...
r30309 try:
import termios
Yuya Nishihara
scmutil: narrow ImportError handling in termwidth()...
r30311 TIOCGWINSZ = termios.TIOCGWINSZ # unavailable on IRIX (issue3449)
except (AttributeError, ImportError):
Yuya Nishihara
scmutil: extend termwidth() to return terminal height, renamed to termsize()...
r30314 return 80, 24
Yuya Nishihara
scmutil: remove superfluous indent from termwidth()
r30312
for dev in (ui.ferr, ui.fout, ui.fin):
try:
Yuya Nishihara
scmutil: move util.termwidth()...
r30309 try:
Yuya Nishihara
scmutil: remove superfluous indent from termwidth()
r30312 fd = dev.fileno()
except AttributeError:
continue
if not os.isatty(fd):
continue
arri = fcntl.ioctl(fd, TIOCGWINSZ, '\0' * 8)
Pulkit Goyal
smcposix: pass unicode as first argument to array.array...
r31339 height, width = array.array(r'h', arri)[:2]
Yuya Nishihara
scmutil: extend termwidth() to return terminal height, renamed to termsize()...
r30314 if width > 0 and height > 0:
return width, height
Yuya Nishihara
scmutil: remove superfluous indent from termwidth()
r30312 except ValueError:
pass
except IOError as e:
if e[0] == errno.EINVAL:
Yuya Nishihara
scmutil: move util.termwidth()...
r30309 pass
Yuya Nishihara
scmutil: remove superfluous indent from termwidth()
r30312 else:
raise
Yuya Nishihara
scmutil: extend termwidth() to return terminal height, renamed to termsize()...
r30314 return 80, 24