*/
public $hash;
+ /**
+ * Commit message of the last (or current) revision
+ *
+ * @var string
+ */
+ public $message;
/**
$this->id = (int)$_GET['id'];
$this->loadDirs();
$this->loadHash();
+ $this->loadMessage();
+ }
+
+ public function loadById($id)
+ {
+ if (!is_numeric($id)) {
+ throw new Exception_Input('Paste ID not numeric');
+ }
+ $this->id = (int)$id;
+ $this->loadDirs();
+ $this->loadHash();
}
protected function loadDirs()
$this->hash = $output;
}
- public function loadById($id)
+ /**
+ * Populates $this->message
+ *
+ * @return void
+ */
+ public function loadMessage()
{
- if (!is_numeric($id)) {
- throw new Exception_Input('Paste ID not numeric');
+ $rev = (isset($this->hash)) ? $this->hash : 'HEAD';
+ $output = $this->getVc()->getCommand('log')
+ ->setOption('oneline')
+ ->addArgument('-1')
+ ->addArgument($rev)
+ ->execute();
+ $output = trim($output);
+ if (strpos($output, ' ') > 0) {
+ $output = substr($output, strpos($output, ' '), strlen($output));
+ $this->message = trim($output);
+ } else {
+ $this->message = "This commit message intentionally left blank.";
}
- $this->id = (int)$id;
- $this->loadDirs();
- $this->loadHash();
}
public function getVc()
file_put_contents($this->gitDir . '/description', $description);
}
+ /**
+ * @return array Array with keys "email" and "name"
+ */
+ public function getOwner()
+ {
+ try {
+ $name = $this->getVc()->getCommand('config')
+ ->addArgument('owner.name')->execute();
+ } catch (\VersionControl_Git_Exception $e) {
+ $name = $GLOBALS['phorkie']['auth']['anonymousName'];
+ }
+ try {
+ $email = $this->getVc()->getCommand('config')
+ ->addArgument('owner.email')->execute();
+ } catch (\VersionControl_Git_Exception $e) {
+ $email = $GLOBALS['phorkie']['auth']['anonymousEmail'];
+ }
+
+ return array('name' => trim($name), 'email' => trim($email));
+ }
+
/**
* Get a link to the repository
*
- * @param string $type Link type. Supported are:
- * - "edit"
- * - "delete"
- * - "delete-confirm"
- * - "display"
- * - "fork"
- * - "revision"
- * @param string $option
+ * @param string $type Link type. Supported are:
+ * - "edit"
+ * - "delete"
+ * - "delete-confirm"
+ * - "display"
+ * - "fork"
+ * - "revision"
+ * @param string $option Additional link option, e.g. revision number
+ * @param boolean $full Return full URL or normal relative
*
* @return string
*/
- public function getLink($type, $option = null)
+ public function getLink($type, $option = null, $full = false)
{
if ($type == 'edit') {
- return '/' . $this->id . '/edit';
+ $link = $this->id . '/edit';
} else if ($type == 'display') {
- return '/' . $this->id;
+ $link = $this->id;
} else if ($type == 'fork') {
- return '/' . $this->id . '/fork';
+ $link = $this->id . '/fork';
+ } else if ($type == 'doap') {
+ $link = $this->id . '/doap';
} else if ($type == 'delete') {
- return '/' . $this->id . '/delete';
+ $link = $this->id . '/delete';
} else if ($type == 'delete-confirm') {
- return '/' . $this->id . '/delete/confirm';
+ $link = $this->id . '/delete/confirm';
} else if ($type == 'revision') {
- return '/' . $this->id . '/rev/' . $option;
+ $link = $this->id . '/rev/' . $option;
+ } else {
+ throw new Exception('Unknown link type');
}
- throw new Exception('Unknown link type');
+
+ if ($full) {
+ $link = Tools::fullUrl($link);
+ }
+ return $link;
}
public function getCloneURL($public = true)
$commit->committerName = $arOutput[$current + 2];
$commit->committerEmail = $arOutput[$current + 3];
+ if (substr($arOutput[$current + 4], 0, 1) != ' ') {
+ //commit without changed lines
+ $arCommits[] = $commit;
+ $current += 4;
+ continue;
+ }
+
$arLineParts = explode(' ', trim($arOutput[$current + 4]));
$commit->filesChanged = $arLineParts[0];
$commit->linesAdded = $arLineParts[3];
return $arCommits;
}
+
+ /**
+ * @return Repository_ConnectionInfo
+ */
+ public function getConnectionInfo()
+ {
+ return new Repository_ConnectionInfo($this);
+ }
}
?>