Patchfile howto
This page is for people who want to contribute to Deos.
Subversion uses patch files to store various changes. They are also the preferred method for sharing a proposed change with a co-worker or placing a proposed change in a PCR. This way, that change can be added later to a later version of a component where other changes have already been made.
For the purposes of this howto, I will make up two scenerios (I won't actually check the results into scm).
Creating a patch file
Let's say that I made a change to the compiler-settings.mk file for the kernel. I can create a patch file by using the command svn diff. When I do I get the following:
$ svn diff > compiler-settings.patch $ cat compiler-settings.patch Index: compiler-settings.mk =================================================================== --- compiler-settings.mk (revision 2213) +++ compiler-settings.mk (working copy) @@ -63,8 +63,7 @@ # switches for a cross-platfrom application (i.e. host platform != target platform) DEOS_COMMON:=-nostdinc -nostdinc++ -fno-builtin -Wall -W -fno-exceptions -DOVERRIDE_CPP_BOOLEAN_TYPE EXPORT_SWITCHES:=-DDEOSAPI_COMPILE -DDEOSAPI_DLL -DEOS_CPP_COMMON:=-Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -fno-rtti \ - -fcheck-new +DEOS_CPP_COMMON:=-Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -fno-rtti DEOS_CPP_RELEASE:= ifeq ($(HOST_PLATFORM),x86-cygwin)
The line --- compiler-settings.mk (revision 2213) is the baseline that the changes were made against. Note the '-' characters which will be referenced later in the howto. The line +++ compiler-settings.mk (working copy) is the version that has the proposed changes. What we are saying, is these are the changes necessary to go from rev 2213 to the current working copy.
In this case there are two changes, the lines that start with '-' in the first column will be removed, and the lines with '+' in the first column will be added (in the example it is a replacement).
Using a patch file
Now let's say that I sent this patch file to AL: and he wants to check the change in his environment before approving it. To do that he will use the svn patch command like this:
$ svn patch compiler-settings.patch patching file compiler-settings.mk $
At this point all of the suggested changes were merged into AL:'s kernel tree and he can try it out.
Diffing the repository
There is one other way you may need to create a patch and then apply it. Let's say that you made a change to an item and CCB or another maintainer wants to have it removed. In this case you need to be able to create a patch from what is in the repository and then apply it to a current working copy and check the changes in. This is how you would do that:
$ svn update # make sure my local copy is up to date $ svn diff -r 2207:2205 release-notes-template.txt > patchfile.txt
Note that in this case we wanted to go backwards in time and get patch file that would revert the change that was made to the release notes going from version 2207 to version 2205. Looking at this file is see:
$ cat release-notes.patch
Index: release-notes-template.txt
===================================================================
--- release-notes-template.txt (revision 2207)
+++ release-notes-template.txt (revision 2205)
@@ -137,8 +137,6 @@
!MAJOR!.!MINOR!.!DEBUG!
- - Fixed defect in excptapi.h. It now includes procapi.h.
-
- Add no-implement-inlines to compiler command line.
- Applied structural coverage changes to exception handling code.
In this case I apparently need to remove the lines that start with '-'. To apply this patch, I would use the patch command just as I did before and when I checked in the changes, the change would have been reverted.
Have fun with diff and patch.
Bugzilla patch viewer
Bugzilla has a patch file viewer that is pretty nice. When you create an attachment, select the "patch" option. Then you can view the attachment as a patch, like this example from PCR:3338.