git-blame --porcelain: quote filename in c-style when needed.
Otherwise a pathname that has funny characters such as LF would screw up the parsing programs of the output. Strictly speaking, this is not backward compatible, but the current output for pathnames that have embedded LF and such cannot be sanely parsed anyway, and pathnames that only use characters from the portable pathname character set won't be affected. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 28, 2007 at 01:42 UTC
46e5e69d5f2e8ae87a29953531a3d1bd7cb0292f
1 file changed
+10
-5
builtin-blame.c
+10
-5
@@ -1182,6 +1182,13 @@ static void get_commit_info(struct commit *commit,
1182
summary_buf[len] = 0;
1183
}
1184
1185
+static void write_filename_info(const char *path)
1186
+{
1187
+ printf("filename ");
1188
+ write_name_quoted(NULL, 0, path, 1, stdout);
1189
+ putchar('\n');
1190
+}
1191
+
1192
static void found_guilty_entry(struct blame_entry *ent)
1193
{
1194
if (ent->guilty)
@@ -1209,9 +1216,7 @@ static void found_guilty_entry(struct blame_entry *ent)
1216
if (suspect->commit->object.flags & UNINTERESTING)
1217
printf("boundary\n");
1218
}
1212
- printf("filename ");
1213
- write_name_quoted(NULL, 0, suspect->path, 1, stdout);
1214
- putchar('\n');
1219
+ write_filename_info(suspect->path);
1220
}
1221
}
1222
@@ -1315,13 +1320,13 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent)
1320
printf("committer-mail %s\n", ci.committer_mail);
1321
printf("committer-time %lu\n", ci.committer_time);
1322
printf("committer-tz %s\n", ci.committer_tz);
1318
- printf("filename %s\n", suspect->path);
1323
+ write_filename_info(suspect->path);
1324
printf("summary %s\n", ci.summary);
1325
if (suspect->commit->object.flags & UNINTERESTING)
1326
printf("boundary\n");
1327
}
1328
else if (suspect->commit->object.flags & MORE_THAN_ONE_PATH)
1324
- printf("filename %s\n", suspect->path);
1329
+ write_filename_info(suspect->path);
1330
1331
cp = nth_line(sb, ent->lno);
1332
for (cnt = 0; cnt < ent->num_lines; cnt++) {