Continued the refactoring of the Subversion backend.

This commit is contained in:
Loic d'Anterroches 2009-04-27 11:39:19 +02:00
parent cf5acfb669
commit a3f40447c0
2 changed files with 26 additions and 30 deletions

View File

@ -22,8 +22,14 @@
# ***** END LICENSE BLOCK ***** */ # ***** END LICENSE BLOCK ***** */
/** /**
* SVN utils. * Subversion backend.
* * When a branch is not a branch.
*
* Contrary to most other SCMs, Subversion is using folders to manage
* the branches and so what is either the commit or the branch in
* other SCMs is the revision number with Subversion. So, do not be
* surprised if you have the feeling that the methods are not really
* returning what could be expected from their names.
*/ */
class IDF_Scm_Svn extends IDF_Scm class IDF_Scm_Svn extends IDF_Scm
{ {
@ -40,6 +46,7 @@ class IDF_Scm_Svn extends IDF_Scm
$this->repo = $repo; $this->repo = $repo;
$this->username = $username; $this->username = $username;
$this->password = $password; $this->password = $password;
$this->cache['commitmess'] = array();
} }
public function isAvailable() public function isAvailable()
@ -163,8 +170,7 @@ class IDF_Scm_Svn extends IDF_Scm
escapeshellarg($this->password), escapeshellarg($this->password),
escapeshellarg($this->repo.'/'.$folder), escapeshellarg($this->repo.'/'.$folder),
escapeshellarg($rev)); escapeshellarg($rev));
$xmlLs = shell_exec($cmd); $xml = simplexml_load_string(shell_exec($cmd));
$xml = simplexml_load_string($xmlLs);
$res = array(); $res = array();
$folder = (strlen($folder)) ? $folder.'/' : ''; $folder = (strlen($folder)) ? $folder.'/' : '';
foreach ($xml->list->entry as $entry) { foreach ($xml->list->entry as $entry) {
@ -175,10 +181,7 @@ class IDF_Scm_Svn extends IDF_Scm
$file['date'] = gmdate('Y-m-d H:i:s', $file['date'] = gmdate('Y-m-d H:i:s',
strtotime((string) $entry->commit->date)); strtotime((string) $entry->commit->date));
$file['rev'] = (string) $entry->commit['revision']; $file['rev'] = (string) $entry->commit['revision'];
// Get commit message $file['log'] = $this->getCommitMessage($file['rev']);
$currentReposFile = $this->repo.'/'.$folder.$file['file'];
$file['log'] = $this->getCommitMessage($currentReposFile, $rev);
// Get the size if the type is blob // Get the size if the type is blob
if ($file['type'] == 'blob') { if ($file['type'] == 'blob') {
$file['size'] = (string) $entry->size; $file['size'] = (string) $entry->size;
@ -192,25 +195,24 @@ class IDF_Scm_Svn extends IDF_Scm
/** /**
* Get a commit message for given file and revision. * Get the commit message of a revision revision.
* *
* @param string File
* @param string Commit ('HEAD') * @param string Commit ('HEAD')
*
* @return String commit message * @return String commit message
*/ */
private function getCommitMessage($file, $rev='HEAD') private function getCommitMessage($rev='HEAD')
{ {
if (isset($commit[$rev])) return $commit[$rev]; if (isset($this->cache['commitmess'][$rev])) {
return $this->cache['commitmess'][$rev];
}
$cmd = sprintf(Pluf::f('svn_path', 'svn').' log --xml --limit 1 --username=%s --password=%s %s@%s', $cmd = sprintf(Pluf::f('svn_path', 'svn').' log --xml --limit 1 --username=%s --password=%s %s@%s',
escapeshellarg($this->username), escapeshellarg($this->username),
escapeshellarg($this->password), escapeshellarg($this->password),
escapeshellarg($file), escapeshellarg($this->repo),
escapeshellarg($rev)); escapeshellarg($rev));
$xmlLog = shell_exec($cmd); $xml = simplexml_load_string(shell_exec($cmd));
$xml = simplexml_load_string($xmlLog); $this->cache['commitmess'][$rev] = (string) $xml->logentry->msg;
$commit[$rev]=(string) $xml->logentry->msg; return $this->cache['commitmess'][$rev];
return (string) $xml->logentry->msg;
} }
/** /**
@ -223,20 +225,18 @@ class IDF_Scm_Svn extends IDF_Scm
escapeshellarg($this->password), escapeshellarg($this->password),
escapeshellarg($this->repo.'/'.$totest), escapeshellarg($this->repo.'/'.$totest),
escapeshellarg($rev)); escapeshellarg($rev));
$xmlInfo = shell_exec($cmd); $xml = simplexml_load_string(shell_exec($cmd));
$xml = simplexml_load_string($xmlInfo);
$entry = $xml->entry; $entry = $xml->entry;
$file = array(); $file = array();
$file['fullpath'] = $totest; $file['fullpath'] = $totest;
$file['hash'] = (string) $entry->repository->uuid; $file['hash'] = (string) $entry->repository->uuid;
$file['type'] = $this->assoc[(string) $entry['kind']]; $file['type'] = $this->assoc[(string) $entry['kind']];
$file['file'] = $totest; $file['file'] = $totest;
$file['rev'] = (string) $entry->commit['revision']; $file['rev'] = $rev;
$file['author'] = (string) $entry->author; $file['author'] = (string) $entry->author;
$file['date'] = gmdate('Y-m-d H:i:s', strtotime((string) $entry->commit->date)); $file['date'] = gmdate('Y-m-d H:i:s', strtotime((string) $entry->commit->date));
$file['size'] = (string) $entry->size; $file['size'] = (string) $entry->size;
$file['log'] = ''; $file['log'] = '';
return (object) $file; return (object) $file;
} }
@ -280,7 +280,7 @@ class IDF_Scm_Svn extends IDF_Scm
escapeshellarg($this->repo.'/trunk')); escapeshellarg($this->repo.'/trunk'));
exec($cmd, $out, $ret); exec($cmd, $out, $ret);
if ($ret == 0) { if ($ret == 0) {
$res = array_merge(array('trunk' => 'trunk'), $res); $res = array('trunk' => 'trunk') + $res;
} }
$this->cache['branches'] = $res; $this->cache['branches'] = $res;
return $res; return $res;

View File

@ -150,16 +150,15 @@ class IDF_Views_Source
$title = sprintf(__('%1$s %2$s Source Tree'), $title = sprintf(__('%1$s %2$s Source Tree'),
$request->project, $this->getScmType($request)); $request->project, $this->getScmType($request));
$scm = IDF_Scm::get($request->project); $scm = IDF_Scm::get($request->project);
$commit = $match[2];
$request_file = $match[3];
if (!$scm->isAvailable()) { if (!$scm->isAvailable()) {
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::help', $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::help',
array($request->project->shortname)); array($request->project->shortname));
return new Pluf_HTTP_Response_Redirect($url); return new Pluf_HTTP_Response_Redirect($url);
} }
$branches = $scm->getBranches(); $branches = $scm->getBranches();
$commit = $match[2];
$request_file = $match[3];
$fburl = Pluf_HTTP_URL_urlForView('IDF_Views_Source::treeBase', $fburl = Pluf_HTTP_URL_urlForView('IDF_Views_Source::treeBase',
array($request->project->shortname, array($request->project->shortname,
$scm->getMainBranch())); $scm->getMainBranch()));
@ -170,18 +169,15 @@ class IDF_Views_Source
$request_file)); $request_file));
return new Pluf_HTTP_Response_Redirect($url, 301); return new Pluf_HTTP_Response_Redirect($url, 301);
} }
if (!$scm->isValidRevision($commit, $request_file)) { if (!$scm->isValidRevision($commit, $request_file)) {
// Redirect to the first branch // Redirect to the first branch
return new Pluf_HTTP_Response_Redirect($fburl); return new Pluf_HTTP_Response_Redirect($fburl);
} }
$request_file_info = $scm->getPathInfo($request_file, $commit); $request_file_info = $scm->getPathInfo($request_file, $commit);
if (!$request_file_info) { if (!$request_file_info) {
// Redirect to the first branch // Redirect to the first branch
return new Pluf_HTTP_Response_Redirect($fburl); return new Pluf_HTTP_Response_Redirect($fburl);
} }
if ($request_file_info->type != 'tree') { if ($request_file_info->type != 'tree') {
$info = self::getRequestedFileMimeType($request_file_info, $info = self::getRequestedFileMimeType($request_file_info,
$commit, $scm); $commit, $scm);