Skip to content

Commit f842d73

Browse files
committed
gerris: Attempt to work around upstream-only commits
1 parent b239177 commit f842d73

File tree

1 file changed

+57
-25
lines changed

1 file changed

+57
-25
lines changed

src/upstream.rs

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,61 @@ pub fn maybe_prefix_cherry_picked_commit() -> Result<(), Error> {
141141
Ok(())
142142
}
143143

144+
// returns (them_msg, us)
145+
fn find_last_upstreamed_commit_us() -> Result<(String, String), Error> {
146+
let mut branch = git::Branch("gcc/trunk".to_owned());
147+
148+
loop {
149+
let last_upstreamed_commit = git::log()
150+
.amount(1)
151+
.grep("gccrs: ")
152+
.branch(branch)
153+
.format(git::Format::Hash)
154+
.spawn()?
155+
.stdout
156+
.trim_end()
157+
.to_owned();
158+
159+
info!("found last upstreamed commit: {}", last_upstreamed_commit);
160+
161+
let last_msg = match git::log()
162+
.amount(1)
163+
.branch(git::Branch(last_upstreamed_commit.as_str()))
164+
.format(git::Format::Title)
165+
.spawn()?
166+
.stdout
167+
.strip_prefix("gccrs: ") {
168+
Some(x) => x.trim_end().to_owned(),
169+
None => {
170+
info!("invalid matching commit, skipping");
171+
branch = git::Branch(last_upstreamed_commit + "~");
172+
continue;
173+
}
174+
};
175+
176+
info!("commit title: {}", last_msg);
177+
178+
let last_commit_us = git::log()
179+
.amount(1)
180+
.grep(last_msg.as_str())
181+
.branch(git::Branch("upstream/master"))
182+
.grep(last_msg.as_str())
183+
.format(git::Format::Hash)
184+
.spawn()?
185+
.stdout
186+
.trim_end()
187+
.to_owned();
188+
189+
if last_commit_us.is_empty() {
190+
info!("could not find matching commit, skipping");
191+
branch = git::Branch(last_upstreamed_commit + "~");
192+
} else {
193+
info!("found equivalent commit: {}", last_commit_us);
194+
return Ok((last_msg, last_commit_us));
195+
}
196+
}
197+
}
198+
144199
fn prepare_body(last_commit: String, rev_list: String) -> String {
145200
format!(
146201
"
@@ -176,31 +231,8 @@ pub async fn prepare_commits(
176231
info!("fetching `gcc`...");
177232
git::fetch().remote("gcc").spawn()?;
178233

179-
let last_upstreamed_commit = git::log()
180-
.amount(1)
181-
.grep("gccrs: ")
182-
.branch(git::Branch("gcc/trunk"))
183-
.format(git::Format::Title)
184-
.spawn()?
185-
.stdout;
186-
187-
info!("found last upstreamed commit: {}", last_upstreamed_commit);
188-
189-
let last_msg = last_upstreamed_commit
190-
.strip_prefix("gccrs: ")
191-
.unwrap()
192-
.trim_end();
193-
194-
let last_commit_us = git::log()
195-
.amount(1)
196-
.grep(last_msg)
197-
.branch(git::Branch("upstream/master"))
198-
.grep(last_msg)
199-
.format(git::Format::Hash)
200-
.spawn()?
201-
.stdout;
202-
203-
info!("found equivalent commit: {}", last_commit_us);
234+
let (last_upstreamed_commit, last_commit_us)
235+
= find_last_upstreamed_commit_us()?;
204236

205237
let rev_list = git::rev_list(last_commit_us, "upstream/master")
206238
.no_merges()

0 commit comments

Comments
 (0)