#!/bin/bash

vcs_id() {
    dir="$1"
    ( cd "$dir" ;
      if [ -d .hg ]; then
	  tag=$(hg id -t -r 'parents(.)') # tag is always followed by tag-commit
	  if [ "$tag" != "" ]; then
	      echo "${tag#$dir-}" # strip dir- prefix from tag if present
	  else 
	      hg id | awk '{ print $1; }'
	  fi
      elif [ -d .git ]; then
	  git rev-parse --short HEAD
      elif [ -d .svn ]; then
	  svn info | grep ^Revision | awk '{ print $2; }'
      else
	  echo "unknown"
      fi
    )
}

