Debian Codegraph @

cli/src/commands/prev.rs

raw
1 // Copyright 2020 The Jujutsu Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 use crate::cli_util::CommandHelper;
16 use crate::command_error::CommandError;
17 use crate::movement_util::Direction;
18 use crate::movement_util::MovementArgs;
19 use crate::movement_util::move_to_commit;
20 use crate::ui::Ui;
21 /// Change the working copy revision relative to the parent revision
22 ///
23 /// The command creates a new empty working copy revision that is the child of
24 /// an ancestor `offset` revisions behind the parent of the current working
25 /// copy.
26 ///
27 /// For example, when the offset is 1:
28 ///
29 /// ```text
30 /// D @ D
31 /// |/ |
32 /// A => A @
33 /// | |/
34 /// B B
35 /// ```
36 ///
37 /// If `--edit` is passed, the working copy revision is changed to the parent of
38 /// the current working copy revision.
39 ///
40 /// ```text
41 /// D @ D
42 /// |/ |
43 /// C => @
44 /// | |
45 /// B B
46 /// | |
47 /// A A
48 /// ```
49 #[derive(clap::Args, Clone, Debug)]
50 #[command(verbatim_doc_comment)]
51 pub(crate) struct PrevArgs {
52 /// How many revisions to move backward. Moves to the parent by default
53 #[arg(default_value_t = 1)]
54 offset: u64,
55
56 /// Edit the parent directly, instead of moving the working-copy commit
57 ///
58 /// Takes precedence over config in `ui.movement.edit`; i.e.
59 /// will negate `ui.movement.edit = false`
60 #[arg(long, short)]
61 edit: bool,
62
63 /// The inverse of `--edit`
64 ///
65 /// Takes precedence over config in `ui.movement.edit`; i.e.
66 /// will negate `ui.movement.edit = true`
67 #[arg(long, short, conflicts_with = "edit")]
68 no_edit: bool,
69
70 /// Jump to the previous conflicted ancestor
71 #[arg(long, conflicts_with = "offset")]
72 conflict: bool,
73 }
74
75 impl From<&PrevArgs> for MovementArgs {
76 fn from(val: &PrevArgs) -> Self {
77 Self {
78 offset: val.offset,
79 edit: val.edit,
80 no_edit: val.no_edit,
81 conflict: val.conflict,
82 }
83 }
84 }
85
86 pub(crate) async fn cmd_prev(
87 ui: &mut Ui,
88 command: &CommandHelper,
89 args: &PrevArgs,
90 ) -> Result<(), CommandError> {
91 move_to_commit(ui, command, Direction::Prev, &MovementArgs::from(args)).await
92 }