Skip to content

Commit

Permalink
cli: leverage Merge::map() in jj chmod
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvonz committed Aug 15, 2023
1 parent 725f79c commit 9a2a8f8
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2673,10 +2673,17 @@ fn cmd_chmod(ui: &mut Ui, command: &CommandHelper, args: &ChmodArgs) -> Result<(
"Some of the sides of the conflict are not files",
));
}
let new_removes = chmod_conflict_sides(conflict.removes(), executable_bit);
let new_adds = chmod_conflict_sides(conflict.adds(), executable_bit);
let new_conflict_id =
store.write_conflict(&repo_path, &Merge::new(new_removes, new_adds))?;
let new_conflict = conflict.map(|value| match value {
Some(TreeValue::File { id, executable: _ }) => Some(TreeValue::File {
id: id.clone(),
executable: executable_bit,
}),
Some(TreeValue::Conflict(_)) => {
panic!("Conflict sides must not themselves be conflicts")
}
value => value.clone(),
});
let new_conflict_id = store.write_conflict(&repo_path, &new_conflict)?;
TreeValue::Conflict(new_conflict_id)
}
Some(_) => return Err(user_error_with_path("Found neither a file nor a conflict")),
Expand All @@ -2691,26 +2698,6 @@ fn cmd_chmod(ui: &mut Ui, command: &CommandHelper, args: &ChmodArgs) -> Result<(
tx.finish(ui)
}

fn chmod_conflict_sides(
sides: &[Option<TreeValue>],
executable_bit: bool,
) -> Vec<Option<TreeValue>> {
let result = sides
.iter()
.map(|side| {
side.as_ref().map(|value| match value {
TreeValue::File { id, executable: _ } => TreeValue::File {
id: id.clone(),
executable: executable_bit,
},
TreeValue::Conflict(_) => panic!("Conflict sides must not themselves be conflicts"),
value => value.clone(),
})
})
.collect();
result
}

#[instrument(skip_all)]
fn cmd_resolve(
ui: &mut Ui,
Expand Down

0 comments on commit 9a2a8f8

Please sign in to comment.