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

r47172:43d63979 default
r47202:32da5891 stable
Show More
list_tracked_files.rs
165 lines | 5.2 KiB | application/rls-services+xml | RustLexer
// list_tracked_files.rs
//
// Copyright 2020 Antoine Cezar <antoine.cezar@octobus.net>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
use crate::dirstate::parsers::parse_dirstate;
use crate::repo::Repo;
use crate::revlog::changelog::Changelog;
use crate::revlog::manifest::{Manifest, ManifestEntry};
use crate::revlog::node::{Node, NodePrefix};
use crate::revlog::revlog::RevlogError;
use crate::revlog::Revision;
use crate::utils::hg_path::HgPath;
use crate::{DirstateParseError, EntryState};
use rayon::prelude::*;
use std::convert::From;
/// Kind of error encountered by `ListDirstateTrackedFiles`
#[derive(Debug)]
pub enum ListDirstateTrackedFilesErrorKind {
/// Error when reading the `dirstate` file
IoError(std::io::Error),
/// Error when parsing the `dirstate` file
ParseError(DirstateParseError),
}
/// A `ListDirstateTrackedFiles` error
#[derive(Debug)]
pub struct ListDirstateTrackedFilesError {
/// Kind of error encountered by `ListDirstateTrackedFiles`
pub kind: ListDirstateTrackedFilesErrorKind,
}
impl From<ListDirstateTrackedFilesErrorKind>
for ListDirstateTrackedFilesError
{
fn from(kind: ListDirstateTrackedFilesErrorKind) -> Self {
ListDirstateTrackedFilesError { kind }
}
}
impl From<std::io::Error> for ListDirstateTrackedFilesError {
fn from(err: std::io::Error) -> Self {
let kind = ListDirstateTrackedFilesErrorKind::IoError(err);
ListDirstateTrackedFilesError { kind }
}
}
/// List files under Mercurial control in the working directory
/// by reading the dirstate
pub struct Dirstate {
/// The `dirstate` content.
content: Vec<u8>,
}
impl Dirstate {
pub fn new(repo: &Repo) -> Result<Self, ListDirstateTrackedFilesError> {
let content = repo.hg_vfs().read("dirstate")?;
Ok(Self { content })
}
pub fn tracked_files(
&self,
) -> Result<Vec<&HgPath>, ListDirstateTrackedFilesError> {
let (_, entries, _) = parse_dirstate(&self.content)
.map_err(ListDirstateTrackedFilesErrorKind::ParseError)?;
let mut files: Vec<&HgPath> = entries
.into_iter()
.filter_map(|(path, entry)| match entry.state {
EntryState::Removed => None,
_ => Some(path),
})
.collect();
files.par_sort_unstable();
Ok(files)
}
}
/// Kind of error encountered by `ListRevTrackedFiles`
#[derive(Debug)]
pub enum ListRevTrackedFilesErrorKind {
/// Error when reading a `revlog` file.
IoError(std::io::Error),
/// The revision has not been found.
InvalidRevision,
/// Found more than one revision whose ID match the requested prefix
AmbiguousPrefix,
/// A `revlog` file is corrupted.
CorruptedRevlog,
/// The `revlog` format version is not supported.
UnsuportedRevlogVersion(u16),
/// The `revlog` data format is not supported.
UnknowRevlogDataFormat(u8),
}
/// A `ListRevTrackedFiles` error
#[derive(Debug)]
pub struct ListRevTrackedFilesError {
/// Kind of error encountered by `ListRevTrackedFiles`
pub kind: ListRevTrackedFilesErrorKind,
}
impl From<ListRevTrackedFilesErrorKind> for ListRevTrackedFilesError {
fn from(kind: ListRevTrackedFilesErrorKind) -> Self {
ListRevTrackedFilesError { kind }
}
}
impl From<RevlogError> for ListRevTrackedFilesError {
fn from(err: RevlogError) -> Self {
match err {
RevlogError::IoError(err) => {
ListRevTrackedFilesErrorKind::IoError(err)
}
RevlogError::UnsuportedVersion(version) => {
ListRevTrackedFilesErrorKind::UnsuportedRevlogVersion(version)
}
RevlogError::InvalidRevision => {
ListRevTrackedFilesErrorKind::InvalidRevision
}
RevlogError::AmbiguousPrefix => {
ListRevTrackedFilesErrorKind::AmbiguousPrefix
}
RevlogError::Corrupted => {
ListRevTrackedFilesErrorKind::CorruptedRevlog
}
RevlogError::UnknowDataFormat(format) => {
ListRevTrackedFilesErrorKind::UnknowRevlogDataFormat(format)
}
}
.into()
}
}
/// List files under Mercurial control at a given revision.
pub fn list_rev_tracked_files(
repo: &Repo,
rev: &str,
) -> Result<FilesForRev, ListRevTrackedFilesError> {
let changelog = Changelog::open(repo)?;
let manifest = Manifest::open(repo)?;
let changelog_entry = match rev.parse::<Revision>() {
Ok(rev) => changelog.get_rev(rev)?,
_ => {
let changelog_node = NodePrefix::from_hex(&rev)
.or(Err(ListRevTrackedFilesErrorKind::InvalidRevision))?;
changelog.get_node(changelog_node.borrow())?
}
};
let manifest_node = Node::from_hex(&changelog_entry.manifest_node()?)
.or(Err(ListRevTrackedFilesErrorKind::CorruptedRevlog))?;
let manifest_entry = manifest.get_node((&manifest_node).into())?;
Ok(FilesForRev(manifest_entry))
}
pub struct FilesForRev(ManifestEntry);
impl FilesForRev {
pub fn iter(&self) -> impl Iterator<Item = &HgPath> {
self.0.files()
}
}