Hi.
How can I apply a *.diff or *.patch?
Is there any difference when applying *.diff AND *.patch?

I use Windows XP Pro, NOT Linux.
I tried to download Cygwin, but I have no clue what package I should install.

Thanks.

Comments

kbahey’s picture

http://drupal.org/diffandpatch

--
Drupal development and customization: 2bits.com
Personal: Baheyeldin.com

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba

Wai_Wai’s picture

Thanks although I knew the existence of this page.
I tried to download Cygwin, but I have no clue what package I should install. The help pages tell nothing about that.

sepeck’s picture

What you are doing has a learning curve for Windows folks (I am a Windows folk too) so you will need to experiment and test as not a lot of Windows folks have reported back.

I found these recently.
http://gnuwin32.sourceforge.net/

Go to their packages page
http://gnuwin32.sourceforge.net/packages.html
and download the diff and patch files. (Download some others too, lots of playing stuff there). THey seem to work just like the native *nix tools with the same commands and instructions.

-sp
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

sepeck’s picture

I just added the information to the handbook too.
http://drupal.org/node/32635

-sp
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

Wai_Wai’s picture

Thanks so much.
You are very helpful!

As to the documentation, there're some linking problems.

The article flow is supposed to be:
"Next" linkage
Diff on Windows --> Patching with Cygwin --> Gnuwin32 diff and patch
"Previous" linkage
Diff on Windows <-- Patching with Cygwin <-- Gnuwin32 diff and patch

The article flow is actually:
"Next" linkage
Diff on Windows --> Gnuwin32 diff and patch
"Previous" linkage
Diff on Windows <-- Patching with Cygwin <-- Gnuwin32 diff and patch

Menu is also broken (missing "Patching with Cygwin").

And some rework is preferred to merge similar articles/pages together.

Thanks!

jozef’s picture

to wai_wai and sepeck:
I prefer to use Cygwin because it is more "unixish" in my opinion. GnuWin32 has no shell, see http://gnuwin32.sourceforge.net/faq.html#How_do_I_run_shell_scripts
and I needed to run msgmerge in shell (look at http://drupal.org/node/11311 ) and Cygwin did it for me. Use Cygwin search to locate diff http://cygwin.com/cgi-bin2/package-grep.cgi?grep=diff, I think the diffutils package is the right one.

Wai_Wai’s picture

Hi.
I have questions regarding Cygwin.
I have opened a new section. See here:
http://drupal.org/node/32627#comment-57452
Thanks.

tesla.nicoli’s picture

I don't have a web host to try this on but it looks like it would work ok if you know php.

http://www.hivemindz.com/using_php_to_do_diff_and_patch_on_the_server

Wai_Wai’s picture

Thanks!
But I'm confused about its code.
It doesn't tell which are variables (that I need to replace with proper file names)

Here's what I understand, see if I'm correct:
1)

$cmd = 'diff -u old.txt new.txt>oldnew.patch  2>&1';
$output = shell_exec($cmd);
echo "$output";

old.txt = name of old file (eg abc.engine)
new.txt = name of new file (eg abc-1.engine)
oldnew.patch = name of the patch (eg abc-update.patch). the extension has to be *.patch

Is it true that it doesn't matter what names I use on these 3 files?
They don't need to follow some naming conventions (eg the names of 3 files have to carry the same name or it will not work properly), right?

2)

$cmd = 'patch < oldnew.patch  2>&1';
$output = shell_exec($cmd);
echo "$output";

oldnew.patch = name of the patch (eg abc-update.patch). the extension has to be *.patch

The strange thing is it seems I don't need to specify which file to patch on. How come it knows which file to patch on?

Does "the name of the patch (ie oldnew.patch)" and "the name of the file I wish to patch on (ie old.txt)" have to be the same?

Thanks.

tesla.nicoli’s picture

I believe the patch contains the information on the files that are going to be patched in first two lines. So it should work regardless of the names.


--- old.txt    2005-09-05 17:12:38.000000000 -0400
+++ new.txt    2005-09-05 17:12:38.000000000 -0400
@@ -1 +1,3 @@
-thisis some text
//No newline at end of file
+thisis some text that was created afterward
+
+by me
tesla.nicoli’s picture

$output is the only variable. The rest is hardcoded so you have change it by hand or modify the code to use variables.

Wai_Wai’s picture

So which names/codes do I need to change?

tesla.nicoli’s picture

What you have in your previous post is the right way. But is not clear by the example how to do this.

Step by step - Put

old.module

in the directory

with

some.patch or some.diff (some patches are have *.diff ext).

When you run the some.patch file then old.module should be overwritten with the new information.

(I find this kind of dangerous becaose things might not work so I always take the patch file and change it so that it outputs a new file or do a new file out put on the command line.)


===================================================================
RCS file: /cvs/drupal/drupal/includes/menu.inc,v
retrieving revision 1.80
diff -u -r1.80 menu.inc
--- includes/menu.inc	24 Apr 2005 16:34:32 -0000	1.80
+++ includes/menu.inc	1 Jun 2005 00:39:44 -0000

Wai_Wai’s picture

I get stuck at Cygwin.

From http://drupal.org/node/23164:

4. Run cygwin. In the explorer, you will see that a unix-like directory-structure has been created inside the installation directory. when you run the program for the first time, a user-directory is created below the "home"-directory. This will be your default directory when working with cygwin - the easiest way is to put the original file & the patch there (so you don't have to enter a lengthy path to your commands).

I installed it in C:\Cygwin
I tried to run Cygwin once.
The following message shows:

Your group is currently...
...
...
Note that the -d switch is necessary for domain users.
user-name@user-group
$

However I can't see there's any "home" folder nor "user" folder created in my "Cygwin" directory.
The most similar one is "usr" folder.

Anyway my question is:
- where is the default folder (so I can put the original file & the patch there and type the "patch" code)?

Thanks.

tesla.nicoli’s picture

I don't use cygwin. The school computers do not like it trying to write to the c:/ . Something about how they are configured. I can't get cygwin to sit on the the drive I am allowed to write on.

jozef’s picture

http://cygwin.com/cygwin-ug-net/cygwin-ug-net.html

OK, my answer
1. there is a "home" in my installation; c:\cygwin\home\
2. you can mkdir a "drupal" folder there and use diff, patch ...
3. probably the easiest way is to install and use cygwin with your Windows Administrator account.

tesla.nicoli’s picture

I can not use cygwin because when I applied for the system (windows) account I used a space in my name. The scripts they use are very literal. So the install directory I would be working from is set at that name. I have tried to get this changed but have not had any luck so far.