##// END OF EJS Templates
exchange: ensure all outgoing subrepo references are present before pushing...
exchange: ensure all outgoing subrepo references are present before pushing We've run into occasional problems with people committing a repo, and then amending or rebasing in the subrepo. That makes it so that the revision in the parent can't be checked out, and the problem gets propagated on push. Mercurial already tries to defend against this sort of dangling reference by pushing *all* subrepo revisions first. This reuses the checks that trigger warnings in `hg verify` to bail on the push unless using `--force`. I thought about putting this on the server side, but at that point, all of the data has been transferred, only to bail out. Additionally, SCM Manager hosts subrepos in a location that isn't nested in the parent, so normal subrepo code would complain that the subrepo is missing when run on the server. Because the push command pushes subrepos before calling this exchange code, a subrepo will be pushed before the parent is verified. Not great, but no dangling references are exchanged, so it solves the problem. This code isn't in the loop that pushes the subrepos because: 1) the list of outgoing revisions is needed to limit the scope of the check 2) the loop only accesses the current revision, and therefore can miss subrepos that were dropped in previous commits 3) this code is called when pushing a subrepo, so the protection is recursive I'm not sure if there's a cheap check for the list of files in the outgoing bundle. If there is, that would provide a fast path to bypass this check for people not using subrepos (or if no subrepo changes were made). There's probably also room for verifying other references like tags. But since that doesn't break checkouts, it's much less of a problem. Differential Revision: https://phab.mercurial-scm.org/D7616

File last commit:

