[metadata: 2/3]: Add helper to get commit for local_change.oid#58
Merged
slinder1 merged 1 commit intoJun 25, 2026
Merged
Conversation
Owner
Author
🛠️ Initial changes (click to expand):diff --git b/src/change.rs a/src/change.rs
@@ -115,9 +115,7 @@ impl LocalChange {
pub fn diff(&self) -> Result<String> {
let change = self.id.as_str();
let repo = env::repo();
- let commit = repo
- .find_commit(self.oid)
- .expect("a local change's commit Oid is not found in the repo now?");
+ let commit = self.commit()?;
let parent = commit
.parent(0)
.with_context(|| format!("change {change} has no parent commit",))?;
@@ -133,6 +131,9 @@ impl LocalChange {
.with_context(|| format!("failed to generate interdiff for change {change}"))?;
Ok(out)
}
+ pub fn commit<'repo>(&self) -> Result<Commit<'repo>> {
+ Ok(env::repo().find_commit(self.oid)?)
+ }
}
#[derive(Debug)]
@@ -143,7 +144,7 @@ pub struct Change {
impl Change {
pub fn render_pr_ui(&self, changes: &[Self], branch_desc: Option<&str>) -> Result<()> {
- let commit = env::repo().find_commit(self.local_change.oid)?;
+ let commit = self.local_change.commit()?;
let mut index = None;
let title = String::from(
commit
@@ -191,9 +192,7 @@ impl Change {
.with_context(|| format!("could not parse revspec for remote branch: {remote_branch}"))?
.peel_to_commit()
.context("revspec for remote branch did not resolve to a commit")?;
- let new_commit = repo
- .find_commit(self.local_change.oid)
- .expect("a local change's commit Oid is not found in the repo now?");
+ let new_commit = self.local_change.commit()?;
let old_merge_base = old_commit
.parent(0)
.with_context(|| format!("old version of change {change} has no parent commit"))?;
|
This was referenced Jun 25, 2026
1216360 to
0e87fa6
Compare
Base automatically changed from
users/slinder1/I1f7839e58659666bb0e0b54a0038a2a22209f808
to
main
June 25, 2026 19:38
Change-Id: I3212a00b2ed3a52952eb3a9ccf9d30e40a51c3f4
0e87fa6 to
1c0aade
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change-Id: I3212a00b2ed3a52952eb3a9ccf9d30e40a51c3f4
Stack:
main(Note: Closed and merged PRs may not be reflected here and PR numbering is not stable.)