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

From X-Cart 4 Classic
Jump to: navigation, search
Line 1: Line 1:
1. Open the diff file in a text editor;
+
==What is diff file?==
  
: Diff files are divided into parts ("hunks"). Each "hunk" starts with a line like this:
+
Diff files consist of [http://en.wikipedia.org/wiki/Hunk "hunks"]. Each "hunk" starts with a line like this:
  
<pre>@@ -67,7 +67,10 @@</pre>
+
<pre>@@ -942,8 +940,7 @@</pre>
  
: where:
+
where:
  
:* 67 - indicates the number of the line of the code where the changes start
+
* 942 - indicates the number of the first line in the original code (before applying patch)
:* 7 - indicates the number of the lines in the hunk before patch application
+
* 8 - indicates the number of lines in the original code (before patch application)
:* 10 - indicates the number of the lines in the hunk after 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 including lines 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.
+
Then follows the file code including lines 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.
  
: Under 'Index:' you will find the name of the file that you should patch, for example:
+
Under 'Index:' you will find the name of the file that you should patch, for example:
  
<pre>Index: admin/category_modify.php</pre>
+
<pre>Index: include/func/func.category.php</pre>
  
: Here is an example of a complete diff file:
+
==Example of diff file==
  
<pre>Index: admin/category_modify.php
+
<pre>Index: include/func/func.category.php
@@ -67,7 +67,10 @@
+
@@ -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') {
  
if ($shop_language == $config['default_admin_language']) {
+
</pre>
- 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;
+
==General instructions==
</pre>
 
  
2. Edit the file (in our example, admin/category_modify.php):
+
1. Open the diff file in a text editor;
  
 +
2. Edit the file (in our example, include/func/func.category.php):
 
:* Find the lines, which are marked by "-" in the text of the patch, and remove them.
 
:* Find the lines, which are marked by "-" in the text of the patch, and remove them.
 
:* Insert the lines, which are marked by "+" in the text of the patch.
 
:* Insert the lines, which are marked by "+" in the text of the patch.
 +
 +
In our example, the original code (before the patch application) would look like:
 +
 +
<pre>
 +
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:
 +
</pre>
 +
 +
Total lines: 9 and 8 in each hunk correspondingly.
 +
 +
The changed code (after the patch application) 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>
 +
 +
Total lines: 7 and 7 in each hunk correspondingly.
 +
 +
[[Category:X-Cart user manual]]
  
 
[[Category:X-Cart user manual]]
 
[[Category:X-Cart user manual]]

Revision as of 09:36, 20 May 2011

What is diff file?

Diff files consist of "hunks". Each "hunk" starts with a line like this:

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

where:

  • 942 - indicates the number of the first line in the original code (before applying patch)
  • 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 including lines 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.

Under 'Index:' you will find the name of the file that you should patch, for example:

Index: include/func/func.category.php

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, which are marked by "-" in the text of the patch, and remove them.
  • Insert the lines, which are marked by "+" in the text of the patch.

In our example, the original code (before the patch application) 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 the patch application) 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.