Indefero

Indefero Commit Details

Date:2008-11-23 17:45:00 (5 years 10 months ago)
Author:Benjamin Jorand
Branch:dev, 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, master, release-1.1, release-1.2, release-1.3
Commit:08145b7b1cabbbe2da93b98c4b698a5b131f6338
Parents: ee8d56075d9dbf00d5ccab135136b894ced2e40b
Message:Added the support of Mercurial.

Changes:
Asrc/IDF/Scm/Mercurial.php (full)
Asrc/IDF/templates/idf/source/mercurial/file.html (full)
Asrc/IDF/templates/idf/source/mercurial/tree.html (full)
Msrc/IDF/Form/SourceConf.php (1 diff)
Msrc/IDF/Project.php (2 diffs)
Msrc/IDF/conf/idf.php-dist (1 diff)
Msrc/IDF/templates/idf/source/changelog.html (2 diffs)

File differences

src/IDF/Form/SourceConf.php
3939
4040
4141
42
4243
4344
4445
array(
__('git') => 'git',
__('Subversion') => 'svn',
__('mercurial') => 'mercurial',
)
),
'widget' => 'Pluf_Form_Widget_SelectInput',
src/IDF/Project.php
353353
354354
355355
356
356
357
358
359
360
357361
358362
359363
......
388392
389393
390394
391
395
public function getScmRoot()
{
$conf = $this->getConf();
$roots = array('git' => 'master', 'svn' => 'HEAD');
$roots = array(
'git' => 'master',
'svn' => 'HEAD',
'mercurial' => 'tip'
);
$scm = $conf->getVal('scm', 'git');
return $roots[$scm];
}
return $this->_pconf;
}
}
}
src/IDF/Scm/Mercurial.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of InDefero, an open source project management application.
# Copyright (C) 2008 CĂ©ondo Ltd and contributors.
#
# InDefero is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# InDefero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
/**
* Mercurial utils.
*
*/
class IDF_Scm_Mercurial
{
public $repo = '';
public function __construct($repo)
{
$this->repo = $repo;
}
/**
* Returns the URL of the git daemon.
*
* @param IDF_Project
* @return string URL
*/
public static function getRemoteAccessUrl($project)
{
$url = Pluf::f('mercurial_remote_url');
if (Pluf::f('mercurial_repositories_unique', true)) {
return $url;
}
return $url.'/'.$project->shortname;
}
/**
* Returns this object correctly initialized for the project.
*
* @param IDF_Project
* @return IDF_Scm_Git
*/
public static function factory($project)
{
$rep = Pluf::f('mercurial_repositories');
if (false == Pluf::f('mercurial_repositories_unique', false)) {
$rep = $rep.'/'.$project->shortname;
}
return new IDF_Scm_Mercurial($rep);
}
/**
* Test a given object hash.
*
* @param string Object hash.
* @param null to be svn client compatible
* @return mixed false if not valid or 'blob', 'tree', 'commit'
*/
public function testHash($hash, $dummy=null)
{
$cmd = sprintf('hg log -R %s -r %s',
escapeshellarg($this->repo),
escapeshellarg($hash));
$ret = 0;
$out = array();
IDF_Scm::exec($cmd, &$out, &$ret);
return ($ret != 0) ? false : 'commit';
}
/**
* Given a commit hash returns an array of files in it.
*
* A file is a class with the following properties:
*
* 'perm', 'type', 'size', 'hash', 'file'
*
* @param string Commit ('HEAD')
* @param string Base folder ('')
* @return array
*/
public function filesAtCommit($commit='tip', $folder='')
{
// now we grab the info about this commit including its tree.
$co = $this->getCommit($commit);
if ($folder) {
// As we are limiting to a given folder, we need to find
// the tree corresponding to this folder.
$found = false;
foreach ($this->getTreeInfo($co->tree, true, '', true) as $file) {
if ($file->type == 'tree' and $file->file == $folder) {
$found = true;
break;
}
}
if (!$found) {
throw new Exception(sprintf(__('Folder %1$s not found in commit %2$s.'), $folder, $commit));
}
}
$res = $this->getTreeInfo($commit, $recurse=true, $folder);
return $res;
}
/**
* Get the tree info.
*
* @param string Tree hash
* @param bool Do we recurse in subtrees (true)
* @return array Array of file information.
*/
public function getTreeInfo($tree, $recurse=true, $folder='', $root=false)
{
if ('commit' != $this->testHash($tree)) {
throw new Exception(sprintf(__('Not a valid tree: %s.'), $tree));
}
$cmd_tmpl = 'hg manifest -R %s --debug -r %s';
$cmd = sprintf($cmd_tmpl, escapeshellarg($this->repo), $tree, ($recurse) ? '' : '');
$out = array();
$res = array();
IDF_Scm::exec($cmd, &$out);
$out_hack = array();
foreach ($out as $line) {
list($hash, $perm, $exec, $file) = preg_split('/ |\t/', $line, 4);
$file = trim($file);
$dir = explode('/', $file, -1);
preg_match_all('|(\w+)/|', $file, $dir);
$tmp = '';
for ($i=0; $i < count($dir[1]); $i++) {
if ($i > 0) {
$tmp .= '/';
}
$tmp .= $dir[1][$i];
if (!in_array("empty\t000\t\t$tmp/", $out_hack))
$out_hack[] = "empty\t000\t\t$tmp/";
}
$out_hack[] = "$hash\t$perm\t$exec\t$file";
}
foreach ($out_hack as $line) {
list($hash, $perm, $exec, $file) = preg_split('/ |\t/', $line, 4);
$file = trim($file);
if (preg_match('/^(.*)\/$/', $file, $match)) {
$type = 'tree';
$file = $match[1];
} else {
$type = 'blob';
}
if (!$root and !$folder and preg_match('/^.*\/.*$/', $file)) {
continue;
}
if ($folder) {
preg_match('|^'.$folder.'[/]?([^/]+)?$|', $file,$match);
if (count($match) > 1) {
$file = $match[1];
} else {
continue;
}
}
$res[] = (object) array('perm' => $perm, 'type' => $type,
'hash' => $hash, 'fullpath' => ($folder) ? $folder.'/'.$file : $file,
'file' => $file);
}
return $res;
}
/**
* Get the file info.
*
* @param string Commit ('HEAD')
* @return false Information
*/
public function getFileInfo($totest, $commit='tip')
{
$cmd_tmpl = 'hg manifest -R %s --debug -r %s | sed \'s/*/ /\' | sort -k 3| uniq -f2';
$cmd = sprintf($cmd_tmpl, escapeshellarg($this->repo), $commit);
$out = array();
$res = array();
IDF_Scm::exec($cmd, &$out);
$out_hack = array();
foreach ($out as $line) {
list($hash, $perm, $exec, $file) = preg_split('/ |\t/', $line, 4);
$file = trim($file);
$dir = explode('/', $file, -1);
preg_match_all('|(\w+)/|', $file, $dir);
$tmp = '';
for ($i=0; $i < count($dir[1]); $i++) {
if ($i > 0) {
$tmp .= '/';
}
$tmp .= $dir[1][$i];
if (!in_array("empty\t000\t\t$tmp/", $out_hack)) {
$out_hack[] = "emtpy\t000\t\t$tmp/";
}
}
$out_hack[] = "$hash\t$perm\t$exec\t$file";
}
foreach ($out_hack as $line) {
list($hash, $perm, $exec, $file) = preg_split('/ |\t/', $line, 4);
$file = trim ($file);
if (preg_match('/^(.*)\/$/', $file, $match)) {
$type = 'tree';
$file = $match[1];
} else {
$type = 'blob';
}
if ($totest == $file) {
return (object) array('perm' => $perm, 'type' => $type,
'hash' => $hash,
'file' => $file,
'commit' => $commit
);
}
}
return false;
}
/**
* Get a blob.
*
* @param string request_file_info
* @param null to be svn client compatible
* @return string Raw blob
*/
public function getBlob($request_file_info, $dummy=null)
{
return IDF_Scm::shell_exec(sprintf('hg cat -R %s -r %s %s',
escapeshellarg($this->repo),
$dummy,
escapeshellarg($this->repo . '/' . $request_file_info->file)));
}
/**
* Get the branches.
*
* @return array Branches.
*/
public function getBranches()
{
$out = array();
IDF_Scm::exec(sprintf('hg branches -R %s',
escapeshellarg($this->repo)), &$out);
$res = array();
foreach ($out as $b) {
preg_match('/(\S+).*\S+:(\S+)/', $b, $match);
$res[] = $match[1];
}
return $res;
}
/**
* Get commit details.
*
* @param string Commit ('HEAD').
* @return array Changes.
*/
public function getCommit($commit='tip')
{
$cmd = sprintf('hg log -p -r %s -R %s', escapeshellarg($commit), escapeshellarg($this->repo));
$out = array();
IDF_Scm::exec($cmd, &$out);
$log = array();
$change = array();
$inchange = false;
foreach ($out as $line) {
if (!$inchange and 0 === strpos($line, 'diff -r')) {
$inchange = true;
}
if ($inchange) {
$change[] = $line;
} else {
$log[] = $line;
}
}
$out = self::parseLog($log, 6);
$out[0]->changes = implode("\n", $change);
return $out[0];
}
/**
* Get latest changes.
*
* @param string Commit ('HEAD').
* @param int Number of changes (10).
* @return array Changes.
*/
public function getChangeLog($commit='tip', $n=10)
{
$cmd = sprintf('hg log -R %s -l%s ', escapeshellarg($this->repo), $n, $commit);
$out = array();
IDF_Scm::exec($cmd, &$out);
return self::parseLog($out, 6);
}
/**
* Parse the log lines of a --pretty=medium log output.
*
* @param array Lines.
* @param int Number of lines in the headers (3)
* @return array Change log.
*/
public static function parseLog($lines, $hdrs=3)
{
$res = array();
$c = array();
$i = 0;
$hdrs += 1;
foreach ($lines as $line) {
$i++;
if (0 === strpos($line, 'changeset:')) {
if (count($c) > 0) {
$c['full_message'] = trim($c['full_message']);
$res[] = (object) $c;
}
$c = array();
$c['commit'] = substr(strrchr($line, ':'), 1);
$c['full_message'] = '';
$i=1;
continue;
}
if ($i == $hdrs) {
$c['title'] = trim($line);
continue;
}
$match = array();
if (preg_match('/(\S+)\s*:\s*(.*)/', $line, $match)) {
$match[1] = strtolower($match[1]);
if ($match[1] == 'user') {
$c['author'] = $match[2];
} elseif ($match[1] == 'summary') {
$c['title'] = $match[2];
} else {
$c[$match[1]] = trim($match[2]);
}
if ($match[1] == 'date') {
$c['date'] = gmdate('Y-m-d H:i:s', strtotime($match[2]));
}
continue;
}
if ($i > ($hdrs+1)) {
$c['full_message'] .= trim($line)."\n";
continue;
}
}
$c['tree'] = $c['commit'];
$c['full_message'] = trim($c['full_message']);
$res[] = (object) $c;
return $res;
}
/**
* Generate the command to create a zip archive at a given commit.
*
* @param string Commit
* @param string Prefix ('git-repo-dump')
* @return string Command
*/
public function getArchiveCommand($commit, $prefix='')
{
return sprintf('hg archive --type=zip -R %s -r %s -',
escapeshellarg($this->repo),
escapeshellarg($commit));
}
}
src/IDF/conf/idf.php-dist
5353
5454
5555
56
57
58
59
60
5661
5762
5863
$cfg['svn_repositories_unique'] = true;
$cfg['svn_remote_url'] = 'http://projects.ceondo.com/svn/indefero';
// Mercurial repositories path
//$cfg['mercurial_repositories'] = '/home/mercurial/repositories';
//$cfg['mercurial_repositories_unique'] = false;
//$cfg['mercurial_remote_url'] = 'http://projects.ceondo.com/hg';
// Example of one *local* subversion repository for each project:
// the path to the repository on disk will automatically created to be
src/IDF/templates/idf/source/changelog.html
2828
2929
3030
31
31
3232
3333
3434
3535
3636
3737
38
39
38
4039
4140
4241
......
4443
4544
4645
47
4846
4947
5048
</table>
{/block}
{block context}
{if $scm == 'git'}
{if $scm != 'svn'}
<p><strong>{trans 'Branches:'}</strong><br />
{foreach $branches as $branch}
{aurl 'url', 'IDF_Views_Source::changeLog', array($project.shortname, $branch)}
<span class="label{if $commit == $branch} active{/if}"><a href="{$url}" class="label">{$branch}</a></span><br />
{/foreach}
</p>
{/if}
{if $scm == 'svn'}
{else}
<form class="star" action="{url 'IDF_Views_Source_Svn::changelogRev', array($project.shortname)}" method="get">
<p><strong>{trans 'Revision:'}</strong> {$commit}</p>
<p>
<input type="submit" name="s" value="{trans 'Go to revision'}" />
</p>
</form>
{/if}
{/block}
src/IDF/templates/idf/source/mercurial/file.html
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
{extends "idf/source/base.html"}
{block extraheader}<link rel="stylesheet" type="text/css" href="{media '/idf/css/prettify.css'}" />{/block}
{block docclass}yui-t1{assign $inSourceTree=true}{/block}
{block body}
<h2 class="top"><a href="{url 'IDF_Views_Source::treeBase', array($project.shortname, $commit)}">{trans 'Root'}</a><span class="sep">/</span>{if $breadcrumb}{$breadcrumb|safe}{/if}</h2>
<table class="code" summary=" ">
{if !$tree_in}
{aurl 'url', 'IDF_Views_Source::commit', array($project.shortname, $commit)}
<tfoot>
<tr><th colspan="2">{blocktrans}Source at commit <a class="mono" href="{$url}">{$commit}</a> created {$cobject.date|dateago}.{/blocktrans}<br />
<span class="smaller">{blocktrans}By {$cobject.author|strip_tags|trim}, {$cobject.title}{/blocktrans}</span>
</th></tr>
</tfoot>
{/if}
<tbody>
{$file}
</tbody>
</table>
{aurl 'url', 'IDF_Views_Source::getFile', array($project.shortname, $commit, $fullpath)}
<p class="right soft"><a href="{$url}"><img style="vertical-align: text-bottom;" src="{media '/idf/img/package-grey.png'}" alt="{trans 'Archive'}" align="bottom" /></a> <a href="{$url}">{trans 'Download this file'}</a></p>
{/block}
{block context}
<p><strong>{trans 'Branches:'}</strong><br />
{foreach $branches as $branch}
{aurl 'url', 'IDF_Views_Source::treeBase', array($project.shortname, $branch)}
<span class="label{if $commit == $branch} active{/if}"><a href="{$url}" class="label">{$branch}</a></span><br />
{/foreach}
</p>
{/block}
{block javascript}
<script type="text/javascript" src="{media '/idf/js/prettify.js'}"></script>
<script type="text/javascript">prettyPrint();</script>
{/block}
src/IDF/templates/idf/source/mercurial/tree.html
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
{extends "idf/source/base.html"}
{block docclass}yui-t1{assign $inSourceTree=true}{/block}
{block body}
<h2><a href="{url 'IDF_Views_Source::treeBase', array($project.shortname, $commit)}">{trans 'Root'}</a><span class="sep">/</span>{if $breadcrumb}{$breadcrumb|safe}{/if}</h2>
<table summary="" class="tree-list">
<thead>
<tr>
<th colspan="2">{trans 'File'}</th>
<th>{trans 'Age'}</th>
<th>{trans 'Message'}</th>
<th>{trans 'Size'}</th>
</tr>
</thead>{if !$tree_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 />
<span class="smaller">{blocktrans}By {$cobject.author|strip_tags|trim}, {$cobject.title}{/blocktrans}</span>
</th></tr>
</tfoot>
{/if}<tbody>
{if $base}
<tr>
<td>&nbsp;</td>
<td>
<a href="{url 'IDF_Views_Source::tree', array($project.shortname, $commit, $prev)}">..</a></td>
<td colspan="3"></td>
</tr>
{/if}
{foreach $files as $file}
{aurl 'url', 'IDF_Views_Source::tree', array($project.shortname, $commit, $file.fullpath)}
<tr>
<td class="fileicon"><img src="{media '/idf/img/'~$file.type~'.png'}" alt="{$file.type}" /></td>
<td{if $file.type != 'blob'} colspan="4"{/if}><a href="{$url}">{$file.file}</a></td>
{if $file.type == 'blob'}
{if isset($file.date)}
<td><span class="smaller">{$file.date|dateago:"wihtout"}</span></td>
<td><span class="smaller">{$file.author|strip_tags|trim}{trans ':'} {$file.log}</span></td>
{else}<td colspan="2"></td>{/if}
<td></td>{/if}
</tr>
{/foreach}
</tbody>
</table>
{aurl 'url', 'IDF_Views_Source::download', array($project.shortname, $commit)}
<p class="right soft"><a href="{$url}"><img style="vertical-align: text-bottom;" src="{media '/idf/img/package-grey.png'}" alt="{trans 'Archive'}" align="bottom" /></a> <a href="{$url}">{trans 'Download this version'}</a> {trans 'or'} <kbd>hg clone {$project.getRemoteAccessUrl()}</kbd></p>
{/block}
{block context}
<p><strong>{trans 'Branches:'}</strong><br />
{foreach $branches as $branch}
{aurl 'url', 'IDF_Views_Source::treeBase', array($project.shortname, $branch)}
<span class="label{if $commit == $branch} active{/if}"><a href="{$url}" class="label">{$branch}</a></span><br />
{/foreach}
</p>
{/block}

Archive Download the corresponding diff file