chiark / gitweb /
Dgit.pm: git_slurp_config_src: Break out from dgit
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 14 Jul 2017 09:53:33 +0000 (10:53 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 18 Jul 2017 23:28:01 +0000 (00:28 +0100)
We are going to want this so we can provide better subtree setup
functions in Dgit.pm, including the config transfer.

No functional change, except that we now run just "git" from the path,
rather than honouring dgit's @git (which is not available in Dgit.pm).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Debian/Dgit.pm
dgit

index aef0112aebb975ce49cca55699808fbe6cf99922..3d97848ff2df75b96491a8fc2ac2d6bd5224a86a 100644 (file)
@@ -58,6 +58,7 @@ BEGIN {
                       $debugprefix *debuglevel *DEBUG
                       shellquote printcmd messagequote
                       $negate_harmful_gitattrs
+                     git_slurp_config_src
                       workarea_setup);
     # implicitly uses $main::us
     %EXPORT_TAGS = ( policyflags => [qw(NOFFCHECK FRESHREPO NOCOMMITCHECK)] );
@@ -417,6 +418,30 @@ sub is_fast_fwd ($$) {
     }
 }
 
+sub git_slurp_config_src ($) {
+    my ($src) = @_;
+    # returns $r such that $r->{KEY}[] = VALUE
+    my @cmd = (qw(git config -z --get-regexp), "--$src", qw(.*));
+    debugcmd "|",@cmd;
+
+    local ($debuglevel) = $debuglevel-2;
+    local $/="\0";
+
+    my $r = { };
+    open GITS, "-|", @cmd or die $!;
+    while (<GITS>) {
+       chomp or die;
+       printdebug "=> ", (messagequote $_), "\n";
+       m/\n/ or die "$_ ?";
+       push @{ $r->{$`} }, $'; #';
+    }
+    $!=0; $?=0;
+    close GITS
+       or ($!==0 && $?==256)
+       or failedcmd @cmd;
+    return $r;
+}
+
 sub workarea_setup ($) {
     # for use in the workarea
     my ($t_local_git_cfg) = @_;
diff --git a/dgit b/dgit
index 89f496d7e72f8a698a6d8bdbd7b817ad354edf4f..4b19384184b9f866890c0039e6c5b6403b1324cc 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -641,30 +641,14 @@ our %gitcfgs;
 our @gitcfgsources = qw(cmdline local global system);
 
 sub git_slurp_config () {
-    local ($debuglevel) = $debuglevel-2;
-    local $/="\0";
-
     # This algoritm is a bit subtle, but this is needed so that for
     # options which we want to be single-valued, we allow the
     # different config sources to override properly.  See #835858.
     foreach my $src (@gitcfgsources) {
        next if $src eq 'cmdline';
        # we do this ourselves since git doesn't handle it
-       
-       my @cmd = (@git, qw(config -z --get-regexp), "--$src", qw(.*));
-       debugcmd "|",@cmd;
 
-       open GITS, "-|", @cmd or die $!;
-       while (<GITS>) {
-           chomp or die;
-           printdebug "=> ", (messagequote $_), "\n";
-           m/\n/ or die "$_ ?";
-           push @{ $gitcfgs{$src}{$`} }, $'; #';
-       }
-       $!=0; $?=0;
-       close GITS
-           or ($!==0 && $?==256)
-           or failedcmd @cmd;
+       $gitcfgs{$src} = git_slurp_config_src $src;
     }
 }