Skip to content

Commit 272d5aa

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 ca6e664 commit 272d5aa

File tree

5 files changed

+37
-6
lines changed

5 files changed

+37
-6
lines changed

crates/but-workspace/src/branch_details.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::collections::HashSet;
22

33
use anyhow::Context as _;
44
use but_core::RefMetadata;
5+
use gitbutler_commit::commit_ext::CommitExt as _;
56
use gix::{
67
date::parse::TimeBuf, prelude::ObjectIdExt as _, reference::Category, remote::Direction,
78
};
@@ -184,6 +185,7 @@ fn upstream_commits_gix(
184185
for info in traversal {
185186
let info = info?;
186187
let commit = info.id().object()?.into_commit();
188+
let change_id = commit.change_id().map(|id| id.to_string());
187189
let commit = commit.decode()?;
188190
let author: ui::Author = commit.author()?.into();
189191
let committer: ui::Author = commit.committer()?.into();
@@ -194,6 +196,7 @@ fn upstream_commits_gix(
194196
message: commit.message.into(),
195197
created_at: i128::from(commit.time()?.seconds) * 1000,
196198
author,
199+
change_id,
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
}

crates/but-workspace/tests/workspace/ui.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
mod changes_in_branch {
22
use but_graph::init::Options;
3-
use but_testsupport::visualize_commit_graph_all;
3+
use but_testsupport::{
4+
seed_cache_with_stable_change_ids_for_all_commits, visualize_commit_graph_all,
5+
};
46
use but_workspace::ui;
57

68
use crate::{ref_info::with_workspace_commit::utils::read_only_in_memory_scenario, utils::r};
@@ -139,6 +141,7 @@ mod changes_in_branch {
139141

140142
let mut ref_info: ui::RefInfo = {
141143
let mut cache = crate::ref_info::in_memory_cache();
144+
seed_cache_with_stable_change_ids_for_all_commits(&repo, &mut cache)?;
142145
but_workspace::head_info(&repo, &*meta, Default::default(), &mut cache)?.try_into()?
143146
};
144147
ref_info = ref_info.pruned_to_entrypoint();
@@ -247,6 +250,7 @@ mod changes_in_branch {
247250
"email": "author@example.com",
248251
"gravatarUrl": "https://www.gravatar.com/avatar/5c1e6d6e64e12aca17657581a48005d1?s=100&r=g&d=retro"
249252
},
253+
"changeId": "msqoopqtzoyyxmomxumvuqxynvsllmpx",
250254
"gerritReviewUrl": null
251255
}
252256
],
@@ -259,7 +263,8 @@ mod changes_in_branch {
259263
"name": "author",
260264
"email": "author@example.com",
261265
"gravatarUrl": "https://www.gravatar.com/avatar/5c1e6d6e64e12aca17657581a48005d1?s=100&r=g&d=retro"
262-
}
266+
},
267+
"changeId": "rqnnxmwzwuyvtuvlqnpoxmzuoqpkzrov"
263268
}
264269
],
265270
"commitsOutside": null,
@@ -430,6 +435,7 @@ mod changes_in_branch {
430435
"email": "author@example.com",
431436
"gravatarUrl": "https://www.gravatar.com/avatar/5c1e6d6e64e12aca17657581a48005d1?s=100&r=g&d=retro"
432437
},
438+
"changeId": "msqoopqtzoyyxmomxumvuqxynvsllmpx",
433439
"gerritReviewUrl": null
434440
}
435441
],
@@ -442,7 +448,8 @@ mod changes_in_branch {
442448
"name": "author",
443449
"email": "author@example.com",
444450
"gravatarUrl": "https://www.gravatar.com/avatar/5c1e6d6e64e12aca17657581a48005d1?s=100&r=g&d=retro"
445-
}
451+
},
452+
"changeId": "rqnnxmwzwuyvtuvlqnpoxmzuoqpkzrov"
446453
}
447454
],
448455
"commitsOutside": null,

crates/but/src/command/legacy/status/json.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ pub(super) fn build_workspace_status_json(
567567
created_at: status_ctx.common_merge_base_data.created_at,
568568
message: status_ctx.common_merge_base_data.message.clone().into(),
569569
author,
570+
change_id: None,
570571
},
571572
None,
572573
);
@@ -583,6 +584,7 @@ pub(super) fn build_workspace_status_json(
583584
created_at: upstream.created_at,
584585
message: upstream.message.clone().into(),
585586
author: upstream_author,
587+
change_id: None,
586588
},
587589
None,
588590
);
@@ -614,6 +616,7 @@ pub(super) fn build_workspace_status_json(
614616
created_at: remote_commit.created_at as i128,
615617
message: remote_commit.description.clone().into(),
616618
author,
619+
change_id: None,
617620
},
618621
None,
619622
))

0 commit comments

Comments
 (0)