Commit b9553eb5 by Qiang Xue

Replaced diff vendor.

parent c7c7683f
...@@ -13,12 +13,6 @@ ...@@ -13,12 +13,6 @@
"source": "https://github.com/yiisoft/yii2" "source": "https://github.com/yiisoft/yii2"
}, },
"minimum-stability": "dev", "minimum-stability": "dev",
"repositories": [
{
"type": "pear",
"url": "http://pear.horde.org"
}
],
"require": { "require": {
"php": ">=5.3.0", "php": ">=5.3.0",
"yiisoft/yii2": "dev-master", "yiisoft/yii2": "dev-master",
......
...@@ -13,12 +13,6 @@ ...@@ -13,12 +13,6 @@
"source": "https://github.com/yiisoft/yii2" "source": "https://github.com/yiisoft/yii2"
}, },
"minimum-stability": "dev", "minimum-stability": "dev",
"repositories": [
{
"type": "pear",
"url": "http://pear.horde.org"
}
],
"require": { "require": {
"php": ">=5.3.0", "php": ">=5.3.0",
"yiisoft/yii2": "dev-master", "yiisoft/yii2": "dev-master",
......
...@@ -63,17 +63,11 @@ ...@@ -63,17 +63,11 @@
"irc": "irc://irc.freenode.net/yii", "irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2" "source": "https://github.com/yiisoft/yii2"
}, },
"repositories": [
{
"type": "pear",
"url": "http://pear.horde.org"
}
],
"require": { "require": {
"php": ">=5.3.7", "php": ">=5.3.7",
"ext-mbstring": "*", "ext-mbstring": "*",
"lib-pcre": "*", "lib-pcre": "*",
"pear-pear.horde.org/horde_text_diff": "2.0.*", "phpspec/php-diff": "1.0.*",
"ezyang/htmlpurifier": "4.5.*" "ezyang/htmlpurifier": "4.5.*"
}, },
"autoload": { "autoload": {
......
...@@ -143,8 +143,7 @@ class CodeFile extends Object ...@@ -143,8 +143,7 @@ class CodeFile extends Object
if (in_array($type, array('jpg', 'gif', 'png', 'exe'))) { if (in_array($type, array('jpg', 'gif', 'png', 'exe'))) {
return false; return false;
} elseif ($this->operation === self::OP_OVERWRITE) { } elseif ($this->operation === self::OP_OVERWRITE) {
list ($diff, $addedLines, $deletedLines) = StringHelper::diff(file($this->path), $this->content); return StringHelper::diff(file($this->path), $this->content);
return $diff;
} else { } else {
return ''; return '';
} }
......
...@@ -111,3 +111,88 @@ body { ...@@ -111,3 +111,88 @@ body {
background: lightgreen; background: lightgreen;
text-decoration: none; text-decoration: none;
} }
.Differences {
width: 100%;
border-collapse: collapse;
border-spacing: 0;
empty-cells: show;
}
.Differences thead {
display: none;
}
.Differences tbody th {
text-align: right;
background: #FAFAFA;
padding: 1px 2px;
border-right: 1px solid #eee;
vertical-align: top;
font-size: 13px;
font-family: Monaco, Menlo, Consolas, 'Courier New', monospace;
font-weight: normal;
color: #999;
width: 5px;
}
.Differences td {
padding: 1px 2px;
font-size: 13px;
font-family: Monaco, Menlo, Consolas, 'Courier New', monospace;
}
.DifferencesSideBySide .ChangeInsert td.Left {
background: #dfd;
}
.DifferencesSideBySide .ChangeInsert td.Right {
background: #cfc;
}
.DifferencesSideBySide .ChangeDelete td.Left {
background: #f88;
}
.DifferencesSideBySide .ChangeDelete td.Right {
background: #faa;
}
.DifferencesSideBySide .ChangeReplace .Left {
background: #fe9;
}
.DifferencesSideBySide .ChangeReplace .Right {
background: #fd8;
}
.Differences ins, .Differences del {
text-decoration: none;
}
.DifferencesSideBySide .ChangeReplace ins, .DifferencesSideBySide .ChangeReplace del {
background: #fc0;
}
.Differences .Skipped {
background: #f7f7f7;
}
.DifferencesInline .ChangeReplace .Left,
.DifferencesInline .ChangeDelete .Left {
background: #fdd;
}
.DifferencesInline .ChangeReplace .Right,
.DifferencesInline .ChangeInsert .Right {
background: #dfd;
}
.DifferencesInline .ChangeReplace ins {
background: #9e9;
}
.DifferencesInline .ChangeReplace del {
background: #e99;
}
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
<?php elseif (empty($diff)): ?> <?php elseif (empty($diff)): ?>
<div class="alert alert-success">Identical.</div> <div class="alert alert-success">Identical.</div>
<?php else: ?> <?php else: ?>
<div class="content"> <?php echo $diff; ?>
<pre><?php echo $diff; ?></pre>
</div>
<?php endif; ?> <?php endif; ?>
</div> </div>
...@@ -71,18 +71,17 @@ class StringHelperBase ...@@ -71,18 +71,17 @@ class StringHelperBase
/** /**
* Compares two strings or string arrays, and return their differences. * Compares two strings or string arrays, and return their differences.
* This is a wrapper of the Horde_Text_Diff package. * This is a wrapper of the [phpspec/php-diff](https://packagist.org/packages/phpspec/php-diff) package.
* @param string|array $lines1 the first string or string array to be compared. If it is a string, * @param string|array $lines1 the first string or string array to be compared. If it is a string,
* it will be converted into a string array by breaking at newlines. * it will be converted into a string array by breaking at newlines.
* @param string|array $lines2 the second string or string array to be compared. If it is a string, * @param string|array $lines2 the second string or string array to be compared. If it is a string,
* it will be converted into a string array by breaking at newlines. * it will be converted into a string array by breaking at newlines.
* @param string $format the output format. It must be 'context', 'inline', or 'unified'. * @param string $format the output format. It must be 'inline', 'unified', 'context', 'side-by-side', or 'array'.
* @param string $engine the diff engine to be used. It must be 'auto', 'native', 'shell', 'string', or 'xdiff'. * @return string|array the comparison result. An array is returned if `$format` is 'array'. For all other
* @return array the comparison result. The first element is a string representing the detailed comparison result. * formats, a string is returned.
* The second and the third elements represent the number of added lines and deleted lines, respectively. * @throws InvalidParamException if the format is invalid.
* @throws InvalidParamException if the format or the engine is invalid.
*/ */
public static function diff($lines1, $lines2, $format = 'inline', $engine = 'auto') public static function diff($lines1, $lines2, $format = 'inline')
{ {
if (!is_array($lines1)) { if (!is_array($lines1)) {
$lines1 = explode("\n", $lines1); $lines1 = explode("\n", $lines1);
...@@ -90,27 +89,32 @@ class StringHelperBase ...@@ -90,27 +89,32 @@ class StringHelperBase
if (!is_array($lines2)) { if (!is_array($lines2)) {
$lines2 = explode("\n", $lines2); $lines2 = explode("\n", $lines2);
} }
foreach ($lines1 as $i => $line) {
$lines1[$i] = rtrim($line, "\r\n");
}
foreach ($lines2 as $i => $line) {
$lines2[$i] = rtrim($line, "\r\n");
}
switch ($format) { switch ($format) {
case 'context':
$renderer = new \Horde_Text_Diff_Renderer_Context();
break;
case 'inline': case 'inline':
$renderer = new \Horde_Text_Diff_Renderer_Inline(); $renderer = new \Diff_Renderer_Html_Inline();
break;
case 'array':
$renderer = new \Diff_Renderer_Html_Array();
break;
case 'side-by-side':
$renderer = new \Diff_Renderer_Html_SideBySide();
break;
case 'context':
$renderer = new \Diff_Renderer_Text_Context();
break; break;
case 'unified': case 'unified':
$renderer = new \Horde_Text_Diff_Renderer_Unified(); $renderer = new \Diff_Renderer_Text_Unified();
break; break;
default: default:
throw new InvalidParamException("Output format must be 'context', 'inline' or 'unified'."); throw new InvalidParamException("Output format must be 'inline', 'side-by-side', 'array', 'context' or 'unified'.");
}
if (!in_array($engine, array('auto', 'native', 'shell', 'string', 'xdiff'))) {
throw new InvalidParamException("Engine must be 'auto', 'native', 'shell', 'string' or 'xdiff'.");
} }
$diff = new \Horde_Text_Diff($engine, array($lines1, $lines2)); $diff = new \Diff($lines1, $lines2);
return array( return $diff->render($renderer);
$renderer->render($diff),
$diff->countAddedLines(),
$diff->countDeletedLines(),
);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment