Skip to content

Commit f8b06f3

Browse files
codexByron
andcommitted
Wire-up RefInfo change-ids in commits to UI (#GB-1165)
This makes the change-ids usable. Note that they won't be stable unless the rebase engine uses the ones in the cache instead of persisting. Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
1 parent da9ebcc commit f8b06f3

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

crates/but-workspace/src/branch_details.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ fn upstream_commits_gix(
194194
message: commit.message.into(),
195195
created_at: i128::from(commit.time()?.seconds) * 1000,
196196
author,
197+
change_id: but_core::commit::Headers::try_from_commit(&commit)
198+
.and_then(|headers| headers.change_id)
199+
.map(|id| id.to_string()),
197200
});
198201
}
199202
Ok(out)
@@ -230,6 +233,10 @@ fn local_commits_gix(
230233
state: CommitState::LocalAndRemote(info.id),
231234
created_at: i128::from(commit.committer.time.seconds) * 1000,
232235
author,
236+
change_id: commit
237+
.headers()
238+
.and_then(|headers| headers.change_id)
239+
.map(|id| id.to_string()),
233240
gerrit_review_url: None,
234241
});
235242
}

crates/but-workspace/src/legacy/stacks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ pub fn local_and_remote_commits(
632632
state,
633633
created_at,
634634
author: gix_commit.author()?.into(),
635+
change_id: change_id.map(|id| id.to_string()),
635636
gerrit_review_url: None,
636637
};
637638
local_and_remote.push(api_commit);

crates/but-workspace/src/ui/mod.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use bstr::{BString, ByteSlice};
2+
use gitbutler_commit::commit_ext::CommitExt as _;
23
use gix::date::parse::TimeBuf;
34
use 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 {
134138
impl 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")]
201212
but_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

Comments
 (0)