[Python-Dev] Sourceforge FAQ

Thomas Wouters thomas@xs4all.net
Sun, 18 Mar 2001 00:26:45 +0100


On Sat, Mar 17, 2001 at 12:40:49AM -0500, Tim Peters wrote:

> >  3. My SF FAQ isn't there: how do I generate a diff that has a new file
> > as part of it?

> "diff -c" <wink -- but I couldn't make much sense of this question>.

What Paul means is that he's added a new file to his tree, and wants to send
in a patch that includes that file. Unfortunately, CVS can't do that :P You
have two choices:

- 'cvs add' the file, but don't commit. This is kinda lame since it requires
 commit access, and it creates the administrativia for the file already. I
 *think* that if you do this, only you can actually add the file (after the
 patch is accepted ;) but I'm not sure. After the cvs add, a cvs diff -c will
 show the file (as all +'es, obviously) even though it will complain to
 stderr about its ignorance about that specific file.

- Don't use cvs diff. Use real diff instead. Something like this:

  mv your tree asside, (can just mv your 'src' dir to 'src.mypatch' or such)
  cvs update -d,
  make distclean in your old tree,
  diff -crN --exclude=CVS src src.mypatch > mypatch.diff

 Scan your diff for bogus files, delete the sections by hand or if there are
 too many of them, add more --exclude options to your diff. I usually use
 '--exclude=".#*"' as well, and I forget what else.  By the way, for those
 who don't know it yet, an easy way to scan the patch is using 'diffstat'.

Note that to *apply* a patch like that (one with a new file), you need a
reasonably up-to-date GNU 'patch'.

I haven't added all this to the SF FAQ because, uhm, well, I consider them
lame hacks. I've long suspected there was a better way to do this, but I
haven't found it or even heard rumours about it yet. We should probably add
it to the FAQ anyway (just the 2nd option, though.)

Of course, there is a third way: write your own diff >;> It's not that hard,
really :) 

diff -crN ....
*** <name of file>      Thu Jan  1 01:00:00 1970
--- <name of file>      <timestamp of file>
***************
*** 0 ****
--- 1,<number of lines in file> ----
<file, each line prefixed by '+ '>

You can just insert this chunk (with an Index: line and some fake RCS cruft,
if you want -- patch doesn't use it anyway, IIRC) somewhere in your patch
file.

A couple of weeks back, while on a 10-hour nighttime spree to fix all our
SSH clients and daemons to openssh 2.5 where possible and a handpatched ssh1
where necessary, I found myself unconciously writing diffs instead of
editing source and re-diffing the files, because I apparently thought it was
faster (it was, too.) Scarily enough, I got all the linenumbers and such
correct, and patch didn't whine about them at all ;)

I haven't added all this to the SF FAQ because, uhm, well, I consider them
lame hacks. I've long suspected there was a better way to do this, but I
haven't found it or even heard rumours about it yet.

Sign-o-the-nerdy-times-I-guess-ly y'rs ;)
-- 
Thomas Wouters <thomas@xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!