feat(file list): add submodule display support (github: #60)

This commit is contained in:
cubic
2022-08-09 15:48:06 +08:00
parent 483a97921c
commit 0be5af755e
2 changed files with 72 additions and 3 deletions

View File

@@ -1093,6 +1093,53 @@ class Repository extends Base
}
}
// add url attribute for sub module
if ($output['object'][0]) {
$gitModuleFlag = FALSE;
$gitModuleURLMap = [];
foreach ($output['object'] as $item) {
if ($item['type'] === 'commit') {
$gitModuleFlag = TRUE;
break;
}
}
if ($gitModuleFlag) {
$rootdirData = $this->repositoryModel->catObject($rKey, $uKey, $rev);
$gitModuleData = NULL;
foreach ($rootdirData[1] as $item) {
if ($item['name'] === '.gitmodules') {
$gitModuleData = $item;
}
}
if ($gitModuleData) {
$gitModuleFileInfo = $this->repositoryModel->catObject($rKey, $uKey, $gitModuleData['object']);
$gitModuleFileContent = Helper::parseObjectToFile($gitModuleFileInfo[1]);
if ($gitModuleFileContent['raw']) {
$matches = [];
preg_match_all('/\[.*\]\r?\n\s*path\s*=\s*(.*)\r?\n\s*url\s*=\s*(.*)\r?\n?/m', $gitModuleFileContent['raw'], $matches);
foreach ($matches[1] as $submoduleIndex => $submodulePath) {
$gitModuleURLMap[$submodulePath] = $matches[2][$submoduleIndex];
}
}
}
}
foreach ($output['object'] as &$item) {
if ($item['type'] === 'commit') {
if ($path) {
$item['url'] = $gitModuleURLMap[$path . '/' . $item['name']];
} else {
$item['url'] = $gitModuleURLMap[$item['name']];
}
} else {
$item['url'] = '';
}
}
}
Response::output($output);
}