Commit | Line | Data |
---|---|---|
d36c5f7b IJ |
1 | # -*- perl -*- |
2 | ||
3 | # uses: | |
4 | # $specpath whole path from caller, minus any leading /s | |
5 | # $spechost host from caller | |
6 | # | |
7 | # sets: | |
8 | # | |
9 | # always: | |
10 | # $uri | |
11 | # | |
12 | # if match found for this host and path: | |
13 | # $serve_user username, or undef if no match (then other serve_* invalid) | |
14 | # $serve_dir directory as specified in config | |
15 | # $serve_repo subpath under $serve_dir _including_ leading / | |
16 | # | |
17 | # for use by user's service program | |
18 | # $repo_regexp | |
19 | # $require_exportok | |
20 | ||
d36c5f7b IJ |
21 | sub remain_path ($) { |
22 | # return value matches {( / [^/]+ )+}x | |
70b9d2e0 IJ |
23 | my ($vsubpath) = @_; |
24 | syslog 'debug', sprintf "DEBUG remain_path %s $specpath", | |
25 | (defined $vsubpath ? $vsubpath : '<undef>'); | |
26 | return "/$specpath" if !defined $vsubpath; | |
27 | return "" if $vsubpath eq $specpath; | |
28 | return substr($specpath,length($vsubpath)) | |
29 | if substr($specpath,0,length($vsubpath)+1) eq "$vsubpath/"; | |
d36c5f7b IJ |
30 | return undef; |
31 | } | |
32 | ||
70b9d2e0 IJ |
33 | fail "no config ??" unless @ARGV; |
34 | fail "no specpath ??" unless length $specpath; | |
d36c5f7b IJ |
35 | |
36 | our $uri = "git://$spechost/$specpath"; | |
70b9d2e0 | 37 | our $repo_regexp= '^/*(\\w[-+._0-9A-Za-z]*)$'; # stupid emacs '; |
d36c5f7b IJ |
38 | our $check_export= 0; |
39 | ||
70b9d2e0 IJ |
40 | our ($serve_user, $serve_dir, $serve_repo); |
41 | ||
42 | sub fexists ($) { | |
43 | my ($f) = @_; | |
44 | if (stat $f) { | |
45 | -f _ or fail "bad config $_ - not a file"; | |
46 | return 1; | |
47 | } else { | |
48 | $!==&ENOENT or fail "bad config $_ - could not stat: $!"; | |
49 | return 0; | |
50 | } | |
51 | } | |
52 | ||
53 | @ARGV = grep { fexists($_) } @ARGV; | |
54 | ||
d36c5f7b | 55 | while (<>) { |
70b9d2e0 | 56 | |
d36c5f7b IJ |
57 | s/^\s*//; |
58 | s/\s+$//; | |
59 | next unless m/\S/; | |
60 | next if m/^\#/; | |
61 | ||
62 | if (m{^ single-user \s+ (\S+?) (/\S*)? \s+ (\S+) (?: \s+ (\S+) )? $ }x) { | |
70b9d2e0 IJ |
63 | my ($h,$v,$u,$d) = ($1,$2,$3,$4); |
64 | next unless $h eq $spechost; | |
65 | $serve_repo= remain_path($v); | |
d36c5f7b IJ |
66 | next unless defined $serve_repo; |
67 | $serve_user= $u; | |
68 | $serve_dir= $d; | |
70b9d2e0 IJ |
69 | syslog 'debug', "DEBUG $ARGV:$. match". |
70 | " $serve_user $serve_dir $serve_repo"; | |
d36c5f7b | 71 | } elsif (m{^ multi-user \s+ (\S+?) (/\S*)? \s+ (\S+) $ }x) { |
70b9d2e0 IJ |
72 | my ($h,$v,$d) = ($1,$2,$3); |
73 | next unless $1 eq $spechost; | |
74 | $serve_repo= remain_path($v); | |
75 | next unless defined $serve_repo; | |
76 | syslog 'debug', "DEBUG $ARGV:$. perhaps $serve_repo"; | |
77 | next unless $serve_repo =~ s{ ^/\~( [a-z][-+_0-9a-z]* )/ }{/}xi; | |
78 | $serve_user= $1; | |
d36c5f7b | 79 | $serve_dir= $d; |
70b9d2e0 IJ |
80 | syslog 'debug', "DEBUG $ARGV:$. match". |
81 | " $serve_user $serve_dir $serve_repo"; | |
d36c5f7b IJ |
82 | } elsif (m{^ repo-regexp \s+ (\S.*) $ }x) { |
83 | $repo_regexp= $1; | |
84 | } elsif (m{^ (no-)?require-git-daemon-export-ok $ }x) { | |
85 | $check_export= !defined $1; | |
86 | } else { | |
70b9d2e0 | 87 | fail "config syntax error at $ARGV:$."; |
d36c5f7b IJ |
88 | } |
89 | } | |
90 | ||
91 | # end |