From e1fd24b2dd26a3b906b90104728a4e246fbf8c9b Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 30 Apr 2009 07:44:16 +0000 Subject: [PATCH] 2009-04-30 09:43 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * utils/hbmk2/hbmk2.prg + Added repository ID retrieval function. Currently supports SVN, GIT and Mercurial. Not yet activated. --- harbour/ChangeLog | 5 ++ harbour/utils/hbmk2/hbmk2.prg | 94 ++++++++++++++++++++++++++++++++++- 2 files changed, 97 insertions(+), 2 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 62fd9d8189..0b39ce5d9f 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,11 @@ past entries belonging to these authors: Viktor Szakats. */ +2009-04-30 09:43 UTC+0200 Viktor Szakats (harbour.01 syenar hu) + * utils/hbmk2/hbmk2.prg + + Added repository ID retrieval function. Currently supports + SVN, GIT and Mercurial. Not yet activated. + 2009-04-30 01:03 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/compiler/hbdbginf.c ! generate debugger break point line info also for very large blocks diff --git a/harbour/utils/hbmk2/hbmk2.prg b/harbour/utils/hbmk2/hbmk2.prg index ecb23b47e6..9ee01bf78e 100644 --- a/harbour/utils/hbmk2/hbmk2.prg +++ b/harbour/utils/hbmk2/hbmk2.prg @@ -4873,8 +4873,8 @@ STATIC FUNCTION GenHbl( aFiles, cFileOut, lEmpty ) IF ISARRAY( aTrans ) pI18N := __I18N_hashTable( __I18N_potArrayToHash( aTrans, lEmpty ) ) - cHblBody := HB_I18N_SaveTable( pI18N ) - IF hb_memoWrit( cFileOut, cHblBody ) + cHblBody := hb_I18N_SaveTable( pI18N ) + IF hb_MemoWrit( cFileOut, cHblBody ) lRetVal := .T. ELSE OutErr( "hbmk: Cannot create file: ", cFileOut, hb_osNewLine() ) @@ -4883,6 +4883,96 @@ STATIC FUNCTION GenHbl( aFiles, cFileOut, lEmpty ) RETURN lRetVal +#define _VCS_UNKNOWN 0 +#define _VCS_SVN 1 +#define _VCS_GIT 2 +#define _VCS_MERCURIAL 3 + +STATIC FUNCTION VCSDetect( cDir ) + + DEFAULT cDir TO "" + + IF ! Empty( cDir ) + cDir := DirAddPathSep( cDir ) + ENDIF + + DO CASE + CASE hb_DirExists( cDir + ".svn" ) ; RETURN _VCS_SVN + CASE hb_DirExists( cDir + ".git" ) ; RETURN _VCS_GIT + CASE hb_DirExists( cDir + ".hg" ) ; RETURN _VCS_MERCURIAL + ENDCASE + + RETURN _VCS_UNKNOWN + +STATIC FUNCTION VCSID( cDir ) +#ifdef _VCSID_USE_PROCESS + LOCAL hStdOut +#endif + LOCAL hnd, cStdOut + LOCAL nType := VCSDetect( cDir ) + LOCAL cCommand + LOCAL cResult := "" + LOCAL cTemp + LOCAL tmp + + SWITCH nType + CASE _VCS_SVN + cCommand := "svnversion" + EXIT + CASE _VCS_GIT + cCommand := "git rev-parse --short HEAD" + EXIT + CASE _VCS_MERCURIAL + cCommand := "hg head" + EXIT + OTHERWISE + cCommand := NIL + ENDSWITCH + + IF ! Empty( cCommand ) + +#ifdef _VCSID_USE_PROCESS + /* This is cleaner, but won't work when using aliases/wrappers + for version control commands. */ + hnd := hb_processOpen( cCommand,, @hStdOut ) + IF hnd != F_ERROR + cStdOut := Space( 256 ) + tmp := FRead( hStdOut, @cStdOut, Len( cStdOut ) ) + cStdOut := Left( cStdOut, tmp ) + hb_processClose( hnd ) + FClose( hStdOut ) +#else + hnd := hb_FTempCreateEx( @cTemp, NIL, "hbmk_", ".txt" ) + IF hnd != F_ERROR + FClose( hnd ) + cCommand += ">" + cTemp + hb_run( cCommand ) + cStdOut := hb_MemoRead( cTemp ) + FErase( cTemp ) +#endif + + SWITCH nType + CASE _VCS_SVN + /* 10959 */ + CASE _VCS_GIT + /* fe3bb56 */ + cStdOut := StrTran( cStdOut, Chr( 13 ), "" ) + cResult := StrTran( cStdOut, Chr( 10 ), "" ) + EXIT + CASE _VCS_MERCURIAL + /* changeset: 696:9e33729cafae... */ + tmp := At( Chr( 10 ), cStdOut ) + IF tmp > 0 + cStdOut := Left( cStdOut, tmp - 1 ) + cResult := AllTrim( StrTran( cStdOut, "changeset:", "" ) ) + ENDIF + EXIT + ENDSWITCH + ENDIF + ENDIF + + RETURN cResult + /* Keep this public, it's used from macro. */ FUNCTION hbmk_ARCH() RETURN s_cARCH