From ff4f8afde892405ed8f6a71fbfb92aafed527ff2 Mon Sep 17 00:00:00 2001 From: Loic d'Anterroches Date: Fri, 6 Nov 2009 18:06:01 +0100 Subject: [PATCH] Added the support of the tags for Mercurial and Subversion. --- src/IDF/Scm/Mercurial.php | 30 +++++++++++++ src/IDF/Scm/Svn.php | 42 ++++++++++++++++++- .../idf/source/mercurial/changelog.html | 8 ++++ .../templates/idf/source/mercurial/file.html | 8 ++++ .../templates/idf/source/mercurial/tree.html | 8 +++- src/IDF/templates/idf/source/svn/file.html | 1 - src/IDF/templates/idf/source/svn/tree.html | 10 ++++- 7 files changed, 103 insertions(+), 4 deletions(-) diff --git a/src/IDF/Scm/Mercurial.php b/src/IDF/Scm/Mercurial.php index b10a78a..d823188 100644 --- a/src/IDF/Scm/Mercurial.php +++ b/src/IDF/Scm/Mercurial.php @@ -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. * diff --git a/src/IDF/Scm/Svn.php b/src/IDF/Scm/Svn.php index 4f8df59..c15caaa 100644 --- a/src/IDF/Scm/Svn.php +++ b/src/IDF/Scm/Svn.php @@ -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. diff --git a/src/IDF/templates/idf/source/mercurial/changelog.html b/src/IDF/templates/idf/source/mercurial/changelog.html index c7893fe..c3c5772 100644 --- a/src/IDF/templates/idf/source/mercurial/changelog.html +++ b/src/IDF/templates/idf/source/mercurial/changelog.html @@ -6,5 +6,13 @@ {$branch}
{/foreach}

+{if $tags} +

{trans 'Tags:'}
+{foreach $tags as $tag => $path} +{aurl 'url', 'IDF_Views_Source::changeLog', array($project.shortname, $tag)} +{$tag}
+{/foreach} +

+{/if} {/block} diff --git a/src/IDF/templates/idf/source/mercurial/file.html b/src/IDF/templates/idf/source/mercurial/file.html index a0b969b..50c9bba 100644 --- a/src/IDF/templates/idf/source/mercurial/file.html +++ b/src/IDF/templates/idf/source/mercurial/file.html @@ -29,6 +29,14 @@ {$branch}
{/foreach}

+{if $tags} +

{trans 'Tags:'}
+{foreach $tags as $tag => $path} +{aurl 'url', 'IDF_Views_Source::tree', array($project.shortname, 'HEAD', $path)} +{$tag}
+{/foreach} +

+{/if} {/block} {block javascript} diff --git a/src/IDF/templates/idf/source/mercurial/tree.html b/src/IDF/templates/idf/source/mercurial/tree.html index d097bc9..98a3990 100644 --- a/src/IDF/templates/idf/source/mercurial/tree.html +++ b/src/IDF/templates/idf/source/mercurial/tree.html @@ -11,7 +11,7 @@ {trans 'Message'} {trans 'Size'} -{if !$tree_in} +{if !$tree_in and !$tags_in} {aurl 'url', 'IDF_Views_Source::commit', array($project.shortname, $commit)} {blocktrans}Source at commit {$commit} created {$cobject.date|dateago}.{/blocktrans}
@@ -53,5 +53,11 @@ {$branch}
{/foreach}

+{if $tags}

{trans 'Tags:'}
+{foreach $tags as $tag => $path} +{aurl 'url', 'IDF_Views_Source::treeBase', array($project.shortname, $tag)} +{$tag}
+{/foreach} +

{/if} {/block} diff --git a/src/IDF/templates/idf/source/svn/file.html b/src/IDF/templates/idf/source/svn/file.html index 944fe60..427bfd4 100644 --- a/src/IDF/templates/idf/source/svn/file.html +++ b/src/IDF/templates/idf/source/svn/file.html @@ -40,7 +40,6 @@

- {/block} {block javascript} diff --git a/src/IDF/templates/idf/source/svn/tree.html b/src/IDF/templates/idf/source/svn/tree.html index 54c1fb1..93c9b89 100644 --- a/src/IDF/templates/idf/source/svn/tree.html +++ b/src/IDF/templates/idf/source/svn/tree.html @@ -12,7 +12,7 @@ {trans 'Message'} {trans 'Size'} - {if !$tree_in || $props} + {if (!$tree_in and !$tags_in and $commit != 'HEAD') || $props} {aurl 'url', 'IDF_Views_Source::commit', array($project.shortname, $commit)} {if $props} @@ -75,5 +75,13 @@ {$branch}
{/foreach}

+{if $tags} +

{trans 'Tags:'}
+{foreach $tags as $tag => $path} +{aurl 'url', 'IDF_Views_Source::tree', array($project.shortname, 'HEAD', $path)} +{$tag}
+{/foreach} +

+{/if} {/block}