tools: allow short SHA1 longer than 7 (#1399)

newer versions of git use a variable lenght proportional to the
repository size (9 for cppcheck)

remove old chomp helper function and make copying the revision
smarter to hopefully cover for edge case that needed it
This commit is contained in:
Carlo Marcelo Arenas Belon 2018-09-28 10:04:39 -07:00 committed by Daniel Marjamäki
parent f65cf220ba
commit 9d73cf08bc
1 changed files with 6 additions and 7 deletions

View File

@ -2,11 +2,11 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
char *replace(char *str, char before, char after) static void revncpy(char *dst, const char *src, size_t len)
{ {
while (strchr(str,before)) int n = 0;
*strchr(str,before) = after; while (n++<len && *src && *src!=' ' && *src!='\r' && *src!='\n')
return str; *dst++ = *src++;
} }
int main() int main()
@ -21,13 +21,12 @@ int main()
float mintime=0.0f, maxtime=0.0f; float mintime=0.0f, maxtime=0.0f;
char rev[10] = {0}; char rev[10] = {0};
char line[128] = {0}; char line[128] = {0};
while (fgets(line,sizeof(line),f) && n < (sizeof(lines)/sizeof(*lines))) { while (fgets(line,sizeof(line),f) && n < (sizeof(lines)/sizeof(*lines))) {
replace(line,'\r','\0');
replace(line,'\n','\0');
if (strncmp(line,"HEAD is now at ", 15) == 0) { if (strncmp(line,"HEAD is now at ", 15) == 0) {
if (rev[0]) if (rev[0])
sprintf(lines[n++],"%s\t%.1f\t%.1f", rev, mintime, maxtime); sprintf(lines[n++],"%s\t%.1f\t%.1f", rev, mintime, maxtime);
strncpy(rev, line+15, 7); revncpy(rev, line+15, sizeof(rev)-1);
mintime = 0.0f; mintime = 0.0f;
maxtime = 0.0f; maxtime = 0.0f;
} }