git-name-rev: don't use printf without format
printf() without an explicit format string is not a good coding practise, unless the printed string is guaranteed to not contain percent signs. While fixing this, we might as well combine the calls to fwrite() and printf(). Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Aug 3, 2008 at 15:44 UTC
7c5b1675a88a52be1822129e4aa915c5531f6700
1 file changed
+5
-7
builtin-name-rev.c
+5
-7
@@ -189,6 +189,7 @@ static void name_rev_line(char *p, struct name_ref_data *data)
189
unsigned char sha1[40];
190
const char *name = NULL;
191
char c = *(p+1);
192
+ int p_len = p - p_start + 1;
193
194
forty = 0;
195
@@ -204,13 +205,10 @@ static void name_rev_line(char *p, struct name_ref_data *data)
205
if (!name)
206
continue;
207
207
- if (data->name_only) {
208
- fwrite(p_start, p - p_start + 1 - 40, 1, stdout);
209
- printf(name);
210
- } else {
211
- fwrite(p_start, p - p_start + 1, 1, stdout);
212
- printf(" (%s)", name);
213
- }
208
+ if (data->name_only)
209
+ printf("%.*s%s", p_len - 40, p_start, name);
210
+ else
211
+ printf("%.*s (%s)", p_len, p_start, name);
212
p_start = p + 1;
213
}
214
}