diff --git a/src/tools/genrevision/genrevision.cpp b/src/tools/genrevision/genrevision.cpp index 7a025f2a..e592b645 100644 --- a/src/tools/genrevision/genrevision.cpp +++ b/src/tools/genrevision/genrevision.cpp @@ -78,7 +78,8 @@ bool extractDataFromGit(std::string filename, std::string path, bool url, RawDat { char buf[1024]; - if (FILE* entriesFile = fopen(filename.c_str(), "r")) + FILE* entriesFile = fopen(filename.c_str(), "r"); + if (entriesFile) { char hash_str[200]; char branch_str[200]; @@ -140,42 +141,47 @@ bool extractDataFromGit(std::string filename, std::string path, bool url, RawDat else { strcpy(data.rev_str, hash_str); } } - else if (entriesFile = fopen((path + ".git/HEAD").c_str(), "r")) + else { - if (!fgets(buf, sizeof(buf), entriesFile)) + entriesFile = fopen((path + ".git/HEAD").c_str(), "r"); + if(entriesFile) { - fclose(entriesFile); - return false; - } - - char refBuff[200]; - if (!sscanf(buf, "ref: %s", refBuff)) - { - fclose(entriesFile); - return false; - } - - fclose(entriesFile); - - if (FILE *refFile = fopen((path + ".git/" + refBuff).c_str(), "r")) - { - char hash[41]; - - if (!fgets(hash, sizeof(hash), refFile)) + if (!fgets(buf, sizeof(buf), entriesFile)) { - fclose(refFile); + fclose(entriesFile); return false; } - strcpy(data.rev_str, hash); + char refBuff[200]; + if (!sscanf(buf, "ref: %s", refBuff)) + { + fclose(entriesFile); + return false; + } + + fclose(entriesFile); + + FILE *refFile = fopen((path + ".git/" + refBuff).c_str(), "r"); + if (refFile) + { + char hash[41]; + + if (!fgets(hash, sizeof(hash), refFile)) + { + fclose(refFile); + return false; + } + + strcpy(data.rev_str, hash); - fclose(refFile); + fclose(refFile); + } + else + { return false; } } else { return false; } } - else - return false; time_t rev_time = 0; // extracting date/time