@matheusbsbs / matheus-bagliano / commits / 2d6b08aff4
Fork 0

remote-mediawiki: provide a list form of run_git()

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>

Ævar Arnfjörð Bjarmason committed Sep 21, 2020 at 12:39 UTC 2d6b08aff41026019e2051abec05e52785450e83
1 file changed +15 -4
contrib/mw-to-git/git-remote-mediawiki.perl
+15 -4
@@ -369,12 +369,14 @@ sub get_mw_pages {
369 return %pages;
370 }
371
372 -# usage: $out = run_git("command args");
373 -# $out = run_git("command args", "raw"); # don't interpret output as UTF-8.
374 -sub run_git {
372 +# usage: $out = run_git_quoted(["command", "args", ...]);
373 +# $out = run_git_quoted(["command", "args", ...], "raw"); # don't interpret output as UTF-8.
374 +# $out = run_git_unquoted(["command args"); # don't quote arguments
375 +# $out = run_git_unquoted(["command args", "raw"); # ditto but raw instead of UTF-8 as above
376 +sub _run_git {
377 my $args = shift;
378 my $encoding = (shift || 'encoding(UTF-8)');
377 - open(my $git, "-|:${encoding}", "git ${args}")
379 + open(my $git, "-|:${encoding}", @$args)
380 or die "Unable to fork: $!\n";
381 my $res = do {
382 local $/ = undef;
@@ -385,6 +387,15 @@ sub run_git {
387 return $res;
388 }
389
390 +sub run_git_quoted {
391 + _run_git(["git", @{$_[0]}], $_[1]);
392 +}
393 +
394 +sub run_git_unquoted {
395 + _run_git(["git $_[0]"], $_[1]);
396 +}
397 +
398 +BEGIN { *run_git = \&run_git_unquoted }
399
400 sub get_all_mediafiles {
401 my $pages = shift;