]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remote-mediawiki: provide a list form of run_git()
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Mon, 21 Sep 2020 10:39:57 +0000 (12:39 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 21 Sep 2020 19:37:38 +0000 (12:37 -0700)
Invoking commands as "git $args" doesn't quote $args. Let's support
["git", $args] as well, and create corresponding run_git_quoted() and
run_git_unquoted() aliases for subsequent changes when we move the
code over to the new style of invoking this function. At that point
we'll delete the then-unused run_git() wrapper.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/mw-to-git/git-remote-mediawiki.perl

index 26d5e1a174ed5ba786b28a88fd0fa33ebfa93309..59cb27751782f111947ecae5de3cb97c91d97ed3 100755 (executable)
@@ -369,12 +369,14 @@ sub get_mw_pages {
        return %pages;
 }
 
-# usage: $out = run_git("command args");
-#        $out = run_git("command args", "raw"); # don't interpret output as UTF-8.
-sub run_git {
+# usage: $out = run_git_quoted(["command", "args", ...]);
+#        $out = run_git_quoted(["command", "args", ...], "raw"); # don't interpret output as UTF-8.
+#        $out = run_git_unquoted(["command args"); # don't quote arguments
+#        $out = run_git_unquoted(["command args", "raw"); # ditto but raw instead of UTF-8 as above
+sub _run_git {
        my $args = shift;
        my $encoding = (shift || 'encoding(UTF-8)');
-       open(my $git, "-|:${encoding}", "git ${args}")
+       open(my $git, "-|:${encoding}", @$args)
            or die "Unable to fork: $!\n";
        my $res = do {
                local $/ = undef;
@@ -385,6 +387,15 @@ sub run_git {
        return $res;
 }
 
+sub run_git_quoted {
+    _run_git(["git", @{$_[0]}], $_[1]);
+}
+
+sub run_git_unquoted {
+    _run_git(["git $_[0]"], $_[1]);
+}
+
+BEGIN { *run_git = \&run_git_unquoted }
 
 sub get_all_mediafiles {
        my $pages = shift;