Merge branch 'jk/fast-export-quote-path'
* jk/fast-export-quote-path: fast-export: quote paths in output
This commit is contained in:
commit
b81b758d50
@ -16,6 +16,7 @@
|
|||||||
#include "string-list.h"
|
#include "string-list.h"
|
||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
#include "parse-options.h"
|
#include "parse-options.h"
|
||||||
|
#include "quote.h"
|
||||||
|
|
||||||
static const char *fast_export_usage[] = {
|
static const char *fast_export_usage[] = {
|
||||||
"git fast-export [rev-list-opts]",
|
"git fast-export [rev-list-opts]",
|
||||||
@ -179,6 +180,15 @@ static int depth_first(const void *a_, const void *b_)
|
|||||||
return (a->status == 'R') - (b->status == 'R');
|
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,
|
static void show_filemodify(struct diff_queue_struct *q,
|
||||||
struct diff_options *options, void *data)
|
struct diff_options *options, void *data)
|
||||||
{
|
{
|
||||||
@ -196,13 +206,18 @@ static void show_filemodify(struct diff_queue_struct *q,
|
|||||||
|
|
||||||
switch (q->queue[i]->status) {
|
switch (q->queue[i]->status) {
|
||||||
case DIFF_STATUS_DELETED:
|
case DIFF_STATUS_DELETED:
|
||||||
printf("D %s\n", spec->path);
|
printf("D ");
|
||||||
|
print_path(spec->path);
|
||||||
|
putchar('\n');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DIFF_STATUS_COPIED:
|
case DIFF_STATUS_COPIED:
|
||||||
case DIFF_STATUS_RENAMED:
|
case DIFF_STATUS_RENAMED:
|
||||||
printf("%c \"%s\" \"%s\"\n", q->queue[i]->status,
|
printf("%c ", q->queue[i]->status);
|
||||||
ospec->path, spec->path);
|
print_path(ospec->path);
|
||||||
|
putchar(' ');
|
||||||
|
print_path(spec->path);
|
||||||
|
putchar('\n');
|
||||||
|
|
||||||
if (!hashcmp(ospec->sha1, spec->sha1) &&
|
if (!hashcmp(ospec->sha1, spec->sha1) &&
|
||||||
ospec->mode == spec->mode)
|
ospec->mode == spec->mode)
|
||||||
@ -217,13 +232,15 @@ static void show_filemodify(struct diff_queue_struct *q,
|
|||||||
* output the SHA-1 verbatim.
|
* output the SHA-1 verbatim.
|
||||||
*/
|
*/
|
||||||
if (no_data || S_ISGITLINK(spec->mode))
|
if (no_data || S_ISGITLINK(spec->mode))
|
||||||
printf("M %06o %s %s\n", spec->mode,
|
printf("M %06o %s ", spec->mode,
|
||||||
sha1_to_hex(spec->sha1), spec->path);
|
sha1_to_hex(spec->sha1));
|
||||||
else {
|
else {
|
||||||
struct object *object = lookup_object(spec->sha1);
|
struct object *object = lookup_object(spec->sha1);
|
||||||
printf("M %06o :%d %s\n", spec->mode,
|
printf("M %06o :%d ", spec->mode,
|
||||||
get_object_mark(object), spec->path);
|
get_object_mark(object));
|
||||||
}
|
}
|
||||||
|
print_path(spec->path);
|
||||||
|
putchar('\n');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -228,7 +228,7 @@ test_expect_success 'fast-export -C -C | fast-import' '
|
|||||||
mkdir new &&
|
mkdir new &&
|
||||||
git --git-dir=new/.git init &&
|
git --git-dir=new/.git init &&
|
||||||
git fast-export -C -C --signed-tags=strip --all > output &&
|
git fast-export -C -C --signed-tags=strip --all > output &&
|
||||||
grep "^C \"file6\" \"file7\"\$" output &&
|
grep "^C file6 file7\$" output &&
|
||||||
cat output |
|
cat output |
|
||||||
(cd new &&
|
(cd new &&
|
||||||
git fast-import &&
|
git fast-import &&
|
||||||
@ -414,4 +414,30 @@ test_expect_success SYMLINKS 'directory becomes symlink' '
|
|||||||
(cd result && git show master:foo)
|
(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 <index &&
|
||||||
|
git commit -m rename &&
|
||||||
|
git read-tree --empty &&
|
||||||
|
git commit -m deletion &&
|
||||||
|
git fast-export HEAD >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
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user