Added the support of the tags for Mercurial and Subversion.

master
Loic d'Anterroches 2009-11-06 18:06:01 +01:00
parent 8050463a12
commit ff4f8afde8
7 changed files with 103 additions and 4 deletions

View File

@ -279,12 +279,42 @@ class IDF_Scm_Mercurial extends IDF_Scm
return $res;
}
/**
* Get the tags.
*
* @return array Tags.
*/
public function getTags()
{
if (isset($this->cache['tags'])) {
return $this->cache['tags'];
}
$out = array();
$cmd = sprintf(Pluf::f('hg_path', 'hg').' tags -R %s',
escapeshellarg($this->repo));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
exec($cmd, $out);
$res = array();
foreach ($out as $b) {
preg_match('/(\S+).*\S+:(\S+)/', $b, $match);
$res[$match[1]] = '';
}
$this->cache['tags'] = $res;
return $res;
}
public function inBranches($commit, $path)
{
return (in_array($commit, array_keys($this->getBranches())))
? array($commit) : array();
}
public function inTags($commit, $path)
{
return (in_array($commit, array_keys($this->getTags())))
? array($commit) : array();
}
/**
* Get commit details.
*

View File

@ -287,7 +287,7 @@ class IDF_Scm_Svn extends IDF_Scm
}
/**
* Subversion branches are repository based.
* Subversion branches are folder based.
*
* One need to list the folder to know them.
*/
@ -325,6 +325,36 @@ class IDF_Scm_Svn extends IDF_Scm
return $res;
}
/**
* Subversion tags are folder based.
*
* One need to list the folder to know them.
*/
public function getTags()
{
if (isset($this->cache['tags'])) {
return $this->cache['tags'];
}
$res = array();
$cmd = sprintf(Pluf::f('svn_path', 'svn').' ls --username=%s --password=%s %s@HEAD',
escapeshellarg($this->username),
escapeshellarg($this->password),
escapeshellarg($this->repo.'/tags'));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
exec($cmd, $out, $ret);
if ($ret == 0) {
foreach ($out as $entry) {
if (substr(trim($entry), -1) == '/') {
$tag = substr(trim($entry), 0, -1);
$res[$tag] = 'tags/'.$tag;
}
}
}
ksort($res);
$this->cache['tags'] = $res;
return $res;
}
public function getMainBranch()
{
return 'HEAD';
@ -340,6 +370,16 @@ class IDF_Scm_Svn extends IDF_Scm
return array();
}
public function inTags($commit, $path)
{
foreach ($this->getTags() as $tag => $tpath) {
if ($tpath and 0 === strpos($path, $tpath)) {
return array($tag);
}
}
return array();
}
/**
* Get commit details.

View File

@ -6,5 +6,13 @@
<span class="label{if in_array($branch, $tree_in)} active{/if}"><a href="{$url}" class="label">{$branch}</a></span><br />
{/foreach}
</p>
{if $tags}
<p><strong>{trans 'Tags:'}</strong><br/>
{foreach $tags as $tag => $path}
{aurl 'url', 'IDF_Views_Source::changeLog', array($project.shortname, $tag)}
<span class="label{if in_array($tag, $tags_in)} active{/if}"><a href="{$url}" class="label">{$tag}</a></span><br/>
{/foreach}
</p>
{/if}
{/block}

View File

@ -29,6 +29,14 @@
<span class="label{if in_array($branch, $tree_in)} active{/if}"><a href="{$url}" class="label">{$branch}</a></span><br />
{/foreach}
</p>
{if $tags}
<p><strong>{trans 'Tags:'}</strong><br/>
{foreach $tags as $tag => $path}
{aurl 'url', 'IDF_Views_Source::tree', array($project.shortname, 'HEAD', $path)}
<span class="label{if in_array($tag, $tags_in)} active{/if}"><a href="{$url}" class="label">{$tag}</a></span><br/>
{/foreach}
</p>
{/if}
{/block}
{block javascript}

View File

@ -11,7 +11,7 @@
<th>{trans 'Message'}</th>
<th>{trans 'Size'}</th>
</tr>
</thead>{if !$tree_in}
</thead>{if !$tree_in and !$tags_in}
{aurl 'url', 'IDF_Views_Source::commit', array($project.shortname, $commit)}
<tfoot>
<tr><th colspan="5">{blocktrans}Source at commit <a class="mono" href="{$url}">{$commit}</a> created {$cobject.date|dateago}.{/blocktrans}<br />
@ -53,5 +53,11 @@
<span class="label{if in_array($branch, $tree_in)} active{/if}"><a href="{$url}" class="label">{$branch}</a></span><br />
{/foreach}
</p>
{if $tags}<p><strong>{trans 'Tags:'}</strong><br />
{foreach $tags as $tag => $path}
{aurl 'url', 'IDF_Views_Source::treeBase', array($project.shortname, $tag)}
<span class="label{if in_array($tag, $tags_in)} active{/if}"><a href="{$url}" class="label">{$tag}</a></span><br />
{/foreach}
</p>{/if}
{/block}

View File

@ -40,7 +40,6 @@
<input type="hidden" name="sourcefile" value="{$base}"/>
<input type="submit" name="s" value="{trans 'Go to revision'}" /></p>
</form>
{/block}
{block javascript}

View File

@ -12,7 +12,7 @@
<th>{trans 'Message'}</th>
<th>{trans 'Size'}</th>
</tr>
</thead>{if !$tree_in || $props}
</thead>{if (!$tree_in and !$tags_in and $commit != 'HEAD') || $props}
{aurl 'url', 'IDF_Views_Source::commit', array($project.shortname, $commit)}
<tfoot>
{if $props}
@ -75,5 +75,13 @@
<span class="label{if in_array($branch, $tree_in)} active{/if}"><a href="{$url}" class="label">{$branch}</a></span><br />
{/foreach}
</p>
{if $tags}
<p><strong>{trans 'Tags:'}</strong><br/>
{foreach $tags as $tag => $path}
{aurl 'url', 'IDF_Views_Source::tree', array($project.shortname, 'HEAD', $path)}
<span class="label{if in_array($tag, $tags_in)} active{/if}"><a href="{$url}" class="label">{$tag}</a></span><br/>
{/foreach}
</p>
{/if}
{/block}