
vpnc at unix-ag
Jan 14, 2012, 1:04 AM
Post #1 of 1
(237 views)
Permalink
|
|
svn commit: vpnc r512 - /branches/vpnc-nortel/mk-version /trunk/mk-version
|
|
Author: Antonio Borneo Date: Sat Jan 14 10:04:23 2012 New Revision: 512 Log: mk-version: provide correct version in git tree while main repository is on svn, git is a nice platform to develop code before committing it to svn. git-svn can be used to clone in git the whole svn repository with command git svn clone http://svn.unix-ag.uni-kl.de/vpnc vpnc.git Code built in git-svn doesn't report correct version. Modified mk-version script to generate correct version string. Modified: branches/vpnc-nortel/mk-version trunk/mk-version Modified: branches/vpnc-nortel/mk-version ============================================================================== --- branches/vpnc-nortel/mk-version (original) +++ branches/vpnc-nortel/mk-version Sat Jan 14 10:04:23 2012 @@ -3,14 +3,69 @@ # print vpnc version from file VERSION, appending the string printed # by svnversion(1) if appropriate +function git_svn_version () +{ + local key value svn_log svn_commit svn_ver + + # exit if not in git repository + if [ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then + return + fi + + # search for svn-remote defined in git configuration + while read key value; do + svn_url_pattern+="\\|$value" + done << EOF + $(git config --get-regexp '^svn-remote\..*\.url$' 2>/dev/null) +EOF + + # exit if no svn-remote defined + if [ ${#svn_url_pattern} -eq 0 ]; then + return + fi + + # scan git-log for latest commit from any svn-remote above + svn_log=($(git log --first-parent -1 \ + --grep="^git-svn-id: \(${svn_url_pattern:2}\)@" 2>/dev/null)) + + # check commit hash is 40 hex digits + svn_commit=${svn_log[1]} + if [ ${#svn_commit} -ne 40 -o -n "${svn_commit//[0-9a-f]/}" ]; then + return + fi + + # check svn version is numeric + svn_ver=${svn_log[ ${#svn_log[@]} - 2 ]} + svn_ver=${svn_ver#*@} + if [ -z "${#svn_ver}" -o -n "${svn_ver//[0-9]/}" ]; then + return + fi + + if [ $(git rev-list --count HEAD...${svn_commit}) -eq 0 ]; then + if [ `git status -s | grep -vc '^??'` -eq 0 ]; then + # no git commits and tree clean + echo "${svn_ver}" + return + fi + fi + # there are local git commits after latest svn commit or tree is dirty + echo "${svn_ver}M" +} + + _version="`cat VERSION`" if [ -d .svn ]; then - if command -v svnversion >/dev/null; then - _version="$_version-`svnversion`" - else - _version="$_version-`sed -n '/^dir$/{n;p;q;}' .svn/entries`" - fi + if command -v svnversion >/dev/null; then + _version="$_version-`svnversion`" + else + _version="$_version-`sed -n '/^dir$/{n;p;q;}' .svn/entries`" + fi +elif command -v git >/dev/null; then + git_ext=$(git_svn_version) + if [ -n "${git_ext}" ]; then + _version="$_version-${git_ext}" + fi fi echo "$_version" Modified: trunk/mk-version ============================================================================== --- trunk/mk-version (original) +++ trunk/mk-version Sat Jan 14 10:04:23 2012 @@ -3,14 +3,69 @@ # print vpnc version from file VERSION, appending the string printed # by svnversion(1) if appropriate +function git_svn_version () +{ + local key value svn_log svn_commit svn_ver + + # exit if not in git repository + if [ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then + return + fi + + # search for svn-remote defined in git configuration + while read key value; do + svn_url_pattern+="\\|$value" + done << EOF + $(git config --get-regexp '^svn-remote\..*\.url$' 2>/dev/null) +EOF + + # exit if no svn-remote defined + if [ ${#svn_url_pattern} -eq 0 ]; then + return + fi + + # scan git-log for latest commit from any svn-remote above + svn_log=($(git log --first-parent -1 \ + --grep="^git-svn-id: \(${svn_url_pattern:2}\)@" 2>/dev/null)) + + # check commit hash is 40 hex digits + svn_commit=${svn_log[1]} + if [ ${#svn_commit} -ne 40 -o -n "${svn_commit//[0-9a-f]/}" ]; then + return + fi + + # check svn version is numeric + svn_ver=${svn_log[ ${#svn_log[@]} - 2 ]} + svn_ver=${svn_ver#*@} + if [ -z "${#svn_ver}" -o -n "${svn_ver//[0-9]/}" ]; then + return + fi + + if [ $(git rev-list --count HEAD...${svn_commit}) -eq 0 ]; then + if [ `git status -s | grep -vc '^??'` -eq 0 ]; then + # no git commits and tree clean + echo "${svn_ver}" + return + fi + fi + # there are local git commits after latest svn commit or tree is dirty + echo "${svn_ver}M" +} + + _version="`cat VERSION`" if [ -d .svn ]; then - if command -v svnversion >/dev/null; then - _version="$_version-`svnversion`" - else - _version="$_version-`sed -n '/^dir$/{n;p;q;}' .svn/entries`" - fi + if command -v svnversion >/dev/null; then + _version="$_version-`svnversion`" + else + _version="$_version-`sed -n '/^dir$/{n;p;q;}' .svn/entries`" + fi +elif command -v git >/dev/null; then + git_ext=$(git_svn_version) + if [ -n "${git_ext}" ]; then + _version="$_version-${git_ext}" + fi fi echo "$_version" _______________________________________________ vpnc-devel mailing list vpnc-devel [at] unix-ag https://lists.unix-ag.uni-kl.de/mailman/listinfo/vpnc-devel http://www.unix-ag.uni-kl.de/~massar/vpnc/
|