From 7badec23a7d0a1a144d1fc7b89f366fbe528c2a0 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 2 Oct 2019 13:26:39 -0700 Subject: [PATCH] Use "git log ... --stdin" instead of "git log ... --not ..." to avoid oversized command lines Summary: Depends on D20853. See PHI1474. If the list of "--not" refs is sufficiently long, we may exceed the maximum size of a command. Use "--stdin" instead, and swap "--not" for the slightly less readable but functionally equivalent "^hash", which has the advantage of actually working with "--stdin". Test Plan: Ran `bin/repository refs ...` with nothing to be done, and with something to be done. Differential Revision: https://secure.phabricator.com/D20854 --- .../engine/PhabricatorRepositoryRefEngine.php | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/applications/repository/engine/PhabricatorRepositoryRefEngine.php b/src/applications/repository/engine/PhabricatorRepositoryRefEngine.php index 8d8e7f45d8..68e2c344fc 100644 --- a/src/applications/repository/engine/PhabricatorRepositoryRefEngine.php +++ b/src/applications/repository/engine/PhabricatorRepositoryRefEngine.php @@ -469,11 +469,26 @@ final class PhabricatorRepositoryRefEngine return phutil_split_lines($stdout, $retain_newlines = false); case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: if ($all_closing_heads) { - list($stdout) = $this->getRepository()->execxLocalCommand( - 'log --format=%s %s --not %Ls', - '%H', - $new_head, - $all_closing_heads); + + // See PHI1474. This length of list may exceed the maximum size of + // a command line argument list, so pipe the list in using "--stdin" + // instead. + + $ref_list = array(); + $ref_list[] = $new_head; + foreach ($all_closing_heads as $old_head) { + $ref_list[] = '^'.$old_head; + } + $ref_list[] = '--'; + $ref_list = implode("\n", $ref_list)."\n"; + + $future = $this->getRepository()->getLocalCommandFuture( + 'log --format=%s --stdin', + '%H'); + + list($stdout) = $future + ->write($ref_list) + ->resolvex(); } else { list($stdout) = $this->getRepository()->execxLocalCommand( 'log --format=%s %s',