-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This version works, although there is only one line of documentation/debug.
- Loading branch information
0 parents
commit b374397
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
char static str[137]; | ||
|
||
int main() | ||
{ | ||
if(!is_in_git_repo()) | ||
return 0; | ||
strcpy(str, "#if defined _INC_GIT_HASH\n"); | ||
strcat(str, " #endinput\n"); | ||
strcat(str, "#else\n"); | ||
strcat(str, " #define _INC_GIT_HASH\n"); | ||
strcat(str, "#endif\n\n"); | ||
strcat(str, "#define GitHash "); | ||
getGitSha(str); | ||
store_data("githash.inc", str); | ||
//printf("%d\n", strlen(str)); //Debug function, to count the string size if there are any changes to 'str'. | ||
} | ||
|
||
getGitSha(char *target) | ||
{ | ||
FILE *sha = popen("git rev-parse --verify HEAD -q", "r"); | ||
char buf[40]; | ||
while (fgets(buf, sizeof(buf), sha) != 0) { | ||
strcat(target, buf); | ||
} | ||
pclose(sha); | ||
} | ||
|
||
int is_in_git_repo() | ||
{ | ||
if(system("git rev-parse --verify HEAD -q")) | ||
return 0; | ||
return 1; | ||
} | ||
|
||
store_data(const char *filepath, const char *data) | ||
{ | ||
FILE *fp = fopen(filepath, "w"); | ||
if (fp != NULL) | ||
{ | ||
fputs(data, fp); | ||
fclose(fp); | ||
} | ||
} |