@matheusbsbs / matheus-bagliano / commits / e00de24b10
Fork 0

format-patch -n: make sorting easier by padding number

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> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Schindelin committed Feb 9, 2007 at 01:43 UTC e00de24b102da647485aeeeff278c21ab31420a2
1 file changed +12 -1
log-tree.c
+12 -1
@@ -102,6 +102,16 @@ static int append_signoff(char *buf, int buf_sz, int at, const char *signoff)
102 return at;
103 }
104
105 +static unsigned int digits_in_number(unsigned int number)
106 +{
107 + unsigned int i = 10, result = 1;
108 + while (i <= number) {
109 + i *= 10;
110 + result++;
111 + }
112 + return result;
113 +}
114 +
115 void show_log(struct rev_info *opt, const char *sep)
116 {
117 static char this_header[16384];
@@ -155,7 +165,8 @@ void show_log(struct rev_info *opt, const char *sep)
165 if (opt->total > 0) {
166 static char buffer[64];
167 snprintf(buffer, sizeof(buffer),
158 - "Subject: [PATCH %d/%d] ",
168 + "Subject: [PATCH %0*d/%d] ",
169 + digits_in_number(opt->total),
170 opt->nr, opt->total);
171 subject = buffer;
172 } else if (opt->total == 0)