9/04/2014

How to apply a patch file?

In a mailing list, I saw someone issued a patch to a program. Out of curiosity, I downloaded the patch. But I had no idea about how to use the patch. I checked the content of the patch file and found only some lines were there. It looks like this:

1537,1542c1537,1543
<         version_match = re.search(r'Version:\s+(\d+)\.(\d+).(\d+)([a-zA-Z]?)', samtools_out)
<         samtools_version_arr = [int(version_match.group(x)) for x in [1,2,3]]
<         if version_match.group(4):
<             samtools_version_arr.append(version_match.group(4))
<         else:
<             samtools_version_arr.append(0)
---
>         version_match = re.search(r'Version:\s+(\d+)\.(\d+)\.?(\d*)([a-zA-Z]?)', samtools_out)
>         samtools_version_arr = [int(version_match.group(x)) for x in [1,2]]
>         for possibly_blank_index in [3, 4]:
>             if version_match.group(possibly_blank_index):
>                 samtools_version_arr.append(version_match.group(possibly_blank_index))
>             else:
>                 samtools_version_arr.append(0)
1559c1560
<     elif  samtools_version_arr[1] < 1 or samtools_version_arr[2] < 7:
---
>     elif samtools_version_arr[0] < 1 and (samtools_version_arr[1] < 1 or samtools_version_arr[2] < 7):
Then I wonder how this file should be used. I googled "how to implement a patch" and soon got the answer. There is a Linux command "patch" to do all the work. In addition, "diff" could be used to generate the patch file. I also got several links that provide very useful infomation, listed as below for reference.

HowTo Apply a Patch File To My Linux / UNIX Source Code
http://www.cyberciti.biz/faq/appy-patch-file-using-patch-command/
This provides a good example showing the full process of patching. You can also reverse the patch using -R option.

How to apply a patch to a contributed module - Beginner's version (Windows)
https://www.drupal.org/node/620014

Applying patches on Mac OS X
https://www.drupal.org/node/60818

No comments:

Post a Comment