]> err.no Git - dpkg/commitdiff
Dpkg::Source::VCS::git: simplify read_git_config
authorFrank Lichtenheld <djpig@debian.org>
Sun, 10 Feb 2008 23:14:28 +0000 (00:14 +0100)
committerFrank Lichtenheld <djpig@debian.org>
Mon, 11 Feb 2008 00:35:58 +0000 (01:35 +0100)
* scripts/Dpkg/Source/VCS/git.pm(read_git_config): Simplify
by setting $/ = "\0" instead of splitting on \n, which
separates keys and values, but can also occour in the
values themself.

scripts/Dpkg/Source/VCS/git.pm

index 686782895e1762d1b7a14c9c231760221d845f8f..9caf241008a40fe1c48f82571326c9fdd69e2a40 100644 (file)
@@ -81,26 +81,11 @@ sub read_git_config {
        my %ret;
        open(GIT_CONFIG, '-|', "git", "config", "--file", $file, "--null", "-l") ||
            subprocerr("git config");
-       my ($key, $value);
+       local $/ = "\0";
        while (<GIT_CONFIG>) {
-               if (! defined $key) {
-                       $key=$_;
-                       chomp $key;
-                       $value="";
-               }
-               elsif (/(.*)\0(.*)/) {
-                       $value.=$1;
-                       push @{$ret{$key}}, $value;
-                       $key=$2;
-                       chomp $key;
-                       $value="";
-               }
-               else {
-                       $value.=$1;
-               }
-       }
-       if (defined $key && length $key) {
-               push @{$ret{$key}}, $value;
+           chomp;
+           my ($key, $value) = split(/\n/, $_, 2);
+           push @{$ret{$key}}, $value;
        }
        close(GIT_CONFIG) || syserr(_g("git config exited nonzero"));
 
@@ -244,7 +229,11 @@ sub post_unpack_tar {
                print GIT_CONFIG "\n# "._g("The following setting(s) were disabled by dpkg-source").":\n";
                foreach my $field (sort keys %config) {
                        foreach my $value (@{$config{$field}}) {
+                           if (defined($value)) {
                                print GIT_CONFIG "# $field=$value\n";
+                           } else {
+                               print GIT_CONFIG "# $field\n";
+                           }
                        }
                }
                close GIT_CONFIG;