Skip to content

Commit 2d6b08a

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f8ab018 commit 2d6b08a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

contrib/mw-to-git/git-remote-mediawiki.perl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,14 @@ sub get_mw_pages {
369369
return %pages;
370370
}
371371

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 {
375377
my $args = shift;
376378
my $encoding = (shift || 'encoding(UTF-8)');
377-
open(my $git, "-|:${encoding}", "git ${args}")
379+
open(my $git, "-|:${encoding}", @$args)
378380
or die "Unable to fork: $!\n";
379381
my $res = do {
380382
local $/ = undef;
@@ -385,6 +387,15 @@ sub run_git {
385387
return $res;
386388
}
387389

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 }
388399

389400
sub get_all_mediafiles {
390401
my $pages = shift;

0 commit comments

Comments
 (0)