(PECL xdiff:0.2-1.4)
xdiff_file_patch — Patche un fichier avec un diff unifié
Patche le fichier file avec le patch unifié dans le fichier patch et stocke le résultat dans le fichier dest .
Le fichier original.
Le patch.
Le chemin vers le fichier résultat.
Peut être soit XDIFF_PATCH_NORMAL (mode par défaut, patch normal) ou XDIFF_PATCH_REVERSE (patch inversé).
Retourne FALSE si une erreur interne s'est produite, une chaîne avec les parties rejetées du patch ou TRUE si le patch a été appliqué avec succès.
Exemple 2812. Exemple avec xdiff_file_patch()
Le code suivant applique un diff à un fichier.
<?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
"Rejets :\n"
;
echo
$errors
;
}
?>
Exemple 2813. Exemple de retour à l'état initial après l'application d'un patch
Le code suivant annule un patch.
<?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
"Rejets :\n"
;
echo
$errors
;
}
?>
xdiff_string_patch() |