From: Junio C Hamano Date: Thu, 11 Aug 2011 18:03:16 +0000 (-0700) Subject: Merge branch 'jk/fast-export-quote-path' X-Git-Tag: v1.7.7-rc0~37 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/b81b758d5001c4ebab1a5b8202bb1b0f4cdf3391?ds=inline;hp=-c Merge branch 'jk/fast-export-quote-path' * jk/fast-export-quote-path: fast-export: quote paths in output --- b81b758d5001c4ebab1a5b8202bb1b0f4cdf3391 diff --combined builtin/fast-export.c index becef85782,e5035675b9..9836e6b7ca --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@@ -16,6 -16,7 +16,7 @@@ #include "string-list.h" #include "utf8.h" #include "parse-options.h" + #include "quote.h" static const char *fast_export_usage[] = { "git fast-export [rev-list-opts]", @@@ -26,7 -27,6 +27,7 @@@ static int progress static enum { ABORT, VERBATIM, WARN, STRIP } signed_tag_mode = ABORT; static enum { ERROR, DROP, REWRITE } tag_of_filtered_mode = ABORT; static int fake_missing_tagger; +static int use_done_feature; static int no_data; static int full_tree; @@@ -179,6 -179,15 +180,15 @@@ static int depth_first(const void *a_, return (a->status == 'R') - (b->status == 'R'); } + static void print_path(const char *path) + { + int need_quote = quote_c_style(path, NULL, NULL, 0); + if (need_quote) + quote_c_style(path, NULL, stdout, 0); + else + printf("%s", path); + } + static void show_filemodify(struct diff_queue_struct *q, struct diff_options *options, void *data) { @@@ -196,13 -205,18 +206,18 @@@ switch (q->queue[i]->status) { case DIFF_STATUS_DELETED: - printf("D %s\n", spec->path); + printf("D "); + print_path(spec->path); + putchar('\n'); break; case DIFF_STATUS_COPIED: case DIFF_STATUS_RENAMED: - printf("%c \"%s\" \"%s\"\n", q->queue[i]->status, - ospec->path, spec->path); + printf("%c ", q->queue[i]->status); + print_path(ospec->path); + putchar(' '); + print_path(spec->path); + putchar('\n'); if (!hashcmp(ospec->sha1, spec->sha1) && ospec->mode == spec->mode) @@@ -217,13 -231,15 +232,15 @@@ * output the SHA-1 verbatim. */ if (no_data || S_ISGITLINK(spec->mode)) - printf("M %06o %s %s\n", spec->mode, - sha1_to_hex(spec->sha1), spec->path); + printf("M %06o %s ", spec->mode, + sha1_to_hex(spec->sha1)); else { struct object *object = lookup_object(spec->sha1); - printf("M %06o :%d %s\n", spec->mode, - get_object_mark(object), spec->path); + printf("M %06o :%d ", spec->mode, + get_object_mark(object)); } + print_path(spec->path); + putchar('\n'); break; default: @@@ -620,16 -636,14 +637,16 @@@ int cmd_fast_export(int argc, const cha OPT_CALLBACK(0, "tag-of-filtered-object", &tag_of_filtered_mode, "mode", "select handling of tags that tag filtered objects", parse_opt_tag_of_filtered_mode), - OPT_STRING(0, "export-marks", &export_filename, "FILE", + OPT_STRING(0, "export-marks", &export_filename, "file", "Dump marks to this file"), - OPT_STRING(0, "import-marks", &import_filename, "FILE", + OPT_STRING(0, "import-marks", &import_filename, "file", "Import marks from this file"), OPT_BOOLEAN(0, "fake-missing-tagger", &fake_missing_tagger, "Fake a tagger when tags lack one"), OPT_BOOLEAN(0, "full-tree", &full_tree, "Output full tree for each commit"), + OPT_BOOLEAN(0, "use-done-feature", &use_done_feature, + "Use the done feature to terminate the stream"), { OPTION_NEGBIT, 0, "data", &no_data, NULL, "Skip output of blob data", PARSE_OPT_NOARG | PARSE_OPT_NEGHELP, NULL, 1 }, @@@ -651,13 -665,10 +668,13 @@@ if (argc > 1) usage_with_options (fast_export_usage, options); + if (use_done_feature) + printf("feature done\n"); + if (import_filename) import_marks(import_filename); - if (import_filename && revs.prune_data) + if (import_filename && revs.prune_data.nr) full_tree = 1; get_tags_and_duplicates(&revs.pending, &extra_refs); @@@ -681,8 -692,5 +698,8 @@@ if (export_filename) export_marks(export_filename); + if (use_done_feature) + printf("done\n"); + return 0; } diff --combined t/t9350-fast-export.sh index f823c05305,d90a4136cf..950d0ff498 --- a/t/t9350-fast-export.sh +++ b/t/t9350-fast-export.sh @@@ -26,7 -26,7 +26,7 @@@ test_expect_success 'setup' test_tick && git tag rein && git checkout -b wer HEAD^ && - echo lange > file2 + echo lange > file2 && test_tick && git commit -m sitzt file2 && test_tick && @@@ -228,7 -228,7 +228,7 @@@ test_expect_success 'fast-export -C -C mkdir new && git --git-dir=new/.git init && git fast-export -C -C --signed-tags=strip --all > output && - grep "^C \"file6\" \"file7\"\$" output && + grep "^C file6 file7\$" output && cat output | (cd new && git fast-import && @@@ -414,4 -414,30 +414,30 @@@ test_expect_success SYMLINKS 'director (cd result && git show master:foo) ' + test_expect_success 'fast-export quotes pathnames' ' + git init crazy-paths && + (cd crazy-paths && + blob=`echo foo | git hash-object -w --stdin` && + git update-index --add \ + --cacheinfo 100644 $blob "$(printf "path with\\nnewline")" \ + --cacheinfo 100644 $blob "path with \"quote\"" \ + --cacheinfo 100644 $blob "path with \\backslash" \ + --cacheinfo 100644 $blob "path with space" && + git commit -m addition && + git ls-files -z -s | perl -0pe "s{\\t}{$&subdir/}" >index && + git read-tree --empty && + git update-index -z --index-info export.out && + git rev-list HEAD >expect && + git init result && + cd result && + git fast-import <../export.out && + git rev-list HEAD >actual && + test_cmp ../expect actual + ) + ' + test_done