Merge branch 'maint'
authorJunio C Hamano <gitster@pobox.com>
Thu, 29 Nov 2012 20:21:17 +0000 (12:21 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 29 Nov 2012 20:21:17 +0000 (12:21 -0800)
* maint:
git-fast-import.txt: improve documentation for quoted paths
git-remote-mediawiki: escape ", \, and LF in file names

Documentation/git-fast-import.txt
contrib/mw-to-git/git-remote-mediawiki
contrib/mw-to-git/t/t9362-mw-to-git-utf8.sh
index 959e4d3aee2c616ec9b12cf84865ade2f2ef7206..d1844ead4a4883cc31447c20763b61091f66ed8e 100644 (file)
@@ -562,8 +562,12 @@ A `<path>` string must use UNIX-style directory separators (forward
 slash `/`), may contain any byte other than `LF`, and must not
 start with double quote (`"`).
 
-If an `LF` or double quote must be encoded into `<path>` shell-style
-quoting should be used, e.g. `"path/with\n and \" in it"`.
+A path can use C-style string quoting; this is accepted in all cases
+and mandatory if the filename starts with double quote or contains
+`LF`. In C-style quoting, the complete name should be surrounded with
+double quotes, and any `LF`, backslash, or double quote characters
+must be escaped by preceding them with a backslash (e.g.,
+`"path/with\n, \\ and \" in it"`).
 
 The value of `<path>` must be in canonical form. That is it must not:
 
index 68555d426540d710b5220168c9fa8eee9f946219..094129de09ca92643d98f34f20a35479089bcbcb 100755 (executable)
@@ -711,6 +711,14 @@ sub fetch_mw_revisions {
        return ($n, @revisions);
 }
 
+sub fe_escape_path {
+    my $path = shift;
+    $path =~ s/\\/\\\\/g;
+    $path =~ s/"/\\"/g;
+    $path =~ s/\n/\\n/g;
+    return '"' . $path . '"';
+}
+
 sub import_file_revision {
        my $commit = shift;
        my %commit = %{$commit};
@@ -738,15 +746,17 @@ sub import_file_revision {
                print STDOUT "from refs/mediawiki/$remotename/master^0\n";
        }
        if ($content ne DELETED_CONTENT) {
-               print STDOUT "M 644 inline $title.mw\n";
+               print STDOUT "M 644 inline " .
+                   fe_escape_path($title . ".mw") . "\n";
                literal_data($content);
                if (%mediafile) {
-                       print STDOUT "M 644 inline $mediafile{title}\n";
+                       print STDOUT "M 644 inline "
+                           . fe_escape_path($mediafile{title}) . "\n";
                        literal_data_raw($mediafile{content});
                }
                print STDOUT "\n\n";
        } else {
-               print STDOUT "D $title.mw\n";
+               print STDOUT "D " . fe_escape_path($title . ".mw") . "\n";
        }
 
        # mediawiki revision number in the git note
index 246d47d8fb4e6aa141e1aa5b10b63bbb179fd73e..b6405ce2628480240fc92ac5d69307991f2d5c69 100755 (executable)
@@ -318,4 +318,30 @@ test_expect_success 'git push with \ in format control' '
 '
 
 
+test_expect_success 'fast-import meta-characters in page name (mw -> git)' '
+       wiki_reset &&
+       wiki_editpage \"file\"_\\_foo "expect to be called \"file\"_\\_foo" false &&
+       git clone mediawiki::'"$WIKI_URL"' mw_dir_21 &&
+       test_path_is_file mw_dir_21/\"file\"_\\_foo.mw &&
+       wiki_getallpage ref_page_21 &&
+       test_diff_directories mw_dir_21 ref_page_21
+'
+
+
+test_expect_success 'fast-import meta-characters in page name (git -> mw) ' '
+       wiki_reset &&
+       git clone mediawiki::'"$WIKI_URL"' mw_dir_22 &&
+       (
+               cd mw_dir_22 &&
+               echo "this file is called \"file\"_\\_foo.mw" >\"file\"_\\_foo &&
+               git add . &&
+               git commit -am "file \"file\"_\\_foo" &&
+               git pull &&
+               git push
+       ) &&
+       wiki_getallpage ref_page_22 &&
+       test_diff_directories mw_dir_22 ref_page_22
+'
+
+
 test_done