LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-14-2012, 04:14 PM   #1
mateor
LQ Newbie
 
Registered: Apr 2012
Posts: 5

Rep: Reputation: Disabled
Noob trouble applying patch from diff


okay, I am real new to computing in general, and brand new to linux, so bear with me. If you think the proper response is to point me back to the man pages, well, so be it...

I am attempting to create a patch made from a diff of two directories. I made the patchfile by running
Code:
diff -Npru old new < file.patch
That successfully produced a file.patch. My trouble is testing the patch. I am trying a --dry-run on old, and all hunks fail, over and over. I've tried various permutations of the below.

Code:
patch --dry-run old < file.patch
with various -p(n), and I tried -l in case the patch was whitespace damaged(?).

The header inside my patch includes:

diff -Npru
---foo/foo/foo/old/bar/bar/bar/bar/file
+++foo/foo/foo/new/bar/bar/bar/bar/file

I have the patch and old in the same directory and have tried applying the patch from inside of old and all the way to the innermost directory which seems to contain all the files with changes.

I am using ubuntu 11.10. Thanks for any advice.

Last edited by mateor; 04-14-2012 at 11:44 PM. Reason: added code tags
 
Old 04-14-2012, 08:35 PM   #2
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Stretch
Posts: 612

Rep: Reputation: 125Reputation: 125
Yet again, please use code tags, it preserves formatting and makes it easier to read.
Code:
diff -Npru old new < file.patch
I'm guessing here that the '<' re-direction is a typo.

Have you tried the -d option:
Code:
patch --dry-run -d /foo/foo/foo/old/bar/bar/bar/bar < file.patch
If I understand it correctly, having file.patch in /foo/foo/foo/old will try to patch <file> within directory <old>.

If you're patching dir <old> create your patch relative to <old>:

Code:
diff -Npru /foo/foo/foo/old /foo/foo/foo/new > file.patch
I've done some basic diff'ing and patching, so hope that works.
 
1 members found this post helpful.
Old 04-14-2012, 10:40 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Note the definition of "-p" in the manpage. It is used to resolve (relative) path mismatch in the current location.
 
1 members found this post helpful.
Old 04-15-2012, 12:59 AM   #4
mateor
LQ Newbie
 
Registered: Apr 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thanks for the responses. I have added code tags, sorry.

I had originally moved a copy of the directory I wanted to patch to a new location for testing purposes. I think I finally somewhat understand the -p option. I still was having trouble, so since all I wanted was a dry-run, I went to the original directory I made the patch from. This directory was five directories up from the one I wanted to patch.
So if

dir=directory patch was made from
target=directory I wanted diff-ed
Code:
dir/dir2/dir3/dir4/targetdir/dir6/dir7/dir8/dir8/filestopatch
My patch has this header, and as do the following hunks, with various file names.
Code:
diff -Npru dir2/dir3/dir4/target/dir6/dir7/dir8/dir9/files
So if I run from within dir
Code:
patch --dry-run /dir2 > file.patch
It no longer fails, just a blinking cursor. I have waited over 45 mins, but no change

I am running the patch file from the same directory it was created from on the same file that was diffed. I don't think I need any -p for that, do I? I've tried -p1 as well. Shouldn't it say hunks successful or something, or am I a real dummy and it just takes FOREVER?
There are like 3500 changes. Maybe I am just not being patient enough?

Last edited by mateor; 04-15-2012 at 01:04 AM. Reason: pasted old info.
 
Old 04-15-2012, 10:57 AM   #5
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Stretch
Posts: 612

Rep: Reputation: 125Reputation: 125
Please have a look at some BASH tutorial on re-direction.
Code:
command > file
means send the output of 'command' to 'file'
Code:
command < file
means use the contents of 'file' as the input to 'command'.

So to create a patchfile:
Code:
diff options oldfile newfile > file.patch
To apply the patch:
Code:
patch options < file.patch
Please take note of the re-direction symbols.

If you are patching in a non-standard way, ie: if the directory levels are different from oldfile and newfile, you can still patch thus:
Code:
patch --dry-run -d /path/to/file/to/patch -i /path/to/patchfile
This assumes the files to patch are all in the same directory.

You should take a careful look at the -p option in the manpages.
 
1 members found this post helpful.
Old 04-16-2012, 12:17 AM   #6
mateor
LQ Newbie
 
Registered: Apr 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
okay, thanks for the pointers.

When I run the above command, all it returns is a $, with no output. I had gotten that before, likely when I had the redirection issue reversed. The first time I posted the above, I was asking about just this issue. I changed it to what it was because at least it looked like it was doing something.

I thought that --dry-run would produce some output. When I add -verbose, it just prints the patch license. Was that a successful dry-run? And if so, how do I check to make sure the changes were correct?
 
Old 04-16-2012, 01:01 AM   #7
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Stretch
Posts: 612

Rep: Reputation: 125Reputation: 125
Using the --dry-run option does everything except applying the patch. Even with this option it should give at least a'patching file <file>' message.

