Archive for MacHG

Versioning your application with the Mercurial changeset hash

A user of MacHg (Marko Käning) wanted to be able to see the changeset hash in the About MacHg box (see here). I had been meaning to do this at some stage and, well, given the request, now seemed as good a time as any… It turns out it was quite easy to configure XCode to create the appropriate information while building MacHg.

(In my workflow I release versions of MacHg every so often, and I want users who get the source code off of bitbucket and build it for themselves to be able to easily tell me something like “In such and such a version of MacHg I am seeing XYZ happen.”)

So now MacHg shows the following sort of thing when you look in the About MacHg box (note the grayed c0d2f1df774d hash code):

ok so how did I go about making this work? It happens in two steps:

  1. As part of the build process, get the hash key automatically and insert it into the applications info.plist.
  2. Inside your application extract the stored value from the hash key and display it in the about box

Steps to Automatically set the BuildHashKey when building your Application

  1. Open your XCode project.
  2. Under targets select your application.
  3. Right click on the target and choose Add -> New Build Phase -> New Run Script Build Phase, as in:
  4. Change the shell to be /usr/bin/python instead of /bin/sh.
  5. Then in the script, copy and paste the following — I actually did this in bash first but decided to do it properly again in python so that I will be able to read it again in six months time if need be, python being that much more readable :

import os, subprocess, re, sys

targetBuildDir = os.getenv("TARGET_BUILD_DIR") getChangeset = subprocess.Popen('hg parent --template "{node|short}" --cwd ' + targetBuildDir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

if ( != ""): print "Error in obtaining current changeset of the Mercurial repository" sys.exit(0) # if you want the build to fail here since the changeset is malformed change this to sys.exit(1)

changeset = if (not"^[0-9a-f]{12}$", changeset)): print "Current changeset of the Mercurial repository is malformed" sys.exit(0) # if you want the build to fail here since the changeset is malformed change this to sys.exit(1)

infoPlist = os.path.join(targetBuildDir, "") if not os.path.exists(infoPlist): print "Cannot locate" sys.exit(1) # if you want the build to not fail here change this to sys.exit(0)

result = subprocess.Popen('/usr/libexec/PlistBuddy -c "Delete BuildHashKey" ' + infoPlist, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) result = subprocess.Popen('/usr/libexec/PlistBuddy -c "Add BuildHashKey string '+ changeset + '" ' + infoPlist, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

print "MacHg BuildHashKey set to " + changeset

Of course you need to change to the name of your application. Also you might need to specify the full path to hg (ie /usr/local/bin/hg) in the line:
getChangeset = subprocess.Popen('hg parent --template "{node|short}" --cwd ' + targetBuildDir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
Also you might want to have the build fail if the changeset is not available, since currently the script above just keeps going.  (I want users who download and compile MacHg to not get lots of critical errors if things are not set up just right.)

Using the BuildHasKey in your Application

Then back in your application you can have a method which will get the hash key from the info.plist:

- (NSString) macHgBuildHashKeyString
    NSString key = [[NSBundle mainBundle] objectForInfoDictionaryKey: @"BuildHashKey"];
    return key ? key : @"";
Then it’s just a matter of styling it and viola, you have the ingredients for versioning your application with the Mercurial changeset hash key. Actually, after doing this I found out that over at Cocoa is My Girlfriend he had done something similar but in bash.

Leave a Comment


Whew! I just launched MacHg 0.9.0 to the public. I opened up the website and bitbucket sources to public viewing, added a google group, updated the sparkle app cast, fixed a few last bugs, synchronized the information now between the website, the bit bucket wiki, and the announcement email, and well launched… Time to go celebrate… Here is the full text of the launch:

Hi All,

I am pleased to announce the initial public release of MacHg. MacHg is a gui client for Mercurial. It runs under OSX 10.6 (Snow leopard). It is free to use and donation ware.


You can get an executable application here:

You can view (and clone) the MacHg sources at:

You can view a screen cast ‘MacHg Introduction’ at:

Discussion group about MacHg at:

MacHg Features

  • Document based structure with multiple repositories per document
  • View incoming and outgoing at a glance between compatible repositories
  • Auto refreshes the status of tracked files when they change
  • Incremental loading of history (for efficiency)
  • Works with large repositories (ie for example can load and work with the Mozilla repository which is 3.35Gb)
  • Fully compatible with command line Mercurial (You can make changes on the command line and they are reflected in MacHg.)
  • Fully multi-threaded using Grand Central Dispatch and threading goodness
  • File browser view to work with files
  • History view to explore the changeset history
  • Differences view to explore the historical changes between different revisions
  • Interacting with other repositories: pull, push, incoming, outgoing, clone, etc
  • Contextual menus and shortcuts in many places
  • Diff multiple files at once
  • Renaming, merging, updating, reverting, adding files, removing files, etc
  • Add and remove local tags, global tags, bookmarks, and branches
  • Interface to history editing: collapse, histedit, rebase, strip
  • Importing and exporting of patches
  • Uses the Sparkle framework for “in application” updates


If you would like to contribute I would be happy to receive and acknowledge help in a large number of areas, including: – Testing – Documentation (MacHg has some documentation but it would be nice to have a much more complete set of documentation.) – Cocoa coding (Lots of potential enhancements here) – Mercurial extension writing (There are a few extensions I could use help with: for example, around permissibility of dragging and dropping in history rewriting, etc.) – Translating (Especially those who have experience using Apple’s polyglot tool, etc.) – Web designers (There are a number of enhancements to be made to web pages, wikis, etc.) – Graphic design (Icon design, etc.)

Thanks, Jason

Leave a Comment

Almost there

Right my first blog post!

In my free time I have been working on developing a cocoa program MacHG. Its almost ready to launch to beta testing…

As is evident word press is mostly set up since you are reading this. My bitbucket setup is almost there… and well dreamhost was activated today and is hosting this as is evident. Google email is up. There are still some services which I will get set up like the forum thingy which is served by php. Also hosting of the screen casts. But soon…

Leave a Comment