11use bstr:: { BString , ByteSlice } ;
2+ use gitbutler_commit:: commit_ext:: CommitExt as _;
23use gix:: date:: parse:: TimeBuf ;
34use serde:: Serialize ;
45
@@ -108,6 +109,8 @@ pub struct Commit {
108109 pub created_at : i128 ,
109110 /// The author of the commit.
110111 pub author : Author ,
112+ /// The GitButler change-id associated with this commit, if available.
113+ pub change_id : Option < String > ,
111114 /// Optional URL to the Gerrit review for this commit, if applicable.
112115 /// Only populated if Gerrit mode is enabled and the commit has an associated review.
113116 pub gerrit_review_url : Option < String > ,
@@ -126,6 +129,7 @@ impl TryFrom<gix::Commit<'_>> for Commit {
126129 state : CommitState :: LocalAndRemote ( commit. id ) ,
127130 created_at : i128:: from ( commit. time ( ) ?. seconds ) * 1000 ,
128131 author : commit. author ( ) ?. into ( ) ,
132+ change_id : commit. change_id ( ) . map ( |id| id. to_string ( ) ) ,
129133 gerrit_review_url : None ,
130134 } )
131135 }
@@ -134,6 +138,10 @@ impl TryFrom<gix::Commit<'_>> for Commit {
134138impl From < but_core:: CommitOwned > for Commit {
135139 fn from ( CommitOwned { id, inner } : CommitOwned ) -> Self {
136140 let headers = commit:: Headers :: try_from_commit ( & inner) ;
141+ let has_conflicts = headers. as_ref ( ) . is_some_and ( |hdr| hdr. is_conflicted ( ) ) ;
142+ let change_id = headers
143+ . and_then ( |hdr| hdr. change_id )
144+ . map ( |id| id. to_string ( ) ) ;
137145 let gix:: objs:: Commit {
138146 tree : _,
139147 parents,
@@ -147,10 +155,11 @@ impl From<but_core::CommitOwned> for Commit {
147155 id,
148156 parent_ids : parents. into_iter ( ) . collect ( ) ,
149157 message,
150- has_conflicts : headers . is_some_and ( |hdr| hdr . is_conflicted ( ) ) ,
158+ has_conflicts,
151159 state : CommitState :: LocalAndRemote ( id) ,
152160 created_at : committer. time . seconds as i128 * 1000 ,
153161 author : author. to_ref ( & mut TimeBuf :: default ( ) ) . into ( ) ,
162+ change_id,
154163 gerrit_review_url : None ,
155164 }
156165 }
@@ -196,6 +205,8 @@ pub struct UpstreamCommit {
196205 pub created_at : i128 ,
197206 /// The author of the commit.
198207 pub author : Author ,
208+ /// The GitButler change-id associated with this commit, if available.
209+ pub change_id : Option < String > ,
199210}
200211#[ cfg( feature = "export-schema" ) ]
201212but_schemars:: register_sdk_type!( UpstreamCommit ) ;
@@ -379,7 +390,7 @@ impl From<&crate::ref_info::Commit> for ui::UpstreamCommit {
379390 flags : _,
380391 // TODO: Represent this in the UI (maybe) and/or deal with divergence of the local and remote tracking branch.
381392 has_conflicts : _,
382- change_id : _ ,
393+ change_id,
383394 } : & crate :: ref_info:: Commit ,
384395 ) -> Self {
385396 ui:: UpstreamCommit {
@@ -389,6 +400,7 @@ impl From<&crate::ref_info::Commit> for ui::UpstreamCommit {
389400 author : author
390401 . to_ref ( & mut gix:: date:: parse:: TimeBuf :: default ( ) )
391402 . into ( ) ,
403+ change_id : change_id. as_ref ( ) . map ( ToString :: to_string) ,
392404 }
393405 }
394406}
@@ -408,7 +420,7 @@ impl From<&LocalCommit> for ui::Commit {
408420 // TODO: also flags refs
409421 flags : _,
410422 has_conflicts,
411- change_id : _ ,
423+ change_id,
412424 } ,
413425 relation,
414426 } : & LocalCommit ,
@@ -423,6 +435,7 @@ impl From<&LocalCommit> for ui::Commit {
423435 author : author
424436 . to_ref ( & mut gix:: date:: parse:: TimeBuf :: default ( ) )
425437 . into ( ) ,
438+ change_id : change_id. as_ref ( ) . map ( ToString :: to_string) ,
426439 gerrit_review_url : None ,
427440 }
428441 }
0 commit comments