added xhr_gettagrev to code.php

This commit is contained in:
hyung-hwan 2015-12-08 03:07:39 +00:00
parent 50c68bbab3
commit 8fa4eecd05
2 changed files with 94 additions and 1 deletions

View File

@ -557,6 +557,50 @@ class Code extends Controller
print $status;
}
function xhr_gettagrev ($projectid = '', $tag = '')
{
$this->load->model ('ProjectModel', 'projects');
$this->load->model ('SubversionModel', 'subversion');
$login = $this->login->getUser ();
$project = $this->projects->get ($projectid);
if ($project === FALSE)
{
$status = "error - failed to get the project {$projectid}";
}
else if ($project === NULL)
{
$status = "error - no such project {$projectid}";
}
else
{
if ($project->public !== 'Y' && $login['id'] == '')
{
// non-public projects require sign-in.
redirect ("main/signin/" . $this->converter->AsciiTohex(current_url()));
}
$tag = $this->converter->HexToAscii ($tag);
$rev = $this->subversion->findRevWithRevProp ($projectid, CODEPOT_SVN_TAG_PROPERTY, $tag);
if ($rev === FALSE)
{
$status = 'repoerr - ' . $this->subversion->getErrorMessage();
}
else if ($rev <= -1)
{
$status = 'noent';
}
else
{
$status = 'ok - ' . $rev;
}
}
print $status;
}
function enjson_save ($projectid = '', $path = '')
{
$this->load->model ('ProjectModel', 'projects');
@ -1574,5 +1618,4 @@ class Code extends Controller
$this->graph->createGraph();
}
}
}

View File

@ -1260,6 +1260,56 @@ class SubversionModel extends Model
return $result;
}
function mapRevPropToRev ($projectid, $revprop_name)
{
$url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}");
set_error_handler (array ($this, 'capture_error'));
$info = @svn_info ($url, FALSE);
restore_error_handler ();
if ($info == FALSE || count($info) != 1) return FALSE;
$props = array ();
$xi = $info[0];
for ($rev = $xi['revision']; $rev > 0; $rev--)
{
set_error_handler (array ($this, 'capture_error'));
$val = @svn_revprop_get ($url, $rev, $revprop_name);
restore_error_handler ();
if ($val != '')
{
$props[$val] = $rev;
}
}
return $props;
}
function findRevWithRevProp ($projectid, $revprop_name, $revprop_value)
{
$url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}");
set_error_handler (array ($this, 'capture_error'));
$info = @svn_info ($url, FALSE);
restore_error_handler ();
if ($info == FALSE || count($info) != 1) return FALSE;
$xi = $info[0];
for ($rev = $xi['revision']; $rev > 0; $rev--)
{
set_error_handler (array ($this, 'capture_error'));
$val = @svn_revprop_get ($url, $rev, $revprop_name);
restore_error_handler ();
if ($val != '' && $revprop_value == $val)
{
return $rev;
}
}
return -1;
}
function listProps ($projectid, $path, $rev)
{
$orgurl = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}");