From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id A1DAB2070D for ; Sun, 25 Dec 2016 10:36:56 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/4] githttpbackend: simplify compatibility code Date: Sun, 25 Dec 2016 10:36:51 +0000 Message-Id: <20161225103653.8325-3-e@80x24.org> In-Reply-To: <20161225103653.8325-1-e@80x24.org> References: <20161225103653.8325-1-e@80x24.org> List-Id: Fewer conditionals means theres fewer code paths to test and makes things easier-to-read. --- examples/public-inbox.psgi | 1 + lib/PublicInbox/GitHTTPBackend.pm | 15 ++++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/examples/public-inbox.psgi b/examples/public-inbox.psgi index e97f917..98cde92 100644 --- a/examples/public-inbox.psgi +++ b/examples/public-inbox.psgi @@ -14,6 +14,7 @@ my $www = PublicInbox::WWW->new; # share the public-inbox code itself: my $src = $ENV{SRC_GIT_DIR}; # '/path/to/public-inbox.git' +$src = PublicInbox::Git->new($src) if defined $src; builder { eval { diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm index 86b8ebc..4ad3fd1 100644 --- a/lib/PublicInbox/GitHTTPBackend.pm +++ b/lib/PublicInbox/GitHTTPBackend.pm @@ -46,6 +46,9 @@ sub r ($;$) { sub serve { my ($env, $git, $path) = @_; + # XXX compatibility... ugh, can we stop supporting this? + $git = PublicInbox::Git->new($git) unless ref($git); + # Documentation/technical/http-protocol.txt in git.git # requires one and exactly one query parameter: if ($env->{QUERY_STRING} =~ /\Aservice=git-\w+-pack\z/ || @@ -98,7 +101,7 @@ sub serve_dumb { return r(404); } - my $f = (ref $git ? $git->{git_dir} : $git) . '/' . $path; + my $f = $git->{git_dir} . '/' . $path; return r(404) unless -f $f && -r _; # just in case it's a FIFO :P my $size = -s _; @@ -196,14 +199,8 @@ sub serve_smart { my $val = $env->{$name}; $env{$name} = $val if defined $val; } - my ($git_dir, $limiter); - if (ref $git) { - $limiter = $git->{-httpbackend_limiter} || $default_limiter; - $git_dir = $git->{git_dir}; - } else { - $limiter = $default_limiter; - $git_dir = $git; - } + my $limiter = $git->{-httpbackend_limiter} || $default_limiter; + my $git_dir = $git->{git_dir}; $env{GIT_HTTP_EXPORT_ALL} = '1'; $env{PATH_TRANSLATED} = "$git_dir/$path"; my $rdr = { 0 => fileno($in) }; -- EW