@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix isValidGitShallowCloneResponse

Summary:
Changes the heuristic method by which non-zero exit statuses from git-http-backend are found to be due to packfile negotiation during shallow fetches, etc.

Instead of checking git-http-backend stderr for a generic "hung up" error message, see if the pack-result response contains a terminating flush packet ("0000"). This should give a greater assurance that the request was handled correctly and the response is complete.

Test Plan: Run `GIT_CURL_VERBOSE=1 git fetch --depth 1 https://host.example/source/repo.git HEAD` to ensure it completes and includes two successful POST requests during packfile negotiation (the last one actually receives the packfile).

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, dzduvall

Tags: #diffusion

Differential Revision: https://secure.phabricator.com/D21484

+14 -6
+14 -6
src/applications/diffusion/controller/DiffusionServeController.php
··· 922 922 // This is a pretty funky fix: it would be nice to more precisely detect 923 923 // that a request is a `--depth N` clone request, but we don't have any code 924 924 // to decode protocol frames yet. Instead, look for reasonable evidence 925 - // in the error and output that we're looking at a `--depth` clone. 925 + // in the output that we're looking at a `--depth` clone. 926 926 927 - // For evidence this isn't completely crazy, see: 928 - // https://github.com/schacon/grack/pull/7 927 + // A valid x-git-upload-pack-result response during packfile negotiation 928 + // should end with a flush packet ("0000"). As long as that packet 929 + // terminates the response body in the response, we'll assume the response 930 + // is correct and complete. 931 + 932 + // See https://git-scm.com/docs/pack-protocol#_packfile_negotiation 929 933 930 934 $stdout_regexp = '(^Content-Type: application/x-git-upload-pack-result)m'; 931 - $stderr_regexp = '(The remote end hung up unexpectedly)'; 932 935 933 936 $has_pack = preg_match($stdout_regexp, $stdout); 934 - $is_hangup = preg_match($stderr_regexp, $stderr); 935 937 936 - return $has_pack && $is_hangup; 938 + if (strlen($stdout) >= 4) { 939 + $has_flush_packet = (substr($stdout, -4) === "0000"); 940 + } else { 941 + $has_flush_packet = false; 942 + } 943 + 944 + return ($has_pack && $has_flush_packet); 937 945 } 938 946 939 947 private function getCommonEnvironment(PhabricatorUser $viewer) {