@@ -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 ) ;
0 commit comments