diff --git a/codepot/src/codepot/controllers/code.php b/codepot/src/codepot/controllers/code.php index 19945d7c..a997c1d5 100644 --- a/codepot/src/codepot/controllers/code.php +++ b/codepot/src/codepot/controllers/code.php @@ -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(); } } - } diff --git a/codepot/src/codepot/models/subversionmodel.php b/codepot/src/codepot/models/subversionmodel.php index a29749b2..51d05ded 100644 --- a/codepot/src/codepot/models/subversionmodel.php +++ b/codepot/src/codepot/models/subversionmodel.php @@ -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}");