[PATCH] format-patch -n: make sorting easier by padding number
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Feb 9, 2007, 00:43 UTC
- Message-ID
- <Pine.LNX.4.63.0702090142100.22628@wbgn013.biozentrum.uni-wuerzburg.de>
- In-Reply-To
- <Pine.LNX.4.64.0702081623460.8424@woody.linux-foundation.org>
Now, when format-patch outputs more than 9 patches, the numbers are padded accordingly. Example:
[PATCH 009/167] The 9th patch of a series of 167
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
On Thu, 8 Feb 2007, Linus Torvalds wrote: > On Thu, 8 Feb 2007, Junio C Hamano wrote: > > > > This came up before, but when you have more than 9 in your > > series, we _could_ do [PATCH 01/12] ... [PATCH 12/12] to line > > them up in e-mail client of the recipients better. > > Not just "line them up". It's more than just a visual thing.
How about this?
Yes, it calculates the width over and over again, but it's not like it's a really performance critical part.
log-tree.c | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/log-tree.c b/log-tree.c index 85acd66..89c29e2 100644 --- a/log-tree.c +++ b/log-tree.c @@ -102,6 +102,16 @@ static int append_signoff(char *buf, int buf_sz, int at, const char *signoff) return at; } +static unsigned int log10(unsigned int number) +{ + unsigned int i = 10, result = 1; + while (i < number) { + i *= 10; + result++; + } + return result; +} + void show_log(struct rev_info *opt, const char *sep) { static char this_header[16384]; @@ -155,7 +165,8 @@ void show_log(struct rev_info *opt, const char *sep) if (opt->total > 0) { static char buffer[64]; snprintf(buffer, sizeof(buffer), - "Subject: [PATCH %d/%d] ", + "Subject: [PATCH %0*d/%d] ", + log10(opt->total), opt->nr, opt->total); subject = buffer; } else if (opt->total == 0)