Indefero

Indefero Commit Details


Date:2011-03-24 17:54:52 (13 years 8 months ago)
Author:Thomas Keller
Branch:develop, feature-issue_links, feature.better-home, feature.content-md5, feature.diff-whitespace, feature.download-md5, feature.issue-links, feature.issue-of-others, feature.issue-summary, feature.search-filter, feature.webrepos, feature.wiki-default-page, release-1.2, release-1.3
Commit:30900f71965875be18c08cbba0cf548b26b34c53
Parents: b753cf083752368093ad184de3276a625f584aed
Message:monotone zip archive entries now all carry the revision date as mtime (issue 645); add a test case for the zip render response that works with and without PHP's zip extension

Changes:

File differences

NEWS.mdtext
44
55
66
7
8
79
810
911
## Bugfixes
- monotone zip archive entries now all carry the revision date as mtime (issue 645)
## Documentation
## Translations
src/IDF/Scm/Monotone/ZipRender.php
6060
6161
6262
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
6383
6484
6585
......
6989
7090
7191
72
92
93
94
95
96
7397
7498
7599
$this->outputHeaders();
if ($output_body) {
$certs = $this->stdio->exec(array('certs', $this->revision));
$stanzas = IDF_Scm_Monotone_BasicIO::parse($certs);
// use the revision's date (if there is one) as timestamp
// for all file entries
$timestamp = time();
foreach ($stanzas as $stanza) {
$next_is_date = false;
foreach ($stanza as $line) {
if ($line['key'] == 'name' && $line['values'][0] == 'date') {
$next_is_date = true;
continue;
}
if ($next_is_date && $line['key'] == 'value') {
$timestamp = strtotime($line['values'][0]);
break;
}
}
}
$manifest = $this->stdio->exec(array('get_manifest_of', $this->revision));
$stanzas = IDF_Scm_Monotone_BasicIO::parse($manifest);
if ($stanza[0]['key'] != 'file')
continue;
$content = $this->stdio->exec(array('get_file', $stanza[1]['hash']));
$zip->add_file($stanza[0]['values'][0], $content);
$zip->add_file(
$stanza[0]['values'][0],
$content,
array('time' => $timestamp)
);
}
$zip->finish();
test/IDF/Scm/Monotone/ZipRenderTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
require_once 'IDF/Scm/Monotone/ZipRender.php';
require_once 'IDF/Scm/Monotone/IStdio.php';
class ZipRenderStdioMock implements IDF_Scm_Monotone_IStdio
{
// unused
public function __construct(IDF_Project $project) {}
// unused
public function start() {}
// unused
public function stop() {}
public function exec(array $args, array $options = array())
{
if ($args[0] == 'certs') {
$basicio =<<<END
key [0504aea5d3716d31281171aaecf3a7c227e5545b]
signature "ok"
name "author"
value "joe@home"
trust "trusted"
key [0504aea5d3716d31281171aaecf3a7c227e5545b]
signature "ok"
name "branch"
value "foo"
trust "trusted"
key [0504aea5d3716d31281171aaecf3a7c227e5545b]
signature "ok"
name "changelog"
value "test"
trust "trusted"
key [0504aea5d3716d31281171aaecf3a7c227e5545b]
signature "ok"
name "date"
value "2009-07-06T22:06:27"
trust "trusted"
END;
return $basicio;
}
if ($args[0] == 'get_manifest_of') {
$basicio =<<<END
format_version "1"
dir ""
file "foo"
content [6fcf9dfbd479ed82697fee719b9f8c610a11ff2a]
dir "bar"
file "bar/baz"
content [9063a9f0e032b6239403b719cbbba56ac4e4e45f]
END;
return $basicio;
}
if ($args[0] == 'get_file') {
if ($args[1] == '6fcf9dfbd479ed82697fee719b9f8c610a11ff2a') {
return 'This is foo.';
}
if ($args[1] == '9063a9f0e032b6239403b719cbbba56ac4e4e45f') {
return 'This is baz.';
}
throw new Exception('unexpected id ' . $args[1]);
}
throw new Exception('unexpected command ' . $args[0]);
}
// unused
public function getLastOutOfBandOutput() {}
}
class IDF_Scm_Monotone_ZipRenderTest extends PHPUnit_Framework_TestCase
{
// we can not test header sending with PHP-CLI, as header() is ignored
// in this environment
public function testRender()
{
$mock = new ZipRenderStdioMock(new IDF_Project());
$renderer = new IDF_Scm_Monotone_ZipRender($mock, '97fee719b9f8c610a11ff2a9063a9f0e032b6');
ob_start();
$renderer->render(true);
$zipcontents = ob_get_contents();
ob_end_clean();
// for this version php needs to be compiled with --enable-zip
if (function_exists('zip_open')) {
// yes, I'd rather have used php://memory here, but ZipArchive::open()
// complained that it could not open the stream in question
$filename = tempnam(Pluf::f('tmp_folder', '/tmp'), __CLASS__.'.');
file_put_contents($filename, $zipcontents);
$za = new ZipArchive();
$za->open($filename);
$this->assertEquals(2, $za->numFiles);
// 2009-07-06T22:06:27 - one second
// (don't ask me why, seems to be some quirk in zipstream)
$mtime = 1246910787 - 1;
// foo
$data = $za->statIndex(0);
$this->assertEquals('foo', $data['name']);
$this->assertEquals(12, $data['size']);
$this->assertEquals($mtime, $data['mtime']);
// bar/baz
$data = $za->statIndex(1);
$this->assertEquals('bar/baz', $data['name']);
$this->assertEquals(12, $data['size']);
$this->assertEquals($mtime, $data['mtime']);
$za->close();
unlink($filename);
}
else {
$wrapped_act = wordwrap(
base64_encode($zipcontents),
32, "\n", true
);
$wrapped_exp = wordwrap(
base64_encode(file_get_contents(DATADIR . '/' . __CLASS__ . '/data.zip')),
32, "\n", true
);
$this->assertEquals($wrapped_exp, $wrapped_act);
}
}
}

Archive Download the corresponding diff file

Page rendered in 0.09716s using 14 queries.