Home » Projekte » Veraltete Projekte » Patcher

Patcher

Download 

Concept 

Patcher is a perl script which I use for managing patches. It's quite powerful, easy to use, and fast.

Patcher keeps track of which files you change. It then can generate patches from your changes, no need for you to handle the diff tool manually.

You can have more than one record of file changes, we call this a patch. A patch is something that the patch(1) command can apply.

The patches can be stacked in series, they define the order they have to applied. Patcher keeps series information as well as information which patches have been applied and which not.

Description 

Later we will have a walk-through, but let me first explain the basic operation modes of patcher:

Editing files 

When you call patcher with a filename, patch will make a backup of this file (if the file exists). Now you can create or change the file. Later you can ask patcher to create a unified diff with all your changes.

Creating unified diffs 

Just call "patcher -r" and you will get a unified diff of all your additions, modification and deletions. The diff will be stored in ".patches/<patchname>.patch". It is in a form that allows direct application via patch(1) or, of course, via "patcher -i".

Whenever you do "patcher -r" your ".patches/<patchname>.patch" file gets refreshed.

Back out a patch 

To revoke your changes and go to the previous version, just enter "patcher -b". Patcher will make sure that you don't loose your changes by asking you to create a diff if something has changed since the last refresh. You may use -f (or --force) patcher to go back anyway.

You can back out more than one patch by either specifying a number a patch name after -b.

Re-Apply a patch 

With "patcher -n <patchname>" you can apply an already existing managed patch. A managed patch is a patch that already is stored in the ".patches" directory and is mentioned in the ".patches/series" file. Patcher tests if the patch would apply without problem and applies it. If the patch would be rejected, you can use "-f" (or "--force") to apply the patch anyway.

You can apply more than one patch by either specifying a number a patch name after -a.

Importing external patches 

Sometimes you have an external patch. That's the opposite of a managed patch, the patch is not stored in the .patches directory. By importing it, it will become a managed patch.

Import the patch simply with "-i <filename>". You can use "-p <num>" to specify the directory level, similar to the "-p<num>" option of patch(1). But please keep in mind that we need a space between "-p" and the number.

Normally only clean patches will be imported. To import a patch that creates rejects use "-f" (or "--force"). You'll see a list of files where the patch did not apply cleanly, fix the problems manually.

Later you can use "patcher -r" to create a clean patch.

Walk-through 

Let's start. Go into "/usr/src/linux" (or wherever). We will first chang some files:

$ patcher -n my-patch kernel/sched.c

OK, patcher copied "kernel/sched.c" to "kernel/sched.c~my-patch" for you, the program has also done some magic in the ".patches" directory, which won't be of interest to us now.

$ edit kernel/sched.c

Now we're ready to document the patch, We create a text file for this and refresh the patch:

$ edit .patches/my-patch.txt

Generate a patch:

$ patcher -r

The "patcher -r" generates ".patches/my-patch.patch". Take a look at this file. Now we remove our change to "sched.c" by going backwards:

$ patcher -b

Display the status of all patches:

$ patcher -s

Now let's add another file to "my-patch". First we re-apply the patch:

$ patcher -a

Now edit a second file:

$ patcher kernel/printk.c

Note that here we gave patcher a single argument. Without any other command line options. This tells patcher to add another file to the current patch. We refresh "my-patch":

$ patcher -r

And create a second patch:

$ patcher -n my-second-patch kernel/sched.c

Here we have a filename in the command line for patcher, so we again edit the file. But now we specified a patch name with -n. This told patcher to create a new patch. Now patcher manages two patches, "my-patch" and "my-second-patch". Change something in "kernel/sched.c".

Now generate the "my-second-patch", as usual with the refresh command:

$ patcher -r

Take a look in ".patches/my-second-patch.patch".

Also note that "my-second-patch.patch" has been added to the series file. Whenever you manually begin a patch, it will automatically be put into the series file.

In this way, the whole thing is stack-able. If you have four patches applied, say "patch-1", "patch-2", "patch-3" and "patch-4", and if "patch-2" and "patch-4" both touch "kernel/sched.c" then you will have:

"`kernel/sched.c~patch-2`" Original copy, before "`patch-2`"
"`kernel/sched.c~patch-4`" Copy before "`patch-4`". Contains changes from "`patch-2`"
"`kernel/sched.c`" Current working copy. Contains changes from "`patch-4`"

This means that your diff headers contain "~patch-name" in them, which is convenient documentation.

To end our tour, we remove both patches:

$ patcher -b
$ patcher -b

That's pretty much it, really.