/** * Get a list of Makefile targets for a (template) repository * @param $param[1] (template) repository */ function api_get_repo_targets($param = array()) { $repo = $param[1]; $cached = get_repo_for_reading($repo); if ($cached === false) { router_error_404('Cannot get ' . $repo); } $targets = make_get_targets(cache_dir($cached)); if ($targets === false) { router_error_500('Cannot get Makefile targets for ' . $repo); } $ignore_targets = config('ignore_targets', array()); $target_descriptions = config('target_descriptions', array()); $default_target = config('default_target'); $ret = array(); foreach ($targets as $target) { // filter certain targets according to ignore_targets config if (in_array($target, $ignore_targets)) { continue; } $tmp = array('target' => $target); $tmp['description'] = isset($target_descriptions[$target]) ? $target_descriptions[$target] : $target; $tmp['default'] = $target === $default_target; $ret[] = $tmp; } return $ret; }
/** * Get a private copy of a remote Git repository * * The private copy can be manipulated with the returned tmp key. Call * release_repo() after it is no longer needed. * @param $url Git (clone) URL * @param $branch branch to check out (default is "master") * @param $force_update force a fetch * @return tmp key, or false if unsuccessful */ function get_repo($url, $branch = 'master', $force_update = false) { $tmp_key = tmp_key(); // get a cached copy, currently on the master branch $cache_key = get_repo_for_reading($url, $force_update); if ($cache_key === false) { return false; } // create files and directories as permissive as possible $old_umask = @umask(00); // copy to tmp if (false === cp_recursive(cache_dir($cache_key), tmp_dir($tmp_key))) { // copying failed, remove again rm_recursive(tmp_dir($tmp_key)); @umask($old_umask); return false; } if ($branch === 'master') { // XXX (later): revisit & document - IIRC the reason for this was that // same of the permissions were off after a regular copy (w/ umask) and // that running the git command somehow fix them? $ret = repo_cleanup($tmp_key); } else { $ret = repo_checkout_branch($tmp_key, $branch); // XXX (later): revisit - does this also need repo_cleanup()? } @umask($old_umask); if ($ret === false) { // copying failed, remove again rm_recursive(tmp_dir($tmp_key)); return false; } // XXX (later): this could be done asynchronously check_tmp_dir_age(); return $tmp_key; }