From 2bdde748d965c4cabaf458e3f889d013d0ad2576 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 27 Apr 2012 12:51:50 -0700 Subject: [PATCH] Fix DiffusionGitBrowseQuery to parse with "git config -l -f" instead of PHP ini parser Summary: See discussion on rPc0aac8267dda74664acac5c93d9aeb5a0f9c4564. Test Plan: Looked at externals/, got a correctly-behaving link. Reviewers: vrana, davidreuss, btrahan Reviewed By: vrana CC: aran Differential Revision: https://secure.phabricator.com/D2317 --- .../browse/git/DiffusionGitBrowseQuery.php | 37 ++++++++++++------- .../diffusion/query/browse/git/__init__.php | 2 + 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/applications/diffusion/query/browse/git/DiffusionGitBrowseQuery.php b/src/applications/diffusion/query/browse/git/DiffusionGitBrowseQuery.php index 0028eee3a5..410f06fec8 100644 --- a/src/applications/diffusion/query/browse/git/DiffusionGitBrowseQuery.php +++ b/src/applications/diffusion/query/browse/git/DiffusionGitBrowseQuery.php @@ -112,22 +112,33 @@ final class DiffusionGitBrowseQuery extends DiffusionBrowseQuery { // find their source URIs. if ($submodules) { - list($module_info) = $repository->execxLocalCommand( - 'show %s:.gitmodules', + + // NOTE: We need to read the file out of git and write it to a temporary + // location because "git config -f" doesn't accept a "commit:path"-style + // argument. + list($contents) = $repository->execxLocalCommand( + 'cat-file blob %s:.gitmodules', $commit); - $module_info = parse_ini_string( - $module_info, - $process_sections = true, - $scanner_mode = INI_SCANNER_RAW); + + $tmp = new TempFile(); + Filesystem::writeFile($tmp, $contents); + list($module_info) = $repository->execxLocalCommand( + 'config -l -f %s', + $tmp); + + $dict = array(); + $lines = explode("\n", trim($module_info)); + foreach ($lines as $line) { + list($key, $value) = explode('=', $line, 2); + $parts = explode('.', $key); + $dict[$key] = $value; + } foreach ($submodules as $path) { - foreach ($module_info as $section) { - if (empty($section['path']) || empty($section['url'])) { - continue; - } - if ($section['path'] == $path->getFullPath()) { - $path->setExternalURI($section['url']); - } + $full_path = $path->getFullPath(); + $key = $dict['submodule.'.$full_path.'.url']; + if (isset($dict[$key])) { + $path->setExternalURI($key); } } } diff --git a/src/applications/diffusion/query/browse/git/__init__.php b/src/applications/diffusion/query/browse/git/__init__.php index ae74d932c4..6287adf4ab 100644 --- a/src/applications/diffusion/query/browse/git/__init__.php +++ b/src/applications/diffusion/query/browse/git/__init__.php @@ -10,6 +10,8 @@ phutil_require_module('phabricator', 'applications/differential/constants/change phutil_require_module('phabricator', 'applications/diffusion/data/repositorypath'); phutil_require_module('phabricator', 'applications/diffusion/query/browse/base'); +phutil_require_module('phutil', 'filesystem'); +phutil_require_module('phutil', 'filesystem/tempfile'); phutil_require_module('phutil', 'utils');