From 9bcf99e3a7e2f7712214c95709eece2f2fe34cb1 Mon Sep 17 00:00:00 2001 From: Loic d'Anterroches Date: Mon, 2 Feb 2009 22:55:45 +0100 Subject: [PATCH] Fixed issue 126, easy link to a file in the repository from the tickets. The syntax src:AUTHORS or src:src/IDF/Scm.php is allowed. --- src/IDF/Template/IssueComment.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/IDF/Template/IssueComment.php b/src/IDF/Template/IssueComment.php index ef4b9c7..5b5e96d 100644 --- a/src/IDF/Template/IssueComment.php +++ b/src/IDF/Template/IssueComment.php @@ -50,6 +50,8 @@ class IDF_Template_IssueComment extends Pluf_Template_Tag if ($request->rights['hasSourceAccess']) { $text = preg_replace_callback('#(commit\s+)([0-9a-f]{1,40})#im', array($this, 'callbackCommit'), $text); + $text = preg_replace_callback('#(src:)([^\s\(\)]+)#im', + array($this, 'callbackSource'), $text); } if ($echo) { echo $text; @@ -102,6 +104,24 @@ class IDF_Template_IssueComment extends Pluf_Template_Tag return ''.$m[1].$m[2].''; } + function callbackSource($m) + { + $branches = $this->scm->getBranches(); + if (count($branches) == 0) return $m[0]; + $file = $m[2]; + if ('commit' != $this->scm->testHash($branches[0], $file)) { + return $m[0]; + } + $request_file_info = $this->scm->getFileInfo($file, $branches[0]); + if (!$request_file_info) { + return $m[0]; + } + if ($request_file_info->type != 'tree') { + return $m[1].''.$m[2].''; + } + return $m[0]; + } + /** * Generate the link to an issue. *