From 35c12e8371820eb471c84ba8dfac1ed635826ca7 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Mon, 21 Nov 2016 13:00:53 -0800 Subject: [PATCH] Pad all patch numbers to the same width using 0s This ensures that sorting by subject will put the patches in the right order. --- src/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index c838475078e322b2eac1970df0c2269407ede505..623c1f89b5eb3fbd458f19ff4170d42bcce6b1e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1484,6 +1484,8 @@ fn format(out: &mut Output, repo: &Repository, m: &ArgMatches) -> Result<()> { |n| format!("{}{}v{}", subject_prefix, ensure_space(&subject_prefix), n)); let file_prefix = version.map_or("".to_string(), |n| format!("v{}-", n)); + let num_width = commits.len().to_string().len(); + let signature = mail_signature(); if to_stdout { @@ -1528,7 +1530,7 @@ fn format(out: &mut Output, repo: &Repository, m: &ArgMatches) -> Result<()> { in_reply_to_message_id = Some(cover_message_id); try!(writeln!(out, "From: {} <{}>", committer_name, committer_email)); try!(writeln!(out, "Date: {}", date_822(committer.when()))); - try!(writeln!(out, "Subject: [{}{}0/{}] {}\n", subject_patch, ensure_space(&subject_patch), commits.len(), subject)); + try!(writeln!(out, "Subject: [{}{}{:0>num_width$}/{}] {}\n", subject_patch, ensure_space(&subject_patch), 0, commits.len(), subject, num_width=num_width)); if !body.is_empty() { try!(writeln!(out, "{}", body)); } @@ -1581,7 +1583,7 @@ fn format(out: &mut Output, repo: &Repository, m: &ArgMatches) -> Result<()> { format!("[{}] ", subject_patch) } } else { - format!("[{}{}{}/{}] ", subject_patch, ensure_space(&subject_patch), commit_num+1, commits.len()) + format!("[{}{}{:0>num_width$}/{}] ", subject_patch, ensure_space(&subject_patch), commit_num+1, commits.len(), num_width=num_width) }; try!(writeln!(out, "Subject: {}{}\n", prefix, subject));