/** * @param string Path to repository * @param int Number of revision (0 = no limit) * @return array Key are revision number example: * array( * 1 => array("author" => "duponc_j", "msg" => "Test", date=> 1265413), * 2 => array("revision" => "crivis_s", "msg" => "Test2", date=>4565654) * ) * * Date are unix timestamp */ public static function log($repository, $limit = 0, $start = 0, $end = 0) { $repository = USVN_SVNUtils::getRepositoryPath($repository); if ($limit) { $limit = escapeshellarg($limit); $limit = "--limit {$limit}"; } else { $limit = ""; } if ($start) { $revision = "-r {$start}"; if ($end) { $revision .= ":{$end}"; } } else { $revision = ""; } $message = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe(USVN_SVNUtils::svnCommand("log --xml {$revision} {$limit} {$repository}"), $return); if ($return) { throw new USVN_Exception(T_("Can't get subversion repository logs: %s"), $message); } return USVN_SVNLog::parseOutput($message); }
/** * Display a file using appropriate highlighting * * @return void */ public function commitAction() { include_once 'geshi/geshi.php'; $this->view->project = $this->_project; $config = new USVN_Config_Ini(USVN_CONFIG_FILE, USVN_CONFIG_SECTION); $project_name = str_replace(USVN_URL_SEP, '/', $this->_project->name); $local_project_path = USVN_SVNUtils::getRepositoryPath($config->subversion->path . "/svn/" . $project_name . "/"); $commit = $this->getRequest()->getParam('commit'); $base = $commit - 1; $cmd = USVN_SVNUtils::svnCommand("log --non-interactive --revision {$commit} {$local_project_path}"); $log = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe($cmd, $return); if (!$return) { $cmd = USVN_SVNUtils::svnCommand("diff --non-interactive --revision " . ($commit - 1) . ":{$commit} {$local_project_path}"); $diff = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe($cmd, $return); if (!$return) { $diff = explode("\n", $diff); array_pop($diff); // Skip the final "\n" $file = NULL; $count = 0; $indiff = FALSE; $tab_diff = array(); $tab_index = NULL; foreach ($diff as $line) { if (strpos($line, 'Index: ') === 0) { $file = substr($line, 7); $tab_diff[$file] = array(); $indiff = FALSE; } elseif (!$indiff) { if (preg_match('#^@@ \\-([0-9]+)(,([0-9]+))? \\+([0-9]+)(,([0-9]+))? @@$#', $line, $tmp)) { $tab_index = count($tab_diff[$file]); $tab_diff[$file][$tab_index] = array($base => array('begin' => $tmp[1], 'end' => empty($tmp[3]) ? $tmp[1] : $tmp[3], 'content' => array()), $commit => array('begin' => $tmp[4], 'end' => empty($tmp[6]) ? $tmp[4] : $tmp[6], 'content' => array()), 'common' => array()); $count = 0; $indiff = TRUE; } } else { $diff_char = substr($line, 0, 1); if ($diff_char == '\\') { continue; } $line = htmlentities(substr($line, 1)); if ($diff_char == '-') { $tab_diff[$file][$tab_index][$base]['content'][$count++] = $line; } elseif ($diff_char == '+') { $tab_diff[$file][$tab_index][$commit]['content'][$count++] = $line; } else { $tab_diff[$file][$tab_index]['common'][$count++] = $line; } } } $this->view->diff = $tab_diff; $this->view->commit = $commit; $this->view->base = $base; unset($tab_diff); $log = explode("\n", $log); if (preg_match('#^r[0-9]* \\| (.*) \\| ([0-9-]+ [0-9:]+) [^\\|]* \\| ([0-9]*)[^\\|]*$#', $log[1], $tmp)) { $this->view->author = $tmp[1]; $this->view->date = $tmp[2]; $this->view->log = NULL; for ($i = 0; $i < $tmp[3]; ++$i) { $this->view->log .= ($this->view->log != NULL ? "\n" : '') . $log[3 + $i]; } } } else { throw new USVN_Exception(T_("Can't read from subversion repository.\nCommand:\n%s\n\nError:\n%s"), $cmd, $message); } } else { throw new USVN_Exception(T_("Can't read from subversion repository.\nCommand:\n%s\n\nError:\n%s"), $cmd, $message); } }
/** * List files into Subversion * * @param string Path to subversion repository * @param string Path into subversion repository * @return associative array like: array(array(name => "tutu", isDirectory => true)) */ public static function listSvn($repository, $path) { $escape_path = USVN_SVNUtils::getRepositoryPath($repository . '/' . $path); $lists = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe(USVN_SVNUtils::svnCommand("ls --xml {$escape_path}"), $return); if ($return) { throw new USVN_Exception(T_("Can't list subversion repository: %s"), $lists); } $res = array(); $xml = new SimpleXMLElement($lists); foreach ($xml->list->entry as $list) { if ($list['kind'] == 'file') { array_push($res, array("name" => (string) $list->name, "isDirectory" => false, "path" => str_replace('//', '/', $path . "/" . $list->name), "size" => $list->size, "revision" => $list->commit['revision'], "author" => $list->commit->author, "date" => $list->commit->date)); } else { array_push($res, array("name" => (string) $list->name, "isDirectory" => true, "path" => str_replace('//', '/', $path . "/" . $list->name . '/'))); } } $sortfunc = create_function('$a,$b', 'return (strcasecmp($a["name"], $b["name"]));'); usort($res, $sortfunc); return $res; }
/** * Run a cmd and return result from stdout and stderror. Html characters are escaped. * * @param string command line * @param reference return value * @return string Ouput of STDOUT and STDERR */ public static function runCmdCaptureMessage($command, &$return) { return htmlspecialchars(USVN_ConsoleUtils::runCmdCaptureMessageUnsafe($command, $return)); }