mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 08:58:56 +00:00
Add examples and notes about memory usage and format of diffs.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@166780 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
b0d5d1f84a
commit
23c4d7f590
7 changed files with 198 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='iso-8859-1'?>
|
||||
<!-- $Revision: 1.3 $ -->
|
||||
<!-- $Revision: 1.4 $ -->
|
||||
<!-- Generated by xml_proto.php v2.0. Found in /scripts directory of phpdoc. -->
|
||||
<refentry id="function.xdiff-file-diff-binary">
|
||||
<refnamediv>
|
||||
|
@ -19,11 +19,33 @@
|
|||
<para>
|
||||
<function>xdiff_file_diff_binary</function> makes binary diff of files
|
||||
<parameter>file1</parameter> and <parameter>file2</parameter> and stores
|
||||
result in file <parameter>dest</parameter>.
|
||||
result in file <parameter>dest</parameter>. This function works with both text
|
||||
and binary files. Resulting file is in binary format.
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
Both files will be loaded into memory so ensure that your memory_limit is set high enough.
|
||||
</para>
|
||||
</note>
|
||||
<para>
|
||||
&return.success;
|
||||
</para>
|
||||
<example>
|
||||
<title><function>xdiff_file_diff_binary</function> example</title>
|
||||
<para>
|
||||
The following code makes binary diff of two archives.
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$old_version = 'my_script_1.0.tgz';
|
||||
$new_version = 'my_script_1.1.tgz';
|
||||
|
||||
xdiff_file_diff_binary($old_version, $new_version, 'my_script.bdiff');
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
See also <function>xdiff_string_diff_binary</function>.
|
||||
</para>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='iso-8859-1'?>
|
||||
<!-- $Revision: 1.2 $ -->
|
||||
<!-- $Revision: 1.3 $ -->
|
||||
<!-- Generated by xml_proto.php v2.0. Found in /scripts directory of phpdoc. -->
|
||||
<refentry id="function.xdiff-file-diff">
|
||||
<refnamediv>
|
||||
|
@ -25,10 +25,33 @@
|
|||
<parameter>context</parameter> indicated how many lines of context you
|
||||
want to include in diff result. Set <parameter>minimal</parameter> to
|
||||
&true; if you want to minimalize size of diff (can take a long time).
|
||||
Resulting file is human-readable.
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
This function doesn't work well with binary files. To make diff of binary
|
||||
files use <function>xdiff_file_diff_binary</function>.
|
||||
</para>
|
||||
</note>
|
||||
<para>
|
||||
&return.success;
|
||||
</para>
|
||||
<example>
|
||||
<title><function>xdiff_file_diff</function> example</title>
|
||||
<para>
|
||||
The following code makes unified diff of two php files.
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$old_version = 'my_script.php';
|
||||
$new_version = 'my_new_script.php';
|
||||
|
||||
xdiff_file_diff($old_version, $new_version, 'my_script.diff', 2);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
See also <function>xdiff_string_diff</function>.
|
||||
</para>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='iso-8859-1'?>
|
||||
<!-- $Revision: 1.2 $ -->
|
||||
<!-- $Revision: 1.3 $ -->
|
||||
<!-- Generated by xml_proto.php v2.0. Found in /scripts directory of phpdoc. -->
|
||||
<refentry id="function.xdiff-file-merge3">
|
||||
<refnamediv>
|
||||
|
@ -27,6 +27,27 @@
|
|||
Returns &true; if merge was successful, string with rejected chunks if
|
||||
it was not or &false; if an internal error happened.
|
||||
</para>
|
||||
<example>
|
||||
<title><function>xdiff_file_merge3</function> example</title>
|
||||
<para>
|
||||
The following code merges three files into one.
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$old_version = 'original_script.php';
|
||||
$fix1 = 'script_with_fix1.php';
|
||||
$fix2 = 'script_with_fix2.php';
|
||||
|
||||
$errors = xdiff_file_merge3($old_version, $fix1, $fix2, 'fixed_script.php');
|
||||
if (is_string($errors)) {
|
||||
echo "Rejects:\n";
|
||||
echo $errors;
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
See also <function>xdiff_string_merge3</function>.
|
||||
</para>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='iso-8859-1'?>
|
||||
<!-- $Revision: 1.4 $ -->
|
||||
<!-- $Revision: 1.5 $ -->
|
||||
<!-- Generated by xml_proto.php v2.0. Found in /scripts directory of phpdoc. -->
|
||||
<refentry id="function.xdiff-file-patch-binary">
|
||||
<refnamediv>
|
||||
|
@ -22,9 +22,36 @@
|
|||
<parameter>patch</parameter> and stores result in file
|
||||
<parameter>dest</parameter>.
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
Both files (file and patch) will be loaded into memory so ensure that your memory_limit is set high enough.
|
||||
</para>
|
||||
</note>
|
||||
<para>
|
||||
&return.success;
|
||||
</para>
|
||||
<example>
|
||||
<title><function>xdiff_file_patch_binary</function> example</title>
|
||||
<para>
|
||||
The following code applies binary diff to a file.
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$old_version = 'archive-1.0.tgz';
|
||||
$patch = 'archive.bpatch';
|
||||
|
||||
$result = xdiff_file_patch_binary($old_version, $patch, 'archive-1.1.tgz');
|
||||
if ($result) {
|
||||
echo "File patched";
|
||||
} else {
|
||||
echo "File couldn't be patched";
|
||||
}
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
See also <function>xdiff_string_patch_binary</function>.
|
||||
</para>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='iso-8859-1'?>
|
||||
<!-- $Revision: 1.3 $ -->
|
||||
<!-- $Revision: 1.4 $ -->
|
||||
<!-- Generated by xml_proto.php v2.0. Found in /scripts directory of phpdoc. -->
|
||||
<refentry id="function.xdiff-file-patch">
|
||||
<refnamediv>
|
||||
|
@ -32,6 +32,48 @@
|
|||
Returns &false; if an internal error happened, string with rejected
|
||||
chunks of patch or &true; if patch has been successfully applied.
|
||||
</para>
|
||||
<example>
|
||||
<title><function>xdiff_file_patch</function> example</title>
|
||||
<para>
|
||||
The following code applies unified diff to a file.
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$old_version = 'my_script-1.0.php';
|
||||
$patch = 'my_script.patch';
|
||||
|
||||
$errors = xdiff_file_patch($old_version, $patch, 'my_script-1.1.php');
|
||||
if (is_string($errors)) {
|
||||
echo "Rejects:\n";
|
||||
echo $errors;
|
||||
}
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<example>
|
||||
<title>Patch reversing example</title>
|
||||
<para>
|
||||
The following code reverses a patch.
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$new_version = 'my_script-1.1.php';
|
||||
$patch = 'my_script.patch';
|
||||
|
||||
$errors = xdiff_file_patch($new_version, $patch, 'my_script-1.0.php', XDIFF_PATCH_REVERSE);
|
||||
if (is_string($errors)) {
|
||||
echo "Rejects:\n";
|
||||
echo $errors;
|
||||
}
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
See also <function>xdiff_string_patch</function>.
|
||||
</para>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='iso-8859-1'?>
|
||||
<!-- $Revision: 1.2 $ -->
|
||||
<!-- $Revision: 1.3 $ -->
|
||||
<!-- Generated by xml_proto.php v2.0. Found in /scripts directory of phpdoc. -->
|
||||
<refentry id="function.xdiff-string-diff">
|
||||
<refnamediv>
|
||||
|
@ -24,9 +24,36 @@
|
|||
want to include in diff result. Set <parameter>minimal</parameter> to
|
||||
&true; if you want to minimalize size of diff (can take a long time).
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
This function doesn't work well with binary strings. To make diff of binary
|
||||
strings use <function>xdiff_string_diff_binary</function>.
|
||||
</para>
|
||||
</note>
|
||||
<para>
|
||||
Returns string with result or &false; if an internal error happened.
|
||||
</para>
|
||||
<example>
|
||||
<title><function>xdiff_string_diff</function> example</title>
|
||||
<para>
|
||||
The following code makes unified diff of two articles.
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$old_article = file_get_contents('./old_article.txt');
|
||||
$new_article = $_REQUEST['article']; /* Let's say that someone pasted a new article to html form */
|
||||
|
||||
$diff = xdiff_string_diff($old_article, $new_article, 1);
|
||||
if (is_string($diff)) {
|
||||
echo "Differences between two articles:\n";
|
||||
echo $diff;
|
||||
}
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
See also <function>xdiff_file_diff</function>.
|
||||
</para>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version='1.0' encoding='iso-8859-1'?>
|
||||
<!-- $Revision: 1.2 $ -->
|
||||
<!-- $Revision: 1.3 $ -->
|
||||
<!-- Generated by xml_proto.php v2.0. Found in /scripts directory of phpdoc. -->
|
||||
<refentry id="function.xdiff-string-patch">
|
||||
<refnamediv>
|
||||
|
@ -31,6 +31,34 @@
|
|||
If <parameter>error</parameter> is passed then rejected parts are stored
|
||||
inside this variable.
|
||||
</para>
|
||||
<example>
|
||||
<title><function>xdiff_string_patch</function> example</title>
|
||||
<para>
|
||||
The following code applies changes to some article.
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$old_article = file_get_contents('./old_article.txt');
|
||||
$diff = $_SERVER['patch']; /* Let's say that someone pasted a patch to html form */
|
||||
|
||||
$errors = '';
|
||||
|
||||
$new_article = xdiff_string_patch($old_article, $diff, XDIFF_PATCH_NORMAL, $errors);
|
||||
if (is_string($new_article)) {
|
||||
echo "New article:\n";
|
||||
echo $new_article;
|
||||
}
|
||||
|
||||
if (strlen($errors)) {
|
||||
echo "Rejects: \n";
|
||||
echo $errors;
|
||||
}
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
Returns a patched string.
|
||||
</para>
|
||||
|
|
Loading…
Reference in a new issue