lfs: verify lfs object content when transferring to and from the remote store
This avoids inserting corrupt files into the usercache, and local and remote
stores. One down side is that the bad file won't be available locally for
forensic purposes after a remote download. I'm thinking about adding an
'incoming' directory to the local lfs store to handle the download, and then
move it to the 'objects' directory after it passes verification. That would
have the additional benefit of not concatenating each transfer chunk in memory
until the full file is transferred.
Verification isn't needed when the data is passed back through the revlog
interface or when the oid was just calculated, but otherwise it is on by
default. The additional overhead should be well worth avoiding problems with
file based remote stores, or buggy lfs servers.
Having two different verify functions is a little sad, but the full data of the
blob is mostly passed around in memory, because that's what the revlog interface
wants. The upload function, however, chunks up the data. It would be ideal if
that was how the content is always handled, but that's probably a huge project.
I don't really like printing the long hash, but `hg debugdata` isn't a public
interface, and is the only way to get it. The filelog and revision info is
nowhere near this area, so recommending `hg verify` is the easiest thing to do.
#!/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,
simplemerge,
ui as uimod,
util,
)
options = [('L', 'label', [], _('labels to use on conflict markers')),
('a', 'text', None, _('treat all files as text')),
('p', 'print', None,
_('print results instead of overwriting LOCAL')),
('', 'no-minimal', None, _('no effect (DEPRECATED)')),
('h', 'help', None, _('display help and exit')),
('q', 'quiet', None, _('suppress output'))]
usage = _('''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():
sys.stdout.write(usage)
sys.stdout.write('\noptions:\n')
out_opts = []
for shortopt, longopt, default, desc in options:
out_opts.append(('%2s%s' % (shortopt and '-%s' % shortopt,
longopt and ' --%s' % longopt),
'%s' % desc))
opts_len = max([len(opt[0]) for opt in out_opts])
for first, second in out_opts:
sys.stdout.write(' %-*s %s\n' % (opts_len, first, second))
try:
for fp in (sys.stdin, sys.stdout, sys.stderr):
util.setbinary(fp)
opts = {}
try:
args = fancyopts.fancyopts(sys.argv[1:], options, opts)
except getopt.GetoptError as e:
raise ParseError(e)
if opts['help']:
showhelp()
sys.exit(0)
if len(args) != 3:
raise ParseError(_('wrong number of arguments'))
local, base, other = args
sys.exit(simplemerge.simplemerge(uimod.ui.load(),
context.arbitraryfilectx(local),
context.arbitraryfilectx(base),
context.arbitraryfilectx(other),
**opts))
except ParseError as e:
sys.stdout.write("%s: %s\n" % (sys.argv[0], e))
showhelp()
sys.exit(1)
except error.Abort as e:
sys.stderr.write("abort: %s\n" % e)
sys.exit(255)
except KeyboardInterrupt:
sys.exit(255)