From 1fd723f211f094c6d2eaf7cdc99b7ab7f679b2d8 Mon Sep 17 00:00:00 2001 From: Heikki Hokkanen Date: Sun, 25 May 2008 16:37:52 +0300 Subject: [PATCH] commitdiff: show list of changed files with #links. --- doc/TODO | 3 ++- index.php | 25 ++++++++++++++++++++++--- templates/commitdiff.php | 22 +++++++++++++++++++++- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/doc/TODO b/doc/TODO index fbcf0ff..0331838 100644 --- a/doc/TODO +++ b/doc/TODO @@ -3,10 +3,11 @@ - how to get the tree hashes for linking fragments? Have to climb up the tree from 'hb' ? - header pagenav: bolden current selection -- commitdiff: after log, show changed files with section link to diff - shortlog: accept branch/tag name as 'h' - or in validate_hash() +- h1: show full first line of commit message instead of first N characters + - research whether git checkout can be made to work through viewgit - If repos use git-update-server-info, could perhaps use internal rewrite to send requests to the .git directories - ^.*\.git$ -> redirect to .git dir diff --git a/index.php b/index.php index 1def1dc..12d55b8 100644 --- a/index.php +++ b/index.php @@ -5,9 +5,19 @@ require_once('inc/config.php'); /** * Formats "git diff" output into xhtml. + * @return array(array of filenames, xhtml) */ function format_diff($text) { + $files = array(); + + // match every "^diff --git a/ b/$" line + foreach (explode("\n", $text) as $line) { + if (preg_match('#^diff --git a/(.*) b/(.*)$#', $line, $matches) > 0) { + $files[$matches[1]] = urlencode($matches[1]); + } + } + $text = htmlentities($text); $text = preg_replace( @@ -15,17 +25,25 @@ function format_diff($text) '/^(\+.*)$/m', '/^(-.*)$/m', '/^(@.*)$/m', - '/^([^\+-@].*)$/m', + //'#^diff --git a/(.*) b/(.*)$#', + '/^([^d\+-@].*)$/m', ), array( '$1', '$1', '$1', + //'diff --git a/$1 b/$2', // FIXME '$1', ), $text); + $text = preg_replace_callback('#^diff --git a/(.*) b/(.*)$#m', + create_function( + '$m', + 'return "diff --git a/$m[1] b/$m[2]";' + ), + $text); - return $text; + return array($files, $text); } function get_project_info($name) @@ -306,7 +324,8 @@ elseif ($action === 'commitdiff') { $page['author_datetime'] = strftime($conf['datetime'], $info['author_utcstamp']); $text = join("\n", run_git($page['project'], "git diff $hash^..$hash")); - $page['diffdata'] = format_diff($text); + list($page['files'], $page['diffdata']) = format_diff($text); + //$page['diffdata'] = format_diff($text); } elseif ($action === 'shortlog') { $template = 'shortlog'; diff --git a/templates/commitdiff.php b/templates/commitdiff.php index 7937668..c617da3 100644 --- a/templates/commitdiff.php +++ b/templates/commitdiff.php @@ -13,7 +13,27 @@ echo ' ['. $page['author_datetime'] .']'; - +
+ + + + + + + + + $url) { + echo "\n"; + echo ""; + echo ""; + echo "\n"; +} +?> + +
FilenameLinks
$fileblob | history
+
-- 
2.11.4.GIT