Note: You are currently viewing documentation for Moodle 1.9. Up-to-date documentation for the latest stable version is available here: Patch.

Patch: Difference between revisions

From MoodleDocs
(Added wikipedia link)
No edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
[http://en.wikipedia.org/wiki/Patch_(Unix) Patch] is the unix program which alters one or more text files by following the instructions in a patch file. Diff is the unix program used to create the patches by comparing two similar files e.g. a file from a standard copy of Moodle and a copy of that file that a programmer has added some code to.
A patch, sometimes also called a diff, is a file that shows what changes have been made to a file, or group of files. They are a common way for developers to exchange changes to software. For practical instructions see:


The reason for using it is that some files in Moodle are very large, so it may be that two programmers are working on separate improvements which you wish to apply to your copy of Moodle, but this can't be done by just downloading two modified versions of the file as each one will only contain one set of changes. Patches insert new code at specific points and leave the rest of the file untouched, so you can apply many of them to the same file with no interference between them.
* [[Development:How_to_create_a_patch|How to create a patch]]
* [[Development:How_to_apply_a_patch|How to apply a patch]]


Most linux distributions come with Patch already installed, but you may need to install it using whatever method your distribution requires. Patch for windows can be downloaded from [http://gnuwin32.sourceforge.net/packages/patch.htm sourceforge].
For more information about the patch format, read on. Here is a simple sample patch file:


How to patch a file
<pre><nowiki>
Index: lang/en_utf8/quiz.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/quiz.php,v
retrieving revision 1.57.2.10
diff -u -r1.57.2.10 quiz.php
--- lang/en_utf8/quiz.php 29 May 2007 17:47:25 -0000 1.57.2.10
+++ lang/en_utf8/quiz.php 25 Jun 2007 12:58:34 -0000
@@ -252,7 +255,6 @@
$string['indivresp'] = 'Responses of Individuals to Each Item';
$string['info'] = 'Info';
$string['introduction'] = 'Introduction';
-$string['invalidcategory'] = 'Category ID is invalid';
$string['invalidnumericanswer'] = 'One of the answers you entered was not a valid number.';
$string['invalidnumerictolerance'] = 'One of the tolerances you entered was not a valid number.';
$string['invalidsource'] = 'The source is not accepted as valid.';
@@ -375,8 +377,10 @@
$string['questiontypesetupoptions'] = 'Setup options for question types:';
$string['quiz:attempt'] = 'Attempt quizzes';
$string['quiz:deleteattempts'] = 'Delete quiz attempts';
+$string['quiz:emailconfirmsubmission'] = 'Receive own quiz submission notification';
+$string['quiz:emailnotifysubmission'] = 'Receive student quiz submission notifications';
$string['quiz:grade'] = 'Grade quizzes manually';
-$string['quiz:ignoretimelimits'] = 'Ignores time limit on quizzes';
+$string['quiz:ignoretimelimits'] = 'Ignores time limit on quizs';
$string['quiz:manage'] = 'Manage quizzes';
$string['quiz:preview'] = 'Preview quizzes';
$string['quiz:view'] = 'View quiz information';
</nowiki></pre>


# download the patch
At the top it says which file is being affected. Changes to several files can be included in one patch. Lines added are shown with a '+', lines removed are shown with a '-', lines changed are shown as the old line being removed and the new one added.
# open it in a text editor and look for the line at the top which references a filename. If it says e.g. --- a/admin/roles/assign.php then put it in the main moodle directory, where the path starts from (ignoring the a). If it just says --- a/assign.php then it will need to go into /admin/roles/ or wherever.
 
# if you are using Windows, click Start->run then type cmd and press enter. If Liunx, open a terminal
Patch files are good because they only show the changed parts of the file. This has two advantages: it easy to understand the change; and if other parts of the same files change between the patch being made an being used, there is no problem, the patch will still apply.
# navigate to the directory that you put the file into
 
# type the following: patch -p0 < filename.patch
Note that there are several slight variants of the patch format. The example above is a 'unified' patch, which is now the standard.
 
==See also==
 
* [[Development:How_to_create_a_patch|How to create a patch]]
* [[Development:How_to_apply_a_patch|How to apply a patch]]
 
[[Category:Developer]]

Latest revision as of 03:31, 12 September 2008

A patch, sometimes also called a diff, is a file that shows what changes have been made to a file, or group of files. They are a common way for developers to exchange changes to software. For practical instructions see:

For more information about the patch format, read on. Here is a simple sample patch file:

Index: lang/en_utf8/quiz.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/quiz.php,v
retrieving revision 1.57.2.10
diff -u -r1.57.2.10 quiz.php
--- lang/en_utf8/quiz.php	29 May 2007 17:47:25 -0000	1.57.2.10
+++ lang/en_utf8/quiz.php	25 Jun 2007 12:58:34 -0000
@@ -252,7 +255,6 @@
 $string['indivresp'] = 'Responses of Individuals to Each Item';
 $string['info'] = 'Info';
 $string['introduction'] = 'Introduction';
-$string['invalidcategory'] = 'Category ID is invalid';
 $string['invalidnumericanswer'] = 'One of the answers you entered was not a valid number.';
 $string['invalidnumerictolerance'] = 'One of the tolerances you entered was not a valid number.';
 $string['invalidsource'] = 'The source is not accepted as valid.';
@@ -375,8 +377,10 @@
 $string['questiontypesetupoptions'] = 'Setup options for question types:';
 $string['quiz:attempt'] = 'Attempt quizzes';
 $string['quiz:deleteattempts'] = 'Delete quiz attempts';
+$string['quiz:emailconfirmsubmission'] = 'Receive own quiz submission notification';
+$string['quiz:emailnotifysubmission'] = 'Receive student quiz submission notifications';
 $string['quiz:grade'] = 'Grade quizzes manually';
-$string['quiz:ignoretimelimits'] = 'Ignores time limit on quizzes';
+$string['quiz:ignoretimelimits'] = 'Ignores time limit on quizs';
 $string['quiz:manage'] = 'Manage quizzes';
 $string['quiz:preview'] = 'Preview quizzes';
 $string['quiz:view'] = 'View quiz information';

At the top it says which file is being affected. Changes to several files can be included in one patch. Lines added are shown with a '+', lines removed are shown with a '-', lines changed are shown as the old line being removed and the new one added.

Patch files are good because they only show the changed parts of the file. This has two advantages: it easy to understand the change; and if other parts of the same files change between the patch being made an being used, there is no problem, the patch will still apply.

Note that there are several slight variants of the patch format. The example above is a 'unified' patch, which is now the standard.

See also