Skip to content

Commit

Permalink
refactored repeated access to specific array elements using reference…
Browse files Browse the repository at this point in the history
…s (patch by Paul Chan)
  • Loading branch information
dirk-thomas committed Aug 1, 2011
1 parent 8b49de4 commit 313c6ed
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 104 deletions.
15 changes: 8 additions & 7 deletions blame.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,27 @@
list($revision, $author, $remainder) = sscanf($blameline, '%d %s %s');
$empty = !$remainder;

$listing[$index]['lineno'] = $index + 1;
$listvar = &$listing[$index];
$listvar['lineno'] = $index + 1;

if ($last_rev != $revision) {
$url = $config->getURL($rep, $path, 'blame');
$listing[$index]['revision'] = '<a id="l'.$index.'-rev" class="blame-revision" href="'.$url.'rev='.$revision.'&amp;peg='.$rev.'">'.$revision.'</a>';
$listvar['revision'] = '<a id="l'.$index.'-rev" class="blame-revision" href="'.$url.'rev='.$revision.'&amp;peg='.$rev.'">'.$revision.'</a>';
$seen_rev[$revision] = 1;
$row_class = ($row_class == 'light') ? 'dark' : 'light';
$listing[$index]['author'] = $author;
$listvar['author'] = $author;
} else {
$listing[$index]['revision'] = '';
$listing[$index]['author'] = '';
$listvar['revision'] = '';
$listvar['author'] = '';
}

$listing[$index]['row_class'] = $row_class;
$listvar['row_class'] = $row_class;
$last_rev = $revision;

$line = rtrim(fgets($file));
if (!$highlighted)
$line = escape(toOutputEncoding($line));
$listing[$index]['line'] = ($empty) ? '&nbsp;' : wrapInCodeTagIfNecessary($line);
$listvar['line'] = ($empty) ? '&nbsp;' : wrapInCodeTagIfNecessary($line);
$index++;
}
}
Expand Down
42 changes: 23 additions & 19 deletions comp.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,14 @@ function clearVars() {
}
}

$listing[$index]['newpath'] = null;
$listing[$index]['endpath'] = null;
$listing[$index]['info'] = null;
$listing[$index]['diffclass'] = null;
$listing[$index]['difflines'] = null;
$listing[$index]['enddifflines'] = null;
$listing[$index]['properties'] = null;
$listvar = &$listing[$index];
$listvar['newpath'] = null;
$listvar['endpath'] = null;
$listvar['info'] = null;
$listvar['diffclass'] = null;
$listvar['difflines'] = null;
$listvar['enddifflines'] = null;
$listvar['properties'] = null;
}

