<?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>Ted Naleid &#187; mercurial</title>
	<atom:link href="http://naleid.com/blog/category/mercurial/feed/" rel="self" type="application/rss+xml" />
	<link>http://naleid.com/blog</link>
	<description>Groovy, Grails and OS X tips and tricks</description>
	<lastBuildDate>Wed, 16 Jun 2010 17:38:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using a Unique Grails Working Directory for each Mercurial Branch</title>
		<link>http://naleid.com/blog/2010/05/07/using-a-unique-grails-working-directory-for-each-mercurial-branch/</link>
		<comments>http://naleid.com/blog/2010/05/07/using-a-unique-grails-working-directory-for-each-mercurial-branch/#comments</comments>
		<pubDate>Fri, 07 May 2010 18:07:40 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[mercurial]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[shortcut]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=184</guid>
		<description><![CDATA[At work, we&#8217;re using mercurial for our source control.  As we&#8217;ve released code to production we&#8217;ve needed to branch our repository to support what&#8217;s in production as well as ongoing development.  
By default, grails uses ~/.grails as the working directory.  If you&#8217;re doing branchy development, you can run into problems with this [...]]]></description>
			<content:encoded><![CDATA[<p>At work, we&#8217;re using <a href="http://mercurial.selenic.com/" onclick="pageTracker._trackPageview('/outgoing/mercurial.selenic.com/?referer=');">mercurial</a> for our source control.  As we&#8217;ve released code to production we&#8217;ve needed to branch our repository to support what&#8217;s in production as well as ongoing development.  </p>
<p>By default, grails uses <code>~/.grails</code> as the working directory.  If you&#8217;re doing branchy development, you can run into problems with this if you&#8217;ve got plugins installed in one branch that aren&#8217;t in the other.  Having a unique directory per branch prevents you from having to run <code>grails clean</code> all the time.</p>
<p>Here&#8217;s a quick shell script that changes the grails working directory to have the branch name as a suffix if your source is contained in a mercurial repository (ex: the default branch would be <code>~/.grails_default</code> and the 1.0 branch would be <code>~/.grails_1.0</code>).  If your application is not in a repo, it just uses the regular <code>~/.grails directory</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">HG_BRANCH</span>=<span style="color: #000000; font-weight: bold;">`</span>hg branch <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">GRAILS_SCRIPT</span>=<span style="color: #007800;">$GRAILS_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>grails
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$HG_BRANCH</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #007800;">GRAILS_WORK_DIR</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> ~<span style="color: #000000; font-weight: bold;">`/</span>.grails_<span style="color: #007800;">$HG_BRANCH</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;** grails working directory: <span style="color: #007800;">$GRAILS_WORK_DIR</span>&quot;</span>
	<span style="color: #007800;">$GRAILS_SCRIPT</span> -Dgrails.work.dir=<span style="color: #007800;">$GRAILS_WORK_DIR</span> $<span style="color: #000000; font-weight: bold;">@</span>
<span style="color: #000000; font-weight: bold;">else</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;** default grails working directory&quot;</span>
	<span style="color: #007800;">$GRAILS_SCRIPT</span> $<span style="color: #000000; font-weight: bold;">@</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>Just save this script as &#8220;grails&#8221; and put it in your PATH before the $GRAILS_HOME/bin directory (also make sure that you&#8217;ve defined $GRAILS_HOME).  I have a ~/bin directory that&#8217;s the first thing in my PATH.</p>
<p>If you use the grails-debug command, you can repeat these steps for that, just change <code>GRAILS_SCRIPT</code> to <code>$GRAILS_HOME/bin/grails-debug</code>.</p>
<p>This same technique could easily be modified to be used for other source control systems such as git or subversion.</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2010/05/07/using-a-unique-grails-working-directory-for-each-mercurial-branch/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mercurial DVCS DevJam Presentation</title>
		<link>http://naleid.com/blog/2009/11/08/mercurial-dvcs-devjam-presentation/</link>
		<comments>http://naleid.com/blog/2009/11/08/mercurial-dvcs-devjam-presentation/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 02:43:20 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[mercurial]]></category>
		<category><![CDATA[presentation]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=106</guid>
		<description><![CDATA[This past week, I gave a presentation to the DevJam meeting on the advantages of using Mercurial, a DVCS (Distributed Version Control System) over tools like Subversion, Perforce, and ClearCase.

I&#8217;ve been using a mercurial repository at bitbucket to host the build-test-data grails plugin, as well as a number of other things that I&#8217;ve done.  [...]]]></description>
			<content:encoded><![CDATA[<p>This past week, I gave a presentation to the <a href="http://www.devjam.com/" onclick="pageTracker._trackPageview('/outgoing/www.devjam.com/?referer=');">DevJam</a> meeting on the advantages of using Mercurial, a DVCS (Distributed Version Control System) over tools like Subversion, Perforce, and ClearCase.<br />
<span id="more-106"></span><br />
I&#8217;ve been using a mercurial repository at bitbucket to host the build-test-data grails plugin, as well as a number of other things that I&#8217;ve done.  We&#8217;re also using it at work to hold our grails applications.  I find that the way Mercurial works fits better with my style of development over git, the other popular DVCS.</p>
<p>The turnout at the meeting was great, and a heated discussion followed the presentation (as it always does at that meeting).</p>
<p>I&#8217;ve checked the original keynote files along with a PDF version into <a href="http://bitbucket.org/tednaleid/dvcs-with-mercurial/src/" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/dvcs-with-mercurial/src/?referer=');">a mercurial repository</a>.</p>
<p>Here&#8217;s <a href="http://www.slideshare.net/tednaleid/mercurial-dvcs-presentation-to-devjam-1142009-2426116" onclick="pageTracker._trackPageview('/outgoing/www.slideshare.net/tednaleid/mercurial-dvcs-presentation-to-devjam-1142009-2426116?referer=');">the presentation on SlideShare</a>:</p>
<div style="width:425px;text-align:left" id="__ss_2426116"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/tednaleid/mercurial-dvcs-presentation-to-devjam-1142009-2426116" title="Mercurial DVCS presentation to DevJam 11/4/2009" onclick="pageTracker._trackPageview('/outgoing/www.slideshare.net/tednaleid/mercurial-dvcs-presentation-to-devjam-1142009-2426116?referer=');">Mercurial DVCS presentation to DevJam 11/4/2009</a><object style="margin:0px" width="600" height="500"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=dvcspresentation-091104221655-phpapp01&#038;stripped_title=mercurial-dvcs-presentation-to-devjam-1142009-2426116" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=dvcspresentation-091104221655-phpapp01&#038;stripped_title=mercurial-dvcs-presentation-to-devjam-1142009-2426116" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="600" height="500"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/" onclick="pageTracker._trackPageview('/outgoing/www.slideshare.net/?referer=');">documents</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/tednaleid" onclick="pageTracker._trackPageview('/outgoing/www.slideshare.net/tednaleid?referer=');">tednaleid</a>.</div>
</div>
<p><script type="text/javascript">var dzone_style = '1';</script><br />
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> </p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2009/11/08/mercurial-dvcs-devjam-presentation/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>My Mercurial Setup (Plus Some Useful Shims and Jigs)</title>
		<link>http://naleid.com/blog/2008/11/25/my-mercurial-setup-plus-some-useful-shims-and-jigs/</link>
		<comments>http://naleid.com/blog/2008/11/25/my-mercurial-setup-plus-some-useful-shims-and-jigs/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 03:48:45 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[mercurial]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[shortcut]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[jig]]></category>
		<category><![CDATA[shim]]></category>
		<category><![CDATA[zsh]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=37</guid>
		<description><![CDATA[In his book, The Productive Programmer, Neal Ford talks about using shims or jigs to help productivity.  Jigs and shims are quickly created little snippets of code that automate repetitive tasks or make them easy enough that they&#8217;re worth doing.  They&#8217;re little tools that help make your job easier and let you avoid [...]]]></description>
			<content:encoded><![CDATA[<p>In his book, <a href="http://productiveprogrammer.com/wiki/index.php/Main_Page" onclick="pageTracker._trackPageview('/outgoing/productiveprogrammer.com/wiki/index.php/Main_Page?referer=');">The Productive Programmer</a>, Neal Ford talks about using shims or jigs to help productivity.  Jigs and shims are quickly created little snippets of code that automate repetitive tasks or make them easy enough that they&#8217;re worth doing.  They&#8217;re little tools that help make your job easier and let you avoid using brute force to solve all of your problems.</p>
<p>My home directory has a bin folder in it that&#8217;s continually getting new jigs added to it, and my zshrc file is an ever-expanding list of quick shell functions.</p>
<p>Recently, I&#8217;ve been doing a lot more work with <a href="http://www.selenic.com/mercurial/wiki/" onclick="pageTracker._trackPageview('/outgoing/www.selenic.com/mercurial/wiki/?referer=');">Mercurial</a> as the team that I&#8217;m on switched from Subversion a couple of months ago on our Grails project.  The initial transition was a little difficult for some people, but I think just about everyone is pretty happy with the transition now that we&#8217;ve made it.  </p>
<p>Something that has helped everyone get comfortable with more complex Distributed Version Control System like Mercurial has been the distribution of shims and jigs amongst the team.  I thought these tips might be useful to others as well.<br />
<span id="more-37"></span></p>
<h2>Configuring Mercurial</h2>
<p>After installing mercurial (the easiest way is to just get the <a href="http://www.selenic.com/mercurial/wiki/index.cgi/BinaryPackages" onclick="pageTracker._trackPageview('/outgoing/www.selenic.com/mercurial/wiki/index.cgi/BinaryPackages?referer=');">appropriate binary package for your OS</a>), you&#8217;ll want to get it configured.</p>
<p>A good place to start is with someone else&#8217;s configuration file.  Here&#8217;s my my current ~/.hgrc configuration file (with the username replaced):</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[extensions] 
fetch=
extdiff=
color=
hgext.graphlog=
hgshelve=~/Documents/workspace/hgshelve/hgshelve.py
rdiff=~/Documents/workspace/rdiff/rdiff.py
hgext.mq =
&nbsp;
[diff]
git = 1
&nbsp;
[ui]
username = YOUR NAME &lt;YOUR_NAME@YOUR_COMPANY.com&gt;
&nbsp;
[extdiff]
cmd.kdiff3 =
cmd.chdiff =
opts.chdiff = --wait
&nbsp;
[merge-tools]
kdiff3.args = $base $local $other -o $output</pre></div></div>

<p>In it, you&#8217;ll see a number of useful extensions, including:</p>
<ul>
<li><code>hg fetch</code> &#8211; automates the pull/update working copy/merge/commit merge steps</li>
<li><code>extdiff extension</code> &#8211; Mercurial allows you to set up external tools to do diffs and merges.  I&#8217;m using 2 different graphical merge tools for different purposes</li>
<ul>
<li><code>hg chdiff</code> &#8211; <a href="http://changesapp.com/" onclick="pageTracker._trackPageview('/outgoing/changesapp.com/?referer=');">Changes.app</a> for just comparing two files in a diff.  Changes is a beautiful shareware diff tool for the mac, it unfortunately doesn&#8217;t do a <a href="http://en.wikipedia.org/wiki/Merge_(revision_control)#Three-way_merge" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Merge_revision_control_Three-way_merge?referer=');">3-way merge</a>.</li>
<li><code>hg kdiff3</code> &#8211; For merging, (and some diff situations), I need the power of a 3-way merge tool and I&#8217;ve found kdiff3 to be the best one that I&#8217;ve used.  It&#8217;s an open source, free, cross platform 3-way merge tool.  Using a 3-way merge tool is imperative for getting your merges correct.</li>
</ul>
<li><code>color extension</code> &#8211; just colorizes some output including the status command</a></li>
<li><code>hg glog</code> &#8211; an ascii graphical log of the commit tree (enhanced &#8220;hg log&#8221;)</li>
<li><code>hg shelve</code> &#8211; simplified patch management that allows you to &#8220;shelve&#8221; changes without committing them locally, for instance if you want to do a fetch, I asked about this on <a href="http://stackoverflow.com/questions/125272/using-mercurial-whats-the-easiest-way-to-commit-and-push-a-single-file-while-le" onclick="pageTracker._trackPageview('/outgoing/stackoverflow.com/questions/125272/using-mercurial-whats-the-easiest-way-to-commit-and-push-a-single-file-while-le?referer=');">Stack Overflow</a></li>
<li><code>hg rdiff</code> &#8211; remote diff, allows you to compare a file checked into your local repo with a file in the remote repository, I also asked about this on <a href="http://stackoverflow.com/questions/156280/using-mercurial-is-there-an-easy-way-to-diff-my-working-copy-with-the-tip-file" onclick="pageTracker._trackPageview('/outgoing/stackoverflow.com/questions/156280/using-mercurial-is-there-an-easy-way-to-diff-my-working-copy-with-the-tip-file?referer=');">Stack Overflow</a></li>
<li><code>mq extension</code> &#8211; mercurial queues, a more advanced topic that I don&#8217;t think anyone else at my workplace uses, but there&#8217;s a lot of power in mqueue if you look into it.  The Mozilla guys have a really <a href="https://developer.mozilla.org/en/Mercurial_Queues" onclick="pageTracker._trackPageview('/outgoing/developer.mozilla.org/en/Mercurial_Queues?referer=');">nice introductory tutorial</a> to using this plugin.</li>
</ul>
<h2>Setting up KDiff3 so you can do 3-way merges</h2>
<p>The simplest way to get KDiff3 is to <a href="http://kdiff3.sourceforge.net/" onclick="pageTracker._trackPageview('/outgoing/kdiff3.sourceforge.net/?referer=');">download the binary from the main website</a> (click on the download link and then choose the binary appropriate for your platform).</p>
<p>For the mac, you&#8217;ll just get a zip file with a KDiff3.app file in it that you should drag to your /Applications directory.  Then, you need to make sure that the actual executable in the application is in your path.  I just create a symlink in my path to the executable inside the application package:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>kdiff3.app<span style="color: #000000; font-weight: bold;">/</span>Contents<span style="color: #000000; font-weight: bold;">/</span>MacOS<span style="color: #000000; font-weight: bold;">/</span>kdiff3 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>kdiff3</pre></div></div>

<p>You might not have /usr/local/bin in your path by default.  If you can execute <code>kdiff3 --help</code> on the command line, you&#8217;re ready to go.</p>
<h2>Setting up the &#8220;<a href='http://www.selenic.com/mercurial/wiki/index.cgi/ShelveExtension' onclick="pageTracker._trackPageview('/outgoing/www.selenic.com/mercurial/wiki/index.cgi/ShelveExtension?referer=');">shelve</a>&#8221; extension</h2>
<p>The easiest way to get the shelve extention set up is to simply clone the project that holds the python script to your local filesystem:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hg clone http:<span style="color: #000000; font-weight: bold;">//</span>freehg.org<span style="color: #000000; font-weight: bold;">/</span>u<span style="color: #000000; font-weight: bold;">/</span>tksoh<span style="color: #000000; font-weight: bold;">/</span>hgshelve<span style="color: #000000; font-weight: bold;">/</span> hgshelve</pre></div></div>

<p>Then just make sure that the path in your ~/.hgrc file points to the correct location of the hgshelve.py file in the cloned repository.</p>
<p>You can test that it&#8217;s working by just executing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hg <span style="color: #7a0874; font-weight: bold;">help</span> shelve</pre></div></div>

<p>If you don&#8217;t get an error message, it&#8217;s set up right and you can start using it.</p>
<h2>Setting up the &#8220;<a href='http://www.selenic.com/mercurial/wiki/index.cgi/RdiffExtension' onclick="pageTracker._trackPageview('/outgoing/www.selenic.com/mercurial/wiki/index.cgi/RdiffExtension?referer=');">rdiff</a>&#8221; extension</h2>
<p>Setting up the rdiff extension is similar to the shelve extension above.  Just clone the repository:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hg clone <span style="color: #660033;">-r</span> c3ac1c497bf0 http:<span style="color: #000000; font-weight: bold;">//</span>hg.kublai.com<span style="color: #000000; font-weight: bold;">/</span>mercurial<span style="color: #000000; font-weight: bold;">/</span>extensions<span style="color: #000000; font-weight: bold;">/</span>rdiff</pre></div></div>

<p><strong>We clone an older revision currently as the tip in that project uses some unsupported stuff that isn&#8217;t in mercurial 1.0.2, if you&#8217;ve got a newer version of mercurial, you might be able to get the tip of the rdiff extension and have it work.<br />
</strong></p>
<p>Then make sure that your ~/.hgrc is pointed to the right path for the rdiff.py file in the repo you just cloned.</p>
<p>It&#8217;s a little quirky in that it actually modifies the existing &#8220;hg diff&#8221; command by detecting if the first parameter is a remote URL. If it is then it will diff that file against your tip file in your local repo (not the working copy). This as the remote repo is first in the arguments, it&#8217;s the reverse of what I&#8217;d expect, but you can pass &#8220;&#8211;reverse&#8221; to the hg diff command to switch that around.</p>
<p>I could see these being potential enhancements to the extension, but for now, I can work around them with a bash/zsh shell function in my startup file. It does a temp checkin of my working copy (held by the mercurial transaction so it can be rolled back), executes the reverse diff, and then rolls the transaction back to return things back to the way they were:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hgrdiff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    hg commit <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;temp commit for remote diff&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> 
    hg <span style="color: #c20cb9; font-weight: bold;">diff</span> <span style="color: #660033;">--reverse</span> http:<span style="color: #000000; font-weight: bold;">//</span>my_hardcoded_repo <span style="color: #007800;">$*</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span>
    hg rollback      <span style="color: #666666; font-style: italic;"># revert the temporary commit</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>And then call it with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hgrdiff <span style="color: #000000; font-weight: bold;">&lt;</span>filename to <span style="color: #c20cb9; font-weight: bold;">diff</span> against remote repo tip<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<h2>Other Mercurial Jigs and Shims</h2>
<p>Here are some other jigs and shims that I&#8217;ve found useful.</p>
<h4>Jig to Get a List of Files With the Same Status</h4>
<p>One jig that I&#8217;ve gotten a ton of use out of, is a modification to the normal &#8220;hg status&#8221; command.  Normally, &#8220;hg status&#8221; returns a list of all files that are different in the working directory when compared to the tip if the repository.  In the output of status, each file is printed with a character in the first column that signifies the status of that file.  Ex:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> hg status
M build.xml
A src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Foobar.groovy
A src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Quux.groovy
? src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Bar.groovy
? src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Baz.groovy</pre></div></div>

<p>Some of the most common statuses are:</p>
<ul>
<li><code>?</code> &#8211; not tracked, unknown to the source control repository
<li>
<li><code>M</code> &#8211; modified, this file is different in the working copy than on the file system
<li><code>A</code> &#8211; added, source control is aware of this file, but it hasn&#8217;t yet been committed
<li><code>R</code> &#8211; removed, this file has been marked for deletion on the next commit
<li><code>!</code> &#8211; missing, this file is not present in the working copy but is in source control
</ul>
<p>Often, I&#8217;ll want to do something with all of the files in a particular status, but I can&#8217;t easily do that as they&#8217;re mixed in with the other file types.  Also, the status flag at the beginning of the line prevents me from piping the status into another command.</p>
<p>I&#8217;ve come up with this shell function to allow me to filter lists of files (it actually works for subversion too, so there are 2 aliases).  Just paste this into your bash/zsh startup file:</p>
<pre code="bash">
vcst() {
	# print out all of the files with a passed in status flag (M - modified, A - added, ? - unknown, etc) (default ?)
	# expects first parameter to be the version control command (likely svn or hg)
	STATUS='\?'
	if [ -n "$2" ]
	then
		STATUS=$2
	fi
	$1 status | egrep "^$STATUS" | awk '{print $2}'
}

alias svnst='vcst svn'
alias hgst='vcst hg'
</pre>
<p>Then you can use the &#8220;hgst&#8221; command to see all the files in a particular status, one per line.  By default, it shows files that aren&#8217;t tracked (&#8220;<code>?</code>&#8220;), but you can pass a parameter that specifies another flag type if it&#8217;s other than &#8220;<code>?</code>&#8220;.</p>
<p>To see the list of files that aren&#8217;t in source control, just use:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> hgst
src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Bar.groovy
src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Baz.groovy</pre></div></div>

<p>If you want to delete all of the files that aren&#8217;t in source control, all you have to do is send the results of that command to rm:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">`</span>hgst<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #666666; font-style: italic;"># removes src/groovy/Bar.groovy and src/groovy/Baz.groovy</span></pre></div></div>

<p>If you want to edit all of the files that have been added in TextMate:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mate <span style="color: #000000; font-weight: bold;">`</span>hgst A<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #666666; font-style: italic;"># opens src/groovy/Foobar.groovy and src/groovy/Quux.groovy in TextMate</span></pre></div></div>

<p>If you want to do a diff and see only the files that have been modified using kdiff3:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hg kdiff3 <span style="color: #000000; font-weight: bold;">`</span>hgst M<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #666666; font-style: italic;"># would show a diff of build.xml vs the working copy</span></pre></div></div>

<h4>Shim to See a List Incoming and Outgoing Files</h4>
<p>When I&#8217;m about to push changes out to a remote server, or pull changes down from that server, I often want to know what files will be affected by this action.  Surprisingly, there isn&#8217;t an easy built-in way to do this.</p>
<p>There is the <code>hg incoming -v</code> command, which will print out a log format of all of the different changesets.  But I don&#8217;t really care about all the changesets, I just want to know which files will be affected.  Here&#8217;s a sample run of incoming with 3 changesets:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> hg incoming <span style="color: #660033;">-v</span>
comparing with <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>ted.naleid<span style="color: #000000; font-weight: bold;">/</span>temp<span style="color: #000000; font-weight: bold;">/</span>foo
searching <span style="color: #000000; font-weight: bold;">for</span> changes
changeset:   <span style="color: #000000;">1</span>:5c5f71bda234
user:        Ted Naleid <span style="color: #000000; font-weight: bold;">&lt;</span>ted.naleid<span style="color: #000000; font-weight: bold;">@</span>carol.com<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #c20cb9; font-weight: bold;">date</span>:        Tue Nov <span style="color: #000000;">25</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">30</span>:<span style="color: #000000;">51</span> <span style="color: #000000;">2008</span> <span style="color: #660033;">-0600</span>
files:       src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Foobar.groovy
description:
initial commit of foobar.groovy
&nbsp;
&nbsp;
changeset:   <span style="color: #000000;">2</span>:fe4a615747af
user:        Ted Naleid <span style="color: #000000; font-weight: bold;">&lt;</span>ted.naleid<span style="color: #000000; font-weight: bold;">@</span>carol.com<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #c20cb9; font-weight: bold;">date</span>:        Tue Nov <span style="color: #000000;">25</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">31</span>:<span style="color: #000000;">36</span> <span style="color: #000000;">2008</span> <span style="color: #660033;">-0600</span>
files:       src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Bar.groovy src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Foobar.groovy
description:
committing <span style="color: #000000;">2</span> files
&nbsp;
&nbsp;
changeset:   <span style="color: #000000;">3</span>:21e3d26bc3eb
tag:         tip
user:        Ted Naleid <span style="color: #000000; font-weight: bold;">&lt;</span>ted.naleid<span style="color: #000000; font-weight: bold;">@</span>carol.com<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #c20cb9; font-weight: bold;">date</span>:        Tue Nov <span style="color: #000000;">25</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">31</span>:<span style="color: #000000;">54</span> <span style="color: #000000;">2008</span> <span style="color: #660033;">-0600</span>
files:       build.xml src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Baz.groovy src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Foobar.groovy src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Quux.groovy
description:
3rd commit of files</pre></div></div>

<p>That&#8217;s not very useful as it&#8217;s hard to parse out the actual files in that list (and see only the unique list).</p>
<p>I use the following shim (just put in your bash/zsh rc file) to make this simple:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># look for lists of files in piped output, sort the unique set of them and print them one per line</span>
lf<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #c20cb9; font-weight: bold;">egrep</span> <span style="color: #ff0000;">&quot;^files:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{for (i=2; i&lt;=NF; i++) print $i}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span> 
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">ic</span>=<span style="color: #ff0000;">&quot;hg incoming -v | lf&quot;</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">og</span>=<span style="color: #ff0000;">&quot;hg outgoing -v | lf&quot;</span></pre></div></div>

<p>Once this is installed, you can simply use the <code>og</code> (outgoing) or <code>ic</code> (incoming) aliases to see what you&#8217;ll affect if you actually do a push or a pull.</p>
<p>Here&#8217;s the output using the incoming shim on same changeset above:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> ic
build.xml
src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Bar.groovy
src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Baz.groovy
src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Foobar.groovy
src<span style="color: #000000; font-weight: bold;">/</span>groovy<span style="color: #000000; font-weight: bold;">/</span>Quux.groovy</pre></div></div>

<p>That makes it quick and easy to see the real things that you&#8217;ll affect by your actions.</p>
<h4>Enhancing Your Shell Prompt With Mercurial Info</h4>
<p>A couple of other commands that I have in my zshrc (they should also work in a bash startup file):</p>
<pre>
hgtarget() {
    hg_root=`hg root 2>&#038;1 | egrep -v "$abort:"`
   	if [ $hg_root ]; then
    	if [ -f $hg_root/.hg/hgrc ]; then
        	hg_target=`cat $hg_root/.hg/hgrc | egrep "^default =" | sed 's/\(^default = \(http:\/\/\)*\)\(.*@\)*//'`
        	echo "$hg_target"
        fi
    fi
}

hgbranch() {
	hg_root=`hg root 2>&#038;1 | egrep -v "$abort:"`
	if [ $hg_root ]; then
		hg_branch=`hg branch`
		echo "$hg_branch"
	fi
}
</pre>
<p>These commands will tell you the path to the default push/pull target for your repository (<code>hgtarget</code>) as well as the current branch that you&#8217;re working on (<code>hgbranch</code>) in your repo.</p>
<p>I&#8217;ve added these to my shell prompt so that when I&#8217;m in a mercurial repository I&#8217;m more informed of the context that I&#8217;m working in.  My prompt is a little complicated (lots more going on there besides this), but there are a number of <a href="http://www.hypexr.org/bash_tutorial.php#cmd_prompt" onclick="pageTracker._trackPageview('/outgoing/www.hypexr.org/bash_tutorial.php_cmd_prompt?referer=');">good tutorials</a> out there for modifying yours.  </p>
<p><script type="text/javascript">var dzone_style = '1';</script><br />
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> </p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2008/11/25/my-mercurial-setup-plus-some-useful-shims-and-jigs/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Distributed Source Control with Mercurial Presentation</title>
		<link>http://naleid.com/blog/2008/06/03/distributed-source-control-with-mercurial-presentation/</link>
		<comments>http://naleid.com/blog/2008/06/03/distributed-source-control-with-mercurial-presentation/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 03:10:28 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[mercurial]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[dvcs mercurial grails svn]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=25</guid>
		<description><![CDATA[I gave a presentation at work today on Distributed Version Control Systems and Mercurial.  We're currently using Subversion, and I'm nudging my co-workers into getting interested in the benefits of distributed version control over a centralized system.]]></description>
			<content:encoded><![CDATA[<p>I gave a presentation at work today on Distributed Version Control Systems and Mercurial.  We&#8217;re currently using Subversion, and I&#8217;m nudging my co-workers into getting interested in the benefits of distributed version control over a centralized system.</p>
<p>The presentation starts with the pros and cons of distributed systems and gives a brief overview of the top 3 most popular DVCS systems:</p>
<ul>
<li><a href="http://git.or.cz/" onclick="pageTracker._trackPageview('/outgoing/git.or.cz/?referer=');">Git</a></li>
<li><a href="http://bazaar-vcs.org/" onclick="pageTracker._trackPageview('/outgoing/bazaar-vcs.org/?referer=');">Bazaar</a></li>
<li><a href="http://www.selenic.com/mercurial/wiki/" onclick="pageTracker._trackPageview('/outgoing/www.selenic.com/mercurial/wiki/?referer=');">Mercurial</a></li>
</ul>
<p>I go into the details of why I chose to use Mercurial and describe some common usage patterns for people used to using Subversion.</p>
<p>I then did a live-coding session where I created a quick grails application, added it to a new repository, cloned the repository and pushed changes back and forth to show how mercurial handles merging and history.</p>
<p>I also suggest how developers can <a href="http://naleid.com/blog/2008/05/01/using-mercurial-as-a-super-client-for-subversion/">use mercurial as a &#8220;super client&#8221;</a> to enable much of this power while still working on a team that uses subversion.<br />
<span id="more-25"></span><br />
Overall the presentation was well received, and many of the developers seemed excited about the potential in a DVCS like mercurial.  I know a number of them downloaded mercurial this afternoon and gave it a shot.  I also spoke with our build guy and one of our architects who both seem interested in switching over.</p>
<p>If you&#8217;re interested in installing mercurial, you can easily <a href="http://mercurial.berkwood.com/" onclick="pageTracker._trackPageview('/outgoing/mercurial.berkwood.com/?referer=');">download binaries</a>, or else you can go to the <a href="http://www.selenic.com/mercurial/wiki/" onclick="pageTracker._trackPageview('/outgoing/www.selenic.com/mercurial/wiki/?referer=');">main mercurial website</a> and compile it from source.</p>
<p>Here&#8217;s the presentation (without notes):</p>
<div style="width:425px;text-align:left" id="__ss_445714"><object style="margin:0px" width="600" height="525"><param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=dvcs-with-mercurialnonotes-1212548095115415-9"/><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=dvcs-with-mercurialnonotes-1212548095115415-9" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="600" height="525"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;"><a href="http://www.slideshare.net/?src=embed" onclick="pageTracker._trackPageview('/outgoing/www.slideshare.net/?src=embed&amp;referer=');"><img src="http://static.slideshare.net/swf/logo_embd.png" style="border:0px none;margin-bottom:-5px" alt="SlideShare"/></a> | <a href="http://www.slideshare.net/tednaleid/dvcs-with-mercurial-no-notes?src=embed" title="View Dvcs With Mercurial (No Notes) on SlideShare" onclick="pageTracker._trackPageview('/outgoing/www.slideshare.net/tednaleid/dvcs-with-mercurial-no-notes?src=embed&amp;referer=');">View</a> | <a href="http://www.slideshare.net/upload?src=embed" onclick="pageTracker._trackPageview('/outgoing/www.slideshare.net/upload?src=embed&amp;referer=');">Upload your own</a></div>
</div>
<p>I&#8217;ve also uploaded a <a href="http://www.slideshare.net/tednaleid/distributed-version-control-dvcs-with-mercurial/" onclick="pageTracker._trackPageview('/outgoing/www.slideshare.net/tednaleid/distributed-version-control-dvcs-with-mercurial/?referer=');">version of the presentation with full notes on slideshare</a>.  Adding the notes makes it too small to read in their flash app, so I suggest downloading the presentation if you want to see them.  The notes also include all of the detail in the live coding session (though you have to have grails 1.0.2 or better installed to get the same stuff I did).</p>
<p>I&#8217;d be interested to hear from others who have convinced their teams to switch from using a centralized repository to a distributed one like Mercurial.  </p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2008/06/03/distributed-source-control-with-mercurial-presentation/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
