From 1585d5248edb7597e5bb28ad5dbcd67d83f48eb1 Mon Sep 17 00:00:00 2001 From: Heikki Hokkanen Date: Thu, 22 May 2008 19:27:35 +0300 Subject: [PATCH] Added page navigation links. This allows switching between summary/shortlog/commit/commitdiff/tree pages more conveniently. --- default.css | 5 +++++ doc/TODO | 3 ++- index.php | 26 ++++++++++++++++++++++---- templates/commit.php | 2 +- templates/header.php | 10 +++++++++- templates/tree.php | 2 +- 6 files changed, 40 insertions(+), 8 deletions(-) diff --git a/default.css b/default.css index 1242eed..0c6d2e7 100644 --- a/default.css +++ b/default.css @@ -36,6 +36,11 @@ table th { border: 1px solid black; } +.pagenav { + font-size: 80%; + padding-top: 0.3em; +} + /* summary template */ table.shortlog th.date { diff --git a/doc/TODO b/doc/TODO index 5a3c7cb..32007cd 100644 --- a/doc/TODO +++ b/doc/TODO @@ -1,9 +1,10 @@ -- all pages: allow navigation between commit/commitdiff/tree/etc easily like gitweb +- WIP all pages: allow navigation between commit/commitdiff/tree/etc easily like gitweb - summary | shortlog | log | commit | commitdiff | tree - keep parameter (commit_id) if provided, otherwise links should default to HEAD - make sure all templates use commit_id so that the header template can use it - commitdiff: after log, show changed files with section link to diff +- full log page - research whether git checkout can be made to work through viewgit diff --git a/index.php b/index.php index 6d92756..1334f1f 100644 --- a/index.php +++ b/index.php @@ -48,7 +48,7 @@ function get_project_info($name) /** * Get details of a commit: tree, parent, author/committer (name, mail, date), message */ -function git_get_commit_info($project, $hash) +function git_get_commit_info($project, $hash = 'HEAD') { $info = array(); $info['h'] = $hash; @@ -82,6 +82,9 @@ function git_get_commit_info($project, $hash) $info['message'] = substr($line, 4, 40); } } + elseif (preg_match('/^[0-9a-f]{40}$/', $line) > 0) { + $info['h'] = $line; + } } return $info; @@ -279,7 +282,7 @@ elseif ($action === 'commit') { $page['committer_mail'] = $info['committer_mail']; $page['committer_datetime'] = strftime($conf['datetime'], $info['committer_utcstamp']); $page['committer_datetime_local'] = strftime($conf['datetime'], $info['committer_stamp']) .' '. $info['committer_timezone']; - $page['tree'] = $info['tree']; + $page['tree_id'] = $info['tree']; $page['parent'] = $info['parent']; $page['message'] = $info['message']; $page['message_full'] = $info['message_full']; @@ -294,6 +297,8 @@ elseif ($action === 'commitdiff') { $info = git_get_commit_info($page['project'], $hash); + $page['tree_id'] = $info['tree']; + $page['message'] = $info['message']; $page['message_full'] = $info['message_full']; $page['author_name'] = $info['author_name']; @@ -313,6 +318,10 @@ elseif ($action === 'shortlog') { $page['ref'] = 'HEAD'; } + $info = git_get_commit_info($page['project']); + $page['commit_id'] = $info['h']; + $page['tree_id'] = $info['tree']; + // TODO merge the logic with 'summary' below $revs = git_get_rev_list($page['project'], $conf['summary_shortlog'], $page['ref']); // TODO pass first rev as parameter foreach ($revs as $rev) { @@ -330,6 +339,10 @@ elseif ($action === 'summary') { $template = 'summary'; $page['project'] = validate_project($_REQUEST['p']); $page['title'] = "$page[project] - Summary - ViewGit"; + + $info = git_get_commit_info($page['project']); + $page['commit_id'] = $info['h']; + $page['tree_id'] = $info['tree']; $revs = git_get_rev_list($page['project'], $conf['summary_shortlog']); foreach ($revs as $rev) { @@ -370,10 +383,15 @@ elseif ($action === 'summary') { elseif ($action === 'tree') { $template = 'tree'; $page['project'] = validate_project($_REQUEST['p']); - $page['tree'] = validate_hash($_REQUEST['h']); + $page['tree_id'] = validate_hash($_REQUEST['h']); $page['title'] = "$page[project] - Tree - ViewGit"; - $page['entries'] = git_ls_tree($page['project'], $page['tree']); + // for the header + // TODO should perhaps get this as a GET parameter from other pages instead of using HEAD's commit_id + $info = git_get_commit_info($page['project']); + $page['commit_id'] = $info['h']; + + $page['entries'] = git_ls_tree($page['project'], $page['tree_id']); } elseif ($action === 'viewblob') { $template = 'blob'; diff --git a/templates/commit.php b/templates/commit.php index 36cfbc2..9a4bbcf 100644 --- a/templates/commit.php +++ b/templates/commit.php @@ -32,7 +32,7 @@ Tree - + Parent diff --git a/templates/header.php b/templates/header.php index 72982dc..65b6565 100644 --- a/templates/header.php +++ b/templates/header.php @@ -26,10 +26,18 @@ elseif ($page['action'] === 'shortlog') { echo " : Shortlog"; } elseif ($page['action'] === 'tree') { - echo " : Tree $page[tree]"; + echo " : Tree $page[tree_id]"; } elseif ($page['action'] === 'viewblob') { echo " : Blob $page[hash]"; } ?> + + diff --git a/templates/tree.php b/templates/tree.php index 936c7ad..dd4b2eb 100644 --- a/templates/tree.php +++ b/templates/tree.php @@ -27,5 +27,5 @@ foreach ($page['entries'] as $e) { -

Download as tar.gz or zip.

+

Download as tar.gz or zip.

-- 2.11.4.GIT