Skip to content

Instantly share code, notes, and snippets.

@rsebbe
Created January 18, 2012 19:33
Show Gist options
  • Save rsebbe/1635072 to your computer and use it in GitHub Desktop.
Save rsebbe/1635072 to your computer and use it in GitHub Desktop.
Computes a value for CFBundleVersion based on changeset graph that is monotonically increasing.
#!/bin/bash
hg="/usr/local/bin/hg"
if [ "x$1" != "x" ]
then
cur=`$hg id -ir $1`
else
# get working copy id (partial hash)
cur=`$hg id -i`
fi
# remove trailing + if uncommitted changes. Could handle that another way
cur=${cur%"+"}
# get full hash
cur=`$hg log -r $cur --template {node}`
nrev=`$hg log -r "0::$cur" --template "{node}\n" | wc -l`
# remove white space
nrev=`echo $nrev`
#echo $cur
cur=${cur:0:3}
# if you need a single int (no dot) for your build version string, you must pad your int with zeros
#cur=`printf '%4.4d' 0x$cur`
# if you use a dot, no padding should be used
cur=`printf '%d' 0x$cur`
#echo $cur
#echo $nrev
echo "$nrev.$cur"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment