v version: do more accurate current git hash detection, when not on a branch

pull/4823/head
Delyan Angelov 2020-05-10 18:56:19 +03:00
parent d33082dffe
commit 1bf13f8a09
1 changed files with 14 additions and 12 deletions

View File

@ -62,6 +62,8 @@ pub fn githash(should_get_from_filesystem bool) string {
head_content := os.read_file(git_head_file) or { head_content := os.read_file(git_head_file) or {
break break
} }
mut current_branch_hash := head_content
if head_content.starts_with('ref: ') {
gcbranch_rel_path := head_content.replace('ref: ', '').trim_space() gcbranch_rel_path := head_content.replace('ref: ', '').trim_space()
gcbranch_file := os.join_path(vroot, '.git', gcbranch_rel_path) gcbranch_file := os.join_path(vroot, '.git', gcbranch_rel_path)
// .git/refs/heads/master // .git/refs/heads/master
@ -69,9 +71,11 @@ pub fn githash(should_get_from_filesystem bool) string {
break break
} }
// get the full commit hash contained in the ref heads file // get the full commit hash contained in the ref heads file
current_branch_hash := os.read_file(gcbranch_file) or { branch_hash := os.read_file(gcbranch_file) or {
break break
} }
current_branch_hash = branch_hash
}
desired_hash_length := 7 desired_hash_length := 7
if current_branch_hash.len > desired_hash_length { if current_branch_hash.len > desired_hash_length {
return current_branch_hash[0..desired_hash_length] return current_branch_hash[0..desired_hash_length]
@ -112,9 +116,7 @@ pub fn launch_tool(is_verbose bool, tool_name string) {
mut should_compile := false mut should_compile := false
if !os.exists(tool_exe) { if !os.exists(tool_exe) {
should_compile = true should_compile = true
} } else {
//
else {
if os.file_last_mod_unix(tool_exe) <= os.file_last_mod_unix(vexe) { if os.file_last_mod_unix(tool_exe) <= os.file_last_mod_unix(vexe) {
// v was recompiled, maybe after v up ... // v was recompiled, maybe after v up ...
// rebuild the tool too just in case // rebuild the tool too just in case