How to diff two folders to multiple patch files

First, I tried asking the same on askubuntu and I'm not getting far there... http://askubuntu.com/questions/186114/how-to-diff-two-folders-to-multiple-patch-files/186121#comment231985_186121

So, i'll copy/paste here in hopes SO gives me a working solution...

I'm not much of a unix guy so I'll just go ahead and ask:

I have a following problem - two folders with plenty of subfolders. I need to diff them.

I tried this:

diff -drupN vanila_kernel_3.0.8 my_kernel_3.0.8 > kernel.patch

and that results in a 185mb file... and not really what I want.

I want the result of the diff to be many smaller patches, ideally one for every changed file with the contents of the change. That means I have t ochange the way I use diff, and I need to put it in some sort of a loop... So i tried running this little script

for file in original_308/*.*; do
    diff -dupN "$file" "my_308/${file##*/}" > "$file".patch
done

But it doesn't work :/

Ideally, I want to have a .patch file for every change, but having patches for files that changed in original would do just fine (as I could filter the newly added files and just copy them over)

Can someone provide me with a decent way to do this please?

UPDATE: I know there are 231 altered files between these folders and 4546 newly added files... I'm just interested in generating those 231 patches. I even have a file containing those 231 filenames so that can be used in a script as well.

I used this to generate the changelog

diff -qdr -x *.o -x *.cmd -x *.d original_308 my_308 | sed "s/^.* and \(.*\) differ/\1/" | sort > changes.txt

and that just prints the filenames that changed, trailed by "only in my_308" files... the 231 files are on the top of that file (the first 231 lines)

So let's make it clear - I want .patch files for source files. If the patches can end up in patches//file_name.c.patch that would be really great...

If you give me PERL scripts please tell me how to best use them since I do not understand that garbage. Please don't fail me SO. I need to get this thing ported, tested and running and I'm wasting time on unix commands and untangible scripts ffs.

Answers


you can grab <Learning Perl> book and learn it in a week, Perl is pretty cool, please don't call it garbage. Here is the shell script for generate patch

find ./original_308 -type f | while read file
do
  nfile="./my_308/${file#*original_308/}"
  if [ -f $nfile ]; then
    patchfile="./patch/${file#*original_308/}.patch"
    mkdir -p `dirname $patchfile`
    echo "checking $file $nfile"
    diff -dupN "$file" "$nfile" > "$patchfile" && rm "$patchfile"
  fi
done

diff xxx >patch && rm patch will only remove empty patch files.


Need Your Help

Is there a way to use normal ASCII characters (like a comma) as wxWidgets menu accelerators?

menu wxwidgets

I want a few menu entries that show accelerators that are normal keys, like the space-bar or comma key, but I don't want wxWidgets to make those accelerators itself (because then they can't be used

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.