Ronald Bradford
MySQL Expert

Various cheatsheets to help the MySQL DBA in the administration of MySQL

Creating Source File Patches

When changing source files outside of using configuration management, it's important to produce a patch file to enable others to easily view and re-create your changes from the original source file.

Syntax

Using the Linux 'diff' command, you can produce a difference between the original (from file), and the new (to file).

  $ diff -u original.cpp newversion.cpp > original.patch

Example

In the following output, you see the difference between the original (from file), and the new (to file). The output highlights lines to be removed with '---' and lines to be added with '+++'

$ diff -u bonnie++-1.03e/bon_time.cpp bon_time.cpp 
--- bonnie++-1.03e/bon_time.cpp	2003-01-08 17:39:12.000000000 -0500
+++ bon_time.cpp	2009-06-03 17:10:49.000000000 -0400
@@ -159,10 +159,10 @@
   if(m_delta[test].Elapsed < MinTime)
   {
     if(m_type == txt)
+    {
       fprintf(m_fp, " +++");
-    else
-      fprintf(m_fp, ",+++");
-    return 0;
+      return 0;
+    }
   }
   int cpu = int(m_delta[test].CPU / m_delta[test].Elapsed * 100.0);
   if(m_type == txt)
@@ -181,12 +181,10 @@
     else
       fprintf(m_fp, ",");
   }
-  else if(m_delta[test].Elapsed < MinTime)
+  else if(m_delta[test].Elapsed < MinTime && m_type==txt)
   {
     if(m_type == txt)
       fprintf(m_fp, " +++++");
-    else
-      fprintf(m_fp, ",+++++");
   }
   else
   {
@@ -224,12 +222,10 @@
     else
       fprintf(m_fp, ",");
   }
-  else if(m_delta[test].Elapsed < MinTime)
+  else if(m_delta[test].Elapsed < MinTime && m_type == txt)
   {
     if(m_type == txt)
       fprintf(m_fp, " +++++");
-    else
-      fprintf(m_fp, ",+++++");
   }
   else
   {

Applying Patches

$ patch < original.patch