##// END OF EJS Templates
largefiles: properly pass kwargs into url.open...
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.

File last commit:

r46195:426294d0 default
r47202:32da5891 stable
Show More
uihandler.rs
94 lines | 2.7 KiB | application/rls-services+xml | RustLexer
// Copyright 2018 Yuya Nishihara <yuya@tcha.org>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
use async_trait::async_trait;
use std::io;
use std::os::unix::io::AsRawFd;
use std::os::unix::process::ExitStatusExt;
use std::process::Stdio;
use tokio;
use tokio::process::{Child, ChildStdin, Command};
use crate::message::CommandSpec;
use crate::procutil;
/// Callback to process shell command requests received from server.
#[async_trait]
pub trait SystemHandler {
type PagerStdin: AsRawFd;
/// Handles pager command request.
///
/// Returns the pipe to be attached to the server if the pager is spawned.
async fn spawn_pager(
&mut self,
spec: &CommandSpec,
) -> io::Result<Self::PagerStdin>;
/// Handles system command request.
///
/// Returns command exit code (positive) or signal number (negative).
async fn run_system(&mut self, spec: &CommandSpec) -> io::Result<i32>;
}
/// Default cHg implementation to process requests received from server.
pub struct ChgUiHandler {
pager: Option<Child>,
}
impl ChgUiHandler {
pub fn new() -> ChgUiHandler {
ChgUiHandler { pager: None }
}
/// Waits until the pager process exits.
pub async fn wait_pager(&mut self) -> io::Result<()> {
if let Some(p) = self.pager.take() {
p.await?;
}
Ok(())
}
}
#[async_trait]
impl SystemHandler for ChgUiHandler {
type PagerStdin = ChildStdin;
async fn spawn_pager(
&mut self,
spec: &CommandSpec,
) -> io::Result<Self::PagerStdin> {
let mut pager =
new_shell_command(&spec).stdin(Stdio::piped()).spawn()?;
let pin = pager.stdin.take().unwrap();
procutil::set_blocking_fd(pin.as_raw_fd())?;
// TODO: if pager exits, notify the server with SIGPIPE immediately.
// otherwise the server won't get SIGPIPE if it does not write
// anything. (issue5278)
// kill(peerpid, SIGPIPE);
self.pager = Some(pager);
Ok(pin)
}
async fn run_system(&mut self, spec: &CommandSpec) -> io::Result<i32> {
let status = new_shell_command(&spec).spawn()?.await?;
let code = status
.code()
.or_else(|| status.signal().map(|n| -n))
.expect("either exit code or signal should be set");
Ok(code)
}
}
fn new_shell_command(spec: &CommandSpec) -> Command {
let mut builder = Command::new("/bin/sh");
builder
.arg("-c")
.arg(&spec.command)
.current_dir(&spec.current_dir)
.env_clear()
.envs(spec.envs.iter().cloned());
builder
}