Please post the exact commands you used for diff and patch, including the re-directions to the patchfile.
 
Old 04-16-2012, 09:56 PM   #8
mateor
LQ Newbie
 
Registered: Apr 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
hey towheedm, thanks so much for the patience and attention. I know I have made some rookie mistakes that can't have made it easy.

Okay, I went back through my command history and re-created the commands. Now these were the exact commands I used before, I just pulled them up with the arrow up key. Anyway, the results were different this time. I got an error message suggesting I may need to use the -p command and prompt about which file to patch.Maybe I had somehow damaged my old patch file.

I entered in the file location, but maybe I am going a level too high or too low. I made a pastebin of the commands and output.

http://pastebin.com/kCLYcjab

Let me know if more info is necessary. Thanks again!
 
Old 04-16-2012, 11:12 PM   #9
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Stretch
Posts: 612

Rep: Reputation: 125Reputation: 125
It would be nice if you pasted that in code tags. Again it makes it easier to read, no need to include the prompt. That being said (again).

You are patching with the command:
Code:
patch --dry-run -d ~/android/pdroidwork/Diff-tests/maguro/system-stock/framework/services/classout -i ~/android/pdroidwork/Diff-tests/maguro/maguro-services-pdroid.patch
You have specified to change to directory
Code:
~/android/pdroidwork/Diff-tests/maguro/system-stock/framework/services/classout
Your old file is:
Code:
~/android/pdroidwork/Diff-tests/maguro/system-stock/framework/services/classout/com/android/server/am/ActivityManagerService$10.smali
Your new file is:
Code:
~/android/pdroidwork/Diff-tests/maguro/system/framework/services/classout/com/android/server/am/ActivityManagerService$10.smali
Your patchfile is
Code:
~/android/pdroidwork/Diff-tests/maguro/maguro-services-pdroid.patch
Therefore your patch command should be:
Code:
patch --dry-run -d ~/android/pdroidwork/Diff-tests/maguro/system-stock/framework/services/classout/com/android/server/am -i ~/android/pdroidwork/Diff-tests/maguro/maguro-services-pdroid.patch
If your PWD is
Code:
~/android/pdroidwork/Diff-tests/maguro
Then you should be able to do:
Code:
patch -p1 < maguro-services-pdroid.patch
Of utmost importance:
The '$' character is a BASH meta-character. You have a meta-character in your filename (ActivityManagerService$10.smali). It must be escaped with the '\' character. I'm not sure how (if at all) this would affect the patch. Personally, I keep away from using meta-characters in my filenames.

Last edited by towheedm; 04-16-2012 at 11:19 PM.
 
1 members found this post helpful.
Old 04-19-2012, 11:19 PM   #10
mateor
LQ Newbie
 
Registered: Apr 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
Sorry I have taken so long to reply, I had to go out of town and was away from my files.

One thing I guess I didn't make clear is that the files I diffed to make the patch were directories. Many of those subfolders are within the original directory.

I diffed two different directories that were both titled classout.

But anyway, thanks for the help! I was able to use the commands you passed me to have a successful dry-run. This is what ended up working for me, from within

Working Directory
Code:
~/android/pdroidwork/Diff-tests/maguro
Code:
patch --dry-run -p4 -d  ~/android/pdroidwork/Diff-tests/maguro/system-stock/framework/services/classout/ -i ~/android/pdroidwork/Diff-tests/maguro/maguro-services-pdroid.patch
Thanks for your time and patience. I put the above in code tags, just for you.
 
Old 04-19-2012, 11:32 PM   #11
towheedm
Member
 
Registered: Sep 2011
Location: Trinidad & Tobago
Distribution: Debian Stretch
Posts: 612

Rep: Reputation: 125Reputation: 125
Quote:
I put the above in code tags, just for you


In the future it will be simpler if the root directory of the diff'ed files is the only one with a different name. Eg:

Original dir structure
Code:
dir1/dir2/file1    # Original file1
dir1/dir2/dir3/file2    # Original file2
dir1/dir2/dir3/file3    # Original file2
Directory structure with patched file:
Code:
dir1-new/dir2/file1   # Patched file1
dir1-new/dir2/dir3/file2    # Patched file2
dir1-new/dir2/dir3/file3    # Patched file3
The create the patchfile:
Code:
diff options dir1 dir1-new > patchfile
Apply the patch:
Code:
patch -p1 < patchfile
Glad it worked out eventually.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Having trouble applying kernel patch. sidholland Red Hat 5 04-05-2008 05:37 PM
patch -p1 x.diff but no patch command!? pyenos Linux - Hardware 1 03-04-2005 03:10 PM
applying patch? alaios Linux - General 1 11-29-2004 10:41 AM
applying a patch darthczyz Linux - Newbie 2 05-07-2004 08:44 AM
stupid newbie question-applying a cvs diff jensend Linux - General 4 01-26-2003 01:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration