@@ -5,6 +5,7 @@ use std::fmt::{self, Debug, Display, Write};
55use std:: io;
66use std:: path:: PathBuf ;
77use std:: process:: { Command , Stdio } ;
8+ use std:: str:: FromStr ;
89use std:: time:: SystemTime ;
910
1011use cursive_core:: utils:: markup:: StyledString ;
@@ -107,6 +108,9 @@ struct DifferentialQueryRevisionResponse {
107108 id : Id ,
108109 phid : Phid ,
109110
111+ #[ serde( default ) ]
112+ hashes : Vec < ( String , String ) > ,
113+
110114 #[ serde( default ) ]
111115 auxiliary : DifferentialQueryAuxiliaryResponse ,
112116}
@@ -247,15 +251,57 @@ impl Forge for PhabricatorForge<'_> {
247251 } )
248252 . try_collect ( ) ?;
249253
254+ let revisions = if should_mock ( ) {
255+ Default :: default ( )
256+ } else {
257+ self . query_revisions ( & DifferentialQueryRequest {
258+ ids : commit_oid_to_revision. values ( ) . flatten ( ) . cloned ( ) . collect ( ) ,
259+ phids : Default :: default ( ) ,
260+ } ) ?
261+ } ;
262+ let commit_hashes: HashMap < Id , NonZeroOid > = revisions
263+ . into_iter ( )
264+ . filter_map ( |item| {
265+ let hashes: HashMap < String , String > = item. hashes . iter ( ) . cloned ( ) . collect ( ) ;
266+ if hashes. is_empty ( ) {
267+ None
268+ } else {
269+ // `gtcm` stands for "git commit" (as opposed to `gttr`, also returned in the same list, or `hgcm`, which stands for "hg commit").
270+ match hashes. get ( "gtcm" ) {
271+ None => {
272+ warn ! ( ?item, "No Git commit hash in item" ) ;
273+ None
274+ }
275+ Some ( commit_oid) => match NonZeroOid :: from_str ( commit_oid. as_str ( ) ) {
276+ Ok ( commit_oid) => Some ( ( item. id , commit_oid) ) ,
277+ Err ( err) => {
278+ warn ! ( ?err, "Couldn't parse Git commit OID" ) ;
279+ None
280+ }
281+ } ,
282+ }
283+ }
284+ } )
285+ . collect ( ) ;
286+
250287 let statuses = commit_oid_to_revision
251288 . into_iter ( )
252289 . map ( |( commit_oid, id) | {
253290 let status = CommitStatus {
254291 submit_status : match id {
255- Some ( _) => {
256- // TODO: could also be `UpToDate`
257- SubmitStatus :: NeedsUpdate
258- }
292+ Some ( id) => match commit_hashes. get ( & id) {
293+ Some ( remote_commit_oid) => {
294+ if remote_commit_oid == & commit_oid {
295+ SubmitStatus :: UpToDate
296+ } else {
297+ SubmitStatus :: NeedsUpdate
298+ }
299+ }
300+ None => {
301+ warn ! ( ?commit_oid, ?id, "No remote commit hash found for commit" ) ;
302+ SubmitStatus :: NeedsUpdate
303+ }
304+ } ,
259305 None => SubmitStatus :: Unsubmitted ,
260306 } ,
261307 remote_name : None ,
@@ -681,6 +727,7 @@ impl PhabricatorForge<'_> {
681727 let DifferentialQueryRevisionResponse {
682728 id,
683729 phid : _,
730+ hashes : _,
684731 auxiliary :
685732 DifferentialQueryAuxiliaryResponse {
686733 phabricator_depends_on,
@@ -703,6 +750,7 @@ impl PhabricatorForge<'_> {
703750 let DifferentialQueryRevisionResponse {
704751 id,
705752 phid,
753+ hashes : _,
706754 auxiliary : _,
707755 } = revision;
708756 ( phid, id)
0 commit comments