aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2012-09-21 10:33:24 +0200
committerChristian Weiske <cweiske@cweiske.de>2012-09-21 10:33:24 +0200
commit5d065586f4c16c0ec6510dba97b0d5facb859d75 (patch)
tree9ac780960aaa01e92235c72443193b585e23f3f9 /src
parent9f4d00eb634cbf75db2143a62ce8733e901b14a8 (diff)
parent6dd1eeafade7105c0785340a43877a8d63793892 (diff)
downloadphorkie-5d065586f4c16c0ec6510dba97b0d5facb859d75.tar.gz
phorkie-5d065586f4c16c0ec6510dba97b0d5facb859d75.zip
Merge branch 'master' into milestone
Diffstat (limited to 'src')
-rw-r--r--src/phorkie/ForkRemote.php114
-rw-r--r--src/phorkie/Forker.php44
-rw-r--r--src/phorkie/Renderer/Geshi.php2
-rw-r--r--src/phorkie/Repository.php7
4 files changed, 166 insertions, 1 deletions
diff --git a/src/phorkie/ForkRemote.php b/src/phorkie/ForkRemote.php
new file mode 100644
index 0000000..524255a
--- /dev/null
+++ b/src/phorkie/ForkRemote.php
@@ -0,0 +1,114 @@
+<?php
+namespace phorkie;
+
+class ForkRemote
+{
+ protected $url;
+
+ /**
+ * Array with keys (URL title) and values (arrays of urls)
+ * Only supported URLs are included.
+ *
+ * @var array
+ */
+ protected $arGitUrls;
+
+
+
+ public function __construct($url)
+ {
+ $this->url = $url;
+ }
+
+ public function parse()
+ {
+ $scheme = parse_url($this->url, PHP_URL_SCHEME);
+ switch ($scheme) {
+ case 'git':
+ //clearly a git url
+ $this->arGitUrls = array(array($this->url));
+ return true;
+
+ case 'ssh':
+ //FIXME: maybe loosen this when we know how to skip the
+ //"do you trust this server" question of ssh
+ $this->error = 'ssh:// URLs are not supported';
+ return false;
+
+ case 'http':
+ case 'https':
+ return $this->extractUrlsFromHtml($this->url);
+ }
+
+ $this->error = 'Unknown URLs scheme: ' . $scheme;
+ return false;
+ }
+
+ protected function extractUrlsFromHtml($url)
+ {
+ //HTML is not necessarily well-formed, and Gitorious has many problems
+ // in this regard
+ //$sx = simplexml_load_file($url);
+ libxml_use_internal_errors(true);
+ $sx = simplexml_import_dom(\DomDocument::loadHtmlFile($url));
+ $elems = $sx->xpath('//*[@rel="vcs-git"]');
+
+ $count = $anonymous = 0;
+ foreach ($elems as $elem) {
+ if (!isset($elem['href'])) {
+ continue;
+ }
+ $str = (string)$elem;
+ if (isset($elem['title'])) {
+ //<link href=".." rel="vcs-git" title="title" />
+ $title = (string)$elem['title'];
+ } else if ($str != '') {
+ //<a href=".." rel="vcs-git">title</a>
+ $title = $str;
+ } else {
+ $title = 'Unnamed repository #' . ++$anonymous;
+ }
+ $url = (string)$elem['href'];
+ if ($this->isSupported($url)) {
+ ++$count;
+ $this->arGitUrls[$title][] = $url;
+ }
+ }
+
+ return $count > 0;
+ }
+
+ /**
+ * Iterate through all git urls and return one if there is only
+ * one supported one.
+ *
+ * @return mixed Boolean false or string
+ */
+ public function getUniqueGitUrl()
+ {
+ $nFound = 0;
+ foreach ($this->arGitUrls as $title => $arUrls) {
+ foreach ($arUrls as $url) {
+ $nFound++;
+ $uniqueUrl = $url;
+ }
+ }
+
+ if ($nFound == 1) {
+ return $uniqueUrl;
+ }
+ return false;
+ }
+
+ public function getGitUrls()
+ {
+ return $this->arGitUrls;
+ }
+
+ public function isSupported($url)
+ {
+ return parse_url($url, PHP_URL_SCHEME) == 'git';
+ }
+}
+
+?>
diff --git a/src/phorkie/Forker.php b/src/phorkie/Forker.php
new file mode 100644
index 0000000..3425a72
--- /dev/null
+++ b/src/phorkie/Forker.php
@@ -0,0 +1,44 @@
+<?php
+namespace phorkie;
+
+class Forker
+{
+ public function forkLocal($repo)
+ {
+ $new = $this->fork($repo->gitDir);
+ \copy($repo->gitDir . '/description', $new->gitDir . '/description');
+ return $new;
+ }
+
+ public function forkRemote($url)
+ {
+ $new = $this->fork($url);
+ file_put_contents(
+ $new->gitDir . '/description',
+ 'Fork of ' . $url
+ );
+ return $new;
+ }
+
+
+ protected function fork($pathOrUrl)
+ {
+ $rs = new Repositories();
+ $new = $rs->createNew();
+ $vc = $new->getVc();
+ \rmdir($new->gitDir);//VersionControl_Git wants an existing dir, git clone not
+ $vc->getCommand('clone')
+ //this should be setOption, but it fails with a = between name and value
+ ->addArgument('--separate-git-dir')
+ ->addArgument($GLOBALS['phorkie']['cfg']['gitdir'] . '/' . $new->id . '.git')
+ ->addArgument($pathOrUrl)
+ ->addArgument($new->workDir)
+ ->execute();
+ foreach (\glob($new->gitDir . '/hooks/*') as $hookfile) {
+ \unlink($hookfile);
+ }
+ return $new;
+ }
+}
+
+?>
diff --git a/src/phorkie/Renderer/Geshi.php b/src/phorkie/Renderer/Geshi.php
index 2010ead..21d36c2 100644
--- a/src/phorkie/Renderer/Geshi.php
+++ b/src/phorkie/Renderer/Geshi.php
@@ -28,7 +28,7 @@ class Renderer_Geshi
}
return '<div class="code">'
- . $geshi->parse_code()
+ . str_replace('&nbsp;', '&#160;', $geshi->parse_code())
. '</div>';
}
diff --git a/src/phorkie/Repository.php b/src/phorkie/Repository.php
index 4ac5ae7..25b049c 100644
--- a/src/phorkie/Repository.php
+++ b/src/phorkie/Repository.php
@@ -310,6 +310,13 @@ class Repository
$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];