Skip to content

Commit 3775e26

Browse files
committed
Remove useless (?) upstream remote functions
1 parent 52e6d1d commit 3775e26

File tree

2 files changed

+2
-79
lines changed

2 files changed

+2
-79
lines changed

src/build_helper/src/git.rs

+1-78
Original file line numberDiff line numberDiff line change
@@ -30,77 +30,6 @@ pub fn output_result(cmd: &mut Command) -> Result<String, String> {
3030
String::from_utf8(output.stdout).map_err(|err| format!("{err:?}"))
3131
}
3232

33-
/// Finds the remote for rust-lang/rust.
34-
/// For example for these remotes it will return `upstream`.
35-
/// ```text
36-
/// origin https://github.com/pietroalbani/rust.git (fetch)
37-
/// origin https://github.com/pietroalbani/rust.git (push)
38-
/// upstream https://github.com/rust-lang/rust (fetch)
39-
/// upstream https://github.com/rust-lang/rust (push)
40-
/// ```
41-
pub fn get_rust_lang_rust_remote(
42-
config: &GitConfig<'_>,
43-
git_dir: Option<&Path>,
44-
) -> Result<String, String> {
45-
let mut git = Command::new("git");
46-
if let Some(git_dir) = git_dir {
47-
git.current_dir(git_dir);
48-
}
49-
git.args(["config", "--local", "--get-regex", "remote\\..*\\.url"]);
50-
let stdout = output_result(&mut git)?;
51-
52-
let rust_lang_remote = stdout
53-
.lines()
54-
.find(|remote| remote.contains(config.git_repository))
55-
.ok_or_else(|| format!("{} remote not found", config.git_repository))?;
56-
57-
let remote_name =
58-
rust_lang_remote.split('.').nth(1).ok_or_else(|| "remote name not found".to_owned())?;
59-
Ok(remote_name.into())
60-
}
61-
62-
pub fn rev_exists(rev: &str, git_dir: Option<&Path>) -> Result<bool, String> {
63-
let mut git = Command::new("git");
64-
if let Some(git_dir) = git_dir {
65-
git.current_dir(git_dir);
66-
}
67-
git.args(["rev-parse", rev]);
68-
let output = git.output().map_err(|err| format!("{err:?}"))?;
69-
70-
match output.status.code() {
71-
Some(0) => Ok(true),
72-
Some(128) => Ok(false),
73-
None => Err(format!(
74-
"git didn't exit properly: {}",
75-
String::from_utf8(output.stderr).map_err(|err| format!("{err:?}"))?
76-
)),
77-
Some(code) => Err(format!(
78-
"git command exited with status code: {code}: {}",
79-
String::from_utf8(output.stderr).map_err(|err| format!("{err:?}"))?
80-
)),
81-
}
82-
}
83-
84-
/// Returns the master branch from which we can take diffs to see changes.
85-
/// This will usually be rust-lang/rust master, but sometimes this might not exist.
86-
/// This could be because the user is updating their forked master branch using the GitHub UI
87-
/// and therefore doesn't need an upstream master branch checked out.
88-
/// We will then fall back to origin/master in the hope that at least this exists.
89-
pub fn updated_master_branch(
90-
config: &GitConfig<'_>,
91-
git_dir: Option<&Path>,
92-
) -> Result<String, String> {
93-
let upstream_remote = get_rust_lang_rust_remote(config, git_dir)?;
94-
let branch = config.nightly_branch;
95-
for upstream_master in [format!("{upstream_remote}/{branch}"), format!("origin/{branch}")] {
96-
if rev_exists(&upstream_master, git_dir)? {
97-
return Ok(upstream_master);
98-
}
99-
}
100-
101-
Err("Cannot find any suitable upstream master branch".to_owned())
102-
}
103-
10433
/// Represents the result of checking whether a set of paths
10534
/// have been modified locally or not.
10635
#[derive(PartialEq, Debug)]
@@ -312,13 +241,7 @@ pub fn get_git_modified_files(
312241
}
313242

314243
/// Returns the files that haven't been added to git yet.
315-
pub fn get_git_untracked_files(
316-
config: &GitConfig<'_>,
317-
git_dir: Option<&Path>,
318-
) -> Result<Option<Vec<String>>, String> {
319-
let Ok(_updated_master) = updated_master_branch(config, git_dir) else {
320-
return Ok(None);
321-
};
244+
pub fn get_git_untracked_files(git_dir: Option<&Path>) -> Result<Option<Vec<String>>, String> {
322245
let mut git = Command::new("git");
323246
if let Some(git_dir) = git_dir {
324247
git.current_dir(git_dir);

src/tools/compiletest/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ fn modified_tests(config: &Config, dir: &Path) -> Result<Vec<PathBuf>, String> {
711711
let files =
712712
get_git_modified_files(&config.git_config(), Some(dir), &vec!["rs", "stderr", "fixed"])?;
713713
// Add new test cases to the list, it will be convenient in daily development.
714-
let untracked_files = get_git_untracked_files(&config.git_config(), None)?.unwrap_or(vec![]);
714+
let untracked_files = get_git_untracked_files(Some(dir))?.unwrap_or(vec![]);
715715

716716
let all_paths = [&files[..], &untracked_files[..]].concat();
717717
let full_paths = {

0 commit comments

Comments
 (0)