Skip to content

Commit 5480861

Browse files
committed
Merge branch 'jk/fast-export-quote-path' into maint
* jk/fast-export-quote-path: fast-export: quote paths in output
2 parents a1ee40f + 6280dfd commit 5480861

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

builtin/fast-export.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "string-list.h"
1717
#include "utf8.h"
1818
#include "parse-options.h"
19+
#include "quote.h"
1920

2021
static const char *fast_export_usage[] = {
2122
"git fast-export [rev-list-opts]",
@@ -178,6 +179,15 @@ static int depth_first(const void *a_, const void *b_)
178179
return (a->status == 'R') - (b->status == 'R');
179180
}
180181

182+
static void print_path(const char *path)
183+
{
184+
int need_quote = quote_c_style(path, NULL, NULL, 0);
185+
if (need_quote)
186+
quote_c_style(path, NULL, stdout, 0);
187+
else
188+
printf("%s", path);
189+
}
190+
181191
static void show_filemodify(struct diff_queue_struct *q,
182192
struct diff_options *options, void *data)
183193
{
@@ -195,13 +205,18 @@ static void show_filemodify(struct diff_queue_struct *q,
195205

196206
switch (q->queue[i]->status) {
197207
case DIFF_STATUS_DELETED:
198-
printf("D %s\n", spec->path);
208+
printf("D ");
209+
print_path(spec->path);
210+
putchar('\n');
199211
break;
200212

201213
case DIFF_STATUS_COPIED:
202214
case DIFF_STATUS_RENAMED:
203-
printf("%c \"%s\" \"%s\"\n", q->queue[i]->status,
204-
ospec->path, spec->path);
215+
printf("%c ", q->queue[i]->status);
216+
print_path(ospec->path);
217+
putchar(' ');
218+
print_path(spec->path);
219+
putchar('\n');
205220

206221
if (!hashcmp(ospec->sha1, spec->sha1) &&
207222
ospec->mode == spec->mode)
@@ -216,13 +231,15 @@ static void show_filemodify(struct diff_queue_struct *q,
216231
* output the SHA-1 verbatim.
217232
*/
218233
if (no_data || S_ISGITLINK(spec->mode))
219-
printf("M %06o %s %s\n", spec->mode,
220-
sha1_to_hex(spec->sha1), spec->path);
234+
printf("M %06o %s ", spec->mode,
235+
sha1_to_hex(spec->sha1));
221236
else {
222237
struct object *object = lookup_object(spec->sha1);
223-
printf("M %06o :%d %s\n", spec->mode,
224-
get_object_mark(object), spec->path);
238+
printf("M %06o :%d ", spec->mode,
239+
get_object_mark(object));
225240
}
241+
print_path(spec->path);
242+
putchar('\n');
226243
break;
227244

228245
default:

t/t9350-fast-export.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ test_expect_success 'fast-export -C -C | fast-import' '
228228
mkdir new &&
229229
git --git-dir=new/.git init &&
230230
git fast-export -C -C --signed-tags=strip --all > output &&
231-
grep "^C \"file6\" \"file7\"\$" output &&
231+
grep "^C file6 file7\$" output &&
232232
cat output |
233233
(cd new &&
234234
git fast-import &&
@@ -414,4 +414,30 @@ test_expect_success SYMLINKS 'directory becomes symlink' '
414414
(cd result && git show master:foo)
415415
'
416416

417+
test_expect_success 'fast-export quotes pathnames' '
418+
git init crazy-paths &&
419+
(cd crazy-paths &&
420+
blob=`echo foo | git hash-object -w --stdin` &&
421+
git update-index --add \
422+
--cacheinfo 100644 $blob "$(printf "path with\\nnewline")" \
423+
--cacheinfo 100644 $blob "path with \"quote\"" \
424+
--cacheinfo 100644 $blob "path with \\backslash" \
425+
--cacheinfo 100644 $blob "path with space" &&
426+
git commit -m addition &&
427+
git ls-files -z -s | perl -0pe "s{\\t}{$&subdir/}" >index &&
428+
git read-tree --empty &&
429+
git update-index -z --index-info <index &&
430+
git commit -m rename &&
431+
git read-tree --empty &&
432+
git commit -m deletion &&
433+
git fast-export HEAD >export.out &&
434+
git rev-list HEAD >expect &&
435+
git init result &&
436+
cd result &&
437+
git fast-import <../export.out &&
438+
git rev-list HEAD >actual &&
439+
test_cmp ../expect actual
440+
)
441+
'
442+
417443
test_done

0 commit comments

Comments
 (0)