r44270:ce088b38 default
r44365:4b7d5d10 default
Show More
filepatterns.rs
133 lines | 4.2 KiB | application/rls-services+xml | RustLexer
Raphaël Gomès
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`...
r42515 // filepatterns.rs
//
// Copyright 2019, Georges Racinet <gracinet@anybox.fr>,
// Raphaël Gomès <rgomes@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.
//! Bindings for the `hg::filepatterns` module provided by the
//! `hg-core` crate. From Python, this will be seen as `rustext.filepatterns`
Yuya Nishihara
rust: apply more formatting fixes...
r43109 //! and can be used as replacement for the the pure `filepatterns` Python
//! module.
Raphaël Gomès
rust: switch hg-core and hg-cpython to rust 2018 edition...
r42828 use crate::exceptions::{PatternError, PatternFileError};
Raphaël Gomès
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`...
r42515 use cpython::{
Raphaël Gomès
py3: send bytes from Rust-created warning patterns...
r44096 PyBytes, PyDict, PyModule, PyObject, PyResult, PyTuple, Python, ToPyObject,
Raphaël Gomès
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`...
r42515 };
Yuya Nishihara
rust-cpython: import utils::files::* function at module level...
r44210 use hg::utils::files;
use hg::{build_single_regex, read_pattern_file, LineNumber, PatternTuple};
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 use std::path::PathBuf;
Raphaël Gomès
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`...
r42515
/// Rust does not like functions with different return signatures.
/// The 3-tuple version is always returned by the hg-core function,
/// the (potential) conversion is handled at this level since it is not likely
/// to have any measurable impact on performance.
///
/// The Python implementation passes a function reference for `warn` instead
/// of a boolean that is used to emit warnings while parsing. The Rust
/// implementation chooses to accumulate the warnings and propagate them to
/// Python upon completion. See the `readpatternfile` function in `match.py`
/// for more details.
fn read_pattern_file_wrapper(
py: Python,
Raphaël Gomès
rust-filepatterns: use bytes instead of String...
r42630 file_path: PyObject,
Raphaël Gomès
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`...
r42515 warn: bool,
source_info: bool,
) -> PyResult<PyTuple> {
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 let bytes = file_path.extract::<PyBytes>(py)?;
Yuya Nishihara
rust-cpython: import utils::files::* function at module level...
r44210 let path = files::get_path_from_bytes(bytes.data(py));
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 match read_pattern_file(path, warn) {
Raphaël Gomès
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`...
r42515 Ok((patterns, warnings)) => {
if source_info {
Raphaël Gomès
rust-filepatterns: use bytes instead of String...
r42630 let itemgetter = |x: &PatternTuple| {
(PyBytes::new(py, &x.0), x.1, PyBytes::new(py, &x.2))
};
let results: Vec<(PyBytes, LineNumber, PyBytes)> =
patterns.iter().map(itemgetter).collect();
Yuya Nishihara
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)...
r42857 return Ok((results, warnings_to_py_bytes(py, &warnings))
.to_py_object(py));
Raphaël Gomès
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`...
r42515 }
Raphaël Gomès
rust-filepatterns: use bytes instead of String...
r42630 let itemgetter = |x: &PatternTuple| PyBytes::new(py, &x.0);
let results: Vec<PyBytes> =
Raphaël Gomès
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`...
r42515 patterns.iter().map(itemgetter).collect();
Yuya Nishihara
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)...
r42857 Ok(
(results, warnings_to_py_bytes(py, &warnings))
.to_py_object(py),
)
Raphaël Gomès
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`...
r42515 }
Err(e) => Err(PatternFileError::pynew(py, e)),
}
}
Yuya Nishihara
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)...
r42857 fn warnings_to_py_bytes(
py: Python,
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 warnings: &[(PathBuf, Vec<u8>)],
Raphaël Gomès
py3: send bytes from Rust-created warning patterns...
r44096 ) -> Vec<(PyBytes, PyBytes)> {
Yuya Nishihara
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)...
r42857 warnings
.iter()
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 .map(|(path, syn)| {
(
Yuya Nishihara
rust-cpython: do not convert warning pattern to utf-8 bytes...
r44211 PyBytes::new(py, &files::get_bytes_from_path(path)),
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 PyBytes::new(py, syn),
)
})
Yuya Nishihara
rust-filepatterns: fix type of warnings tuple to (bytes, bytes)...
r42857 .collect()
}
Raphaël Gomès
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`...
r42515 fn build_single_regex_wrapper(
py: Python,
Raphaël Gomès
rust-filepatterns: use bytes instead of String...
r42630 kind: PyObject,
pat: PyObject,
globsuffix: PyObject,
) -> PyResult<PyBytes> {
Raphaël Gomès
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`...
r42515 match build_single_regex(
Raphaël Gomès
rust-filepatterns: use bytes instead of String...
r42630 kind.extract::<PyBytes>(py)?.data(py),
pat.extract::<PyBytes>(py)?.data(py),
globsuffix.extract::<PyBytes>(py)?.data(py),
Raphaël Gomès
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`...
r42515 ) {
Raphaël Gomès
rust-filepatterns: use bytes instead of String...
r42630 Ok(regex) => Ok(PyBytes::new(py, &regex)),
Raphaël Gomès
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`...
r42515 Err(e) => Err(PatternError::pynew(py, e)),
}
}
pub fn init_module(py: Python, package: &str) -> PyResult<PyModule> {
let dotted_name = &format!("{}.filepatterns", package);
let m = PyModule::new(py, dotted_name)?;
m.add(py, "__package__", package)?;
m.add(
py,
"__doc__",
"Patterns files parsing - Rust implementation",
)?;
m.add(
py,
"build_single_regex",
py_fn!(
py,
build_single_regex_wrapper(
Raphaël Gomès
rust-filepatterns: use bytes instead of String...
r42630 kind: PyObject,
pat: PyObject,
globsuffix: PyObject
Raphaël Gomès
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`...
r42515 )
),
)?;
m.add(
py,
"read_pattern_file",
py_fn!(
py,
read_pattern_file_wrapper(
Raphaël Gomès
rust-filepatterns: use bytes instead of String...
r42630 file_path: PyObject,
Raphaël Gomès
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`...
r42515 warn: bool,
source_info: bool
)
),
)?;
Raphaël Gomès
rust-filepatterns: use bytes instead of String...
r42630 m.add(py, "PatternError", py.get_type::<PatternError>())?;
Raphaël Gomès
rust-filepatterns: add `rust-cpython` bindings for `filepatterns`...
r42515 let sys = PyModule::import(py, "sys")?;
let sys_modules: PyDict = sys.get(py, "modules")?.extract(py)?;
sys_modules.set_item(py, dotted_name, &m)?;
Ok(m)
}