<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://www.skepticats.com/LnBlog/themes/default/styles/rss.css" ?>
<rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/">
<channel>
<link>http://linlog.skepticats.com/feeds/Software_news.xml</link>
<title>LinLog</title>
<description>Linux, Programming, and Computing in General</description>
<generator>LnBlog 1.0.0</generator>
<item>
<title>More Mercurial hooks - well that was confusing  </title>
<link>http://linlog.skepticats.com/entries/2011/06/More_Mercurial_hooks_-_well_that_was_confusing.php</link>
<description>
&lt;p&gt;OK, that was a little confusing.  &lt;/p&gt;&lt;p&gt;So after my &lt;a href=&quot;http://linlog.skepticats.com/entries/2010/12/Mercurial_hooks.php&quot;&gt;initial attempt&lt;/a&gt; at a Mercurial hook to connect my public repository to my &lt;a href=&quot;http://www.mantisbt.org/&quot;&gt;Mantis&lt;/a&gt; instance, I decided to rearrange things a little.  Initially, I was using a &amp;quot;commit&amp;quot; hook on my local machine.  However, for the public bug tracker with the public repository, it made more sense to put the hook on the server.  So I switched it to an &amp;quot;incoming&amp;quot; hook in my hgweb.config.&lt;/p&gt;&lt;p&gt;Actually converting the script to work with my Linux based web host was pretty easy.  Just one command, really:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/bash&lt;/p&gt;&lt;p&gt;basedir='/path/to/base/hg/install/dir'&lt;br /&gt;mantis='/path/to/mantis/wwwroot/scripts/checkin.php'&lt;br /&gt;hg=&amp;quot;$basedir/hg&amp;quot;&lt;/p&gt;&lt;p&gt;$hg log -vr $HG_NODE --style $basedir/mercurial/templates/multiline | php $mantis&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Nice and simple, right?&lt;/p&gt;&lt;p&gt;The hard/annoying part was in the style template file.  Seem I wanted my commit message to have multiple lines and indent the file list, like this:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Changeset 85:5f7504e02f1c by Peter Geer, Mon Jan 17 23:12:46 2011 -0500&lt;br /&gt; Updated plugin for PHP5 and fixed blog root when taken from defined constant (fix bug 0000021).&lt;br /&gt;     lib/blog.php&lt;br /&gt;     plugins/menubar_breadcrumbs.php&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Problem was, it just didn't work.  I was using exactly the same template text as in the old hook script, but I was getting everything on the same line.  By switching from &amp;quot;\n&amp;quot; to &amp;quot;\r\n&amp;quot; as my newline escape code, I was able to get newlines to work, but the indentation still didn't.&lt;/p&gt;&lt;p&gt;Guess what fixed it - switching from double to single quotes.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;changeset = 'Changeset {branches}{rev}:{node|short} by {author|person}, {date|date}\n{desc}\n{files} '&lt;br /&gt;file = '     {file}\n'&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Seriously.  That's it.  No mention of that in the manual - they're supposed to be the same.  In fact, the example of this in the manual uses double-quotes.&lt;/p&gt;&lt;p&gt;Oddly enough, using double-quotes worked just fine on the command line.  I'm wondering if it has something to do with the fact that I'm using hgweb or something.  Either way, that really sucked.&lt;/p&gt;
</description>
<author>pageer@skepticats.com (Peter Geer)</author>
<comments>http://linlog.skepticats.com/entries/2011/06/12_2337/comments/</comments>
<guid>http://linlog.skepticats.com/entries/2011/06/12_2337/</guid>
</item>
<item>
<title>Powershell is not BASH and SVN pain </title>
<link>http://linlog.skepticats.com/entries/2010/12/Powershell_is_not_BASH_and_SVN_pain.php</link>
<description>
&lt;p&gt;Note to self: just because Powershell defines aliases that mimic many of the standard UNIX commands does not mean they function the same way.&lt;/p&gt;&lt;p&gt;Last night, I was trying to migrate my company's Subversion repository to Mercurial - not for production use (yet), just as an experiment.  After eventually getting the latest Mercurial installed on the Ubuntu 8.04 VM that hosts our Subversion repository, I tried running &lt;code&gt;hg convert -s svn /path/to/svn/repo /path/to/hg/repo&lt;/code&gt;.  As expected, the conversion process took some time, but chugged along nicely...for a while.  Eventually, it hit an error and came back with:&lt;br /&gt;&lt;code&gt;svn: In file '/build/buildd/subversion-1.6.9dfsg/subversion/libsvn_ra/ra_loader.c' line 595: assertion failed (*path != '/')&lt;/code&gt;&lt;/p&gt;&lt;p&gt;I Googled around a bit, but still have no idea what that error message means or how to fix it.  My best guess is that something is borked in our repo - not broken enough to break SVN, but maybeSo I tried a different tack - take the repository dump I had, import it into a fresh repository, and try again.  That didn't go so well....&lt;/p&gt;&lt;p&gt;Since the SVN VM has a very small drive, I decided to load the dumpfile on my local Windows box.  As you may know, &lt;code&gt;svnadmin load&lt;/code&gt; reads streams, so you have to either pipe the dump file in or redirect standard input.  Well, my first instinct was to do something like this:&lt;br /&gt;&lt;code&gt;svnadmin load newrepos &amp;lt; dumpfile.repo&lt;/code&gt;&lt;br /&gt;One problem with that: the &amp;quot;&amp;lt;&amp;quot; character that you normally use for redirecting STDIN is reserved in Powershell.  Drat!  So I figured I'd just use a pipe instead:&lt;br /&gt;&lt;code&gt;cat dumpfile.repo | svnadmin load newrepos&lt;/code&gt;&lt;br /&gt;So I ran that and waited.  And shortly after I started waiting, I noticed my system slowing down.  And then things started grinding to a halt - it was just &lt;em&gt;barely&lt;/em&gt; responding.  When I finally managed to get resmon up, I noticed that Powershell was eating nearly &lt;em&gt;all&lt;/em&gt; of my system's RAM!  And the command still hadn't produced a single line of output!&lt;/p&gt;&lt;p&gt;I'm not sure exactly what Powershell was doing, but it must have something to do with the Get-Content commandlet (for which &amp;quot;cat&amp;quot; is an alias) not liking the 1.4 GB dump file.  Why it would use up more than twice the size of the file in memory, I'm not sure.  &lt;/p&gt;&lt;p&gt;Anyway, I just switched to cmd.exe and did the input redirection method, which didn't eat huge amounts of memory.  However, it didn't work either.  The import died shortly after starting with an error about a bad transaction.  Looks like the gods of revision control are not smiling on me today.&lt;/p&gt;
</description>
<author>pageer@skepticats.com (Peter Geer)</author>
<comments>http://linlog.skepticats.com/entries/2010/12/22_1148/comments/</comments>
<guid>http://linlog.skepticats.com/entries/2010/12/22_1148/</guid>
</item>
<item>
<title>Mercurial hooks                      </title>
<link>http://linlog.skepticats.com/entries/2010/12/Mercurial_hooks.php</link>
<description>
&lt;p&gt;Last time I mentioned that I'd &lt;a href=&quot;http://linlog.skepticats.com/entries/2010/12/Bug_tracking_and_SVN_hooks_for_Mantis.php&quot;&gt;set up Mantis with a Subversion hook&lt;/a&gt;.  Well, I've been rethinking the Subversion part.&lt;/p&gt;&lt;p&gt;I was listened to a back episode of Hanselminutes last week in which Scott was interviewing &lt;a href=&quot;http://www.sourcegear.com/&quot;&gt;SourceGear&lt;/a&gt;'s &lt;a href=&quot;http://www.hanselminutes.com/default.aspx?showID=250&quot;&gt;interviewing Eric Sink about &lt;abbr title=&quot;Distributed Version Control Systems&quot;&gt;DVCS&lt;/abbr&gt;&lt;/a&gt; and it was a very interesting conversation.  Source control is one of those things you don't usually think about as a developer.  You learn how to use a source control system that's &amp;quot;good enough&amp;quot;, and after that, just sort of take it for granted.  You certainly don't spend a lot of time jumping back and forth between systems and trying out the possibilities.&lt;/p&gt;&lt;p&gt;I really liked the way Eric explained distributed version control.  As he pointed out, most of the arguments for &lt;abbr title=&quot;Distributed Version Control Systems&quot;&gt;DVCS&lt;/abbr&gt; that you hear seem pretty pointless, such as &amp;quot;There's no central server,&amp;quot; or &amp;quot;You can commit on an airplane.&amp;quot;  Well...so what?  Why &lt;em&gt;wouldn't&lt;/em&gt; I want a central server - how else do you determine the authoritative repository?  And honestly, who does important work on an airplane?&lt;/p&gt;&lt;p&gt;Instead, Eric framed the discussion in terms of flexibility.  The flip-side of the above stupid arguments is actually pretty compelling.  With &lt;abbr title=&quot;Distributed Version Control Systems&quot;&gt;DVCS&lt;/abbr&gt;, there's no central server, but that just means that your central server is determined by convention, not by the software, and it's much easier to set up &amp;quot;slave&amp;quot; repositories for remote sites.  Likewise, while being able to commit on a plane is pointless, there's definite value in not needing to have a connection to the server to do core version control operations.  Or, to put it another way, I may not code on a plane, but I &lt;em&gt;do&lt;/em&gt; often code in coffee shops with slow WiFi connections.&lt;/p&gt;&lt;p&gt;So, in light of that, I decided to give &lt;a href=&quot;http://mercurial.selenic.com/&quot;&gt;Mercurial&lt;/a&gt; a try.  According to Eric, it's fairly user-friendly, especially for Subversion users, and it's fairly Windows-friendly (it even has a TortoiseHg client, for whatever that's worth).  So, since I was thinking of resurrecting &lt;a href=&quot;http://lnblog.skepticats.com/&quot;&gt;LnBlog&lt;/a&gt;, I decided to use that as my test-case.  &lt;/p&gt;&lt;p&gt;That leads me back into the Subversion hooks tie-in.  Since I went to all the trouble of setting up an issue tracker and hooking it to SVN, I figured I'd do the same with Mercurial.  Fortunately, it wasn't too bad once I figured out what I needed to do.  I was able to fairly easily adapt the Powershell script I wrote for Subversion to work with Mercurial.  In fact, the Mercurial version was actually shorter.&lt;/p&gt;&lt;p&gt;Actually adding a commit hook in Mercurial is pretty simple.  You just add a line to your .hgrc file:&lt;br /&gt;&lt;code&gt;[hooks]&lt;br /&gt;commit = powershell \path\to\hg-commit-hook.ps1&lt;/code&gt;&lt;br /&gt;It seems that Mercurial preserves the environment for hooks, so you don't seem to have to worry about absolute paths and such like you do in Subversion.&lt;/p&gt;&lt;p&gt;The changes to the script itself were fairly small.  &lt;a href=&quot;http://mercurial.selenic.com/wiki/Hook&quot;&gt;This wiki page&lt;/a&gt; had a few good examples that got me started.  The two big things were the passing of data and generating the message to pass to Mantis.  Mercurial actually passes data into hook scripts through environment variables rather than command-line parameters, which is nice in that you actually get meaningful variable names coming in.  As for the message generation, Mercurial's log command allows you to &lt;a href=&quot;http://hgbook.red-bean.com/read/customizing-the-output-of-mercurial.html&quot;&gt;specify a template&lt;/a&gt; for its output, including substitution variables and some simple formatting functions.  The result is a nice, short script with only a couple of calls to &lt;code&gt;hg&lt;/code&gt;:&lt;/p&gt;&lt;p&gt;&lt;code&gt;[System.Reflection.Assembly]::LoadWithPartialName(&amp;quot;System.Web&amp;quot;) | Out-Null&lt;/p&gt;&lt;p&gt;$issue = hg log -vr $env:HG_NODE&lt;/p&gt;&lt;p&gt;# If we don't have an issue number, just exit.&lt;br /&gt;if ($issue -match &amp;quot;\b(?:bug|issue)\s*[#]{0,1}(\d+)\b&amp;quot;) {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;$style_file = @'&lt;br /&gt;changeset = &amp;quot;Changeset {branches}{rev}:{node|short} by {author|person}, {date|date}\n{desc}\n{files}&amp;quot;&lt;br /&gt;file = &amp;quot;    {file}\n&amp;quot;&lt;br /&gt;'@&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Write-Output $style_file | Out-File -Encoding ASCII -Width 1000 hgstyle&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;$data =  hg log -vr $env:HG_NODE --style hgstyle&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;rm hgstyle&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;# Keep the cast to string from clobbering line breaks.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;$data = [String]::Join(&amp;quot;`n&amp;quot;, $data)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;$postData = &amp;quot;secret=somePassword&amp;amp;message=&amp;quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;$postData += [System.Web.HttpUtility]::UrlEncode($data)&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;C:\Cygwin\bin\wget.exe -O req.out --post-data=$postData http://yourhost.com/path/to/mantis/scripts/do_checkin.php&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;rm req.out&lt;br /&gt;}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;That's it - a measly two calls to Mercurial, including one to see if we even need to run the hook.  By specifying the right template, we can get the entire message in one command.  That template gives me something like this:&lt;br /&gt;&lt;code&gt;Changeset 70:cbdb625298ca by Peter Geer, Mon Dec 13 16:45:53 2010 -0500&lt;br /&gt;Got rid of unneeded requires now that we have an autoloader (issue #0000005).&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;lib/article.php&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;lib/creators.php&lt;/code&gt;&lt;br /&gt;Perhaps not quite as pretty as the Subversion version, but close enough for now.  Perhaps if I feel like getting really fancy, I'll look at the Python API for Mercurial and try my hand at writing some in-process hook code.  &lt;/p&gt;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; Updated the script to put each of the listed file on a new, indented line.&lt;/p&gt;
</description>
<author>pageer@skepticats.com (Peter Geer)</author>
<comments>http://linlog.skepticats.com/entries/2010/12/13_1821/comments/</comments>
<guid>http://linlog.skepticats.com/entries/2010/12/13_1821/</guid>
</item>
</channel>
</rss>
