| | $hasTags = true; |
| | |
| | - $filesUrl = '?hash=' . $sha . $repoParam; |
| | - $commitUrl = '?action=commit&hash=' . $sha . $repoParam; |
| | - |
| | - // Parse date from object (Tag or Commit) |
| | + // Read the object to peel tags and get dates |
| | $data = $this->git->read($sha); |
| | - $date = ''; |
| | + $targetSha = $sha; |
| | + $timestamp = 0; |
| | |
| | - // Check for 'tagger' (Annotated Tag) |
| | - if (preg_match('/^tagger .* (\d+) [+\-]\d{4}$/m', $data, $matches)) { |
| | - $date = date('Y-m-d', $matches[1]); |
| | + // Check if Annotated Tag (starts with 'object <sha>') |
| | + if (strncmp($data, 'object ', 7) === 0) { |
| | + // Extract target SHA |
| | + if (preg_match('/^object ([0-9a-f]{40})$/m', $data, $matches)) { |
| | + $targetSha = $matches[1]; |
| | + } |
| | + // Extract Tagger Date |
| | + if (preg_match('/^tagger .* (\d+) [+\-]\d{4}$/m', $data, $matches)) { |
| | + $timestamp = (int)$matches[1]; |
| | + } |
| | } |
| | - // Fallback to 'author' (Lightweight Tag / Commit) |
| | - elseif (preg_match('/^author .* (\d+) [+\-]\d{4}$/m', $data, $matches)) { |
| | - $date = date('Y-m-d', $matches[1]); |
| | + // Lightweight Tag (Commit object, starts with 'tree <sha>') |
| | + else { |
| | + // Extract Author Date |
| | + if (preg_match('/^author .* (\d+) [+\-]\d{4}$/m', $data, $matches)) { |
| | + $timestamp = (int)$matches[1]; |
| | + } |
| | } |
| | + |
| | + $dateStr = $timestamp ? date('Y-M-d', $timestamp) : ''; |
| | + |
| | + // Links use the Target SHA (Commit) to avoid "Binary file" errors |
| | + $filesUrl = '?hash=' . $targetSha . $repoParam; |
| | + $commitUrl = '?action=commit&hash=' . $targetSha . $repoParam; |
| | |
| | echo '<div class="ref-item">'; |
| | echo '<span class="ref-type tag">Tag</span>'; |
| | echo '<a href="' . $filesUrl . '" class="ref-name">' . htmlspecialchars($name) . '</a>'; |
| | |
| | - if ($date) { |
| | - echo '<span class="commit-date" style="margin-left: auto;">' . $date . '</span>'; |
| | - echo '<a href="' . $commitUrl . '" class="commit-hash">' . substr($sha, 0, 7) . '</a>'; |
| | - } else { |
| | - echo '<a href="' . $commitUrl . '" class="commit-hash" style="margin-left: auto;">' . substr($sha, 0, 7) . '</a>'; |
| | + if ($dateStr) { |
| | + echo '<span class="commit-date" style="margin-left: auto; margin-right: 15px;">' . $dateStr . '</span>'; |
| | } |
| | |
| | + // We display the Tag SHA, but link to the Commit SHA |
| | + echo '<a href="' . $commitUrl . '" class="commit-hash" ' . (!$dateStr ? 'style="margin-left: auto;"' : '') . '>' . substr($sha, 0, 7) . '</a>'; |
| | echo '</div>'; |
| | }); |