Applying a patch manually

Last modified: August 16, 2009 - 12:12

You can use a patch program to apply a patch, but you don't need to. Doing it manually is perfectly ok for smaller patches, and gives you a better idea of what's going on in your code.

As said in the main article, don't patch your live site directly! Instead, patch your test site, test it, then upload the changes.

Example

The given patch could begin with something like this,

Index: modules/system/system.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v
retrieving revision 1.63.2.8
diff -u -p -r1.63.2.8 system.admin.inc
--- modules/system/system.admin.inc 9 Jun 2009 10:58:09 -0000 1.63.2.8
+++ modules/system/system.admin.inc 16 Jul 2009 20:06:05 -0000

This tells you which file you need to edit: modules/system/system.admin.inc.

@@ -618,10 +618,6 @@ function _system_is_incompatible(&$incom
  *   The form array.
  */
function system_modules($form_state = array()) {
-  drupal_rebuild_theme_registry();
-  node_types_rebuild();
-  menu_rebuild();
-  cache_clear_all('schema', 'cache');
   // Get current list of modules.
   $files = module_rebuild_cache();

Here is the first snippet that you need to change. 618 must be the line number. "_system_is_incompatible" must be a function name.

  • Lines beginning with "-" are deleted.
  • Lines beginning with "+" are added (without the "+", of course).
  • Lines beginning with nothing remain as they are. Their only purpose is to give you an idea where you are in the code.

@@ -933,6 +929,10 @@ function system_modules_submit($form, &$
     drupal_set_message(t('The configuration options have been saved.'));
   }

+  drupal_rebuild_theme_registry();
+  node_types_rebuild();
+  menu_rebuild();
+  cache_clear_all('schema', 'cache');
   drupal_clear_css_cache();
   drupal_clear_js_cache();

Same procedure here.

Please note: If you want to be able to revert the patch with an automated tool at a later time, you should be careful that you don't insert additional linebreaks or comments.

On the other hand, you might want to mark the modifications with comments, to find them later on.

Finding modified code

If your code is checked out from CVS, you can use CVS to view the modifications.

Otherwise, you can download a clean copy of Drupal + contributed modules into a separate folder, and use a diff tool like WinMerge to compare the clean download with your modified code.

 
 

Drupal is a registered trademark of Dries Buytaert.