From ca2ef814fbe5c055e5cc0fce2e6d46aa9373f645 Mon Sep 17 00:00:00 2001 From: Thomas Keller Date: Tue, 31 May 2011 13:11:55 +0200 Subject: [PATCH] Add support for the display of monotone node attributes. (also fix the way the attributes view is displayed, i.e. do not use single strings, but one string in context which is much easier to translate) --- NEWS.mdtext | 6 +++-- src/IDF/Scm/Monotone.php | 27 ++++++++++++++++++++-- src/IDF/templates/idf/source/mtn/file.html | 21 +++++++++++++---- src/IDF/templates/idf/source/mtn/tree.html | 23 ++++++++++++++---- src/IDF/templates/idf/source/svn/file.html | 4 ++-- src/IDF/templates/idf/source/svn/tree.html | 6 ++--- test/IDF/Scm/MonotoneTest.php | 25 ++++++++++++++++++++ 7 files changed, 94 insertions(+), 18 deletions(-) diff --git a/NEWS.mdtext b/NEWS.mdtext index 8820900..9251896 100644 --- a/NEWS.mdtext +++ b/NEWS.mdtext @@ -4,12 +4,14 @@ - Mercurial source views now show parent revisions (if any) and detailed change information - File download URLs now contain the file name rather than the upload id; old links still work though (issue 686) +- Display monotone file and directory attributes in the tree and file view + (needs a monotone with an interface version of 13.1 or newer) -## Bugfixes +## Bugfixes - monotone zip archive entries now all carry the revision date as mtime (issue 645) - Timeline only displays filter options for items a user has actually access to (issue 655) -- The log, tags and branches parsers for Mercurial are more robust now (issue 663) +- The log, tags and branches parsers for Mercurial are more robust now (issue 663) - Fix SSH public key parsing issues and improve the check for existing, uploaded keys (issue 679) - Let the SVN command line client not store the login credentials we give him as arguments diff --git a/src/IDF/Scm/Monotone.php b/src/IDF/Scm/Monotone.php index d75fa6d..d04c53b 100644 --- a/src/IDF/Scm/Monotone.php +++ b/src/IDF/Scm/Monotone.php @@ -31,10 +31,10 @@ class IDF_Scm_Monotone extends IDF_Scm /** the minimum supported interface version */ public static $MIN_INTERFACE_VERSION = 13.0; - private $stdio; - private static $instances = array(); + private $stdio; + /** * Constructor */ @@ -698,6 +698,29 @@ class IDF_Scm_Monotone extends IDF_Scm return (object) $res; } + /** + * @see IDF_Scm::getProperties() + */ + public function getProperties($rev, $path='') + { + $out = $this->stdio->exec(array('interface_version')); + // support for querying file attributes of committed revisions + // was added for mtn 1.1 (interface version 13.1) + if (floatval($out) < 13.1) + return array(); + + $out = $this->stdio->exec(array('get_attributes', $path), array('r' => $rev)); + $stanzas = IDF_Scm_Monotone_BasicIO::parse($out); + $res = array(); + + foreach ($stanzas as $stanza) { + $line = $stanza[0]; + $res[$line['values'][0]] = $line['values'][1]; + } + + return $res; + } + /** * @see IDF_Scm::getExtraProperties */ diff --git a/src/IDF/templates/idf/source/mtn/file.html b/src/IDF/templates/idf/source/mtn/file.html index 2901c60..0c1bd19 100644 --- a/src/IDF/templates/idf/source/mtn/file.html +++ b/src/IDF/templates/idf/source/mtn/file.html @@ -5,12 +5,25 @@

{trans 'Root'}/{if $breadcrumb}{$breadcrumb|safe}{/if}

