Use git tag --contains REV for the IDF_Scm::inTags() implementation.

This works similar to git branch --contains REV; additionally give the
revision id and not some possibly symbolic name to the inBranches()
call when we determine the branches a commit is in.
release-1.1
Thomas Keller 2011-03-16 23:03:36 +01:00
parent b75884c57e
commit 6fb9b72e22
2 changed files with 33 additions and 38 deletions

View File

@ -52,6 +52,7 @@
- Disable browser autocomplete of password fields in the account settings (issue 616) - Disable browser autocomplete of password fields in the account settings (issue 616)
- Improvements in the automatic linker parser (issue 618) - Improvements in the automatic linker parser (issue 618)
- The `createIssue` API method did not check the API authentication (issue 619) - The `createIssue` API method did not check the API authentication (issue 619)
- Print active git branch heads and tags in bold
## Documentation ## Documentation

View File

@ -62,20 +62,20 @@ class IDF_Scm_Git extends IDF_Scm
$out = array(); $out = array();
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd; $cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
self::exec('IDF_Scm_Git::getChanges', $cmd, $out); self::exec('IDF_Scm_Git::getChanges', $cmd, $out);
$return = (object) array( $return = (object) array(
'additions' => array(), 'additions' => array(),
'deletions' => array(), 'deletions' => array(),
'renames' => array(), 'renames' => array(),
'patches' => array(), 'patches' => array(),
'properties' => array(), 'properties' => array(),
); );
foreach ($out as $line) { foreach ($out as $line) {
$line = trim($line); $line = trim($line);
if ($line != '') { if ($line != '') {
$action = $line[0]; $action = $line[0];
if ($action == 'A') { if ($action == 'A') {
$filename = trim(substr($line, 1)); $filename = trim(substr($line, 1));
$return->additions[] = $filename; $return->additions[] = $filename;
@ -88,10 +88,10 @@ class IDF_Scm_Git extends IDF_Scm
} else if ($action == 'R') { } else if ($action == 'R') {
$matches = split ("\t", $line); $matches = split ("\t", $line);
$return->renames[$matches[1]] = $matches[2]; $return->renames[$matches[1]] = $matches[2];
} }
} }
} }
return $return; return $return;
} }
@ -170,7 +170,7 @@ class IDF_Scm_Git extends IDF_Scm
if (isset($this->cache['inBranches'][$commit])) { if (isset($this->cache['inBranches'][$commit])) {
return $this->cache['inBranches'][$commit]; return $this->cache['inBranches'][$commit];
} }
$cmd = Pluf::f('idf_exec_cmd_prefix', '') $cmd = Pluf::f('idf_exec_cmd_prefix', '')
.sprintf('GIT_DIR=%s %s branch --contains %s', .sprintf('GIT_DIR=%s %s branch --contains %s',
escapeshellarg($this->repo), escapeshellarg($this->repo),
@ -187,9 +187,9 @@ class IDF_Scm_Git extends IDF_Scm
foreach ($out as $line) { foreach ($out as $line) {
$res[] = substr($line, 2); $res[] = substr($line, 2);
} }
$this->cache['inBranches'][$commit] = $res; $this->cache['inBranches'][$commit] = $res;
return $res; return $res;
} }
/** /**
@ -238,35 +238,29 @@ class IDF_Scm_Git extends IDF_Scm
**/ **/
public function inTags($commit, $path) public function inTags($commit, $path)
{ {
return $this->_inObject($commit, 'tag'); if (isset($this->cache['inTags'][$commit])) {
} return $this->cache['inTags'][$commit];
}
/** $cmd = Pluf::f('idf_exec_cmd_prefix', '')
* Returns in which branches or tags a commit is. .sprintf('GIT_DIR=%s %s tag --contains %s',
* escapeshellarg($this->repo),
* @param string Commit Pluf::f('git_path', 'git'),
* @param string Object's type: 'branch' or 'tag'. escapeshellarg($commit));
* @return array self::exec('IDF_Scm_Git::inTags', $cmd, $out, $return);
*/ if (0 != $return) {
private function _inObject($commit, $object) throw new IDF_Scm_Exception(sprintf($this->error_tpl,
{ $cmd, $return,
$object = strtolower($object); implode("\n", $out)));
if ('branch' === $object) {
$objects = $this->getBranches();
} else if ('tag' === $object) {
$objects = $this->getTags();
} else {
throw new InvalidArgumentException(sprintf(__('Invalid value for the parameter %1$s: %2$s. Use %3$s.'),
'$object',
$object,
'\'branch\' or \'tag\''));
} }
unset($object);
$result = array(); $res = array();
if (array_key_exists($commit, $objects)) { foreach ($out as $line) {
$result[] = $commit; $res[] = $line;
} }
return $result;
$this->cache['inTags'][$commit] = $res;
return $res;
} }
/** /**
@ -368,8 +362,8 @@ class IDF_Scm_Git extends IDF_Scm
$keys = $user->get_idf_key_list(); $keys = $user->get_idf_key_list();
if (count ($keys) == 0) if (count ($keys) == 0)
return self::getAnonymousAccessUrl($project); return self::getAnonymousAccessUrl($project);
} }
return sprintf(Pluf::f('git_write_remote_url'), $project->shortname); return sprintf(Pluf::f('git_write_remote_url'), $project->shortname);
} }
@ -527,7 +521,7 @@ class IDF_Scm_Git extends IDF_Scm
$out[0]->diff = ''; $out[0]->diff = '';
} }
$out[0]->branch = implode(', ', $this->inBranches($commit, null)); $out[0]->branch = implode(', ', $this->inBranches($out[0]->commit, null));
return $out[0]; return $out[0];
} }