[comp.os.minix] CDIFFs and PATCH explained and examplified

cs00chs@unccvax.UUCP (charles spell) (11/19/89)

It took me a while to put this information together without others directly
telling me so I decided to post this for the beginners. If you know how to use
diff(1) and patch(1), please review for syntax, comments and flames.

WHAT IS A CDIFF?

A cdiff is a file produced by:
	 diff -c <orig> <changed_orig> > <cdiff>

				-OR-	

     cdiff   <orig> <changed_orig> > <cdiff>

WHAT IS PATCH?

A program that produces a fixed file from an original and a cdiff. Usually:

     patch < <cdiff>

		  -OR-

     patch <orig> <cdiff>


EXAMPLE: (hypothetical)

prog1.c is a 500 line program that everyone on the net has. A bug was found
and only 10 lines needed to be added to fix it.

Now I dont want to re-send 500 lines that everyone else already has.
I just want to send the lines to add. If I send a cdiff, there is less chance
that someone could accidentally put the lines in the wrong place. So I

    cp prog1.c prog1.c.orig      #this is done before adding the 10 lines

and then add the 10 lines in prog1.c that fixed the bug. I re-test the fix
to make sure prog1.c works properly. Now I get the patch (cdiff) by issuing
the following command:

    diff -c prog1.c.orig prog1.c > prog1.c.cdif


Usually, sysIII sysV unix boxes do not have the -c option with diff(1).
There is a source program, diffc.c that produces diff -c output. This was
written for unix boxes that are deprived of the -c option. If I didn't have
diff with the -c option I would have used the following command:

    diffc prog1.c.orig prog1.c > prog1.c.cdif

Now I can insert lines at the top of prog1.c.cdif to explain the change and
explain whatever needed to prepare it for posting. If there was more than one
program to fix, I would shar everything together, for example:

shar prog1.c.cdif prog2.c.cdif > prog.shar

After you save my posting, you would delete all lines at the top so that you
would have prog1.c.cdif as it was right after I diff'ed it.

You would then type:

    patch < prog1.c.cdif

If that doesnt work you would type:

    patch prog1.c prog1.c.cdif

After this command, the original prog1.c would be saved as prog1.c.orig
and prog1.c would have the new lines in it.

The PROS of this method:

The changes to a program can be easily seen by examining the cdif file.
  (not always so with diff and other options (formats) that's why -c used).
Only the changes are sent over the network, reducing the load.
Patch is smart, it can make sure the changes are made without errors.
Patch will backup the original automatically, just in case.
Changes are useful only to people with the originals. (also a disadvantage)

The CONS:

It is assumed that the target audience has the original.
It is assumed that the target audience has diff(1) -c or cdiff(1).
It is assumed that the target audience has patch(1).
Only text files can be patched. (there are ways around this).

_____________________________________________________________________________
Signature?  Nahhhh...