<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BigSmoke &#187; patch</title>
	<atom:link href="http://blog.bigsmoke.us/tag/patch/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.bigsmoke.us</link>
	<description>Smokes your problems, coughs fresh air.</description>
	<lastBuildDate>Sat, 04 Feb 2012 18:03:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using diff and patch to upgrade web application installations</title>
		<link>http://blog.bigsmoke.us/2008/03/13/upgrading-web-apps-with-diff-and-patch</link>
		<comments>http://blog.bigsmoke.us/2008/03/13/upgrading-web-apps-with-diff-and-patch#comments</comments>
		<pubDate>Thu, 13 Mar 2008 20:38:46 +0000</pubDate>
		<dc:creator>Rowan Rodrik</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[CLI]]></category>
		<category><![CDATA[diff]]></category>
		<category><![CDATA[patch]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/2008/03/13/upgrading-web-apps-with-diff-and-patch</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><b>Update (July 30, 2008):</b> I added information about making sure that the patch was successful.</p>

<p>When you install a big-ass web application such as WordPress or MediaWiki, you usually end with a bunch of configuration files and customizations (skins/themes, extension/plugins, uploads, etc.). This makes upgrading the files that come with the application a bit tricky. There&#8217;s a simple solution, however, which work regardless of whether you use a revision control system or not.</p>

<p>First of all, you do, of course, always need a revision control system. I personally recommend Git or Subversion, which are both excellent tools. But, that&#8217;s not what this post is about. I&#8217;m going to use two simple tools which are uniformly available on all (Unixy) platforms: diff and patch.</p>

<p>The procedure is simple:</p>

<ol>
  <li><p>Download the version of the application which you&#8217;re currently running. For our example, we pretend that this version is extracted into the directory <tt>webapp-1.4.3</tt>.</p></li>
  <li><p>Then, download the version to which you&#8217;d like to upgrade. (We&#8217;re assuming that this version is extracted into the <tt>webapp-1.6.2</tt> directory.)</p></li>
  <li><p>Compare the two versions to create a patch file:</p>
<pre>
$ diff --unified --recursive --new-file webapp-1.4.3 webapp-1.6.2 > webapp-upgrade.diff
</pre>
  </li>
  <li><p>Apply the patch to the installation of said web app:</p>
<pre>
$ cd webapp-installed
$ patch --strip=1 --remove-empty-files < ../webapp-upgrade.diff || echo "Some failures!"
</pre>
</ol>

<h2>Check if everything was patched perfectly</h2>

<p>Now, if the patch command returned a non-zero status (printing <q>Some failures!</q> in the above example), it's time to check which chunks of which files failed. Get a summary by searching all files with an <q><tt>.rej</tt></q> or a <q><tt>.orig</tt></q> suffix:</p>

<pre>$ find . -name "*.rej"</pre>

<p>After manually applying any failed hunks, what's left is to compare your directory containing the patched application to the directory with the contents of the new application archive which you've used to create the patch:</p>

<pre>
$ cd ..
$ diff --unified --recursive --new-file webapp-1.6.2 webapp-installed
</pre>

<h2>Version management</h2>

<p>Your upgrade is done. Now, if your using a revision control system, you just need to check in new files and check out deleted files. In Subversion, I do this quickly using the following command sequence:</p>

<pre>
$ svn status|sed -e '/^\?/!d; s/^\?//'|xargs svn add
$ svn status|sed -e '/^\!/!d; s/^\!//'|xargs svn del
</pre>

<p>If you'd been using Git, you could do this all a little bit more sophisticatedly, but my Git skills are not advanced enough to go around giving others advice. Also, it's nice to learn a generic method before learning more specific tools.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2008/03/13/upgrading-web-apps-with-diff-and-patch/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

