Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Don't ask to ask, just ask
 
PerlMonks  

submitting a patch for a directory

by nglenn (Beadle)
on Aug 16, 2012 at 13:37 UTC ( #987768=perlquestion: print w/ replies, xml ) Need Help??
nglenn has asked for the wisdom of the Perl Monks concerning the following question:

Last night I submitted my first patch (woohoo!). I made a change to both a PM file and a test file, so I used diff to generate a patch for the entire directory: diff -urd oldDir newDir

When I tried to apply the patch to the code before I submitted it, however, I was having trouble figuring out the correct patch command. Patch would tell me that it couldn't find the right file to patch, or would just crash (apparently the MinGW version isn't very stable). Can anyone give me a pointer on submitting patches for whole distributions? Is it normal, rather, to make a patch file for each changed file and submit all of them? If so, what is the quickest way to create and test a patch for several files?

Comment on submitting a patch for a directory
Select or Download Code
Re: submitting a patch for a directory
by aitap (Chaplain) on Aug 16, 2012 at 14:05 UTC
    To apply this patch you need to cd to the directory to be patched and run: patch -p1 < .../.../your/patch/file. -p1 flag means "ignore one directory name from the beginning of the file paths in the patch", so file to be patched will be found and the resulting file will have the same name.
    Sorry if my advice was wrong.
Re: submitting a patch for a directory
by daxim (Chaplain) on Aug 16, 2012 at 14:21 UTC
    I was having trouble figuring out the correct patch command
    Generally, patch -p0 < /tmp/the.patch suffices.
    diff -urd oldDir newDir > /tmp/the.patch head -n 1 /tmp/the.patch # directory should show as relative path, # e.g. oldDir/foo/bar/quux.pl cd oldDir/.. # move above the directory to patch # to ensure we are in the correct position mv newDir newDir.disabled # it must not interfere with the # following test application of the patch patch -p0 < /tmp/the.patch mv newDir.disabled newDir # restore
    submitting patches for whole distributions
    Learn git, this will be the single most useful tool for contributing patches to Perl projects.
    Is it normal, rather, to make a patch file for each changed file and submit all of them?
    No, that's abnormal. Your usage of diff -urd was customary, i.e. make one patch each containing the all changes for one feature or bugfix across all files.

      The module I contributed to didn't use git. Is CPAN being ported to a git repository?

        No, it is up to the individual module owner to decide which, if any, version control system he or she will use. (The gitpan link submitted by daxim is not "official" and should be viewed as something to fork from to start your repository, if you decide to use github).

        I submitted a patch last year to a CPAN member whose code resides on sourceforge, and I'm sure there are coders out there who don't use version control systems at all beyond what CPAN/BackPAN provide.

      Not just git; any DVCS that can quickly be applied to an existing source tree will do. Try Bazaar, Mercurial. I'm personally using Bazaar and find it a joy to use. (Of course, if the project has a git/bzr/hg repository, that tool will be the most convenient.)

Re: submitting a patch for a directory (mini diff/patch tutorial)
by Anonymous Monk on Aug 16, 2012 at 16:26 UTC

    The situation ( file/directory tree )

    Foo is the original directory (CGI.pm-3.59)

    Foo-old is the backup pristine copy (CGI.pm-3.59-old)

    Foo-new is thing you've edited that you generate the patch from (CGI.pm-3.59-new)

    Creating a new patch ( Foo-new.patch, CGI.pm-3.59-new.patch )

    $ diff -Npurd Foo-old Foo-new > Foo-new.patch

    What the switches mean

    • -N => --new-file Treat absent files as empty.
    • -p => --show-c-function Show which C function each change is in.
    • -u => -U NUM --unified=NUM Output NUM (default 3) lines of unified context.
    • -r => --recursive Recursively compare any subdirectories found.
    • -d => --minimal Try hard to find a smaller set of changes.

    NOTE: If you're making a patch from a directory like CGI.pm-3.59, where you've used perl Makefile.PL && make, esp if using -N, you should clean up before making a patch, you should make realclean

    What a patch looks like

    Applying your new patch to Foo (CGI.pm-3.59), what the recipient of that patch would do, is first change working directory, then call patch

    $ cd Foo

    $ patch -p1 -i../Foo-new.patch

    -p1 means ignore the first path part, ignore the bold parts

    --- Foo-old/two.txt 1969-12-31 16:00:00.000000000 -0800

    +++ Foo-new/two.txt 2012-08-16 08:19:25.500000000 -0700

    It also means don't create a Foo-new directory :)

    If you used -p0 (ignore no path parts) the patching would fail in two ways, it wouldn't find one.txt, and it would create a Foo-new directory

    For best patching experience

    Always use relative paths for diff -Npurd diffolddir newdir

    Always use the p1 or p0 option, otherwise patch will ignore all directories/patch the wrong file

     

    To re-create my original situation, to create files and directories out of a patch, first produce the patch

    diff -Npurd emptyDir tmpFoo > tmpFoo.patch

    The new patch tmpFoo.patch looks like

    Then apply the patch in your new working directory tmp2Foo

    Oh noes, a mistake! I forgot to include the -p1 switch, and no directories were created! Trying again with -p1

    Hooray! Hmm, I'll try p0 in the same directory

    Whoa, that worked also and it didn't interfere :) but I don't really need that extra tmpFoo, now to get rid of it without rm -rfv -- from the same working directory

    -Reversing a patch (just add -R to the command you used to apply the patch)

     

    See also http://perldoc.perl.org/5.14.0/perlhack.html#Patching, http://perldoc.perl.org/5.10.0/perlhack.html#Patching

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://987768]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2014-04-18 11:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (466 votes), past polls