@matheusbsbs / matheus-bagliano / commits / 22ddf71979
Fork 0

Update ls-files and ls-tree to use C-style quoting for funny pathnames.

Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Oct 14, 2005 at 21:56 UTC 22ddf7197958337a8c254122eae4efcd8a54098a
2 files changed +19 -9
ls-files.c
+15 -7
@@ -9,6 +9,7 @@
9 #include <fnmatch.h>
10
11 #include "cache.h"
12 +#include "quote.h"
13
14 static int show_deleted = 0;
15 static int show_cached = 0;
@@ -342,7 +343,9 @@ static void show_dir_entry(const char *tag, struct nond_on_fs *ent)
343 if (pathspec && !match(pathspec, ent->name, len))
344 return;
345
345 - printf("%s%s%c", tag, ent->name + offset, line_terminator);
346 + fputs(tag, stdout);
347 + write_name_quoted("", ent->name + offset, line_terminator, stdout);
348 + putchar(line_terminator);
349 }
350
351 static void show_killed_files(void)
@@ -405,15 +408,20 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
408 if (pathspec && !match(pathspec, ce->name, len))
409 return;
410
408 - if (!show_stage)
409 - printf("%s%s%c", tag, ce->name + offset, line_terminator);
410 - else
411 - printf("%s%06o %s %d\t%s%c",
411 + if (!show_stage) {
412 + fputs(tag, stdout);
413 + write_name_quoted("", ce->name + offset, line_terminator, stdout);
414 + putchar(line_terminator);
415 + }
416 + else {
417 + printf("%s%06o %s %d\t",
418 tag,
419 ntohl(ce->ce_mode),
420 sha1_to_hex(ce->sha1),
415 - ce_stage(ce),
416 - ce->name + offset, line_terminator);
421 + ce_stage(ce));
422 + write_name_quoted("", ce->name + offset, line_terminator, stdout);
423 + putchar(line_terminator);
424 + }
425 }
426
427 static void show_files(void)
ls-tree.c
+4 -2
@@ -6,6 +6,7 @@
6 #include "cache.h"
7 #include "blob.h"
8 #include "tree.h"
9 +#include "quote.h"
10
11 static int line_termination = '\n';
12 #define LS_RECURSIVE 1
@@ -156,8 +157,9 @@ static int show_entry(struct tree_entry_list *e, int level, char *pathbuf)
157 int err = 0;
158
159 if (e != &root_entry) {
159 - printf("%06o %s %s %s%s", e->mode, entry_type(e),
160 - entry_hex(e), pathbuf, e->name);
160 + printf("%06o %s %s ",
161 + e->mode, entry_type(e), entry_hex(e));
162 + write_name_quoted(pathbuf, e->name, line_termination, stdout);
163 putchar(line_termination);
164 }
165