<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>CVS</title>
  <link rel="alternate" type="text/html" href="http://pingv.com/tag/cvs"/>
  <link rel="self" type="application/atom+xml" href="http://pingv.com/taxonomy/term/83/atom/feed"/>
  <id>http://pingv.com/taxonomy/term/83/atom/feed</id>
  <updated>2006-10-30T15:12:41-06:00</updated>
  <entry>
    <title>Getting Historic Revisions of Drupal Modules for Comparison</title>
    <link rel="alternate" type="text/html" href="http://pingv.com/blog/greg/200610/getting-historic-revisions-of-drupal-modules-for-comparison" />
    <id>http://pingv.com/blog/greg/200610/getting-historic-revisions-of-drupal-modules-for-comparison</id>
    <published>2006-10-30T15:04:17-06:00</published>
    <updated>2006-10-30T15:12:41-06:00</updated>
    <author>
      <name>Greg</name>
    </author>
    <category term="Partners" />
    <category term="code" />
    <category term="CVS" />
    <category term="Drupal" />
    <content type="html"><![CDATA[ <p>I was recently working on an older <a href="http://drupal.org">Drupal</a> site that hadn't been updated in a while.  It used lots of contributed modules and we were unsure whether these had any custom hacks in them.  So, I needed a way to find what version of the module was in use, and then pulling down to relevant version of that module in a format suitable to use in a "diff" tool.  </p>
<p>So, I did a couple fancy little things and wanted to share them for others to enjoy:</p>
<h3>Finding the Id string</h3>
<p>Many Drupal modules have an "Id" string in the top of the file.  The CVS system replaces these with some information about the file when they are checked out of CVS.  This gives you an automatically updated set of information about the file you are using.  So, if we can find files named .module, grab the first 3 lines of those files, search for the string Id, and output the results into a file then we've tackled the question <strong>"What version of this module do I have?</strong></p>
<div class="codeblock"><code>find ./ -name &#039;*.module&#039; -exec head -n 3 {} \; | grep Id &gt;&gt; versionNumbers.txt</code></div>
<p>(Note that all of the pieces of text that are in these little boxes should be one one line.)</p>
<p>Which gives you output like:</p>
<div class="codeblock"><code>// $Id: devel.module,v 1.108 2006/10/15 21:59:25 weitzman Exp $<br />// $Id: devel_node_access.module,v 1.7 2006/08/17 12:33:29 dww Exp $<br />// $Id: color.module,v 1.3 2006/10/29 15:13:01 unconed Exp $<br />// $Id: gsitemap.module, v4.8.11</code></div>
<h3>Getting the corresponding code from CVS</h3>
<p>The next step is to use that Id information to find the version from CVS.  Fortunately, CVS provides the capability of checking out files based upon a date.  First, we need to parse out the section of the Id string that contains the module name and the date.  The fanciest way would be to use awk, but the problem with that is not all modules use the Id string.  So, I used the <a href="http://www.openoffice.org/">OpenOffice.org Calc spreadsheet program</a> and the <a>Text to Columns Macro</a>.  From there, two formulas got me the data I wanted: </p>
<div class="codeblock"><code>=LEFT(C1;FIND(&quot;.&quot;;C1)-1)</code></div>
<p>and</p>
<div class="codeblock"><code>=CONCATENATE(&quot;cvs -d :pserver:greggles@cvs.drupal.org:/cvs/drupal-contrib checkout -r DRUPAL-4-6 -D &quot;&quot;&quot;;F1;&quot;&quot;&quot; contributions/modules/&quot;;B1)</code></div>
<p>The benefit of doing this in a spreadsheet is that it makes it easy to find modules (e.g. <a href="http://cvs.drupal.org/viewcvs/drupal/contributions/modules/gsitemap/gsitemap.module?rev=1.53&amp;view=markup">gsitemap</a>) where the Id string has been implemented in a non-standard way so that I can search down the right details myself.</p>
<p>When the information is present, these functions get me the module name out of name.module and then provides a cvs checkout command to pull down the DRUPAL-4-6 branch from the date that was in the top of the module file.</p>
<p>So, I paste those into my shell pastebuffer, they pull down all the modules, and I can do my diff.</p>
<h3>What's the Diff</h3>
<p>Once you are there it's trivial to use your favorite comparison/diff tool to find the difference between the modules.  And from there, you can follow the road back to Drupal sanity by removing custom modifications from the modules and implementing them as theme_ and hook_ functions.</p>
<p>Whew!  That was difficult, but now it's easier for others to do (or for me to do again, I have a feeling I'll need it).</p>
<h3>Drupal Project Module Updates</h3>
<p>It's worth noting that most of this tom-foolery will no longer be necessary after some more improvements to the <a href="http://drupal.org/project/project">Drupal Project Module</a>.  If you are interested in supporting that work, take a look at <a href="http://drupal.org/node/77562">this overview and fundraising page</a>.</p>
<p>Final note: there are many ways to do these kinds of tricks, these just happen to be the way.</p>
     ]]></content>
  </entry>
</feed>
