Difference between revisions of "X-Cart:To apply a patch manually"

From X-Cart 4 Classic
Jump to: navigation, search
(What is diff file?)
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
1. Open the diff file in a text editor;
+
==What is diff (patch) file?==
  
: Diff files are divided into parts ("hunks"). Each "hunk" starts with a line like this:
+
[http://en.wikipedia.org/wiki/Diff Diff] (or patch) is a file that displays the changes made per line for text files, and in particular, for X-Cart source files.
  
<pre>@@ -67,7 +67,10 @@</pre>
+
Diff can include changes for several files. The name of each modified file is specified under a header line that may look something like this:
  
: where:
+
<pre>Index: include/func/func.category.php</pre>
:* 67 - indicates the number of the line of the code where the changes start
 
:* 7 - indicates the number of the lines in the hunk before patch applying
 
:* 10 - indicates the number of the lines in the hunk after patch applying
 
  
: Then follows the file code marked with "+" and "-" signs. Lines marked with "+" are the lines that you need to add in the file that you should patch. Lines marked with "-" are the lines that you need to remove from the file that you should patch.
+
The above header line indicates that the diff displays the changes for <xcart_dir>/include/func/func.category.php file.
  
: Under 'Index:' you will find the name of the file that you should patch, for example:
+
Each header line is then followed with one or several [http://en.wikipedia.org/wiki/Hunk "hunks"]. Each "hunk" starts with a line that may look something like this:
  
<pre>Index: admin/category_modify.php</pre>
+
<pre>@@ -942,8 +940,7 @@</pre>
  
: Here is an example of complete diff file:
+
where:
 +
 
 +
* 942 - indicates the number of the first line in the original code (before patch application)
 +
* 8 - indicates the number of lines in the original code (before patch application)
 +
* 940 - indicates the number of the first line in the changed code (after patch application)
 +
* 7 - indicates the number of lines in the changed code (after patch application)
 +
 
 +
Then follows the file code that includes lines marked with the "+" and "-" signs.
 +
 
 +
Lines marked with "+" are the lines that you need to add in the file to be patched.
 +
 
 +
Lines marked with "-" are the lines that you need to remove from the file to be patched.
 +
 
 +
==Example of diff file==
 +
 
 +
<pre>Index: include/func/func.category.php
 +
@@ -585,9 +585,7 @@
 +
 
 +
$cat = abs(intval($cat));
 +
 
 +
-    $to_search =
 +
-    $search_condition =
 +
-    $join_tbl = array();
 +
+    $to_search = $search_condition = $join_tbl = array();
 +
 
 +
$from = "$sql_tbl[categories] AS node ";
 +
 
 +
@@ -942,8 +940,7 @@
 +
'c.rpos'
 +
);
 +
 
 +
-    $search_condition =
 +
-    $join_tbl = array();
 +
+    $search_condition = $join_tbl = array();
 +
 
 +
if ($current_area == 'A' || $current_area == 'P') {
 +
 
 +
</pre>
 +
 
 +
==General instructions==
 +
 
 +
1. Open the diff file in a text editor.
 +
 
 +
2. Edit the file (in our example, <u>include/func/func.category.php</u>):
 +
:* Find the lines marked with "-" in the text of the patch and remove them.
 +
:* Insert the lines marked with "+" in the text of the patch.
 +
 
 +
In our example, the original code (before applying the patch) would look like:
  
 
<pre>
 
<pre>
Index: admin/category_modify.php
+
line 585:
@@ -67,7 +67,10 @@
+
line 586:    $cat = abs(intval($cat));
#
+
line 587:
 +
line 588:    $to_search =
 +
line 589:    $search_condition =
 +
line 590:    $join_tbl = array();
 +
line 591:
 +
line 593:    $from = "$sql_tbl[categories] AS node ";
 +
line 594:
 +
...
 +
line 942:        'c.rpos'
 +
line 943:    );
 +
line 944:
 +
line 945:    $search_condition =
 +
line 946:    $join_tbl = array();
 +
line 947:
 +
line 948:    if ($current_area == 'A' || $current_area == 'P') {
 +
line 949:
 +
</pre>
  
if ($shop_language == $config['default_admin_language']) {
+
Total lines: 9 and 8 in each hunk correspondingly.
-
 
func_array2update("categories", $category_lng, "categoryid = '$cat'");
 
+ $_category_lng = $category_lng;
 
+
 
if (empty($_category_lng['category']))
 
+
 
func_unset($_category_lng, 'category');
 
+
 
func_array2update("categories", $_category_lng, "categoryid = '$cat'");
 
}
 
  
$category_lng['code'] = $shop_language;
+
The changed code (after applying the patch) would look like:
  
 +
<pre>
 +
line 585:
 +
line 586:    $cat = abs(intval($cat));
 +
line 587:
 +
line 588:    $to_search = $search_condition = $join_tbl = array();
 +
line 589:
 +
line 590:    $from = "$sql_tbl[categories] AS node ";
 +
line 591:
 +
...
 +
line 940:        'c.rpos'
 +
line 941:    );
 +
line 942:
 +
line 943:    $search_condition = $join_tbl = array();
 +
line 944:
 +
line 945:    if ($current_area == 'A' || $current_area == 'P') {
 +
line 946:
 
</pre>
 
</pre>
  
2. Edit the file (in our example, admin/category_modify.php):
+
Total lines: 7 and 7 in each hunk correspondingly.
 +
 
 +
==Understanding the process==
 +
 
 +
In simple words, the patch application procedure for each hunk is as follows:
 +
 
 +
* Search for the code to be replaced around (above and below) the expected line.
 +
* If found, change it to the new code.
 +
 
 +
Let us take another look at the second hunk of the example patch provided above to understand the process:
 +
 
 +
<pre>
 +
@@ -942,8 +940,7 @@
 +
'c.rpos'
 +
);
 +
 
 +
-    $search_condition =
 +
-    $join_tbl = array();
 +
+    $search_condition = $join_tbl = array();
 +
 
 +
if ($current_area == 'A' || $current_area == 'P') {
 +
</pre>
 +
 
 +
* Original code to search for (8 lines of code around the line 942):
 +
 
 +
<pre>
 +
'c.rpos'
 +
);
 +
 
 +
$search_condition =
 +
$join_tbl = array();
 +
 
 +
if ($current_area == 'A' || $current_area == 'P') {
 +
 
 +
</pre>
 +
 
 +
* New code to change to (7 lines of code):
 +
 
 +
<pre>
 +
'c.rpos'
 +
);
 +
 
 +
$search_condition = $join_tbl = array();
 +
 
 +
if ($current_area == 'A' || $current_area == 'P') {
 +
 
 +
</pre>
  
:* Find the lines, which are marked by "-" in the text of patch, and remove them.
+
The built-in patch/upgrade utility basically works in the same way.
:* Insert the lines, which are marked by "+" in the text of patch.
 
  
If you cannot apply the patch in these ways it means the file that needs to be patched has been modified or this file is from another version of X-Cart and cannot be patched by this patch. Ask technical support to help you.
+
[[Category:X-Cart user manual]]
  
 
[[Category:X-Cart user manual]]
 
[[Category:X-Cart user manual]]

Latest revision as of 11:40, 1 October 2011

What is diff (patch) file?

Diff (or patch) is a file that displays the changes made per line for text files, and in particular, for X-Cart source files.

Diff can include changes for several files. The name of each modified file is specified under a header line that may look something like this:

Index: include/func/func.category.php

The above header line indicates that the diff displays the changes for <xcart_dir>/include/func/func.category.php file.

Each header line is then followed with one or several "hunks". Each "hunk" starts with a line that may look something like this:

@@ -942,8 +940,7 @@

where:

  • 942 - indicates the number of the first line in the original code (before patch application)
  • 8 - indicates the number of lines in the original code (before patch application)
  • 940 - indicates the number of the first line in the changed code (after patch application)
  • 7 - indicates the number of lines in the changed code (after patch application)

Then follows the file code that includes lines marked with the "+" and "-" signs.

Lines marked with "+" are the lines that you need to add in the file to be patched.

Lines marked with "-" are the lines that you need to remove from the file to be patched.

Example of diff file

Index: include/func/func.category.php
@@ -585,9 +585,7 @@

$cat = abs(intval($cat));

-    $to_search =
-    $search_condition =
-    $join_tbl = array();
+    $to_search = $search_condition = $join_tbl = array();

$from = "$sql_tbl[categories] AS node ";

@@ -942,8 +940,7 @@
'c.rpos'
);

-    $search_condition =
-    $join_tbl = array();
+    $search_condition = $join_tbl = array();

if ($current_area == 'A' || $current_area == 'P') {

General instructions

1. Open the diff file in a text editor.

2. Edit the file (in our example, include/func/func.category.php):

  • Find the lines marked with "-" in the text of the patch and remove them.
  • Insert the lines marked with "+" in the text of the patch.

In our example, the original code (before applying the patch) would look like:

line 585:
line 586:    $cat = abs(intval($cat));
line 587:
line 588:    $to_search =
line 589:    $search_condition =
line 590:    $join_tbl = array();
line 591:
line 593:    $from = "$sql_tbl[categories] AS node ";
line 594:
...
line 942:        'c.rpos'
line 943:    );
line 944:
line 945:    $search_condition =
line 946:    $join_tbl = array();
line 947:
line 948:    if ($current_area == 'A' || $current_area == 'P') {
line 949:

Total lines: 9 and 8 in each hunk correspondingly.

The changed code (after applying the patch) would look like:

line 585:
line 586:    $cat = abs(intval($cat));
line 587:
line 588:    $to_search = $search_condition = $join_tbl = array();
line 589:
line 590:    $from = "$sql_tbl[categories] AS node ";
line 591:
...
line 940:        'c.rpos'
line 941:    );
line 942:
line 943:    $search_condition = $join_tbl = array();
line 944:
line 945:    if ($current_area == 'A' || $current_area == 'P') {
line 946:

Total lines: 7 and 7 in each hunk correspondingly.

Understanding the process

In simple words, the patch application procedure for each hunk is as follows:

  • Search for the code to be replaced around (above and below) the expected line.
  • If found, change it to the new code.

Let us take another look at the second hunk of the example patch provided above to understand the process:

@@ -942,8 +940,7 @@
'c.rpos'
);

-    $search_condition =
-    $join_tbl = array();
+    $search_condition = $join_tbl = array();

if ($current_area == 'A' || $current_area == 'P') {
  • Original code to search for (8 lines of code around the line 942):
'c.rpos'
);

$search_condition =
$join_tbl = array();

if ($current_area == 'A' || $current_area == 'P') {

  • New code to change to (7 lines of code):
'c.rpos'
);

$search_condition = $join_tbl = array();

if ($current_area == 'A' || $current_area == 'P') {

The built-in patch/upgrade utility basically works in the same way.