-{if !$tree_in and !$tags_in} +{if (!$tree_in and !$tags_in) or $props} {aurl 'url', 'IDF_Views_Source::commit', array($project.shortname, $commit)} - + {if $props} + + {/if} + {if !$tree_in and !$tags_in} + + + + {/if} {/if} diff --git a/src/IDF/templates/idf/source/mtn/tree.html b/src/IDF/templates/idf/source/mtn/tree.html index 5ca9db5..2a77ad3 100644 --- a/src/IDF/templates/idf/source/mtn/tree.html +++ b/src/IDF/templates/idf/source/mtn/tree.html @@ -11,14 +11,27 @@ -{if !$tree_in and !$tags_in} + +{if (!$tree_in and !$tags_in) or $props} {aurl 'url', 'IDF_Views_Source::commit', array($project.shortname, $commit)} - + {if $props} + + {/if} + {if !$tree_in and !$tags_in} + + {/if} +{/if} -{/if} + {if $base} diff --git a/src/IDF/templates/idf/source/svn/file.html b/src/IDF/templates/idf/source/svn/file.html index 5ed8114..27e6aca 100644 --- a/src/IDF/templates/idf/source/svn/file.html +++ b/src/IDF/templates/idf/source/svn/file.html @@ -6,13 +6,13 @@
{blocktrans}Source at commit {$commit} created {$cobject.date|dateago}.{/blocktrans}
-{blocktrans}By {$cobject.author|strip_tags|trim}, {$cobject.title}{/blocktrans} -
+
    + {foreach $props as $prop => $val} +
  • {blocktrans}Property {$prop} set to {$val}{/blocktrans}
  • + {/foreach} +
+
{blocktrans}Source at commit {$commit} created {$cobject.date|dateago}.{/blocktrans}
+ {blocktrans}By {$cobject.author|strip_tags|trim}, {$cobject.title}{/blocktrans} +
{trans 'Message'} {trans 'Size'}
{blocktrans}Source at commit {$commit} created {$cobject.date|dateago}.{/blocktrans}
-{blocktrans}By {$cobject.author|strip_tags|trim}, {$cobject.title}{/blocktrans} -
+
    + {foreach $props as $prop => $val} +
  • {blocktrans}Property {$prop} set to {$val}{/blocktrans}
  • + {/foreach} +
+
{blocktrans}Source at commit {$commit} created {$cobject.date|dateago}.{/blocktrans}
+ {blocktrans}By {$cobject.author|strip_tags|trim}, {$cobject.title}{/blocktrans} +
 
{if !$tree_in || $props} - {aurl 'url', 'IDF_Views_Source::commit', array($project.shortname, $commit)} + {aurl 'url', 'IDF_Views_Source::commit', array($project.shortname, $commit)} {if $props} diff --git a/src/IDF/templates/idf/source/svn/tree.html b/src/IDF/templates/idf/source/svn/tree.html index dbb1713..c6ecad2 100644 --- a/src/IDF/templates/idf/source/svn/tree.html +++ b/src/IDF/templates/idf/source/svn/tree.html @@ -13,13 +13,13 @@ {if (!$tree_in and !$tags_in and $commit != 'HEAD') || $props} - {aurl 'url', 'IDF_Views_Source::commit', array($project.shortname, $commit)} + {aurl 'url', 'IDF_Views_Source::commit', array($project.shortname, $commit)} {if $props} @@ -45,7 +45,7 @@ - + {$file.author|strip_tags|trim}{trans ':'} {issuetext $file.log, $request, true, false} {if $file.type == 'blob'} diff --git a/test/IDF/Scm/MonotoneTest.php b/test/IDF/Scm/MonotoneTest.php index a278fba..c50c1b0 100644 --- a/test/IDF/Scm/MonotoneTest.php +++ b/test/IDF/Scm/MonotoneTest.php @@ -714,6 +714,31 @@ END; $this->assertEquals('', $commit->diff); } + public function testGetProperties() + { + $rev = "2345678901234567890123456789012345678901"; + + $instance = $this->createMock(); + $instance->getStdio()->setExpectedOutput(array('interface_version'), array(), '13.1'); + + $stdio =<<- +nesses" +END; + $instance->getStdio()->setExpectedOutput(array('get_attributes', 'foo'), array('r' => $rev), $stdio); + $res = $instance->getProperties($rev, 'foo'); + + $this->assertEquals(2, count($res)); + $this->assertEquals(array( + 'foo' => 'bar', + "some new\nline" => "and more -\nnesses" + ), $res); + } + public function testGetExtraProperties() { $instance = $this->createMock();
    {foreach $props as $prop => $val} -
  • {trans 'Property'} {$prop} {trans 'set to:'} {$val}
  • +
  • {blocktrans}Property {$prop} set to {$val}{/blocktrans}
  • {/foreach}
{trans 'Size'}
    {foreach $props as $prop => $val} -
  • {trans 'Property'} {$prop} {trans 'set to:'} {$val}
  • +
  • {blocktrans}Property {$prop} set to {$val}{/blocktrans}
  • {/foreach}
{$file.type} {$file.file}{$file.date|dateago:"without"}{$file.date|dateago:"without"} {$file.rev}