mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-24 21:13:47 +00:00
cleanup: propagate errors from Commit::predecessors()
This commit is contained in:
parent
0a758e7024
commit
ee9d3271c1
4 changed files with 18 additions and 20 deletions
|
@ -12,8 +12,9 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use itertools::Itertools;
|
||||
use jj_lib::commit::Commit;
|
||||
use jj_lib::dag_walk::topo_order_reverse;
|
||||
use jj_lib::dag_walk::topo_order_reverse_ok;
|
||||
use jj_lib::matchers::EverythingMatcher;
|
||||
use jj_lib::rewrite::rebase_to_dest_parent;
|
||||
use tracing::instrument;
|
||||
|
@ -102,11 +103,11 @@ pub(crate) fn cmd_obslog(
|
|||
let mut formatter = ui.stdout_formatter();
|
||||
let formatter = formatter.as_mut();
|
||||
|
||||
let mut commits = topo_order_reverse(
|
||||
vec![start_commit],
|
||||
let mut commits = topo_order_reverse_ok(
|
||||
vec![Ok(start_commit)],
|
||||
|commit: &Commit| commit.id().clone(),
|
||||
|commit: &Commit| commit.predecessors(),
|
||||
);
|
||||
|commit: &Commit| commit.predecessors().collect_vec(),
|
||||
)?;
|
||||
if let Some(n) = args.limit {
|
||||
commits.truncate(n);
|
||||
}
|
||||
|
@ -114,8 +115,8 @@ pub(crate) fn cmd_obslog(
|
|||
let mut graph = get_graphlog(command.settings(), formatter.raw());
|
||||
for commit in commits {
|
||||
let mut edges = vec![];
|
||||
for predecessor in &commit.predecessors() {
|
||||
edges.push(Edge::Direct(predecessor.id().clone()));
|
||||
for predecessor in commit.predecessors() {
|
||||
edges.push(Edge::Direct(predecessor?.id().clone()));
|
||||
}
|
||||
let mut buffer = vec![];
|
||||
with_content_format.write_graph_text(
|
||||
|
@ -164,13 +165,13 @@ fn show_predecessor_patch(
|
|||
commit: &Commit,
|
||||
diff_formats: &[DiffFormat],
|
||||
) -> Result<(), CommandError> {
|
||||
let predecessors = commit.predecessors();
|
||||
let predecessor = match predecessors.first() {
|
||||
Some(predecessor) => predecessor,
|
||||
let mut predecessors = commit.predecessors();
|
||||
let predecessor = match predecessors.next() {
|
||||
Some(predecessor) => predecessor?,
|
||||
None => return Ok(()),
|
||||
};
|
||||
let predecessor_tree =
|
||||
rebase_to_dest_parent(workspace_command.repo().as_ref(), predecessor, commit)?;
|
||||
rebase_to_dest_parent(workspace_command.repo().as_ref(), &predecessor, commit)?;
|
||||
let tree = commit.tree()?;
|
||||
diff_util::show_diff(
|
||||
ui,
|
||||
|
|
|
@ -92,12 +92,11 @@ impl Commit {
|
|||
&self.data.predecessors
|
||||
}
|
||||
|
||||
pub fn predecessors(&self) -> Vec<Commit> {
|
||||
pub fn predecessors(&self) -> impl Iterator<Item = BackendResult<Commit>> + '_ {
|
||||
self.data
|
||||
.predecessors
|
||||
.iter()
|
||||
.map(|id| self.store.get_commit(id).unwrap())
|
||||
.collect()
|
||||
.map(|id| self.store.get_commit(id))
|
||||
}
|
||||
|
||||
pub fn tree(&self) -> BackendResult<MergedTree> {
|
||||
|
|
|
@ -80,7 +80,7 @@ fn test_initial(backend: TestRepoBackend) {
|
|||
|
||||
let parents: Vec<_> = commit.parents().try_collect().unwrap();
|
||||
assert_eq!(parents, vec![store.root_commit()]);
|
||||
assert_eq!(commit.predecessors(), vec![]);
|
||||
assert!(commit.predecessors().next().is_none());
|
||||
assert_eq!(commit.description(), "description");
|
||||
assert_eq!(commit.author(), &author_signature);
|
||||
assert_eq!(commit.committer(), &committer_signature);
|
||||
|
@ -156,10 +156,8 @@ fn test_rewrite(backend: TestRepoBackend) {
|
|||
tx.commit("test");
|
||||
let parents: Vec<_> = rewritten_commit.parents().try_collect().unwrap();
|
||||
assert_eq!(parents, vec![store.root_commit()]);
|
||||
assert_eq!(
|
||||
rewritten_commit.predecessors(),
|
||||
vec![initial_commit.clone()]
|
||||
);
|
||||
let predecessors: Vec<_> = rewritten_commit.predecessors().try_collect().unwrap();
|
||||
assert_eq!(predecessors, vec![initial_commit.clone()]);
|
||||
assert_eq!(rewritten_commit.author().name, settings.user_name());
|
||||
assert_eq!(rewritten_commit.author().email, settings.user_email());
|
||||
assert_eq!(
|
||||
|
|
|
@ -173,7 +173,7 @@ fn test_init_checkout(backend: TestRepoBackend) {
|
|||
wc_commit.store_commit().parents,
|
||||
vec![repo.store().root_commit_id().clone()]
|
||||
);
|
||||
assert_eq!(wc_commit.predecessors(), vec![]);
|
||||
assert!(wc_commit.predecessors().next().is_none());
|
||||
assert_eq!(wc_commit.description(), "");
|
||||
assert_eq!(wc_commit.author().name, settings.user_name());
|
||||
assert_eq!(wc_commit.author().email, settings.user_email());
|
||||
|
|
Loading…
Reference in a new issue