Skip to content

Commit

Permalink
modified path in log-view to show most precise subfolder containing a…
Browse files Browse the repository at this point in the history
…ll modifications (fixed #313)
  • Loading branch information
dirk-thomas committed Mar 5, 2011
1 parent 2a1799d commit d6d32c3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
52 changes: 52 additions & 0 deletions include/svnlook.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SVNMod {
var $copyfrom = '';
var $copyrev = '';
var $path = '';
var $isdir = false;
}

class SVNListEntry {
Expand Down Expand Up @@ -69,6 +70,7 @@ class SVNLogEntry {
var $age = '';
var $msg = '';
var $path = '';
var $precisePath = '';

var $mods;
var $curMod;
Expand Down Expand Up @@ -346,6 +348,11 @@ function logStartElement($parser, $name, $attrs) {
case 'COPYFROM-REV':
$curLog->curEntry->curMod->copyrev = $v;
break;

case 'KIND':
if ($debugxml) print 'Kind '.$v."\n";
$curLog->curEntry->curMod->isdir = ($v == 'dir');
break;
}
}
}
Expand Down Expand Up @@ -538,6 +545,22 @@ function encodePath($uri) {

// }}}

function _equalPart($str1, $str2) {
$len1 = strlen($str1);
$len2 = strlen($str2);
$i = 0;
while ($i < $len1 && $i < $len2) {
if (strcmp($str1{$i}, $str2{$i}) != 0) {
break;
}
$i++;
}
if ($i == 0) {
return '';
}
return substr($str1, 0, $i);
}

// The SVNRepository class

class SVNRepository {
Expand Down Expand Up @@ -1190,10 +1213,33 @@ function getLog($path, $brev = '', $erev = 1, $quiet = false, $limit = 2, $peg =
foreach ($curLog->entries as $entryKey => $entry) {
$fullModAccess = true;
$anyModAccess = (count($entry->mods) == 0);
$precisePath = null;
foreach ($entry->mods as $modKey => $mod) {
$access = $this->repConfig->hasReadAccess($mod->path);
if ($access) {
$anyModAccess = true;

// find path which is parent of all modification but more precise than $curLogEntry->path
$modpath = $mod->path;
if (!$mod->isdir || $mod->action == 'D') {
$pos = strrpos($modpath, '/');
$modpath = substr($modpath, 0, $pos + 1);
}
if (strlen($modpath) == 0 || substr($modpath, -1) !== '/') {
$modpath .= '/';
}
//compare with current precise path
if ($precisePath === null) {
$precisePath = $modpath;
} else {
$equalPart = _equalPart($precisePath, $modpath);
if (substr($equalPart, -1) !== '/') {
$pos = strrpos($equalPart, '/');
$equalPart = substr($equalPart, 0, $pos + 1);
}
$precisePath = $equalPart;
}

} else {
// hide modified entry when access is prohibited
unset($curLog->entries[$entryKey]->mods[$modKey]);
Expand Down Expand Up @@ -1221,6 +1267,12 @@ function getLog($path, $brev = '', $erev = 1, $quiet = false, $limit = 2, $peg =
$curLog->entries[$entryKey]->committime = '';
$curLog->entries[$entryKey]->age = '';
}

if ($precisePath !== null) {
$curLog->entries[$entryKey]->precisePath = $precisePath;
} else {
$curLog->entries[$entryKey]->precisePath = $curLog->entries[$entryKey]->path;
}
}
return $curLog;
}
Expand Down
14 changes: 10 additions & 4 deletions log.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,19 @@ function removeAccents($string) {
if ($match) {
// Add the trailing slash if we need to (svnlook history doesn't return trailing slashes!)
$rpath = $revision->path;

if (empty($rpath)) {
$rpath = '/';
} else if ($isDir && $rpath{strlen($rpath) - 1} != '/') {
$rpath .= '/';
}

$precisePath = $revision->precisePath;
if (empty($precisePath)) {
$precisePath = '/';
} else if ($isDir && $precisePath{strlen($precisePath) - 1} != '/') {
$precisePath .= '/';
}

// Find the parent path (or the whole path if it's already a directory)
$pos = strrpos($rpath, '/');
$parent = substr($rpath, 0, $pos + 1);
Expand All @@ -285,9 +291,9 @@ function removeAccents($string) {
$url = $config->getURL($rep, $rpath, 'revision').$thisRevString;
$listing[$index]['revlink'] = '<a href="'.$url.'">'.$thisrev.'</a>';

$url = $config->getURL($rep, $rpath, ($isDir ? 'dir' : 'file')).$thisRevString;
$listing[$index]['revpathlink'] = '<a href="'.$url.'">'.$rpath.'</a>';
$listing[$index]['revpath'] = $rpath;
$url = $config->getURL($rep, $precisePath, ($isDir ? 'dir' : 'file')).$thisRevString;
$listing[$index]['revpathlink'] = '<a href="'.$url.'">'.$precisePath.'</a>';
$listing[$index]['revpath'] = $precisePath;
$listing[$index]['revauthor'] = $revision->author;
$listing[$index]['revdate'] = $revision->date;
$listing[$index]['revage'] = $revision->age;
Expand Down

0 comments on commit d6d32c3

Please sign in to comment.