Re: [PATCH] largefiles: properly pass kwargs into url.open

2021-02-05 Thread Yuya Nishihara
On Thu, 04 Feb 2021 17:06:09 -0500, Jordi Gutiérrez Hermoso wrote:
> # HG changeset patch
> # User Jordi Gutiérrez Hermoso 
> # Date 1612475986 18000
> #  Thu Feb 04 16:59:46 2021 -0500
> # Node ID fee215d5eb63abf93c50de4355fbd46123f50cba
> # Parent  95b276283b671cd835a2a0918f4297eb2baab425
> largefiles: properly pass kwargs into url.open

Queued for stable, thanks.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH] largefiles: properly pass kwargs into url.open

2021-02-04 Thread Jordi Gutiérrez Hermoso
# HG changeset patch
# User Jordi Gutiérrez Hermoso 
# Date 1612475986 18000
#  Thu Feb 04 16:59:46 2021 -0500
# Node ID fee215d5eb63abf93c50de4355fbd46123f50cba
# Parent  95b276283b671cd835a2a0918f4297eb2baab425
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 
  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 
  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.

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -1853,7 +1853,7 @@ def upgraderequirements(orig, repo):
 
 
 @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 @@ def openlargefile(orig, ui, url_, data=N
 lfid = url_[len(_lfscheme) :]
 return storefactory.getlfile(ui, lfid)
 else:
-return orig(ui, url_, data=data)
+return orig(ui, url_, data=data, **kwargs)
diff --git a/tests/test-hgweb-diffs.t b/tests/test-hgweb-diffs.t
--- a/tests/test-hgweb-diffs.t
+++ b/tests/test-hgweb-diffs.t
@@ -1138,6 +1138,21 @@ test import rev as raw-rev
   $ 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
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel