Several diff programs for Windows

Last modified: February 16, 2009 - 16:57

(against a cvs source with the cvs.exe built-in diff. do diff local files, you need a windows diff program, command line or visual)

Generic:
  • find the cvs.exe of your cvs package (WinCVS, TortoiseCVS, cygwin, ...) and make sure it is in your PATH
  • cd to your drupal root dir
  • cvs diff -u [[-r rev1|-D date1] [-r rev2|-D date2]] [file_to_diff] [> file_to_diff.patch]
    • -u: unified format
    • -r: revision(s) to diff
      • no -r: compare the working file with the revision it was based on
      • one -r: compare that revision with your current working file
      • two -r: compare those two revisions
    • -D: use a date_spec to specify revisions. examples: "1972-09-24 20:05", "24 Sep 1972 20:05".
    • file_to_diff: path to the file or directory you want to diff. if you specify a directory, the output will include the diff of all differing files in this directory and all subdirectories.
    • > file_to_diff.patch: creates a patch - saves the diff in file_to_diff.patch instead of outputting it on stdout. if you send a patch, make sure it has the proper line endings
    • see the CVS manual for a complete list of and additional options
via WinCVS GUI
Just select the file you edited and right-mouse-click > "diff selection" (or press the "diff selected"-icon on the toolbar, or do Menubar > "Query" > "diff selection"). This brings up a "Diff settings" dialog box that offers some limited options as "revisions to diff" and "ignore whitespace/case" [update 2003-Feb-07: starting with WinCvs 1.3b11, "Full diff options [are] available from the diff dialog"]. The resulting diff is output to the WinCVS-Console and can be copied and pasted.
via WinCVS/TortoiseCVS external diff
  • WinCVS: Menubar > "Admin" > "Preferences" > "WinCVS" > "External diff program ". This program will be invoked by the "Diff selection" when "Use the external diff" is checked.
  • TortoiseCVS: CVS > "Preferences" > "External diff application". This program will be invoked by "CVS Diff ..."
Some external visual diff programs for Windows:

Notes:

  • While these programs do a nice job in showing file differences visually, side by side, non of them (as i can tell) allows to actually save the difference in unified format (most allow to save a standard diff, though) - update: TortoiseCVS lets you save patches. It does unified format by default. See its Make Patch option. Note that this 'Make Patch' option can make recursive patches when applied to directories. - update2: WinMerge also can produce unified diffs.
  • You cannot specify the "-u" in the External diff preferences (eg "diff -u") as this will result in "Unable to open 'diff -u' (The system cannot find the file specified.)". A workaround for this is to, in the preferences, specify a batch-file that calls the external diff with the -u option. Another workaround is meta-diff, which allows for launching of special diff programs for certain file types.)

line endings: an issue with using diff on windows is that generated patches have windows line endings, which makes them impossible to apply on unix boxes [1][2]. unfortunately, there seems to be no way to convince "cvs diff" to output unix line endings*. so the only way for making a proper patch on windows that i see is to convert / filter the output from "cvs diff" to unix line endings:

  • filter: pipe "cvs diff"s output through some dos2unix tool (like the one from Robert B. Clark, or like cygwins's dos2unix / d2u):
    cvs diff [options] file_to_diff  | unix2dos -u > file_to_diff.patch
  • convert: save "cvs diff"s output to a file:
    cvs diff [options] file_to_diff > file_to_diff.patch
    and manually convert file_to_diff.patch to unix line endings. every developers editor should be capable of this; besides, there are many dos2unix versions that operate on files.
 
 

Drupal is a registered trademark of Dries Buytaert.