##// 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:

r47163:3e2d539d default
r47202:32da5891 stable
Show More
find_root.rs
100 lines | 2.7 KiB | application/rls-services+xml | RustLexer
use std::fmt;
use std::path::{Path, PathBuf};
/// Kind of error encoutered by FindRoot
#[derive(Debug)]
pub enum FindRootErrorKind {
/// Root of the repository has not been found
/// Contains the current directory used by FindRoot
RootNotFound(PathBuf),
/// The current directory does not exists or permissions are insufficient
/// to get access to it
GetCurrentDirError(std::io::Error),
}
/// A FindRoot error
#[derive(Debug)]
pub struct FindRootError {
/// Kind of error encoutered by FindRoot
pub kind: FindRootErrorKind,
}
impl std::error::Error for FindRootError {}
impl fmt::Display for FindRootError {
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
unimplemented!()
}
}
/// Find the root of the repository
/// by searching for a .hg directory in the process’ current directory and its
/// ancestors
pub fn find_root() -> Result<PathBuf, FindRootError> {
let current_dir = std::env::current_dir().map_err(|e| FindRootError {
kind: FindRootErrorKind::GetCurrentDirError(e),
})?;
Ok(find_root_from_path(&current_dir)?.into())
}
/// Find the root of the repository
/// by searching for a .hg directory in the given directory and its ancestors
pub fn find_root_from_path(start: &Path) -> Result<&Path, FindRootError> {
if start.join(".hg").exists() {
return Ok(start);
}
for ancestor in start.ancestors() {
if ancestor.join(".hg").exists() {
return Ok(ancestor);
}
}
Err(FindRootError {
kind: FindRootErrorKind::RootNotFound(start.into()),
})
}
#[cfg(test)]
mod tests {
use super::*;
use std::fs;
use tempfile;
#[test]
fn dot_hg_not_found() {
let tmp_dir = tempfile::tempdir().unwrap();
let path = tmp_dir.path();
let err = find_root_from_path(&path).unwrap_err();
// TODO do something better
assert!(match err {
FindRootError { kind } => match kind {
FindRootErrorKind::RootNotFound(p) => p == path.to_path_buf(),
_ => false,
},
})
}
#[test]
fn dot_hg_in_current_path() {
let tmp_dir = tempfile::tempdir().unwrap();
let root = tmp_dir.path();
fs::create_dir_all(root.join(".hg")).unwrap();
let result = find_root_from_path(&root).unwrap();
assert_eq!(result, root)
}
#[test]
fn dot_hg_in_parent() {
let tmp_dir = tempfile::tempdir().unwrap();
let root = tmp_dir.path();
fs::create_dir_all(root.join(".hg")).unwrap();
let directory = root.join("some/nested/directory");
let result = find_root_from_path(&directory).unwrap();
assert_eq!(result, root)
}
} /* tests */