forked from ctcherry/phplibgitdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.php
More file actions
63 lines (49 loc) · 1.11 KB
/
example.php
File metadata and controls
63 lines (49 loc) · 1.11 KB
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
<style type="text/css">
body {
font-family: monospace;
}
.remove {
background: #fcc;
}
.add {
background: #cfc;
}
tr {
background: #eee;
}
td {
padding: 2px 4px;
}
tr:hover {
background: #ffc;
}
</style>
<?php
require 'lib/GitDiff.class.php';
function display($diff) {
foreach($diff->files as $file) {
echo "<h2>$file->file_name</h2>";
foreach($file->sections as $section) {
echo "<h3>".$section->header."</h3>";
echo "<table>";
foreach($section->lines as $line) {
$class = '';
if ($line->mode == 1) {
$class = 'class="add"';
}
if ($line->mode == -1) {
$class = 'class="remove"';
}
echo "<tr $class><td>".$line->line_numbers['left']."</td><td>".$line->line_numbers['right']."</td><td>".$line."</td></tr>";
}
echo "</table>";
}
}
}
$start = microtime(true);
$diff1 = new GitDiff(file_get_contents('sample1.diff'));
$diff2 = new GitDiff(file_get_contents('sample2.diff'));
display($diff1);
display($diff2);
$time = microtime(true) - $start;
echo $time;