From f39a0064f8eb701e2cc673f443913f263ac3342f Mon Sep 17 00:00:00 2001 From: Heikki Hokkanen Date: Thu, 26 Jun 2008 20:36:59 +0300 Subject: [PATCH] tree: added a "browse at HEAD" link. --- doc/TODO | 4 ---- inc/functions.php | 10 ++++++++-- index.php | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/doc/TODO b/doc/TODO index 9d342e9..1573b70 100644 --- a/doc/TODO +++ b/doc/TODO @@ -1,9 +1,5 @@ - bundle about page that says what the software is and where to download it -- should be possible to link to a path at HEAD without the need for a tree hash - - tree: "Browse this tree at HEAD" -link - - index.php/tree: if 'h' is not set but 'hb' = HEAD, walk the tree using 'f' - [Milestones] - Public Launch (0.0.1?) - a public demo diff --git a/inc/functions.php b/inc/functions.php index 49b5e4c..33c84b2 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -153,10 +153,16 @@ function git_get_heads($project) * Get array containing path information for parts, starting from root_hash. * * @param root_hash commit/tree hash for the root tree - * @param parts array of path fragments + * @param path path */ -function git_get_path_info($project, $root_hash, $parts) +function git_get_path_info($project, $root_hash, $path) { + if (strlen($path) > 0) { + $parts = explode('/', $path); + } else { + $parts = array(); + } + $pathinfo = array(); $tid = $root_hash; diff --git a/index.php b/index.php index 9635a4d..e2dab2a 100644 --- a/index.php +++ b/index.php @@ -310,10 +310,10 @@ elseif ($action === 'tree') { } // get path info for the header - $page['pathinfo'] = git_get_path_info($page['project'], $page['commit_id'], explode('/', $page['path'])); + $page['pathinfo'] = git_get_path_info($page['project'], $page['commit_id'], $page['path']); if (!isset($page['tree_id'])) { // Take the last hash from the tree - if (count($page['pathinfo']) > 1) { + if (count($page['pathinfo']) > 0) { $page['tree_id'] = $page['pathinfo'][count($page['pathinfo']) - 1]['hash']; } else { $page['tree_id'] = 'HEAD'; @@ -350,7 +350,7 @@ elseif ($action === 'viewblob') { $page['commit_id'] = $info['h']; $page['tree_id'] = $info['tree']; - $page['pathinfo'] = git_get_path_info($page['project'], $page['commit_id'], explode('/', $page['path'])); + $page['pathinfo'] = git_get_path_info($page['project'], $page['commit_id'], $page['path']); $page['data'] = join("\n", run_git($page['project'], "git cat-file blob $page[hash]")); -- 2.11.4.GIT