Skip to content

Commit d652bb0

Browse files
fix(cli): keep multi-entry log diffs compact
1 parent 714cc4f commit d652bb0

2 files changed

Lines changed: 81 additions & 7 deletions

File tree

crates/loc-cli/src/commands.rs

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,10 @@ struct LogCliArgs {
474474
help = "Only show one push journal entry."
475475
)]
476476
push_id: Option<String>,
477-
#[arg(long, help = "Print the readable diff saved with each journal entry.")]
477+
#[arg(
478+
long,
479+
help = "Print the readable diff when the log resolves to one journal entry."
480+
)]
478481
diff: bool,
479482
}
480483

@@ -4262,6 +4265,7 @@ fn write_log_report<W: Write>(report: &LogReport, output: &mut W) -> io::Result<
42624265
return Ok(());
42634266
}
42644267

4268+
let inline_diff = report.entries.len() == 1;
42654269
for (index, entry) in report.entries.iter().enumerate() {
42664270
if index > 0 {
42674271
writeln!(output)?;
@@ -4291,7 +4295,11 @@ fn write_log_report<W: Write>(report: &LogReport, output: &mut W) -> io::Result<
42914295
entry.plan_summary.blocks_archived
42924296
)?;
42934297
writeln!(output, " operations: {}", entry.operation_count)?;
4294-
write_readable_diff(output, entry.readable_diff.as_ref())?;
4298+
if inline_diff {
4299+
write_readable_diff(output, entry.readable_diff.as_ref())?;
4300+
} else if entry.readable_diff.is_some() {
4301+
writeln!(output, " diff: loc log --push-id {} --diff", entry.push_id)?;
4302+
}
42954303
}
42964304

42974305
Ok(())
@@ -7782,6 +7790,66 @@ mod tests {
77827790
);
77837791
}
77847792

7793+
#[test]
7794+
fn log_report_writer_omits_inline_diffs_for_multiple_entries() {
7795+
let entry = |push_id: &str, diff_text: &str| JournalEntryOutput {
7796+
push_id: push_id.to_string(),
7797+
mount_id: "notion-main".to_string(),
7798+
remote_ids: vec!["page-1".to_string()],
7799+
status: "reconciled".to_string(),
7800+
failure: None,
7801+
author: "anonymous".to_string(),
7802+
previous_push_id: None,
7803+
created_at_unix_ms: None,
7804+
readable_diff: Some(locality_core::readable_diff::ReadableDiffOutput {
7805+
files: Vec::new(),
7806+
text: diff_text.to_string(),
7807+
}),
7808+
preimage_count: 1,
7809+
apply_effect_count: 1,
7810+
plan_summary: PlanSummaryOutput {
7811+
blocks_created: 0,
7812+
blocks_updated: 1,
7813+
blocks_replaced: 0,
7814+
blocks_moved: 0,
7815+
media_updated: 0,
7816+
blocks_archived: 0,
7817+
entities_created: 0,
7818+
entities_archived: 0,
7819+
entities_moved: 0,
7820+
properties_updated: 0,
7821+
},
7822+
operation_count: 1,
7823+
};
7824+
let report = LogReport {
7825+
ok: true,
7826+
command: "log",
7827+
entries: vec![
7828+
entry("push-2", "diff --locality a/two.md b/two.md\n"),
7829+
entry("push-1", "diff --locality a/one.md b/one.md\n"),
7830+
],
7831+
};
7832+
let mut output = Vec::new();
7833+
7834+
write_log_report(&report, &mut output).expect("write log report");
7835+
let rendered = String::from_utf8(output).expect("utf8 output");
7836+
7837+
assert!(rendered.contains("push push-2"), "{rendered}");
7838+
assert!(rendered.contains("push push-1"), "{rendered}");
7839+
assert!(
7840+
!rendered.contains("diff --locality"),
7841+
"multi-entry log should not inline diff bodies:\n{rendered}"
7842+
);
7843+
assert!(
7844+
rendered.contains("diff: loc log --push-id push-2 --diff"),
7845+
"{rendered}"
7846+
);
7847+
assert!(
7848+
rendered.contains("diff: loc log --push-id push-1 --diff"),
7849+
"{rendered}"
7850+
);
7851+
}
7852+
77857853
#[test]
77867854
fn clean_diff_report_exits_successfully() {
77877855
assert_eq!(diff_report_exit_code(&report(true)), EXIT_SUCCESS);

docs/cli.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,10 @@ unified diff when file content changed.
680680
remote mutations. Once a push is journaled, Locality stores linked edit metadata
681681
and the readable diff in the durable push journal.
682682

683-
`loc log --diff` reads those journaled diffs back for audit and review. Combine
684-
it with `--push-id <push-id>` to show the readable diff for one push entry, or
685-
with a path to narrow the journal before selecting a push.
683+
`loc log --diff` reads those journaled diffs back for audit and review. Use
684+
`--push-id <push-id> --diff` to show the readable diff for one push entry; when
685+
a human log view has multiple entries, Locality keeps the list compact and
686+
prints the command to inspect each entry's diff.
686687

687688
## Initial `loc push --json` Shape
688689

@@ -780,7 +781,10 @@ from the SQLite state store. Without a path it lists all journal entries; with a
780781
path it resolves the path through the mount/entity mapping and lists entries
781782
that touched that entity. `--push-id` filters the path-scoped result to one push
782783
entry. By default, JSON and human output omit saved readable diffs so regular log
783-
calls stay compact; pass `--diff` to include them.
784+
calls stay compact. Pass `--diff` to include them in JSON. In human output,
785+
`--diff` prints the saved readable diff when the result has one entry; for
786+
multi-entry results it prints per-entry `loc log --push-id <push-id> --diff`
787+
hints instead of dumping every diff body.
784788

785789
Each JSON entry includes:
786790

@@ -801,7 +805,9 @@ Each JSON entry includes:
801805

802806
Human output is a compact git-log-style list headed by `push <push-id>`. It
803807
prints linked edit fields such as `author`, `created_at_unix_ms`, and `previous`
804-
when available; with `--diff`, it then prints the saved readable diff text.
808+
when available. With `--diff`, one-entry output prints the saved readable diff
809+
text; multi-entry output prints a `diff: loc log --push-id <push-id> --diff`
810+
hint for each entry that has a saved diff.
805811

806812
## Initial `loc undo --json` Shape
807813

0 commit comments

Comments
 (0)