Search This Blog

Tuesday, February 22, 2011

TOS Chapter 7

Chapter 7 of the Teaching Open Source book is about patches.  In short, patches involve running the diff command on a file that has been changed.

Exercise 7.2.2
The -u option to the diff command makes for a much more readable output, and it even includes some context (which isn't strictly necessary since "hunks" of code are labeled with line numbers.)  The diff command without the -u option is still useful, it's just not as easy to read.

In the initial, simplistic example, only one file was modified and patched.  A more comprehensive example followed which made a change to two files in a directory and a diff was applied recursively to the directories.  This captured the changes to all files within the directory, which will be much more useful when working with huge source code directories.

Both the individual file and the directory diff patch methods are not using an SCM.  Using an SCM to create a patch is almost identical, except, instead of using two different files/directories, the SCM compares changes in the current working copy against the most recent revision.  The latest HEAD code should always be used when making a patch, so that the development team can more easily integrate the patched changes.

Applying a patch is a simple matter.  It's similar to the shell redirect described in the initial diff section, only instead of redirecting the output of a command to a file, a file is redirected to the input of a command.  That command is, shockingly, patch.  Running patch from the directory in which to make changes seems easiest.  The option exists to run the command from root, but I don't fully understand the -p flags.  From the text it sounded like I could strip off x number of directories from the paths listed in the patch, but if I'm running the patch from the root directory, wouldn't those files then exist in the root directory?  I'll have to remember to ask about this in class.

I think I missed the point of Exercise 7.8.  Creating an empty file called foo, and then running diff on that new file against /dev/null resulted in no output from the diff.  I imagine that's because both files are empty and there's no difference between them.
So I asked about the exercise in class; turns out, the fonts on my screen look too similar to tell apart.  I was supposed to create an empty file called foo and put "bar" as the contents of the file.  This would have yielded some output from diff -u when run against /dev/null.

Exercise 7.9 was almost identical to the example for running diff on a single file from the very beginning of the chapter.  The only difference was the file was located at the end of a path, instead of in the working directory.  The patch file was formatted exactly the same.

Exercise 7.10 tells us to make a patch for our selected project.  We're steadily working on that, and I'm convinced we'll have this feature request completed "soon."

No comments:

Post a Comment