Ensure that gen_git_commit_h works even without git.

This commit is contained in:
levlam 2022-07-07 20:38:44 +03:00
parent 81cb929b37
commit f8b49fe421
4 changed files with 23 additions and 10 deletions

View File

@ -1,6 +1,6 @@
$commit = git rev-parse HEAD
git diff-index --quiet HEAD
$dirty = $LASTEXITCODE
$commit = try { git rev-parse HEAD } catch { "unknown" }
try { git diff-index --quiet HEAD } catch {}
$dirty = if ($LASTEXITCODE) { "true" } else { "false" }
echo "#pragma once`r`n#define GIT_COMMIT `"$commit`"`r`n#define GIT_DIRTY $dirty" | out-file -encoding ASCII auto/git_info.h.new
if (-not (Test-Path .\auto\git_info.h) -or (Compare-Object $(Get-Content .\auto\git_info.h.new) $(Get-Content .\auto\git_info.h))) {
mv -Force auto/git_info.h.new auto/git_info.h

View File

@ -1,8 +1,14 @@
#!/bin/sh
cd $(dirname $0)
commit=$(git rev-parse HEAD)
git diff-index --quiet HEAD
dirty=$?
commit="$(git rev-parse HEAD 2> /dev/null)"
commit="${commit:-unknown}"
git diff-index --quiet HEAD 2> /dev/null
if [ $? -ne 0 ]
then
dirty="true"
else
dirty="false"
fi
printf "#pragma once\n#define GIT_COMMIT \"$commit\"\n#define GIT_DIRTY $dirty\n" > auto/git_info.h.new
if cmp -s auto/git_info.h.new auto/git_info.h 2>&1 > /dev/null
then

View File

@ -8,11 +8,20 @@
#include "auto/git_info.h"
#if !defined(GIT_COMMIT)
#define GIT_COMMIT "unknown"
#endif
#if !defined(GIT_DIRTY)
#define GIT_DIRTY false
#endif
namespace td {
CSlice GitInfo::commit() {
const char *GitInfo::commit() {
return GIT_COMMIT;
}
bool GitInfo::is_dirty() {
return GIT_DIRTY;
}

View File

@ -6,13 +6,11 @@
//
#pragma once
#include "td/utils/Slice.h"
namespace td {
class GitInfo {
public:
static CSlice commit();
static const char *commit();
static bool is_dirty();
};