Skip to content

Commit 5f32717

Browse files
committed
document the new git logic in more detail
Signed-off-by: onur-ozkan <[email protected]>
1 parent 0a7f9e2 commit 5f32717

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

Diff for: src/tools/build_helper/src/git.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,14 @@ pub fn updated_master_branch(
9696
Err("Cannot find any suitable upstream master branch".to_owned())
9797
}
9898

99-
fn get_git_merge_base(config: &GitConfig<'_>, git_dir: Option<&Path>) -> Result<String, String> {
99+
/// Finds the nearest merge commit by comparing the local `HEAD` with the upstream branch's state.
100+
/// To work correctly, the upstream remote must be properly configured using `git remote add <name> <url>`.
101+
/// In most cases `get_closest_merge_commit` is the function you are looking for as it doesn't require remote
102+
/// to be configured.
103+
fn git_upstream_merge_base(
104+
config: &GitConfig<'_>,
105+
git_dir: Option<&Path>,
106+
) -> Result<String, String> {
100107
let updated_master = updated_master_branch(config, git_dir)?;
101108
let mut git = Command::new("git");
102109
if let Some(git_dir) = git_dir {
@@ -105,9 +112,10 @@ fn get_git_merge_base(config: &GitConfig<'_>, git_dir: Option<&Path>) -> Result<
105112
Ok(output_result(git.arg("merge-base").arg(&updated_master).arg("HEAD"))?.trim().to_owned())
106113
}
107114

108-
/// Resolves the closest merge commit by the given `author` and `target_paths`.
115+
/// Searches for the nearest merge commit in the repository that also exists upstream.
109116
///
110-
/// If it fails to find the commit from upstream using `git merge-base`, fallbacks to HEAD.
117+
/// If it fails to find the upstream remote, it then looks for the most recent commit made
118+
/// by the merge bot by matching the author's email address with the merge bot's email.
111119
pub fn get_closest_merge_commit(
112120
git_dir: Option<&Path>,
113121
config: &GitConfig<'_>,
@@ -119,7 +127,7 @@ pub fn get_closest_merge_commit(
119127
git.current_dir(git_dir);
120128
}
121129

122-
let merge_base = get_git_merge_base(config, git_dir).unwrap_or_else(|_| "HEAD".into());
130+
let merge_base = git_upstream_merge_base(config, git_dir).unwrap_or_else(|_| "HEAD".into());
123131

124132
git.args([
125133
"rev-list",

Diff for: src/tools/compiletest/src/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,12 @@ pub fn parse_config(args: Vec<String>) -> Config {
164164
.optopt("", "edition", "default Rust edition", "EDITION")
165165
.reqopt("", "git-repository", "name of the git repository", "ORG/REPO")
166166
.reqopt("", "nightly-branch", "name of the git branch for nightly", "BRANCH")
167-
.reqopt("", "git-merge-commit-email", "email address used for the merge commits", "EMAIL");
167+
.reqopt(
168+
"",
169+
"git-merge-commit-email",
170+
"email address used for finding merge commits",
171+
"EMAIL",
172+
);
168173

169174
let (argv0, args_) = args.split_first().unwrap();
170175
if args.len() == 1 || args[1] == "-h" || args[1] == "--help" {

0 commit comments

Comments
 (0)