From bd5ae5189289741a508751418b162a01611a6dd5 Mon Sep 17 00:00:00 2001 From: Austin Best Date: Wed, 31 Jan 2024 23:12:07 -0500 Subject: [PATCH] Move git methods to the files that use them --- root/app/www/public/ajax/branches.php | 3 ++ root/app/www/public/ajax/code.php | 18 ++++++++++ root/app/www/public/ajax/commits.php | 2 ++ root/app/www/public/ajax/common.php | 2 ++ root/app/www/public/ajax/contributors.php | 3 ++ root/app/www/public/ajax/overview.php | 37 +++++++++++++++++++++ root/app/www/public/ajax/shared.php | 40 ----------------------- 7 files changed, 65 insertions(+), 40 deletions(-) diff --git a/root/app/www/public/ajax/branches.php b/root/app/www/public/ajax/branches.php index d072c44..dc40d9a 100644 --- a/root/app/www/public/ajax/branches.php +++ b/root/app/www/public/ajax/branches.php @@ -12,6 +12,9 @@ if ($_POST['m'] == 'init') { ?>

Branches


branches(); + $branchHeads = $git->branchHeads(); + $remoteLabel = false; ?>
diff --git a/root/app/www/public/ajax/code.php b/root/app/www/public/ajax/code.php index 4f26adb..aa57d0e 100644 --- a/root/app/www/public/ajax/code.php +++ b/root/app/www/public/ajax/code.php @@ -12,6 +12,24 @@ if ($_POST['m'] == 'init') { ?>

Code


totalLines(); + $fileTypes = []; + + foreach ($totalLines['shell'] as $file) { + $fileParts = array_filter(explode(' ', $file)); + sort($fileParts, SORT_NUMERIC); + + if (str_contains($fileParts[0], '.') && $fileParts[0][0] != '.' && !is_dir(ABSOLUTE_PATH . $repository . '.' . $fileParts[0][0])) { + $filePathParts = explode('.', $fileParts[0]); + $extension = trim(end($filePathParts)); + + if (!in_array($extension, $ignoreCodePageExtensions) && !str_contains($extension, '/') && $extension) { + $fileTypes[$extension]['files']++; + $fileTypes[$extension]['lines'] += intval($fileParts[1]); + } + } + } + $labels = $dataFiles = $dataLines = $colors = ''; $usedColors = []; array_sort_by_key($fileTypes, 'lines', 'desc'); diff --git a/root/app/www/public/ajax/commits.php b/root/app/www/public/ajax/commits.php index 7ba8b4c..eba936a 100644 --- a/root/app/www/public/ajax/commits.php +++ b/root/app/www/public/ajax/commits.php @@ -12,6 +12,8 @@ if ($_POST['m'] == 'init') { ?>

Commits


log(); + $regex = '/{(?(.*))}~{(?(.*))}~{(?(.*))}~{(?(.*))}~{(?(.*))}~{(?(.*))}~{(?(.*))}/'; $yearData = $monthData = $weekData = $dayData = []; diff --git a/root/app/www/public/ajax/common.php b/root/app/www/public/ajax/common.php index 91c70fb..43afe1f 100644 --- a/root/app/www/public/ajax/common.php +++ b/root/app/www/public/ajax/common.php @@ -9,6 +9,8 @@ require 'shared.php'; +$branches = $git->branches(); + if ($_POST['m'] == 'loadRepositoryBranches') { foreach ($branches['shell'] as $branch) { $branchOptions .= ''; diff --git a/root/app/www/public/ajax/contributors.php b/root/app/www/public/ajax/contributors.php index e8b4863..a26315c 100644 --- a/root/app/www/public/ajax/contributors.php +++ b/root/app/www/public/ajax/contributors.php @@ -12,6 +12,9 @@ if ($_POST['m'] == 'init') { ?>

Contributors


contributors(); + $totalCommits = $git->totalCommits(); + ?>

Overview


size(); + $overview = $git->log(); + $branches = $git->branches(); + $contributors = $git->contributors(); + $totalFiles = $git->totalFiles(); + $totalCommits = $git->totalCommits(); + $totalLines = $git->totalLines(); + $linesOfCode = 0; + $fileTypes = []; + + foreach ($totalLines['shell'] as $file) { + $fileParts = array_filter(explode(' ', $file)); + sort($fileParts, SORT_NUMERIC); + $linesOfCode += intval($fileParts[1]); + + if (str_contains($fileParts[0], '.') && $fileParts[0][0] != '.' && !is_dir(ABSOLUTE_PATH . $repository . '.' . $fileParts[0][0])) { + $filePathParts = explode('.', $fileParts[0]); + $extension = trim(end($filePathParts)); + + if (!in_array($extension, $ignoreCodePageExtensions) && !str_contains($extension, '/') && $extension) { + $fileTypes[$extension]['files']++; + $fileTypes[$extension]['lines'] += intval($fileParts[1]); + } + } + } + + foreach ($repoObjects['shell'] as $repoSizeObject) { + if (str_contains($repoSizeObject, 'count') || str_contains($repoSizeObject, 'in-pack')) { + $repoObjectCount += preg_replace("/[^0-9]/", '', $repoSizeObject); + } + if (str_contains($repoSizeObject, 'size') || str_contains($repoSizeObject, 'size-pack')) { + $repoSizeTotal += preg_replace("/[^0-9]/", '', $repoSizeObject); + } + } + $repoObjects = number_format(intval($repoObjectCount)); + $repoSize = byteConversion(intval($repoSizeTotal) * 1000); + $regex = '/{(?(.*))}~{(?(.*))}~{(?(.*))}~{(?(.*))}~{(?(.*))}~{(?(.*))}~{(?(.*))}/'; //-- GET MAX WIDTH diff --git a/root/app/www/public/ajax/shared.php b/root/app/www/public/ajax/shared.php index b99fd7c..4b02434 100644 --- a/root/app/www/public/ajax/shared.php +++ b/root/app/www/public/ajax/shared.php @@ -20,43 +20,3 @@ $repository = $_POST['repository']; $git = new Git($repository); - -if ($_POST['page'] != 'settings') { - $repoObjects = $git->size(); - $overview = $git->log(); - $branches = $git->branches(); - $contributors = $git->contributors(); - $totalFiles = $git->totalFiles(); - $totalCommits = $git->totalCommits(); - $totalLines = $git->totalLines(); - $branchHeads = $git->branchHeads(); - $linesOfCode = 0; - $fileTypes = []; - - foreach ($repoObjects['shell'] as $repoSizeObject) { - if (str_contains($repoSizeObject, 'count') || str_contains($repoSizeObject, 'in-pack')) { - $repoObjectCount += preg_replace("/[^0-9]/", '', $repoSizeObject); - } - if (str_contains($repoSizeObject, 'size') || str_contains($repoSizeObject, 'size-pack')) { - $repoSizeTotal += preg_replace("/[^0-9]/", '', $repoSizeObject); - } - } - $repoObjects = number_format(intval($repoObjectCount)); - $repoSize = byteConversion(intval($repoSizeTotal) * 1000); - - foreach ($totalLines['shell'] as $file) { - $fileParts = array_filter(explode(' ', $file)); - sort($fileParts, SORT_NUMERIC); - $linesOfCode += intval($fileParts[1]); - - if (str_contains($fileParts[0], '.') && $fileParts[0][0] != '.' && !is_dir(ABSOLUTE_PATH . $repository . '.' . $fileParts[0][0])) { - $filePathParts = explode('.', $fileParts[0]); - $extension = trim(end($filePathParts)); - - if (!in_array($extension, $ignoreCodePageExtensions) && !str_contains($extension, '/') && $extension) { - $fileTypes[$extension]['files']++; - $fileTypes[$extension]['lines'] += intval($fileParts[1]); - } - } - } -}