kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #20059
[PATCH] Fixed a False BZR Version Number Built From Local Branch of GIT-Source-Mirror
Please review and apply the attached patch file of CreateGitVersion.cmake.
*Issue to be fixed: a False BZR version number**
*
The details:
After cloning the repo of git-source-mirror, and working in my own local
branch, and committing a X times, the BZR version-number that is
generated by file CreateGitVersion.cmake is incremented by X number.
This is a mismatch of the true BZR number.
The tests:
_Before applying this patch_:
The command "Copy Version Info" built from the origin "master" branch
displays the following:
Version: (2015-08-30 *BZR 6134, Git 4e94d52*)-product release build
which is correct.
_However_, after creating a local branch based off the "master" branch,
and having committed 2 more times in the local branch, the command "Copy
Version Info" built from the local branch displays the following false
BZR number:
Version: (2015-08-30 *BZR 6136, Git edfb32e*)-product release build
which is _false_, because at the time the official BZR number is only
*6134*.
_After applying this_patch_:
The command "Copy Version Info" built from the "master" branch displays
the following:
Version: (2015-08-30 *BZR 6134, Git 4e94d52*)-product release build
which is still correct.
Now, the command "Copy Version Info" built from the local branch that
has 2 extra commits displayes the following:
Version: (2015-08-30 *BZR 6134, Git 4e94d52-ede23f9*)-product
release build
which is still correct with a _true_ *BZR 6134*, plus it has an *added
GIT short hash* from the local branch HEAD.
This added GIT short hash tells us that the running version is built
based off a true BZR 6134, plus some local modifications up to GIT short
hash of *ede23f9.*
--Joe
diff --git a/CMakeModules/CreateGitVersionHeader.cmake b/CMakeModules/CreateGitVersionHeader.cmake
index 42cf4b4..03b6388 100644
--- a/CMakeModules/CreateGitVersionHeader.cmake
+++ b/CMakeModules/CreateGitVersionHeader.cmake
@@ -46,12 +46,22 @@ macro( create_git_version_header _git_src_path )
OUTPUT_STRIP_TRAILING_WHITESPACE)
if( ${_git_log_result} EQUAL 0 )
+ # Get origin/HEAD hash:
+ execute_process(
+ COMMAND
+ ${GIT_EXECUTABLE} --no-pager log -1 origin/HEAD
+ --pretty=format:%h
+ WORKING_DIRECTORY ${_git_src_path}
+ OUTPUT_VARIABLE _git_SHORT_HASH_ORIGIN
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ # Get local HEAD hash:
execute_process(
COMMAND
${GIT_EXECUTABLE} --no-pager log -1 HEAD
--pretty=format:%h
WORKING_DIRECTORY ${_git_src_path}
- OUTPUT_VARIABLE _git_SHORT_HASH
+ OUTPUT_VARIABLE _git_SHORT_HASH_LOCAL
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
@@ -69,20 +79,29 @@ macro( create_git_version_header _git_src_path )
WORKING_DIRECTORY ${_git_src_path}
OUTPUT_VARIABLE _git_LAST_CHANGE_LOG
OUTPUT_STRIP_TRAILING_WHITESPACE)
+ # Get origin Repo HEAD (matched official BZR number) Version Number:
+ execute_process(
+ COMMAND
+ ${GIT_EXECUTABLE} rev-list origin/HEAD --count
+ --first-parent
+ WORKING_DIRECTORY ${_git_src_path}
+ OUTPUT_VARIABLE _git_SERIAL_ORIGIN
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ # Get local Repo HEAD (matched official BZR number) Version Number:
execute_process(
COMMAND
${GIT_EXECUTABLE} rev-list HEAD --count
--first-parent
WORKING_DIRECTORY ${_git_src_path}
- OUTPUT_VARIABLE _git_SERIAL
+ OUTPUT_VARIABLE _git_SERIAL_LOCAL
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Git hash: ${_git_LONG_HASH}")
if( ${_git_log_result} EQUAL 0 )
string( REGEX REPLACE "^(.*\n)?revno: ([^ \n]+).*"
- "\\2" Kicad_REPO_REVISION "BZR ${_git_SERIAL}, Git ${_git_SHORT_HASH}" )
+ "\\2" Kicad_REPO_REVISION "BZR ${_git_SERIAL_ORIGIN}, Git ${_git_SHORT_HASH_ORIGIN}" )
string( REGEX REPLACE "^(.*\n)?committer: ([^\n]+).*"
"\\2" Kicad_REPO_LAST_CHANGED_AUTHOR "${_git_LAST_COMITTER}")
string( REGEX REPLACE "^(.*\n)?timestamp: [a-zA-Z]+ ([^ \n]+).*"
@@ -98,7 +117,13 @@ macro( create_git_version_header _git_src_path )
if( Kicad_REPO_LAST_CHANGED_DATE )
string( REGEX REPLACE "^([0-9]+)\\-([0-9]+)\\-([0-9]+)" "\\1-\\2-\\3"
_kicad_git_date ${Kicad_REPO_LAST_CHANGED_DATE} )
- set( KICAD_BUILD_VERSION "(${_kicad_git_date} ${Kicad_REPO_REVISION})" )
+
+ if( ${_git_SHORT_HASH_LOCAL} EQUAL ${_git_SHORT_HASH_ORIGIN} )
+ set( KICAD_BUILD_VERSION "(${_kicad_git_date} ${Kicad_REPO_REVISION})" )
+ else()
+ message(STATUS "Your local git repo is different from the origin")
+ set( KICAD_BUILD_VERSION "(${_kicad_git_date} ${Kicad_REPO_REVISION}-${_git_SHORT_HASH_LOCAL})" )
+ endif()
endif()
set( KICAD_BUILD_VERSION ${KICAD_BUILD_VERSION} )
Follow ups