Diff and Patch Tools

Unix diff and patch tools allow you to manage your custom changes easily across newer versions of sql-ledger.

1. Identifying what is changed in new version

Let us say that we have two versions of sql-ledger in folders sql-ledger-2.8.13 and sql-ledger-2.8.14. We try to find what has been changes in 2.8.14.

  • Files changes
  freebsd# diff -r -q sql-ledger-2.8.13 sql-ledger-2.8.14

Files sql-ledger-2.8.13/SL/Form.pm and sql-ledger-2.8.14/SL/Form.pm differ
Files sql-ledger-2.8.13/SL/IC.pm and sql-ledger-2.8.14/SL/IC.pm differ
Files sql-ledger-2.8.13/SL/IR.pm and sql-ledger-2.8.14/SL/IR.pm differ
Files sql-ledger-2.8.13/SL/IS.pm and sql-ledger-2.8.14/SL/IS.pm differ
Files sql-ledger-2.8.13/SL/OE.pm and sql-ledger-2.8.14/SL/OE.pm differ
Files sql-ledger-2.8.13/SL/RP.pm and sql-ledger-2.8.14/SL/RP.pm differ
Files sql-ledger-2.8.13/VERSION and sql-ledger-2.8.14/VERSION differ
Files sql-ledger-2.8.13/bin/lynx/arapprn.pl and sql-ledger-2.8.14/bin/lynx/arapprn.pl differ
...
...
  • Code changes
  freebsd# diff -r -u sql-ledger-2.8.13 sql-ledger-2.8.14

diff -r -u sql-ledger-2.8.13/SL/Form.pm sql-ledger-2.8.14/SL/Form.pm
--- sql-ledger-2.8.13/SL/Form.pm        2008-02-17 17:57:39.000000000 +0000
+++ sql-ledger-2.8.14/SL/Form.pm        2008-03-19 14:54:21.000000000 +0000
@@ -78,7 +78,7 @@

   $self->{menubar} = 1 if $self->{path} =~ /lynx/i;

-  $self->{version} = "2.8.13";
+  $self->{version} = "2.8.14";
   $self->{dbversion} = "2.8.8";

   bless $self, $type;
@@ -2330,7 +2330,7 @@

   # remove expired locks
   $query = qq|DELETE FROM semaphore
-              WHERE expires < $expires|;
+              WHERE expires < '$expires'|;
   $dbh->do($query) || $self->dberror($query);
...
...

2. Preparing and Applying Patch

  • Prepare a file containing changes in new version
freebsd# diff -r -u sql-ledger-2.8.13 sql-ledger-2.8.14 > changes2814.diff
  • Now changes2814.diff will contain all the changes made in new version. You can apply these changes to old version to bring it update to new version with a single command:
freebsd# patch -p0 -r sql-ledger-2.8.13 < changes2814.diff

Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|diff -r -u sql-ledger-2.8.13/SL/Form.pm sql-ledger-2.8.14/SL/Form.pm
|--- sql-ledger-2.8.13/SL/Form.pm       2008-02-17 17:57:39.000000000 +0000
|+++ sql-ledger-2.8.14/SL/Form.pm       2008-03-19 14:54:21.000000000 +0000
--------------------------
Patching file sql-ledger-2.8.13/SL/Form.pm using Plan A...
Hunk #1 succeeded at 78.
Hunk #2 succeeded at 2330.
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|diff -r -u sql-ledger-2.8.13/SL/IC.pm sql-ledger-2.8.14/SL/IC.pm
|--- sql-ledger-2.8.13/SL/IC.pm 2007-12-28 23:55:33.000000000 +0000
|+++ sql-ledger-2.8.14/SL/IC.pm 2008-03-05 20:02:07.000000000 +0000
--------------------------
Patching file sql-ledger-2.8.13/SL/IC.pm using Plan A...
Hunk #1 succeeded at 199.
...
...
  • Now both sql-ledger-2.8.13 and sql-ledger-2.8.14 contain 100% exact code. Let us see what happens when we run diff on these two folders
freebsd# diff -r -u sql-ledger-2.8.13 sql-ledger-2.8.14

Only in sql-ledger-2.8.13/SL: Form.pm.orig
Only in sql-ledger-2.8.13/SL: IC.pm.orig
Only in sql-ledger-2.8.13/SL: IR.pm.orig
...
...

Form.pm.orig (and other .orig files) is the file which was created by patch command and contains the file contents before applying the patch. These files can be deleted safely.

3. Upgrading Your Custom Sql-Ledger

Let us say we have our custom sql-ledger which is a modified copy of sql-ledger-2.8.13 and resides in folder 'ourledger-2.8.13'. Our goal is to bring all changes in 2.8.14 to our custom version. Here are the steps:

  1. Prepare the patch for differences in 2.8.13 and 2.8.14 as described above.
  1. Make sure that your changes in 'ourledger-2.8.13' do not conflict with original author's changes in 2.8.14. You can do this by reviewing changes in 'changes-2814.diff'. See notes below
  1. Apply the patch to 'ourledger-2.8.13'.
freebsd# patch -p0 -r ourledger-2.8.13 < changes2814.diff

4. Notes

Here are few points to keep in mind:

  1. Your patch will apply cleanly even if lines have been added or deleted from the SL/Form.pm provided that your changes do not conflict with the changes of the original author.
  2. If your changes conflict with the original author changes, you need to manually adjust the code by discarding some of your changes or discarding the original author changes. For this purpose, you can make adjustments directly in changes2814.diff'
  3. If you do not want to apply a particular change by the orignal author, you can delete the relevant hunks from changes-2814.diff before applying it to your version of sql-ledger
 
diff_patch_tools.txt · Last modified: 2010/05/06 12:05 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki