File: history.php

package info (click to toggle)
chora2 2.0.1-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,208 kB
  • ctags: 302
  • sloc: php: 1,298; xml: 406; makefile: 66
file content (215 lines) | stat: -rw-r--r-- 7,634 bytes parent folder | download
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
<?php
/**
 * $Horde: chora/history.php,v 1.53.8.2 2005/07/01 01:26:10 selsky Exp $
 *
 * Copyright 2000-2005 Anil Madhavapeddy <anil@recoil.org>
 *
 * See the enclosed file COPYING for license information (GPL).  If you
 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
 */

@define('CHORA_BASE', dirname(__FILE__));
require_once CHORA_BASE . '/lib/base.php';

// Exit if it's not supported.
if (is_a($VC, 'VC_svn')) {
    header('Location: ' . Chora::url('browse', $where));
    exit;
}

/* Spawn the file object */
$fl = &$VC->getFileObject($where, $cache);
Chora::checkError($fl);

/* $trunk contains an array of trunk revisions */
$trunk = array();

/* $branches is a hash with the branch revision as the
 * key, and value being an array of revs on that branch */
$branches = array();

/* Populate $col with a list of all the branch points */
foreach ($fl->branches as $rev => $sym) {
    $branches[$rev] = array();
}

/* For every revision, figure out if it is a trunk
 * revision, or instead associated with a branch.
 * If trunk, add it to the $trunk array.
 * Otherwise, add it to an array in $branches[$branch]
 */

foreach ($fl->logs as $log) {
    $rev = $log->queryRevision();
    $baseRev = VC_Revision::strip($rev, 1);
    $branchFound = false;
    foreach ($fl->branches as $branch => $name) {
        if ($branch == $baseRev) {
            array_unshift($branches[$branch], $rev);
            $branchFound = true;
        }
    }
    /* If its not a branch, then add it to the trunk */
    /* TODO: this silently drops vendor branches atm! - avsm */
    if (!$branchFound && VC_Revision::sizeof($rev) == 2) {
        array_unshift($trunk, $rev);
    }
}

foreach ($branches as $col => $rows) {
    /* If this branch has no actual commits on it, then it's a
     * stub branch, and we can remove it for this view */
    if (!sizeof($rows)) {
        unset($branches[$col]);
    }
}

$colset = array('#ccdeff','#eeccff','#ffeecc','#eeffcc','#ccffdd','#dcdba0');
$colStack = array();
$branchColours = array();
foreach ($branches as $brrev => $brcont) {
   if (!sizeof($colStack)) $colStack = $colset;
   $branchColours[$brrev] = array_shift($colset);
}

/* This takes a row and a column, and recursively iterates through
 * any sub-revisions or branches from the value that was already in
 * the grid at the co-ordinates that it was called with.
 *
 * Calling this function on every revision of the trunk is enough
 * to render out the whole tree. */

function populateGrid($row, $col) {
    global $grid, $branches;

    /* Figure out the starting revision this function uses */
    $rev = $grid[$row][$col];

    /* For every branch that is known, try to see if it forks here */
    $brkeys = array_keys($branches);

    /* NOTE: do not optimise to use foreach () or each() here, as that
     * really screws up the $branches pointer array due to the
     * recursion, and parallel branches fail - avsm */
    for ($a = 0; $a < sizeof($brkeys); $a++) {
        $brrev = $brkeys[$a];
        $brcont = $branches[$brrev];
        /* Check to see if current point matches a branch point */
        if (!strcmp($rev, VC_Revision::strip($brrev, 1))) {
            /* If it does, figure out how many rows we have to add */
            $numRows = sizeof($brcont);
            /* Check rows in columns to the right, until one is free */
            $insCol = $col + 1;
            while (true) {
                /* Look in the current column for a set value */
                $inc = false;
                for ($i = $row; $i <= ($row + $numRows); $i++) {
                    if (isset($grid[$i][$insCol])) {
                        $inc = true;
                    }
                }
                /* If a set value was found, shift to the right and
                 * try again.  Otherwise, break out of the loop */
                if ($inc) {
                    if (!isset($grid[$row][$insCol])) {
                        $grid[$row][$insCol] = ':' . $brcont[0];
                    }
                    $insCol++;
                } else {
                    break;
                }
            }

            /* Put a fork marker in the top of the branch */
            $grid[$row][$insCol] = $brrev;

            /* Populate the grid with the branch values at this point */
            for ($i = 0; $i < $numRows; $i++) {
                $grid[1 + $i + $row][$insCol] = $brcont[$i];
            }
            /* For each value just set, check for sub-branches,
             * - but in reverse (VERY IMPORTANT!) */
            for ($i = $numRows - 1; $i >= 0 ; $i--) {
                populateGrid(1+$i+$row, $insCol);
            }
        }
    }
}

