Indefero

Indefero Commit Details


Date:2011-08-12 19:28:15 (13 years 4 months ago)
Author:Thomas Keller
Branch:develop, feature.diff-whitespace, feature.issue-of-others, feature.search-filter, feature.webrepos, feature.wiki-default-page, release-1.2, release-1.3
Commit:b17de014ec5c0c6431667aa428903e633562d598
Parents: b1b72190e1cdf256d58eeafd3858e5d9a1ff3ff0
Message:Reworked the option / argument handling in the SVN interface to have less code duplication.

Changes:

File differences

src/IDF/Scm/Svn.php
3333
3434
3535
36
3736
3837
3938
......
4847
4948
5049
51
52
53
54
55
50
5651
5752
5853
......
163158
164159
165160
166
167
168
169
170
171
172
161
173162
174163
175164
......
191180
192181
193182
194
195
196
197
198
199
200
183
184
185
201186
202187
203188
......
219204
220205
221206
222
223
224
225
226
227
228
207
208
209
229210
230211
231212
......
261242
262243
263244
264
265
266
267
268
269
270
245
271246
272247
273248
......
283258
284259
285260
286
287
288
289
290
291
292
261
262
293263
294264
295265
......
311281
312282
313283
314
315
316
317
318
319
320
284
285
286
321287
322288
323289
......
333299
334300
335301
336
337
338
339
340
302
341303
342304
343305
......
348310
349311
350312
351
352
353
354
355
313
314
356315
357316
358317
......
372331
373332
374333
375
376
377
378
379
334
380335
381336
382337
......
429384
430385
431386
432
433
434
435
436
437
438
387
388
439389
440390
441391
......
477427
478428
479429
480
481
482
483
484
485
430
486431
487432
488433
......
494439
495440
496441
497
498
499
500
501
442
502443
503
504444
505445
506446
......
577517
578518
579519
580
520
581521
582
522
583523
584
524
585525
586526
587
588
589
590
591
592
593
594
527
528
595529
596530
597531
......
617551
618552
619553
620
621
622
623
624
625
626
554
555
627556
628557
629558
......
652581
653582
654583
655
656
657
658
659
660
661
662
584
585
663586
664587
665588
......
676599
677600
678601
679
680
681
682
683
684
685
602
686603
687604
688605
689606
690607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
691635
692636
*/
class IDF_Scm_Svn extends IDF_Scm
{
public $username = '';
public $password = '';
private $assoc = array('dir' => 'tree',
public function isAvailable()
{
$cmd = sprintf(Pluf::f('svn_path', 'svn').' info --no-auth-cache --xml --username=%s --password=%s %s',
escapeshellarg($this->username),
escapeshellarg($this->password),
escapeshellarg($this->repo));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$cmd = $this->svnCmd(array('info', '--xml'), $this->repo);
$xmlInfo = self::shell_exec('IDF_Scm_Svn::isAvailable', $cmd);
try {
return IDF_Scm::REVISION_VALID;
}
$cmd = sprintf(Pluf::f('svn_path', 'svn').' info --no-auth-cache --username=%s --password=%s --revision=%s %s@%s',
escapeshellarg($this->username),
escapeshellarg($this->password),
escapeshellarg($rev),
escapeshellarg($this->repo),
escapeshellarg($rev));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$cmd = $this->svnCmd(array('info'), $this->repo, $rev);
self::exec('IDF_Scm_Svn::validateRevision', $cmd, $out, $ret);
if ($ret == 0)
}
// Else, test the path on revision
$cmd = sprintf(Pluf::f('svn_path', 'svn').' info --no-auth-cache --xml --username=%s --password=%s --revision=%s %s@%s',
escapeshellarg($this->username),
escapeshellarg($this->password),
escapeshellarg($rev),
escapeshellarg($this->repo.'/'.self::smartEncode($path)),
escapeshellarg($rev));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$cmd = $this->svnCmd(array('info', '--xml'),
$this->repo.'/'.self::smartEncode($path),
$rev);
$xmlInfo = self::shell_exec('IDF_Scm_Svn::testHash', $cmd);
// If exception is thrown, return false
public function getTree($commit, $folder='/', $branch=null)
{
$cmd = sprintf(Pluf::f('svn_path', 'svn').' ls --no-auth-cache --xml --username=%s --password=%s --revision=%s %s@%s',
escapeshellarg($this->username),
escapeshellarg($this->password),
escapeshellarg($commit),
escapeshellarg($this->repo.'/'.self::smartEncode($folder)),
escapeshellarg($commit));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$cmd = $this->svnCmd(array('ls', '--xml'),
$this->repo.'/'.self::smartEncode($folder),
$commit);
$xml = simplexml_load_string(self::shell_exec('IDF_Scm_Svn::getTree', $cmd));
$res = array();
$folder = (strlen($folder) and ($folder != '/')) ? $folder.'/' : '';
if (isset($this->cache['commitmess'][$rev])) {
return $this->cache['commitmess'][$rev];
}
$cmd = sprintf(Pluf::f('svn_path', 'svn').' log --no-auth-cache --xml --limit 1 --username=%s --password=%s --revision=%s %s@%s',
escapeshellarg($this->username),
escapeshellarg($this->password),
escapeshellarg($rev),
escapeshellarg($this->repo),
escapeshellarg($rev));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$cmd = $this->svnCmd(array('log', '--xml', '--limit', '1'), $this->repo, $rev);
try {
$xml = simplexml_load_string(self::shell_exec('IDF_Scm_Svn::getCommitMessage', $cmd));
$this->cache['commitmess'][$rev] = (string) $xml->logentry->msg;
if ($rev == null) {
$rev = 'HEAD';
}
$cmd = sprintf(Pluf::f('svn_path', 'svn').' info --no-auth-cache --xml --username=%s --password=%s --revision=%s %s@%s',
escapeshellarg($this->username),
escapeshellarg($this->password),
escapeshellarg($rev),
escapeshellarg($this->repo.'/'.self::smartEncode($filename)),
escapeshellarg($rev));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$cmd = $this->svnCmd(array('info', '--xml'),
$this->repo.'/'.self::smartEncode($filename), $rev);
$xml = simplexml_load_string(self::shell_exec('IDF_Scm_Svn::getPathInfo', $cmd));
if (!isset($xml->entry)) {
return false;
public function getFile($def, $cmd_only=false)
{
$cmd = sprintf(Pluf::f('svn_path', 'svn').' cat --no-auth-cache --username=%s --password=%s --revision=%s %s@%s',
escapeshellarg($this->username),
escapeshellarg($this->password),
escapeshellarg($def->rev),
escapeshellarg($this->repo.'/'.self::smartEncode($def->fullpath)),
escapeshellarg($def->rev));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$cmd = $this->svnCmd(array('cat'),
$this->repo.'/'.self::smartEncode($def->fullpath),
$def->rev);
return ($cmd_only) ?
$cmd : self::shell_exec('IDF_Scm_Svn::getFile', $cmd);
}
return $this->cache['branches'];
}
$res = array();
$cmd = sprintf(Pluf::f('svn_path', 'svn').' ls --no-auth-cache --username=%s --password=%s --revision=HEAD %s@HEAD',
escapeshellarg($this->username),
escapeshellarg($this->password),
escapeshellarg($this->repo.'/branches'));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$cmd = $this->svnCmd(array('ls'), $this->repo.'/branches', 'HEAD');
self::exec('IDF_Scm_Svn::getBranches', $cmd, $out, $ret);
if ($ret == 0) {
foreach ($out as $entry) {
}
}
ksort($res);
$cmd = sprintf(Pluf::f('svn_path', 'svn').' info --no-auth-cache --username=%s --password=%s --revision=HEAD %s@HEAD',
escapeshellarg($this->username),
escapeshellarg($this->password),
escapeshellarg($this->repo.'/trunk'));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$cmd = $this->svnCmd(array('info'), $this->repo.'/trunk', 'HEAD');
self::exec('IDF_Scm_Svn::getBranches', $cmd, $out, $ret);
if ($ret == 0) {
$res = array('trunk' => 'trunk') + $res;
return $this->cache['tags'];
}
$res = array();
$cmd = sprintf(Pluf::f('svn_path', 'svn').' ls --no-auth-cache --username=%s --password=%s --revision=HEAD %s@HEAD',
escapeshellarg($this->username),
escapeshellarg($this->password),
escapeshellarg($this->repo.'/tags'));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$cmd = $this->svnCmd(array('ls'), $this->repo.'/tags', 'HEAD');
self::exec('IDF_Scm_Svn::getTags', $cmd, $out, $ret);
if ($ret == 0) {
foreach ($out as $entry) {
return false;
}
$res = array();
$cmd = sprintf(Pluf::f('svn_path', 'svn').' log --no-auth-cache --xml --limit 1 -v --username=%s --password=%s --revision=%s %s@%s',
escapeshellarg($this->username),
escapeshellarg($this->password),
escapeshellarg($commit),
escapeshellarg($this->repo),
escapeshellarg($commit));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$cmd = $this->svnCmd(array('log', '--xml', '--limit', '1', '-v'),
$this->repo, $commit);
$xmlRes = self::shell_exec('IDF_Scm_Svn::getCommit', $cmd);
$xml = simplexml_load_string($xmlRes);
$res['author'] = (string) $xml->logentry->author;
private function getDiff($rev='HEAD')
{
$res = array();
$cmd = sprintf(Pluf::f('svn_path', 'svn').' diff --no-auth-cache -c %s --username=%s --password=%s %s',
escapeshellarg($rev),
escapeshellarg($this->username),
escapeshellarg($this->password),
escapeshellarg($this->repo));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$cmd = $this->svnCmd(array('diff', '-c', $rev), $this->repo);
return self::shell_exec('IDF_Scm_Svn::getDiff', $cmd);
}
if ($this->validateRevision($commit) != IDF_Scm::REVISION_VALID) {
return null;
}
$cmd = sprintf(Pluf::f('svn_path', 'svn').' log --xml -v --no-auth-cache -r %s --username=%s --password=%s %s',
escapeshellarg($commit),
escapeshellarg($this->username),
escapeshellarg($this->password),
escapeshellarg($this->repo));
$cmd = $this->svnCmd(array('log', '--xml', '-v'), $this->repo, $commit);
$out = array();
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$out = self::shell_exec('IDF_Scm_Svn::getChanges', $cmd);
$xml = simplexml_load_string($out);
if (count($xml) == 0) {
*
* @return array Changes.
*/
public function getChangeLog($branch=null, $n=10)
public function getChangeLog($rev=null, $n=10)
{
if ($branch != 'HEAD' and !preg_match('/^\d+$/', $branch)) {
if ($rev != 'HEAD' and !preg_match('/^\d+$/', $rev)) {
// we accept only revisions or HEAD
$branch = 'HEAD';
$rev = 'HEAD';
}
$res = array();
$cmd = sprintf(Pluf::f('svn_path', 'svn').' log --no-auth-cache --xml -v --limit %s --username=%s --password=%s --revision=%s %s@%s',
escapeshellarg($n),
escapeshellarg($this->username),
escapeshellarg($this->password),
escapeshellarg($branch),
escapeshellarg($this->repo),
escapeshellarg($branch));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$cmd = $this->svnCmd(array('log', '--xml', '-v', '--limit', $n),
$this->repo.'@'.$rev);
$xmlRes = self::shell_exec('IDF_Scm_Svn::getChangeLog', $cmd);
$xml = simplexml_load_string($xmlRes);
foreach ($xml->logentry as $entry) {
public function getProperties($rev, $path='')
{
$res = array();
$cmd = sprintf(Pluf::f('svn_path', 'svn').' proplist --no-auth-cache --xml --username=%s --password=%s --revision=%s %s@%s',
escapeshellarg($this->username),
escapeshellarg($this->password),
escapeshellarg($rev),
escapeshellarg($this->repo.'/'.self::smartEncode($path)),
escapeshellarg($rev));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$cmd = $this->svnCmd(array('proplist', '--xml'),
$this->repo.'/'.self::smartEncode($path), $rev);
$xmlProps = self::shell_exec('IDF_Scm_Svn::getProperties', $cmd);
$props = simplexml_load_string($xmlProps);
private function getProperty($property, $rev, $path='')
{
$res = array();
$cmd = sprintf(Pluf::f('svn_path', 'svn').' propget --no-auth-cache --xml %s --username=%s --password=%s --revision=%s %s@%s',
escapeshellarg($property),
escapeshellarg($this->username),
escapeshellarg($this->password),
escapeshellarg($rev),
escapeshellarg($this->repo.'/'.self::smartEncode($path)),
escapeshellarg($rev));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$cmd = $this->svnCmd(array('propget', $property, '--xml'),
$this->repo.'/'.self::smartEncode($path), $rev);
$xmlProp = self::shell_exec('IDF_Scm_Svn::getProperty', $cmd);
$prop = simplexml_load_string($xmlProp);
public function getLastCommit($rev='HEAD')
{
$xmlInfo = '';
$cmd = sprintf(Pluf::f('svn_path', 'svn').' info --no-auth-cache --xml --username=%s --password=%s --revision=%s %s@%s',
escapeshellarg($this->username),
escapeshellarg($this->password),
escapeshellarg($rev),
escapeshellarg($this->repo),
escapeshellarg($rev));
$cmd = Pluf::f('idf_exec_cmd_prefix', '').$cmd;
$cmd = $this->svnCmd(array('info', '--xml'), $this->repo, $rev);
$xmlInfo = self::shell_exec('IDF_Scm_Svn::getLastCommit', $cmd);
$xml = simplexml_load_string($xmlInfo);
return (string) $xml->entry->commit['revision'];
}
private function svnCmd($args = array(), $repoarg = null, $revarg = null)
{
$cmdline = array();
$cmdline[] = Pluf::f('idf_exec_cmd_prefix', '');
$cmdline[] = Pluf::f('svn_path', 'svn');
$cmdline[] = '--no-auth-cache';
$cmdline[] = '--username='.escapeshellarg($this->username);
$cmdline[] = '--password='.escapeshellarg($this->password);
foreach ($args as $arg) {
$cmdline[] = escapeshellarg($arg);
}
if ($repoarg != null) {
if ($revarg != null) {
$repoarg .= '@'.$revarg;
}
$cmdline[] = escapeshellarg($repoarg);
}
if ($revarg != null) {
$cmdline[] = '--revision='.escapeshellarg($revarg);
}
return implode(' ', $cmdline);
}
}

Archive Download the corresponding diff file

Page rendered in 0.09170s using 13 queries.