$vars['success'] = false;
Expand Down Expand Up @@ -287,21 +288,22 @@ function clearVars() {
$subline = escape(toOutputEncoding(substr($line, 1)));
$subline = rtrim($subline, "\n\r");
$subline = ($subline) ? expandTabs($subline) : '&nbsp;';
$listing[$index]['line'] = $subline;
$listvar = &$listing[$index];
$listvar['line'] = $subline;

switch ($line[0]) {
case ' ':
$listing[$index]['diffclass'] = 'diff';
$listvar['diffclass'] = 'diff';
if ($debug) print 'Including as diff: '.$subline.'<br />';
break;

case '+':
$listing[$index]['diffclass'] = 'diffadded';
$listvar['diffclass'] = 'diffadded';
if ($debug) print 'Including as added: '.$subline.'<br />';
break;

case '-':
$listing[$index]['diffclass'] = 'diffdeleted';
$listvar['diffclass'] = 'diffdeleted';
if ($debug) print 'Including as removed: '.$subline.'<br />';
break;
}
Expand Down Expand Up @@ -337,16 +339,17 @@ function clearVars() {
$listing[$index++]['info'] = $lang['FILEDELETED'];

} else {
$listing[$index]['difflines'] = $line;
$listvar = &$listing[$index];
$listvar['difflines'] = $line;
$sline = 0;
$slen = 0;
$eline = 0;
$elen = 0;
sscanf($line, '@@ -%d,%d +%d,%d @@', $sline, $slen, $eline, $elen);
$listing[$index]['rev1line'] = $sline;
$listing[$index]['rev1len'] = $slen;
$listing[$index]['rev2line'] = $eline;
$listing[$index]['rev2len'] = $elen;
$listvar['rev1line'] = $sline;
$listvar['rev1len'] = $slen;
$listvar['rev2line'] = $eline;
$listvar['rev2len'] = $elen;

$indiffproper = true;

Expand Down Expand Up @@ -381,9 +384,10 @@ function clearVars() {
$absnode .= $node;
}

$listing[$index]['newpath'] = $absnode;
$listvar = &$listing[$index];
$listvar['newpath'] = $absnode;

$listing[$index]['fileurl'] = $config->getURL($rep, $absnode, 'file').'rev='.$rev2;
$listvar['fileurl'] = $config->getURL($rep, $absnode, 'file').'rev='.$rev2;

if ($debug) echo 'Creating node '.$node.'<br />';

Expand All @@ -395,7 +399,7 @@ function clearVars() {
$line = fgets($diff);
if ($debug) print 'Examining: '.$line.'<br />';
if (strpos($line, '(revision 0)')) {
$listing[$index]['info'] = $lang['FILEADDED'];
$listvar['info'] = $lang['FILEADDED'];
}

if (strncmp(trim($line), 'Cannot display:', 15) == 0) {
Expand Down
15 changes: 8 additions & 7 deletions include/diff_inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ function _add($text1, $lineno1, $class1, $text2, $lineno2, $class2) {
$listing = &$this->_listing;
$index = &$this->_index;

$listing[$index]['rev1diffclass'] = $class1;
$listing[$index]['rev2diffclass'] = $class2;
$listvar = &$listing[$index];
$listvar['rev1diffclass'] = $class1;
$listvar['rev2diffclass'] = $class2;

$listing[$index]['rev1line'] = $text1;
$listing[$index]['rev2line'] = $text2;
$listvar['rev1line'] = $text1;
$listvar['rev2line'] = $text2;

$listing[$index]['rev1lineno'] = $lineno1;
$listing[$index]['rev2lineno'] = $lineno2;
$listing[$index]['startblock'] = $this->_blockStart;
$listvar['rev1lineno'] = $lineno1;
$listvar['rev2lineno'] = $lineno2;
$listvar['startblock'] = $this->_blockStart;
$this->_blockStart = false;
$index++;
}
Expand Down
38 changes: 20 additions & 18 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,48 +51,50 @@
if (!$project->hasReadAccess('/', true))
continue;

$listvar = &$listing[$i];
// If this is the first project in a group, add an entry for the group.
if ($curgroup != $project->group) {
$groupcount++;
$groupparity = 0;
$listing[$i]['notfirstgroup'] = !empty($curgroup);
$listvar['notfirstgroup'] = !empty($curgroup);
$curgroup = $project->group;
$listing[$i]['groupname'] = $curgroup; // Applies until next group is set.
$listing[$i]['groupid'] = strtr(base64_encode('grp'.$curgroup), array('+' => '-', '/' => '_', '=' => ''));
$listvar['groupname'] = $curgroup; // Applies until next group is set.
$listvar['groupid'] = strtr(base64_encode('grp'.$curgroup), array('+' => '-', '/' => '_', '=' => ''));

$listing[$i]['projectlink'] = null; // Because template.php won't unset this
$listvar['projectlink'] = null; // Because template.php won't unset this
$i++; // Causes the subsequent lines to store data in the next array slot.
$listing[$i]['groupid'] = null; // Because template.php won't unset this
$listvar = &$listing[$i];
$listvar['groupid'] = null; // Because template.php won't unset this
}
$listing[$i]['clientrooturl'] = $project->clientRootURL;
$listvar['clientrooturl'] = $project->clientRootURL;

// Populate variables for latest modification to the current repository
if ($config->showLastModInIndex()) {
$svnrep = new SVNRepository($project);
$log = $svnrep->getLog('/', '', '', true, 1);
if (isset($log->entries[0])) {
$head = $log->entries[0];
$listing[$i]['revision'] = $head->rev;
$listing[$i]['date'] = $head->date;
$listing[$i]['age'] = datetimeFormatDuration(time() - strtotime($head->date));
$listing[$i]['author'] = $head->author;
$listvar['revision'] = $head->rev;
$listvar['date'] = $head->date;
$listvar['age'] = datetimeFormatDuration(time() - strtotime($head->date));
$listvar['author'] = $head->author;
} else {
$listing[$i]['revision'] = 0;
$listing[$i]['date'] = '';
$listing[$i]['age'] = '';
$listing[$i]['author'] = '';
$listvar['revision'] = 0;
$listvar['date'] = '';
$listvar['age'] = '';
$listvar['author'] = '';
}
}

// Create project (repository) listing
$url = str_replace('&amp;', '', $config->getURL($project, '', 'dir'));
$name = ($config->flatIndex) ? $project->getDisplayName() : $project->name;
$listing[$i]['projectlink'] = '<a href="'.$url.'">'.escape($name).'</a>';
$listing[$i]['rowparity'] = $parity % 2;
$listvar['projectlink'] = '<a href="'.$url.'">'.escape($name).'</a>';
$listvar['rowparity'] = $parity % 2;
$parity++;
$listing[$i]['groupparity'] = $groupparity % 2;
$listvar['groupparity'] = $groupparity % 2;
$groupparity++;
$listing[$i]['groupname'] = ($curgroup != null) ? $curgroup : '';
$listvar['groupname'] = ($curgroup != null) ? $curgroup : '';
$i++;
}
if (empty($listing) && !empty($projects)) {
Expand Down
82 changes: 42 additions & 40 deletions listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,20 @@ function showDirFiles($svnrep, $subs, $level, $limit, $rev, $peg, $listing, $ind
unset($parentPath[count($parentPath) - 2]);
$parentPath = implode('/', $parentPath);
if ($rep->hasReadAccess($parentPath, false)) {
$listing[$index]['rowparity'] = $index % 2;
$listing[$index]['path'] = $parentPath;
$listing[$index]['filetype'] = 'dir';
$listing[$index]['filename'] = '..';
$listing[$index]['fileurl'] = urlForPath($parentPath, $passRevString);
$listing[$index]['filelink'] = '<a href="'.$listing[$index]['fileurl'].'">'.$listing[$index]['filename'].'</a>';
$listing[$index]['level'] = 0;
$listing[$index]['node'] = 0; // t-node
$listing[$index]['revision'] = $rev;
$listing[$index]['revurl'] = $config->getURL($rep, $parentPath, 'revision').'rev='.$rev.'&amp;isdir=1';
$listvar = &$listing[$index];
$listvar['rowparity'] = $index % 2;
$listvar['path'] = $parentPath;
$listvar['filetype'] = 'dir';
$listvar['filename'] = '..';
$listvar['fileurl'] = urlForPath($parentPath, $passRevString);
$listvar['filelink'] = '<a href="'.$listvar['fileurl'].'">'.$listvar['filename'].'</a>';
$listvar['level'] = 0;
$listvar['node'] = 0; // t-node
$listvar['revision'] = $rev;
$listvar['revurl'] = $config->getURL($rep, $parentPath, 'revision').'rev='.$rev.'&amp;isdir=1';
global $vars;
$listing[$index]['date'] = $vars['date'];
$listing[$index]['age'] = datetimeFormatDuration(time() - strtotime($vars['date']), true, true);
$listvar['date'] = $vars['date'];
$listvar['age'] = datetimeFormatDuration(time() - strtotime($vars['date']), true, true);
$index++;
}
}
Expand All @@ -108,61 +109,62 @@ function showDirFiles($svnrep, $subs, $level, $limit, $rev, $peg, $listing, $ind
// Only list files/directories that are not designated as off-limits
$access = ($isDir) ? $rep->hasReadAccess($path.$file, true)
: $accessToThisDir;
$listvar = &$listing[$index];
if ($access) {
$listing[$index]['rowparity'] = $index % 2;
$listvar['rowparity'] = $index % 2;

if ($isDir) {
$listing[$index]['filetype'] = ($openDir) ? 'diropen' : 'dir';
$listvar['filetype'] = ($openDir) ? 'diropen' : 'dir';
$openDir = isset($subs[$level + 1]) && (!strcmp($subs[$level + 1].'/', $file) || !strcmp($subs[$level + 1], $file));
} else {
$listing[$index]['filetype'] = strtolower(strrchr($file, '.'));
$listvar['filetype'] = strtolower(strrchr($file, '.'));
$openDir = false;
}
$listing[$index]['isDir'] = $isDir;
$listing[$index]['openDir'] = $openDir;
$listing[$index]['level'] = ($treeview) ? $level : 0;
$listing[$index]['node'] = 0; // t-node
$listing[$index]['path'] = $path.$file;
$listing[$index]['filename'] = $file;
$listvar['isDir'] = $isDir;
$listvar['openDir'] = $openDir;
$listvar['level'] = ($treeview) ? $level : 0;
$listvar['node'] = 0; // t-node
$listvar['path'] = $path.$file;
$listvar['filename'] = $file;
if ($isDir) {
$listing[$index]['fileurl'] = urlForPath($path.$file, $passRevString);
$listvar['fileurl'] = urlForPath($path.$file, $passRevString);
} else {
$listing[$index]['fileurl'] = urlForPath($path.$file, createDifferentRevAndPegString($passrev, $peg));
$listvar['fileurl'] = urlForPath($path.$file, createDifferentRevAndPegString($passrev, $peg));
}
$listing[$index]['filelink'] = '<a href="'.$listing[$index]['fileurl'].'">'.$listing[$index]['filename'].'</a>';
$listvar['filelink'] = '<a href="'.$listvar['fileurl'].'">'.$listvar['filename'].'</a>';
if ($isDir) {
$listing[$index]['logurl'] = $config->getURL($rep, $path.$file, 'log').$isDirString.$passRevString;
$listvar['logurl'] = $config->getURL($rep, $path.$file, 'log').$isDirString.$passRevString;
} else {
$listing[$index]['logurl'] = $config->getURL($rep, $path.$file, 'log').$isDirString.createDifferentRevAndPegString($passrev, $peg);
$listvar['logurl'] = $config->getURL($rep, $path.$file, 'log').$isDirString.createDifferentRevAndPegString($passrev, $peg);
}

if ($treeview) {
$listing[$index]['compare_box'] = '<input type="checkbox" name="compare[]" value="'.$path.$file.'@'.$passrev.'" onclick="checkCB(this)" />';
$listvar['compare_box'] = '<input type="checkbox" name="compare[]" value="'.$path.$file.'@'.$passrev.'" onclick="checkCB(this)" />';
}
if ($config->showLastModInListing()) {
$listing[$index]['committime'] = $entry->committime;
$listing[$index]['revision'] = $entry->rev;
$listing[$index]['author'] = $entry->author;
$listing[$index]['age'] = $entry->age;
$listing[$index]['date'] = $entry->date;
$listing[$index]['revurl'] = $config->getURL($rep, $path.$file, 'revision').$isDirString.createRevAndPegString($entry->rev, $peg ? $peg : $rev);
$listvar['committime'] = $entry->committime;
$listvar['revision'] = $entry->rev;
$listvar['author'] = $entry->author;
$listvar['age'] = $entry->age;
$listvar['date'] = $entry->date;
$listvar['revurl'] = $config->getURL($rep, $path.$file, 'revision').$isDirString.createRevAndPegString($entry->rev, $peg ? $peg : $rev);
}
if ($rep->isDownloadAllowed($path.$file)) {
$downloadurl = $config->getURL($rep, $path.$file, 'dl').$isDirString.$downloadRevAndPeg;
if ($isDir) {
$listing[$index]['downloadurl'] = $downloadurl;
$listing[$index]['downloadplainurl'] = '';
$listvar['downloadurl'] = $downloadurl;
$listvar['downloadplainurl'] = '';
} else {
$listing[$index]['downloadplainurl'] = $downloadurl;
$listing[$index]['downloadurl'] = '';
$listvar['downloadplainurl'] = $downloadurl;
$listvar['downloadurl'] = '';
}
} else {
$listing[$index]['downloadplainurl'] = '';
$listing[$index]['downloadurl'] = '';
$listvar['downloadplainurl'] = '';
$listvar['downloadurl'] = '';
}
if ($rep->isRssEnabled()) {
// RSS should always point to the latest revision, so don't include rev
$listing[$index]['rssurl'] = $config->getURL($rep, $path.$file, 'rss').$isDirString.createRevAndPegString('', $peg);
$listvar['rssurl'] = $config->getURL($rep, $path.$file, 'rss').$isDirString.createRevAndPegString('', $peg);
}

$loop++;
Expand Down
27 changes: 14 additions & 13 deletions log.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,20 +293,21 @@ function removeAccents($string) {

$compareValue = (($isDir) ? $parent : $rpath).'@'.$thisrev;

$listing[$index]['compare_box'] = '<input type="checkbox" name="compare[]" value="'.$compareValue.'" onclick="checkCB(this)" />';
$listvar = &$listing[$index];
$listvar['compare_box'] = '<input type="checkbox" name="compare[]" value="'.$compareValue.'" onclick="checkCB(this)" />';
$url = $config->getURL($rep, $rpath, 'revision').$thisRevString;
$listing[$index]['revlink'] = '<a href="'.$url.'">'.$thisrev.'</a>';
$listvar['revlink'] = '<a href="'.$url.'">'.$thisrev.'</a>';

$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;
$listing[$index]['revlog'] = nl2br($bugtraq->replaceIDs(create_anchors(xml_entities($revision->msg))));
$listing[$index]['rowparity'] = $row;
$listvar['revpathlink'] = '<a href="'.$url.'">'.$precisePath.'</a>';
$listvar['revpath'] = $precisePath;
$listvar['revauthor'] = $revision->author;
$listvar['revdate'] = $revision->date;
$listvar['revage'] = $revision->age;
$listvar['revlog'] = nl2br($bugtraq->replaceIDs(create_anchors(xml_entities($revision->msg))));
$listvar['rowparity'] = $row;

$listing[$index]['compareurl'] = $config->getURL($rep, '', 'comp').'compare[]='.$rpath.'@'.($thisrev - 1).'&amp;compare[]='.$rpath.'@'.$thisrev;
$listvar['compareurl'] = $config->getURL($rep, '', 'comp').'compare[]='.$rpath.'@'.($thisrev - 1).'&amp;compare[]='.$rpath.'@'.$thisrev;

if ($showchanges) {
// Aggregate added/deleted/modified paths for display in table
Expand All @@ -320,9 +321,9 @@ function removeAccents($string) {
$modpaths[$action] = $paths;
}

$listing[$index]['revadded'] = (isset($modpaths['A'])) ? implode('<br/>', $modpaths['A']) : '';
$listing[$index]['revdeleted'] = (isset($modpaths['D'])) ? implode('<br/>', $modpaths['D']) : '';
$listing[$index]['revmodified'] = (isset($modpaths['M'])) ? implode('<br/>', $modpaths['M']) : '';
$listvar['revadded'] = (isset($modpaths['A'])) ? implode('<br/>', $modpaths['A']) : '';
$listvar['revdeleted'] = (isset($modpaths['D'])) ? implode('<br/>', $modpaths['D']) : '';
$listvar['revmodified'] = (isset($modpaths['M'])) ? implode('<br/>', $modpaths['M']) : '';
}

$row = 1 - $row;
Expand Down

0 comments on commit 313c6ed

Please sign in to comment.