/* Start row at the bottom trunk revision.  Since branches always
 * go down, there can never be one above 1.1, and so this is a
 * safe location to start.  We will then work our way up,
 * recursively populating the grid with branch revisions */

for ($row = sizeof($trunk) - 1; $row >= 0; $row--) {
    $grid[$row][0] = $trunk[$row];
    populateGrid($row, 0);
}

/* Sort the grid array into row order, and determine the maximum column
 * size that we need to render out in HTML */

ksort($grid);
$maxCol = 0;
foreach ($grid as $cols) {
    krsort($cols);
    list($val) = each($cols);
    $maxCol = max($val, $maxCol);
}

$title = sprintf(_("Source Branching View for %s"), Text::htmlallspaces($where));
$extraLink = Chora::getFileViews();

require CHORA_TEMPLATES . '/common-header.inc';
require CHORA_TEMPLATES . '/menu.inc';
require CHORA_TEMPLATES . '/headerbar.inc';
require CHORA_TEMPLATES . '/history/header.inc';

foreach ($grid as $row) {
    require CHORA_TEMPLATES . '/history/row_start.inc';

    /* Start traversing the grid of rows and columns */
    for ($i = 0; $i <= $maxCol; $i++) {

        /* If this column has nothing in it, require a blank cell */
        if (!isset($row[$i])) {
             $bg = '';
             require CHORA_TEMPLATES.'/history/blank.inc';
             continue;
        }

        /* Otherwise, this cell has content; determine what it is */
        $rev = $row[$i];

        if (VC_Revision::valid($rev) && (VC_Revision::sizeof($rev) % 2)) {
            /* This is a branch point, so put the info out */
            $bg = isset($branchColours[$rev]) ? $branchColours[$rev] : 'white';
            $symname = $fl->branches[$rev];
            require CHORA_TEMPLATES . '/history/branch_cell.inc';

        } elseif (preg_match('|^:|', $rev)) {
            /* This is a continuation cell, so render it with the branch colour */
            $bgbr = VC_Revision::strip(preg_replace('|^\:|', '', $rev), 1);
            $bg = isset($branchColours[$bgbr]) ? $branchColours[$bgbr] : 'white';
            require CHORA_TEMPLATES . '/history/blank.inc';

        } elseif (VC_Revision::valid($rev)) {
            /* This cell contains a revision, so render it */
            $bgbr = VC_Revision::strip($rev, 1);
            $bg = isset($branchColours[$bgbr]) ? $branchColours[$bgbr] : 'white';
            $log = $fl->logs[$rev];
            $author = Chora::showAuthorName($log->queryAuthor());
            $date = strftime('%e %b %Y', $log->queryDate());
            $lines = $log->queryChangedLines();
            require CHORA_TEMPLATES . '/history/rev.inc';

        } else {
            /* Exhausted other possibilities, just show a blank cell */
            require CHORA_TEMPLATES . '/history/blank.inc';
        }
    }
    require CHORA_TEMPLATES . '/history/row_end.inc';
}

require CHORA_TEMPLATES . '/history/footer.inc';
require $registry->get('templates', 'horde') . '/common-footer.inc';