##// 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
build.rs
126 lines | 3.4 KiB | application/rls-services+xml | RustLexer
Gregory Szorc
rust: implementation of `hg`...
r35587 // build.rs -- Configure build environment for `hgcli` Rust package.
//
// Copyright 2017 Gregory Szorc <gregory.szorc@gmail.com>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
use std::collections::HashMap;
use std::env;
use std::path::Path;
use std::process::Command;
struct PythonConfig {
python: String,
config: HashMap<String, String>,
}
fn get_python_config() -> PythonConfig {
// The python27-sys crate exports a Cargo variable defining the full
// path to the interpreter being used.
Gregory Szorc
rust: run rustfmt...
r44270 let python = env::var("DEP_PYTHON27_PYTHON_INTERPRETER")
.expect("Missing DEP_PYTHON27_PYTHON_INTERPRETER; bad python27-sys crate?");
Gregory Szorc
rust: implementation of `hg`...
r35587
if !Path::new(&python).exists() {
panic!(
"Python interpreter {} does not exist; this should never happen",
python
);
}
// This is a bit hacky but it gets the job done.
let separator = "SEPARATOR STRING";
let script = "import sysconfig; \
Gregory Szorc
rust: run rustfmt...
r44270 c = sysconfig.get_config_vars(); \
print('SEPARATOR STRING'.join('%s=%s' % i for i in c.items()))";
Gregory Szorc
rust: implementation of `hg`...
r35587
let mut command = Command::new(&python);
command.arg("-c").arg(script);
let out = command.output().unwrap();
if !out.status.success() {
panic!(
"python script failed: {}",
String::from_utf8_lossy(&out.stderr)
);
}
let stdout = String::from_utf8_lossy(&out.stdout);
let mut m = HashMap::new();
for entry in stdout.split(separator) {
let mut parts = entry.splitn(2, "=");
let key = parts.next().unwrap();
let value = parts.next().unwrap();
m.insert(String::from(key), String::from(value));
}
PythonConfig {
python: python,
config: m,
}
}
#[cfg(not(target_os = "windows"))]
fn have_shared(config: &PythonConfig) -> bool {
match config.config.get("Py_ENABLE_SHARED") {
Some(value) => value == "1",
None => false,
}
}
#[cfg(target_os = "windows")]
fn have_shared(config: &PythonConfig) -> bool {
Gregory Szorc
rust: move import of PathBuf...
r35621 use std::path::PathBuf;
Gregory Szorc
rust: implementation of `hg`...
r35587 // python27.dll should exist next to python2.7.exe.
let mut dll = PathBuf::from(&config.python);
dll.pop();
dll.push("python27.dll");
return dll.exists();
}
Gregory Szorc
rust: avoid redundant 'static lifetime...
r35625 const REQUIRED_CONFIG_FLAGS: [&str; 2] = ["Py_USING_UNICODE", "WITH_THREAD"];
Gregory Szorc
rust: implementation of `hg`...
r35587
fn main() {
let config = get_python_config();
println!("Using Python: {}", config.python);
println!("cargo:rustc-env=PYTHON_INTERPRETER={}", config.python);
let prefix = config.config.get("prefix").unwrap();
println!("Prefix: {}", prefix);
// TODO Windows builds don't expose these config flags. Figure out another
// way.
#[cfg(not(target_os = "windows"))]
for key in REQUIRED_CONFIG_FLAGS.iter() {
let result = match config.config.get(*key) {
Some(value) => value == "1",
None => false,
};
if !result {
panic!("Detected Python requires feature {}", key);
}
}
// We need a Python shared library.
if !have_shared(&config) {
panic!("Detected Python lacks a shared library, which is required");
}
let ucs4 = match config.config.get("Py_UNICODE_SIZE") {
Some(value) => value == "4",
None => false,
};
if !ucs4 {
#[cfg(not(target_os = "windows"))]
panic!("Detected Python doesn't support UCS-4 code points");
}
}