Skip to content

Commit

Permalink
commands: move show_predecessor_patch code to obslog.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineCezar committed Nov 3, 2023
1 parent 5d45bd1 commit b7c480a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
27 changes: 1 addition & 26 deletions cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ use crate::cli_util::{
run_ui_editor, user_error, Args, CommandError, CommandHelper, WorkspaceCommandHelper,
};
use crate::diff_util::{self, DiffFormat};
use crate::formatter::{Formatter, PlainTextFormatter};
use crate::formatter::PlainTextFormatter;
use crate::text_util;
use crate::ui::Ui;

Expand Down Expand Up @@ -147,31 +147,6 @@ enum Commands {
Workspace(workspace::WorkspaceCommands),
}

fn show_predecessor_patch(
ui: &Ui,
formatter: &mut dyn Formatter,
workspace_command: &WorkspaceCommandHelper,
commit: &Commit,
diff_formats: &[DiffFormat],
) -> Result<(), CommandError> {
let predecessors = commit.predecessors();
let predecessor = match predecessors.first() {
Some(predecessor) => predecessor,
None => return Ok(()),
};
let predecessor_tree = rebase_to_dest_parent(workspace_command, predecessor, commit)?;
let tree = commit.tree()?;
diff_util::show_diff(
ui,
formatter,
workspace_command,
&predecessor_tree,
&tree,
&EverythingMatcher,
diff_formats,
)
}

fn rebase_to_dest_parent(
workspace_command: &WorkspaceCommandHelper,
source: &Commit,
Expand Down
35 changes: 32 additions & 3 deletions cli/src/commands/obslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@

use jj_lib::commit::Commit;
use jj_lib::dag_walk::topo_order_reverse;
use jj_lib::matchers::EverythingMatcher;
use tracing::instrument;

use super::show_predecessor_patch;
use crate::cli_util::{CommandError, CommandHelper, LogContentFormat, RevisionArg};
use crate::diff_util::{self, DiffFormatArgs};
use super::rebase_to_dest_parent;
use crate::cli_util::{
CommandError, CommandHelper, LogContentFormat, RevisionArg, WorkspaceCommandHelper,
};
use crate::diff_util::{self, DiffFormat, DiffFormatArgs};
use crate::formatter::Formatter;
use crate::graphlog::{get_graphlog, Edge};
use crate::ui::Ui;

Expand Down Expand Up @@ -136,3 +140,28 @@ pub(crate) fn cmd_obslog(

Ok(())
}

fn show_predecessor_patch(
ui: &Ui,
formatter: &mut dyn Formatter,
workspace_command: &WorkspaceCommandHelper,
commit: &Commit,
diff_formats: &[DiffFormat],
) -> Result<(), CommandError> {
let predecessors = commit.predecessors();
let predecessor = match predecessors.first() {
Some(predecessor) => predecessor,
None => return Ok(()),
};
let predecessor_tree = rebase_to_dest_parent(workspace_command, predecessor, commit)?;
let tree = commit.tree()?;
diff_util::show_diff(
ui,
formatter,
workspace_command,
&predecessor_tree,
&tree,
&EverythingMatcher,
diff_formats,
)
}

0 comments on commit b7c480a

Please sign in to comment.