largefiles: properly pass kwargs into url.open
The url.open function has acquired a lot of kwargs over the years.
When running `hg import http://example.com/hg/diff/1`, since at least
a708e1e4d7a8 in March, 2018, the calling sites for url.open try to
pass a `sendaccept` parameter that largefiles' override doesn't accept.
Currently that stack traces something like this:
Traceback (most recent call last):
File "/tmp/hgtests.sv744r5t/install/bin/hg", line 59, in <module>
dispatch.run()
File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 143, in run
status = dispatch(req)
File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 245, in dispatch
status = _rundispatch(req)
File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 289, in _rundispatch
ret = _runcatch(req) or 0
File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 465, in _runcatch
return _callcatch(ui, _runcatchfunc)
File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 475, in _callcatch
return scmutil.callcatch(ui, func)
File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/scmutil.py", line 155, in callcatch
return func()
File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 455, in _runcatchfunc
return _dispatch(req)
File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 1259, in _dispatch
lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions
File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 913, in runcommand
ret = _runcommand(ui, options, cmd, d)
File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 1270, in _runcommand
return cmdfunc()
File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/dispatch.py", line 1256, in <lambda>
d = lambda: util.checksignature(func)(ui, *args, **strcmdopt)
File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/util.py", line 1867, in check
return func(*args, **kwargs)
File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/commands.py", line 4184, in import_
patchfile = hg.openpath(ui, patchurl, sendaccept=False)
File "/tmp/hgtests.sv744r5t/install/lib/python/mercurial/hg.py", line 181, in openpath
return url.open(ui, path, sendaccept=sendaccept)
TypeError: openlargefile() got an unexpected keyword argument 'sendaccept'
So, just accept and pass along any kwargs of the overridden function.
from __future__ import absolute_import, print_function
# Import something from Mercurial, so the module loader gets initialized.
from mercurial import pycompat
del pycompat # unused for now
from hgext.lfs import pointer
def tryparse(text):
r = {}
try:
r = pointer.deserialize(text)
print('ok')
except Exception as ex:
print((b'%s' % ex).decode('ascii'))
if r:
text2 = r.serialize()
if text2 != text:
print('reconstructed text differs')
return r
t = (
b'version https://git-lfs.github.com/spec/v1\n'
b'oid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1'
b'258daaa5e2ca24d17e2393\n'
b'size 12345\n'
b'x-foo extra-information\n'
)
tryparse(b'')
tryparse(t)
tryparse(t.replace(b'git-lfs', b'unknown'))
tryparse(t.replace(b'v1\n', b'v1\n\n'))
tryparse(t.replace(b'sha256', b'ahs256'))
tryparse(t.replace(b'sha256:', b''))
tryparse(t.replace(b'12345', b'0x12345'))
tryparse(t.replace(b'extra-information', b'extra\0information'))
tryparse(t.replace(b'extra-information', b'extra\ninformation'))
tryparse(t.replace(b'x-foo', b'x_foo'))
tryparse(t.replace(b'oid', b'blobid'))
tryparse(t.replace(b'size', b'size-bytes').replace(b'oid', b'object-id'))