# Splitting config.txt

1 messages from 2013-03-06 to 2013-03-06. Participants: Duy Nguyen.
Thread: https://gitlist.dev/t/33087

## Duy Nguyen, 2013-03-06 14:01

Subject: Splitting config.txt
Message-ID: <20130306140141.GA24386@lanh>
URL: https://gitlist.dev/e/20130306140141.GA24386%40lanh

```
We discussed this before about adding configuration variables into
individual command man pages [1]. This may be a step towards
that. With this, I could add selected configuration variables to
git-push.txt, for example, with a simple patch:

-- 8< --
diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
index 1398025..c130c90 100644
--- a/Documentation/git-push.txt
+++ b/Documentation/git-push.txt
@@ -348,6 +348,13 @@ you are certain that nobody in the meantime fetched your earlier commit A
 overwrite it. In other words, "git push --force" is a method reserved for
 a case where you do mean to lose history.
 
+CONFIGURATION
+-------------
+
+include::config/push.default.txt[]
+include::config/remote.name.pushurl.txt[]
+include::config/remote.name.push.txt[]
+
 
 Examples
 --------
-- 8< --

I know it makes man pages longer (and more intimidating for new
users), but the point is we could select just important keys for each
man page, instead of all keys affecting the command.

I don't post the final patch that splits config.txt, just the script I
use to split it. You can try it yourself. It puts each config key into
a file under Documentation/config, with some characters mangled to be
more fs friendly. Run it inside Documentation/. generated git-config.1
is the same after the split.

-- 8< --
#!/usr/bin/perl

sub extract {
    my ($line) = @_;
    open CC, ">config/$filename" || die "failed to open config/$filename";
    foreach $l (@lines[($start - 1)..($line - 2)]) {
	$l =~ s/^include::/include::..\//;
	print CC $l;
    }
    close CC;
    print C "include::config/$filename" . "[]\n";
}

open C, "config.txt" || die "failed to open config.txt";
our @lines = <C>;
close C;

our $start = 0;
our $filename;

open F, "grep -n '^[a-z].*::\$' config.txt|" || die "failed to grep";
open C, ">config.txt.new" || die "unable to open config.txt.new";
while (<F>) {
    chomp;
    $_ =~ m/([^:]*):(.*)/;
    my $line = $1;
    my $name = $2;
    $name =~ s/\*/_/g;
    $name =~ s/<//g;
    $name =~ s/>//g;
    $name =~ s/::$//;
    $name = "http.speedLimit" if $name eq "http.lowSpeedLimit, http.lowSpeedTime";
    $name = "gitcvs.userpass" if $name eq "gitcvs.dbuser, gitcvs.dbpass";
    next if $line - $start == 1;
    if ($start > 0) {
	extract $line;
    } else {
	foreach $l (@lines[0..($line-2)]) {
	    print C $l;
	}
    }
    $start = $line;
    $filename = $name . ".txt";
}

extract $#lines + 2;
close C;
system "mv config.txt.new config.txt";
-- 8< --

[1] http://thread.gmane.org/gmane.comp.version-control.git/206780/focus=206939

```
