Diff'n'Patch

Creating a Patch

This section describes how to create a patch for the uClinux source distribution. This is just a general explanation of how to do this and is not specific to the Game Boy. I just thought it would be helpful to explain this, because quite some things can be done wrong. Here is how I set up the initial local repository for my work (Note that you will need a CVS system set up appropriately for this to work. If you don't have or don't want a repository there may be other methods more useful for your situation.):


$ tar xzf uClinux-dist-20030909.tar.gz
$ cd uClinux-dist
$ cvs import -ko -d -I ! -m "Initial import of uClinux-dist-20030909" uclgba/uClinux-dist UCL_DIST UCL_20030909

			

The CVS import is a bit complicated, but necessary for creating a patch later:

  • Keyword substitution has to be prohibited in order to prevent CVS from changing the keywords in the distribution sources, which actually belong to the versioning system of uClinux, and not to us. This is done by supplying the -k option of the cvs command with the o (omit) flag.

  • The timestamp of the uClinux distribution is used for the date specification of the CVS import. This is not strictly necessary for us, because we are going to identify versions on a tag basis anyways, but it is simply nice to have the correct dates. This is accomplished by providing the -d option.

  • The import must not ignore any files. There are some files, especially the net/core directory, in the distribution which would be ignored by default. The ignore option passed with an exclamation mark (-I !) tells CVS not to ignore any files at all.

  • As is obligatory for the import command, the vendor and release tags are supplied. These tags can be used to identify the release, on which the changes are based. CVS is even capable of merging these changes with a new release of the vendor sources. This could be used to update the repository to the 20040218 or any future distribution of uClinux. For additional information see the "Tracking third-party sources" section of the CVS info manual.

After a successful import of the new files, CVS exits after printing the following message:

No conflicts created by this import
			

Consequently, a patch can simply be created by issuing the following command from inside a working copy:


$ cvs diff -u -r UCL_20030909 > mychanges_`date +%F`.patch

			

Applying a Patch

To apply a patch you will first need the source files the patch is based on. For the patch created in the example above you would first unpack the uClinux-dist-20030909 distribution and then issue the following command:


$ tar xzf uClinux-dist-20030909.tar.gz
$ cd uClinux-dist
$ patch -p1 < uclgba_2004-03-14.patch

			

Naturally, you will have to change the path to and the name of the patch appropriately.

The patch command takes an option -p (short for --strip), which requires an argument to specify the number of leading directories that should be stripped from each file name found in the patch. In our case the CVS diff command prepends the fictitious directory names a and b in order to distinguish the files from the old and the new revision, because the filename path is, of course, always the same. (This does not always seem to be true? I just created a patch in unified format using CVS and it didn't prepend anything to the pathname. Anyways, you will simply have to look at the pathnames to figure out how many directory levels to strip.)