From ee6744c75e3e5e50be6dda14f1d8f1598d9ff1cc Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Sat, 11 Apr 2026 22:21:07 +0200 Subject: [PATCH 1/3] Use more github friendly change graph close #156 Created using jj-spr --- spr/src/commands/push.rs | 44 ++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/spr/src/commands/push.rs b/spr/src/commands/push.rs index d4819db..b53ff34 100644 --- a/spr/src/commands/push.rs +++ b/spr/src/commands/push.rs @@ -377,7 +377,7 @@ where Ok(seen) } -fn prepare_revision_comment( +fn prepare_revision_comment_inner( tree: &crate::tree::Tree, config: &crate::config::Config, ) -> Vec @@ -405,7 +405,7 @@ where match children.as_slice() { [] => {} [next] => { - lines.extend(prepare_revision_comment(next, config)); + lines.extend(prepare_revision_comment_inner(next, config)); } // We have more than one child branch. // We need to actually build an unicode-art tree @@ -418,7 +418,7 @@ where .take(child.width() * 2 - 1) .reduce(|l, r| format!("{l}{r}")) .unwrap_or(config.drawing.space.clone()); - let new_lines = prepare_revision_comment(child, config); + let new_lines = prepare_revision_comment_inner(child, config); let old_lines = child_lines.into_iter().enumerate().map(|(i, l)| { format!( "{}{}{}", @@ -442,12 +442,44 @@ where return lines; } +fn prepare_revision_comment( + tree: &crate::tree::Tree, + config: &crate::config::Config, +) -> Vec +where + T: AsRef, +{ + if tree.width() == 1 { + let mut lines = Vec::with_capacity(tree.len()); + let mut iter = tree; + loop { + lines.push(format!( + "* {}", + config.pull_request_url(iter.get().as_ref().pull_request_number.unwrap_or(0)) + )); + + if let Some(tree) = iter.get_children().first() { + iter = tree; + } else { + break; + } + } + lines + } else { + prepare_revision_comment_inner(tree, config) + } +} + fn finalize_revision_comment( revision: &crate::jj::Revision, config: &crate::config::Config, prepared: &Vec, ) -> String { let mut lines = Vec::new(); + if prepared.len() == 1 { + return String::from("This PR is a standalone change."); + } + lines.push(format!( "This PR is part of a {} changes series", prepared.len() @@ -1945,7 +1977,7 @@ pub mod tests { assert_eq!( str_lines.as_slice(), - &["• [My Title](https://github.com/test_owner/test_repo/pull/1)"], + &["* https://github.com/test_owner/test_repo/pull/1"], "Lines didn't match expectation: {str_lines:?}" ); } @@ -1974,8 +2006,8 @@ pub mod tests { assert_eq!( str_lines.as_slice(), &[ - "• [My Title](https://github.com/test_owner/test_repo/pull/1)", - "• [My Other Title](https://github.com/test_owner/test_repo/pull/2)" + "* https://github.com/test_owner/test_repo/pull/1", + "* https://github.com/test_owner/test_repo/pull/2" ], "Lines didn't match expectation {str_lines:?}" ); From d1ec62759bb700d7a36aeebdb7b7e3b62541586e Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Sat, 11 Apr 2026 22:46:03 +0200 Subject: [PATCH 2/3] Simplify unicode drawing logic Created using jj-spr --- spr/src/commands/push.rs | 52 ++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/spr/src/commands/push.rs b/spr/src/commands/push.rs index b53ff34..13e84c2 100644 --- a/spr/src/commands/push.rs +++ b/spr/src/commands/push.rs @@ -5,7 +5,7 @@ use crate::{ utils::run_command, }; use git2::Oid; -use std::{io::ErrorKind, iter::zip}; +use std::io::ErrorKind; #[derive(Debug, clap::Parser, Default)] pub struct PushOptions { @@ -412,27 +412,15 @@ where children => { let mut child_lines = Vec::new(); for child in children { - let indent = [config.drawing.space.clone()] - .into_iter() - .cycle() + let indent: String = std::iter::repeat(config.drawing.space.clone()) .take(child.width() * 2 - 1) - .reduce(|l, r| format!("{l}{r}")) - .unwrap_or(config.drawing.space.clone()); + .collect(); + let drawing = std::iter::once(config.drawing.fork.clone()) + .chain(std::iter::repeat(config.drawing.cont.clone())); let new_lines = prepare_revision_comment_inner(child, config); - let old_lines = child_lines.into_iter().enumerate().map(|(i, l)| { - format!( - "{}{}{}", - if i == 0 { - &config.drawing.fork - } else { - &config.drawing.cont - }, - indent, - l - ) - }); - child_lines = old_lines.collect(); - child_lines.extend(new_lines); + let old_lines = + std::iter::zip(drawing, child_lines).map(|(i, l)| format!("{i}{indent}{l}",)); + child_lines = old_lines.chain(new_lines.into_iter()).collect(); } lines.extend(child_lines); @@ -629,17 +617,19 @@ where )?; crate::jj::RevSet::from_remote_branch(&branch, &config.remote_name)? }; - let work = zip(workset, pull_requests).into_iter().map(|(ws, pr)| { - if let Some(ref pr) = pr { - ws.progress_bar.set_prefix(format!( - "{} ({})", - ws.revision.title, - config.pull_request_url(pr.pr_number()) - )); - } - ws.progress_bar.set_message("Figured out PRs"); - ws.map(|_| pr) - }); + let work = std::iter::zip(workset, pull_requests) + .into_iter() + .map(|(ws, pr)| { + if let Some(ref pr) = pr { + ws.progress_bar.set_prefix(format!( + "{} ({})", + ws.revision.title, + config.pull_request_url(pr.pr_number()) + )); + } + ws.progress_bar.set_message("Figured out PRs"); + ws.map(|_| pr) + }); setup.set_message("Pushing revisions"); let mut actions = do_push(config, jj, &opts, work, &trunk).await?; From 22190becc2f137ded77dc5c81012d2cdd9e823d3 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Sat, 11 Apr 2026 22:49:35 +0200 Subject: [PATCH 3/3] Mark current PR better Created using jj-spr --- spr/src/commands/push.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spr/src/commands/push.rs b/spr/src/commands/push.rs index b53ff34..ce24643 100644 --- a/spr/src/commands/push.rs +++ b/spr/src/commands/push.rs @@ -488,11 +488,14 @@ fn finalize_revision_comment( lines.extend_from_slice(prepared.as_slice()); if let Some(number) = revision.pull_request_number { let pattern = format!("[{}]({})", revision.title, config.pull_request_url(number)); + let simple_pattern = format!("* {}", config.pull_request_url(number)); lines = lines .into_iter() .map(|s| { if s.contains(&pattern) { s.replace(&pattern, &revision.title) + } else if s == simple_pattern { + format!("* {}", revision.title) } else { s }