]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
repobrowse: start reducing Plack::Request dependencies
authorEric Wong <e@80x24.org>
Wed, 14 Dec 2016 00:31:30 +0000 (00:31 +0000)
committerEric Wong <e@80x24.org>
Wed, 14 Dec 2016 00:31:30 +0000 (00:31 +0000)
We'll be migrating away from it to minimize dependencies
and surprises, just like the rest of public-inbox did
several months ago.

lib/PublicInbox/RepobrowseGitAtom.pm
lib/PublicInbox/RepobrowseGitBlob.pm
lib/PublicInbox/RepobrowseGitCommit.pm
lib/PublicInbox/RepobrowseGitDiff.pm
lib/PublicInbox/RepobrowseGitLog.pm
lib/PublicInbox/RepobrowseGitPatch.pm
lib/PublicInbox/RepobrowseGitQuery.pm
lib/PublicInbox/RepobrowseGitSnapshot.pm
lib/PublicInbox/RepobrowseGitTag.pm
lib/PublicInbox/RepobrowseGitTree.pm

index 9326841d86391693b6bc116f400da209dfe17fe1..063cd2e42a5989a3a482cad1251912b220c509de 100644 (file)
@@ -21,7 +21,7 @@ sub call_git_atom {
        $max = 50 if $max == 0;
 
        my $git = $repo_info->{git};
-       my $q = PublicInbox::RepobrowseGitQuery->new($req->{cgi});
+       my $q = PublicInbox::RepobrowseGitQuery->new($req->{env});
        my $h = $q->{h};
        $h eq '' and chomp($h = $git->qx(qw(symbolic-ref --short HEAD)));
 
index f2b38a0c32ca01a07d5522eded44b4a18c198c8e..d38101ed280821f5005c7d935c8861bdf9c7340b 100644 (file)
@@ -12,7 +12,7 @@ our @EXPORT = qw(git_blob_mime_type git_blob_stream_response);
 sub call_git_blob {
        my ($self, $req) = @_;
        my $git = $req->{repo_info}->{git};
-       my $q = PublicInbox::RepobrowseGitQuery->new($req->{cgi});
+       my $q = PublicInbox::RepobrowseGitQuery->new($req->{env});
        my $id = $q->{id};
        $id eq '' and $id = 'HEAD';
 
index 227dad97ba6d7e2c9c4a7341d8e9f50dc99a43cb..2577ea3452aa7670fac256b2c5fe8781d3dec998 100644 (file)
@@ -144,7 +144,7 @@ sub git_commit_stream ($$$$) {
 sub call_git_commit {
        my ($self, $req) = @_;
 
-       my $q = PublicInbox::RepobrowseGitQuery->new($req->{cgi});
+       my $q = PublicInbox::RepobrowseGitQuery->new($req->{env});
        my $id = $q->{id};
        $id eq '' and $id = 'HEAD';
 
@@ -160,7 +160,7 @@ sub call_git_commit {
                        --no-notes --no-color -c),
                        $git->abbrev, GIT_FMT, $id, '--' ];
        $req->{rpipe} = $git->popen($cmd, undef, { 2 => $git->err_begin });
-       my $env = $req->{cgi}->env;
+       my $env = $req->{env};
        my $err = $env->{'psgi.errors'};
        my $vin;
        $req->{dbuf} = '';
index 02a2c562116e9c063be41f4ec41b956259c9a470..d65973c1a5157b05f4b3ee74a2df34aa9bd3ccb2 100644 (file)
@@ -20,7 +20,7 @@ use PublicInbox::RepobrowseGitDiffCommon qw/git_diffstat_emit
 sub call_git_diff {
        my ($self, $req) = @_;
        my $git = $req->{repo_info}->{git};
-       my $q = PublicInbox::RepobrowseGitQuery->new($req->{cgi});
+       my $q = PublicInbox::RepobrowseGitQuery->new($req->{env});
        my $id = $q->{id};
        my $id2 = $q->{id2};
 
@@ -30,7 +30,7 @@ sub call_git_diff {
        my $expath = $req->{expath};
        push @cmd, $expath if defined $expath;
        $req->{rpipe} = $git->popen(\@cmd, undef, { 2 => $git->err_begin });
-       my $env = $req->{cgi}->env;
+       my $env = $req->{env};
        my $err = $env->{'psgi.errors'};
        my ($vin);
        $req->{dbuf} = '';
index 0c360e737d80f925d13b96db446844349b3b5059..44b405bcd6503ecefacf24f3405b7401c0a7f2c3 100644 (file)
@@ -19,7 +19,7 @@ sub call_git_log {
        $max = int($max);
        $max = 50 if $max == 0;
 
-       my $q = PublicInbox::RepobrowseGitQuery->new($req->{cgi});
+       my $q = PublicInbox::RepobrowseGitQuery->new($req->{env});
        my $h = $q->{h};
        $h eq '' and $h = 'HEAD';
 
index b8a44e512c135840dab15b7a4e135dd6e6578fe1..eeffc5cb248ebf5e588789b008adee7fac8bf3f7 100644 (file)
@@ -15,7 +15,8 @@ my $sig = '--signature=git '.join(' ', @CMD);
 sub call_git_patch {
        my ($self, $req) = @_;
        my $git = $req->{repo_info}->{git};
-       my $q = PublicInbox::RepobrowseGitQuery->new($req->{cgi});
+       my $env = $req->{env};
+       my $q = PublicInbox::RepobrowseGitQuery->new($env);
        my $id = $q->{id};
        $id =~ /\A[\w-]+([~\^][~\^\d])*\z/ or $id = 'HEAD';
 
@@ -27,7 +28,6 @@ sub call_git_patch {
                push @cmd, $expath;
        }
        my $rpipe = $git->popen(@cmd);
-       my $env = $req->{cgi}->env;
        my $err = $env->{'psgi.errors'};
        my ($n, $res, $vin, $fh);
        my $end = sub {
index 0ee9df046df563cb6c408d102067b89177355526..1140f6faf8fac1ad7222f076f68b07a4ad159e8d 100644 (file)
@@ -6,17 +6,25 @@ package PublicInbox::RepobrowseGitQuery;
 use strict;
 use warnings;
 use PublicInbox::Hval;
+use URI::Escape qw(uri_unescape);
 my @KNOWN_PARAMS = qw(id id2 h ofs);
 
 sub new {
-       my ($class, $cgi) = @_;
-       my $self = bless {}, $class;
-
-       foreach my $k (@KNOWN_PARAMS) {
-               my $v = $cgi->param($k);
-               $self->{$k} = defined $v ? $v : '';
+       my ($class, $env) = @_;
+       # we don't care about multi-value
+       my %tmp = map {
+               my ($k, $v) = split('=', uri_unescape($_), 2);
+               $v = '' unless defined $v;
+               $v =~ tr/+/ /;
+               ($k, $v)
+       } split(/[&;]/, $env->{QUERY_STRING});
+
+       my $self = {};
+       foreach (@KNOWN_PARAMS) {
+               my $v = $tmp{$_};
+               $self->{$_} = defined $v ? $v : '';
        }
-       $self;
+       bless $self, $class;
 }
 
 sub qs {
index 8bd4b0a57cf319e171d1bdc6cc44d8b4c59de274..4783e1506d4aa4986865c450821a9a21c652f5e9 100644 (file)
@@ -76,7 +76,7 @@ sub call_git_snapshot ($$) { # invoked by PublicInbox::RepobrowseBase::call
        my @cmd = ('archive', "--prefix=$pfx", "--format=$fmt", $tree);
        $req->{rpipe} = $git->popen(\@cmd, undef, { 2 => $git->err_begin });
 
-       my $env = $req->{cgi}->env;
+       my $env = $req->{env};
        my $vin;
        my $end = sub {
                my ($n) = @_;
index 229d5ff0968f78392bc07b63179c012ae0054d1b..cf835aed274592102ec5799f1ae69dbe7181a85b 100644 (file)
@@ -18,7 +18,7 @@ my %cmd_map = ( # type => action
 sub call_git_tag {
        my ($self, $req) = @_;
 
-       my $q = PublicInbox::RepobrowseGitQuery->new($req->{cgi});
+       my $q = PublicInbox::RepobrowseGitQuery->new($req->{env});
        my $h = $q->{h};
        $h eq '' and return sub {
                my ($res) = @_;
index 3900cf9d1ab83b123b82290c358ec5b4fea67297..01f29bb0b2134129fbeca89d4792c684cc306cd7 100644 (file)
@@ -20,7 +20,7 @@ sub git_tree_stream {
        my ($self, $req, $res) = @_; # res: Plack callback
        my @extra = @{$req->{extra}};
        my $git = $req->{repo_info}->{git};
-       my $q = PublicInbox::RepobrowseGitQuery->new($req->{cgi});
+       my $q = PublicInbox::RepobrowseGitQuery->new($req->{env});
        my $id = $q->{id};
        if ($id eq '') {
                chomp($id = $git->qx(qw(rev-parse --short=10 HEAD)));