<img src="/phorkie/dot-{{dot}}.png" alt="" style="padding-left:1px" width="4" height="4"/>
{% endfor %}
{% endspaceless %}
- <a class="hash" href="{{repo.getLink('commit', commit.hash)}}">{{commit.hash|slice(0, 6)}}</a>
+ <a class="hash" href="{{repo.getLink('revision', commit.hash)}}">{{commit.hash|slice(0, 6)}}</a>
<img src="{{commit.getIconUrl}}" alt="{{commit.committerName}}" title="{{commit.committerName}}" width="20"/>
<span title="{{commit.committerTime|date('c')}}">{{dh.get(commit.committerTime)}}</span>
</li>
class File
{
/**
- * Full path to the file
+ * Path to the file, relative to repository work directory
*
* @var string
*/
*/
public $repo;
+ /**
+ * Commit revision this file is at
+ */
+ public $hash;
+
public function __construct($path, Repository $repo = null)
{
$this->path = $path;
*/
public function getFilename()
{
- return basename($this->path);
+ return $this->path;
}
/**
*
* @return string
*/
- public function getPath()
+ public function getFullPath()
{
- return $this->path;
+ return $this->repo->workDir . '/' . $this->path;
}
/**
public function getContent()
{
- return file_get_contents($this->path);
+ if ($this->repo->hash) {
+ return $this->repo->getVc()->getCommand('show')
+ ->addArgument($this->repo->hash . ':' . $this->path)
+ ->execute();
+ }
+
+ return file_get_contents($this->getFullPath());
}
public function getRenderedContent(Tool_Result $res = null)
if (!is_numeric($_GET['id'])) {
throw new Exception_Input('Paste ID not numeric');
}
+ if (isset($_GET['rev'])) {
+ $this->hash = $_GET['rev'];
+ }
+
$this->id = (int)$_GET['id'];
$this->loadDirs();
$this->loadHash();
public function loadHash()
{
+ return;
if ($this->hash !== null) {
return;
}
*/
public function getFiles()
{
- $files = glob($this->workDir . '/*');
+ if ($this->hash === null) {
+ $hash = 'HEAD';
+ } else {
+ $hash = $this->hash;
+ }
+ $output = $this->getVc()->getCommand('ls-tree')
+ ->setOption('r')
+ ->setOption('name-only')
+ ->addArgument($hash)
+ ->execute();
+ $files = explode("\n", trim($output));
$arFiles = array();
- foreach ($files as $path) {
- $arFiles[] = new File($path, $this);
+ foreach ($files as $name) {
+ $arFiles[] = new File($name, $this);
}
return $arFiles;
}
if ($name == '') {
throw new Exception_Input('Empty file name given');
}
- $path = $this->workDir . '/' . $base;
- if ($bHasToExist && !is_readable($path)) {
+ $fullpath = $this->workDir . '/' . $base;
+ if ($bHasToExist && !is_readable($fullpath)) {
throw new Exception_Input('File does not exist');
}
- return new File($path, $this);
+ return new File($base, $this);
}
public function hasFile($name)
* Get a link to the repository
*
* @param string $type Link type. Supported are:
- * - "commit"
* - "edit"
* - "delete"
* - "delete-confirm"
* - "display"
* - "fork"
+ * - "revision"
* @param string $option
*
* @return string
return '/' . $this->id . '/delete';
} else if ($type == 'delete-confirm') {
return '/' . $this->id . '/delete/confirm';
- } else if ($type == 'commit') {
- return '/' . $this->id . '/' . $option;
+ } else if ($type == 'revision') {
+ return '/' . $this->id . '/rev/' . $option;
}
throw new Exception('Unknown link type');
}
$bChanged = true;
} else if ($bUpload) {
move_uploaded_file(
- $_FILES['files']['tmp_name'][$num]['upload'], $file->getPath()
+ $_FILES['files']['tmp_name'][$num]['upload'], $file->getFullPath()
);
$command = $vc->getCommand('add')
->addArgument($file->getFilename())
->execute();
$bChanged = true;
} else if ($bNew || (isset($arFile['content']) && $file->getContent() != $arFile['content'])) {
- file_put_contents($file->getPath(), $arFile['content']);
+ file_put_contents($file->getFullPath(), $arFile['content']);
$command = $vc->getCommand('add')
->addArgument($file->getFilename())
->execute();
public function run(File $file)
{
- $fpath = $file->getPath();
+ $fpath = $file->getFullPath();
$fpathlen = strlen($fpath);
$res = new Tool_Result();
public function run(File $file)
{
- $fpath = $file->getPath();
+ $fpath = $file->getFullPath();
$fpathlen = strlen($fpath);
$res = new Tool_Result();
RewriteRule ^([0-9]+)/edit$ /edit.php?id=$1
RewriteRule ^([0-9]+)/fork$ /fork.php?id=$1
RewriteRule ^([0-9]+)/raw/(.+)$ /raw.php?id=$1&file=$2
+RewriteRule ^([0-9]+)/rev/(.+)$ /revision.php?id=$1&rev=$2
RewriteRule ^([0-9]+)/tool/([^/]+)/(.+)$ /tool.php?id=$1&tool=$2&file=$3
RewriteRule ^list$ /list.php
$mimetype = 'text/plain';
}
header('Content-Type: ' . $mimetype);
-readfile($file->path);
+readfile($file->getFullPath());
?>
--- /dev/null
+<?php
+namespace phorkie;
+/**
+ * Display paste contents
+ */
+require_once 'www-header.php';
+
+$repo = new Repository();
+$repo->loadFromRequest();
+
+render(
+ 'display',
+ array(
+ 'repo' => $repo,
+ 'dh' => new \Date_HumanDiff(),
+ )
+);
+?>