largefiles: properly pass kwargs into url.open stable
authorJordi Gutiérrez Hermoso <jordigh@octave.org>
Thu, 04 Feb 2021 16:59:46 -0500
branchstable
changeset 46464 32da58916fd0
parent 46459 128a17d8436f
child 46474 dd926ce1de28
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.
hgext/largefiles/overrides.py
tests/test-hgweb-diffs.t
--- a/hgext/largefiles/overrides.py	Thu Feb 04 19:56:45 2021 +0900
+++ b/hgext/largefiles/overrides.py	Thu Feb 04 16:59:46 2021 -0500
@@ -1853,7 +1853,7 @@
 
 
 @eh.wrapfunction(urlmod, b'open')
-def openlargefile(orig, ui, url_, data=None):
+def openlargefile(orig, ui, url_, data=None, **kwargs):
     if url_.startswith(_lfscheme):
         if data:
             msg = b"cannot use data on a 'largefile://' url"
@@ -1861,4 +1861,4 @@
         lfid = url_[len(_lfscheme) :]
         return storefactory.getlfile(ui, lfid)
     else:
-        return orig(ui, url_, data=data)
+        return orig(ui, url_, data=data, **kwargs)
--- a/tests/test-hgweb-diffs.t	Thu Feb 04 19:56:45 2021 +0900
+++ b/tests/test-hgweb-diffs.t	Thu Feb 04 16:59:46 2021 -0500
@@ -1138,6 +1138,21 @@
   $ cd test1
   $ hg import -q --bypass --exact http://localhost:$HGPORT/rev/1
 
+repeat test above, with largefiles enabled
+
+  $ cd ..
+  $ rm -r test1
+  $ hg clone -r0 test test1
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 2 changes to 2 files
+  new changesets 0cd96de13884
+  updating to branch default
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd test1
+  $ hg import --config extensions.largefiles= -q --bypass --exact http://localhost:$HGPORT/rev/1
+
 raw revision with diff block numbers
 
   $ killdaemons.py