 |
linux howto - fabio de lorenzo personal informations and experiences kernel modules and software
|
| View previous topic :: View next topic |
| Author |
Message |
root Site Admin
Joined: 27 Apr 2004 Posts: 156
|
Posted: Wed Jan 10, 2007 7:33 pm Post subject: Create patches |
|
|
Diff can be found on most UNIX systems and is included in the packages UnxUtils and Cygwin for use on Windows.
Although diff can output in diverse formats, the easiest to read is the unified format; simply use the -u switch to generate unified output.
diff -u old.php new.php > file.patch
Note: the symbol > will redirect the output to the file file.patch
Because patch readability is important for the review process it's best to add another switch: -p. This switch shows the function closest to the difference, making it easy to see what function changed. (alternately you can use the flag -F^function or in abbreviated form -F^f)
diff -up old.php new.php > file.patch
When you've modified multiple files in the source tree, use diffs ability to compare directories. Add the -r switch to instruct diff to recurse (sub)directories and add the -N switch to account for new or deleted files:
diff -urNp old_directory new_directory > file.patch
---- from :: http://drupal.org/diffandpatch --- |
|
| Back to top |
|
 |
root Site Admin
Joined: 27 Apr 2004 Posts: 156
|
Posted: Thu Jul 31, 2008 8:04 pm Post subject: Unified format |
|
|
Unified format
The unified format (or unidiff) inherits the technical improvements made by the context format, but produces a smaller diff with old and new text presented immediately adjacent. Unified format is usually invoked using the "-u" command line option. This output is often used as input to the patch program. Many projects specifically request that "diffs" be submitted in the unified format, making unified diff format the most common format for exchange between software developers.
Unified context diffs were originally developed by Wayne Davison in August 1990 (in unidiff which appeared in Volume 14 of comp.sources.misc). Richard Stallman added unified diff support to the GNU Project's diff utility one month later, and the feature debuted in GNU diff 1.15, released in January 1991. GNU diff has since generalized the context format to allow arbitrary formatting of diffs.
The format starts with the same two-line header as the context format, except that the original file is preceded by "---" and the new file is preceded by "+++". Following this are one or more change hunks (chunks) that contain the line differences in the file. The unchanged, contextual lines are preceded by a space character, addition lines are preceded by a plus sign, and deletion lines are preceded by a minus sign.
A chunk begins with range information and is immediately followed with the line additions, line deletions, and any number of the contextual lines. The range information is surrounded by double-at signs and combines onto a single line what appears on two lines for the context format (see above). The format of the range information line is as follows:
@@ -R +R @@
The chunk range information contains two chunk ranges. The one preceded by a minus symbol is the range for the chunk of the original file, and the range for the new file is preceded by a plus symbol. Each chunk range, R, is of the format l,s where l is the starting line number and s is the number of lines the change hunk applies to for each respective file. In many versions of GNU diff, R can omit the comma and trailing value s, in which case s defaults to 1. Note that the only really interesting value is the l line number of the first range; all the other values can be computed from the diff.
The chunk range for the original should be the sum of all contextual and deletion (including changed) chunk lines. The chunk range for the new file should be a sum of all contextual and addition (including changed) chunk lines. If chunk size information does not correspond with the number of lines in the hunk, then the diff could be considered invalid and be rejected. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|