diff options
author | Eric Wong <e@yhbt.net> | 2020-06-27 10:03:41 +0000 |
---|---|---|
committer | Eric Wong <e@yhbt.net> | 2020-06-28 22:27:18 +0000 |
commit | 67592c40510dae8604580cf4b2a0a0f665b84501 (patch) | |
tree | 426f2abd4af167df7b7f3e49d5ea95e7dfe8b773 /lib/PublicInbox/Config.pm | |
parent | bbf4159b7694241d2139be641ced4c485303714a (diff) | |
download | public-inbox-67592c40510dae8604580cf4b2a0a0f665b84501.tar.gz |
config: support ->urlmatch method for -watch
Since we have IMAP client support in -watch; make sure per-URL settings are familiar to git users by taking advantage of git's URL matching abilities. This requires git 1.8.5+, which most users ought to have (though base CentOS 7 is on 1.8.3).
Diffstat (limited to 'lib/PublicInbox/Config.pm')
-rw-r--r-- | lib/PublicInbox/Config.pm | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index 19535beb..c0e2cc57 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -9,7 +9,7 @@ package PublicInbox::Config; use strict; -use warnings; +use v5.10.1; use PublicInbox::Inbox; use PublicInbox::Spawn qw(popen_rd); @@ -462,4 +462,23 @@ sub _fill { $ibx } +sub urlmatch { + my ($self, $key, $url) = @_; + state $urlmatch_broken; # requires git 1.8.5 + return if $urlmatch_broken; + my $file = default_file(); + my $cmd = [qw/git config -z --includes --get-urlmatch/, + "--file=$file", $key, $url ]; + my $fh = popen_rd($cmd); + local $/ = "\0"; + my $val = <$fh>; + if (close($fh)) { + chomp($val); + $val; + } else { + $urlmatch_broken = 1 if (($? >> 8) != 1); + undef; + } +} + 1; |