@@ -141,6 +141,57 @@ 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 = 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+ . unwrap ( )
169+ . trim_end ( )
170+ . to_owned ( ) ;
171+
172+ info ! ( "commit title: {}" , last_msg) ;
173+
174+ let last_commit_us = git:: log ( )
175+ . amount ( 1 )
176+ . grep ( last_msg. as_str ( ) )
177+ . branch ( git:: Branch ( "upstream/master" ) )
178+ . grep ( last_msg. as_str ( ) )
179+ . format ( git:: Format :: Hash )
180+ . spawn ( ) ?
181+ . stdout
182+ . trim_end ( )
183+ . to_owned ( ) ;
184+
185+ if last_commit_us. is_empty ( ) {
186+ info ! ( "could not find matching commit, skipping" ) ;
187+ branch = git:: Branch ( last_upstreamed_commit + "~" ) ;
188+ } else {
189+ info ! ( "found equivalent commit: {}" , last_commit_us) ;
190+ return Ok ( ( last_msg, last_commit_us) ) ;
191+ }
192+ }
193+ }
194+
144195fn prepare_body ( last_commit : String , rev_list : String ) -> String {
145196 format ! (
146197 "
@@ -176,31 +227,8 @@ pub async fn prepare_commits(
176227 info ! ( "fetching `gcc`..." ) ;
177228 git:: fetch ( ) . remote ( "gcc" ) . spawn ( ) ?;
178229
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) ;
230+ let ( last_upstreamed_commit, last_commit_us)
231+ = find_last_upstreamed_commit_us ( ) ?;
204232
205233 let rev_list = git:: rev_list ( last_commit_us, "upstream/master" )
206234 . no_merges ( )
0 commit comments