Skip to content

Commit

Permalink
Revert "Auto merge of #130121 - lolbinarycat:bootstrap-warn-old-upstr…
Browse files Browse the repository at this point in the history
…eam-worktree, r=albertlarsan68"

This reverts commit 507c05b, reversing
changes made to 0609062.
  • Loading branch information
onur-ozkan committed Oct 6, 2024
1 parent 96d9d8a commit dd0bcf5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 47 deletions.
10 changes: 9 additions & 1 deletion src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,5 +383,13 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
cmd_finder.must_have(s);
}

warn_old_master_branch(&build.config.git_config(), &build.config.src);
// this warning is useless in CI,
// and CI probably won't have the right branches anyway.
if !build_helper::ci::CiEnv::is_ci() {
if let Err(e) = warn_old_master_branch(&build.config.git_config(), &build.config.src)
.map_err(|e| e.to_string())
{
eprintln!("unable to check if upstream branch is old: {e}");
}
}
}
62 changes: 16 additions & 46 deletions src/tools/build_helper/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,59 +204,29 @@ pub fn get_git_untracked_files(
///
/// This can result in formatting thousands of files instead of a dozen,
/// so we should warn the user something is wrong.
pub fn warn_old_master_branch(config: &GitConfig<'_>, git_dir: &Path) {
if crate::ci::CiEnv::is_ci() {
// this warning is useless in CI,
// and CI probably won't have the right branches anyway.
return;
}
// this will be overwritten by the actual name, if possible
let mut updated_master = "the upstream master branch".to_string();
match warn_old_master_branch_(config, git_dir, &mut updated_master) {
Ok(branch_is_old) => {
if !branch_is_old {
return;
pub fn warn_old_master_branch(
config: &GitConfig<'_>,
git_dir: &Path,
) -> Result<(), Box<dyn std::error::Error>> {
use std::time::Duration;
const WARN_AFTER: Duration = Duration::from_secs(60 * 60 * 24 * 10);
let updated_master = updated_master_branch(config, Some(git_dir))?;
let branch_path = git_dir.join(".git/refs/remotes").join(&updated_master);
match std::fs::metadata(branch_path) {
Ok(meta) => {
if meta.modified()?.elapsed()? > WARN_AFTER {
eprintln!("warning: {updated_master} has not been updated in 10 days");
} else {
return Ok(());
}
// otherwise fall through and print the rest of the warning
}
Err(err) => {
eprintln!("warning: unable to check if {updated_master} is old due to error: {err}")
}
}
eprintln!(
"warning: {updated_master} is used to determine if files have been modified\n\
warning: if it is not updated, this may cause files to be needlessly reformatted"
warning: if it is not updated, this may cause files to be needlessly reformatted"
);
}

pub fn warn_old_master_branch_(
config: &GitConfig<'_>,
git_dir: &Path,
updated_master: &mut String,
) -> Result<bool, Box<dyn std::error::Error>> {
use std::time::Duration;
*updated_master = updated_master_branch(config, Some(git_dir))?;
let branch_path = git_dir.join(".git/refs/remotes").join(&updated_master);
const WARN_AFTER: Duration = Duration::from_secs(60 * 60 * 24 * 10);
let meta = match std::fs::metadata(&branch_path) {
Ok(meta) => meta,
Err(err) => {
let gcd = git_common_dir(&git_dir)?;
if branch_path.starts_with(&gcd) {
return Err(Box::new(err));
}
std::fs::metadata(Path::new(&gcd).join("refs/remotes").join(&updated_master))?
}
};
if meta.modified()?.elapsed()? > WARN_AFTER {
eprintln!("warning: {updated_master} has not been updated in 10 days");
Ok(true)
} else {
Ok(false)
}
}

fn git_common_dir(dir: &Path) -> Result<String, String> {
output_result(Command::new("git").arg("-C").arg(dir).arg("rev-parse").arg("--git-common-dir"))
.map(|x| x.trim().to_string())
Ok(())
}

0 comments on commit dd0bcf5

Please sign in to comment.