*Backed out changeset 3be01fb200a5
--HG-- branch : trunk
This commit is contained in:
@@ -15,12 +15,15 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#pragma warning(disable:4996)
|
||||
|
||||
struct RawData
|
||||
{
|
||||
char hash_str[200];
|
||||
@@ -28,11 +31,14 @@ struct RawData
|
||||
char date_str[200];
|
||||
char time_str[200];
|
||||
};
|
||||
|
||||
void extractDataFromSvn(FILE* EntriesFile, bool url, RawData& data)
|
||||
{
|
||||
char buf[200];
|
||||
|
||||
char repo_str[200];
|
||||
char num_str[200];
|
||||
|
||||
fgets(buf,200,EntriesFile);
|
||||
fgets(buf,200,EntriesFile);
|
||||
fgets(buf,200,EntriesFile);
|
||||
@@ -43,16 +49,20 @@ void extractDataFromSvn(FILE* EntriesFile, bool url, RawData& data)
|
||||
fgets(buf,200,EntriesFile);
|
||||
fgets(buf,200,EntriesFile);
|
||||
fgets(buf,200,EntriesFile); sscanf(buf,"%10sT%8s",data.date_str,data.time_str);
|
||||
|
||||
if(url)
|
||||
sprintf(data.rev_str,"%s at %s",num_str,repo_str);
|
||||
else
|
||||
strcpy(data.rev_str,num_str);
|
||||
}
|
||||
|
||||
void extractDataFromHG(FILE* EntriesFile, std::string path, bool url, RawData& data)
|
||||
{
|
||||
char buf[200];
|
||||
|
||||
char hash_str[200];
|
||||
char revision_str[200];
|
||||
|
||||
bool found = false;
|
||||
while(fgets(buf,200,EntriesFile))
|
||||
{
|
||||
@@ -62,6 +72,7 @@ void extractDataFromHG(FILE* EntriesFile, std::string path, bool url, RawData& d
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found)
|
||||
{
|
||||
strcpy(data.hash_str,"*");
|
||||
@@ -70,22 +81,28 @@ void extractDataFromHG(FILE* EntriesFile, std::string path, bool url, RawData& d
|
||||
strcpy(data.time_str,"*");
|
||||
return;
|
||||
}
|
||||
|
||||
char thash_str[200];
|
||||
for(int i = 11;i >= 0; --i)
|
||||
{
|
||||
thash_str[i] = hash_str[i];
|
||||
}
|
||||
thash_str[12] = '\0';
|
||||
|
||||
strcpy(data.hash_str,thash_str);
|
||||
strcpy(data.rev_str,revision_str);
|
||||
|
||||
strcpy(data.date_str,"*");
|
||||
strcpy(data.time_str,"*");
|
||||
}
|
||||
|
||||
void extractDataFromArchive(FILE* EntriesFile, std::string path, bool url, RawData& data)
|
||||
{
|
||||
char buf[200];
|
||||
|
||||
char hash_str[200];
|
||||
char revision_str[200];
|
||||
|
||||
bool found = false;
|
||||
fgets(buf,200,EntriesFile);
|
||||
while(fgets(buf,200,EntriesFile))
|
||||
@@ -96,6 +113,7 @@ void extractDataFromArchive(FILE* EntriesFile, std::string path, bool url, RawDa
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found)
|
||||
{
|
||||
strcpy(data.hash_str,"*");
|
||||
@@ -104,23 +122,29 @@ void extractDataFromArchive(FILE* EntriesFile, std::string path, bool url, RawDa
|
||||
strcpy(data.time_str,"*");
|
||||
return;
|
||||
}
|
||||
|
||||
char thash_str[200];
|
||||
for(int i = 11;i >= 0; --i)
|
||||
{
|
||||
thash_str[i] = hash_str[i];
|
||||
}
|
||||
thash_str[12] = '\0';
|
||||
|
||||
strcpy(data.hash_str,thash_str);
|
||||
strcpy(data.rev_str,"Archive");
|
||||
|
||||
strcpy(data.date_str,"*");
|
||||
strcpy(data.time_str,"*");
|
||||
}
|
||||
|
||||
void extractDataFromGit(FILE* EntriesFile, std::string path, bool url, RawData& data)
|
||||
{
|
||||
char buf[200];
|
||||
|
||||
char hash_str[200];
|
||||
char branch_str[200];
|
||||
char url_str[200];
|
||||
|
||||
bool found = false;
|
||||
while(fgets(buf,200,EntriesFile))
|
||||
{
|
||||
@@ -130,6 +154,7 @@ void extractDataFromGit(FILE* EntriesFile, std::string path, bool url, RawData&
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found)
|
||||
{
|
||||
strcpy(data.hash_str,"*");
|
||||
@@ -138,11 +163,13 @@ void extractDataFromGit(FILE* EntriesFile, std::string path, bool url, RawData&
|
||||
strcpy(data.time_str,"*");
|
||||
return;
|
||||
}
|
||||
|
||||
if(url)
|
||||
{
|
||||
char* host_str = NULL;
|
||||
char* acc_str = NULL;
|
||||
char* repo_str = NULL;
|
||||
|
||||
// parse URL like [email protected]:mangos/mangos
|
||||
char url_buf[200];
|
||||
int res = sscanf(url_str,"git@%s",url_buf);
|
||||
@@ -162,6 +189,7 @@ void extractDataFromGit(FILE* EntriesFile, std::string path, bool url, RawData&
|
||||
repo_str = strtok(NULL,".");
|
||||
}
|
||||
}
|
||||
|
||||
// can generate nice link
|
||||
if(res)
|
||||
sprintf(data.rev_str,"http://%s/%s/%s/commit/%s",host_str,acc_str,repo_str,hash_str);
|
||||
@@ -172,6 +200,7 @@ void extractDataFromGit(FILE* EntriesFile, std::string path, bool url, RawData&
|
||||
else
|
||||
strcpy(data.rev_str,hash_str);
|
||||
strcpy(data.hash_str,"*");
|
||||
|
||||
time_t rev_time = 0;
|
||||
// extracting date/time
|
||||
FILE* LogFile = fopen((path+".git/logs/HEAD").c_str(), "r");
|
||||
@@ -185,12 +214,16 @@ void extractDataFromGit(FILE* EntriesFile, std::string path, bool url, RawData&
|
||||
int res2 = sscanf(buf,"%s %s %s %s %i",buf2,new_hash,buf2,buf2,&unix_time);
|
||||
if(res2!=5)
|
||||
continue;
|
||||
|
||||
if(strcmp(hash_str,new_hash))
|
||||
continue;
|
||||
|
||||
rev_time = unix_time;
|
||||
break;
|
||||
}
|
||||
|
||||
fclose(LogFile);
|
||||
|
||||
if(rev_time)
|
||||
{
|
||||
tm* aTm = localtime(&rev_time);
|
||||
@@ -215,42 +248,51 @@ void extractDataFromGit(FILE* EntriesFile, std::string path, bool url, RawData&
|
||||
strcpy(data.time_str,"*");
|
||||
}
|
||||
}
|
||||
|
||||
bool extractDataFromSvn(std::string filename, bool url, RawData& data)
|
||||
{
|
||||
FILE* EntriesFile = fopen(filename.c_str(), "r");
|
||||
if(!EntriesFile)
|
||||
return false;
|
||||
|
||||
extractDataFromSvn(EntriesFile,url,data);
|
||||
fclose(EntriesFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool extractDataFromGit(std::string filename, std::string path, bool url, RawData& data)
|
||||
{
|
||||
FILE* EntriesFile = fopen(filename.c_str(), "r");
|
||||
if(!EntriesFile)
|
||||
return false;
|
||||
|
||||
extractDataFromGit(EntriesFile,path,url,data);
|
||||
fclose(EntriesFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool extractDataFromHG(std::string filename, std::string path, bool url, RawData& data)
|
||||
{
|
||||
FILE* EntriesFile = fopen(filename.c_str(), "r");
|
||||
if(!EntriesFile)
|
||||
return false;
|
||||
|
||||
extractDataFromHG(EntriesFile,path,url,data);
|
||||
fclose(EntriesFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool extractDataFromArchive(std::string filename, std::string path, bool url, RawData& data)
|
||||
{
|
||||
FILE* EntriesFile = fopen(filename.c_str(), "r");
|
||||
if(!EntriesFile)
|
||||
return false;
|
||||
|
||||
extractDataFromArchive(EntriesFile,path,url,data);
|
||||
fclose(EntriesFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string generateHeader(char const* rev_str, char const* date_str, char const* time_str, char const* hash_str)
|
||||
{
|
||||
std::ostringstream newData;
|
||||
@@ -273,8 +315,10 @@ std::string generateHeader(char const* rev_str, char const* date_str, char const
|
||||
newData << " #define STRFILEVER \"0, 0, " << rev_str << ", " << hash_str << "\""<< std::endl;
|
||||
newData << " #define STRPRODUCTVER \"0, 0, " << rev_str << ", " << hash_str << "\""<< std::endl;
|
||||
newData << "#endif // __REVISION_H__" << std::endl;
|
||||
|
||||
return newData.str();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
bool use_url = false;
|
||||
@@ -282,6 +326,7 @@ int main(int argc, char **argv)
|
||||
bool git_prefered = false;
|
||||
bool svn_prefered = false;
|
||||
std::string path;
|
||||
|
||||
// Call: tool {options} [path]
|
||||
// -h use hg prefered (default)
|
||||
// -g use git prefered
|
||||
@@ -292,6 +337,7 @@ int main(int argc, char **argv)
|
||||
{
|
||||
if(!argv[k] || !*argv[k])
|
||||
break;
|
||||
|
||||
if(argv[k][0]!='-')
|
||||
{
|
||||
path = argv[k];
|
||||
@@ -299,6 +345,7 @@ int main(int argc, char **argv)
|
||||
path += '/';
|
||||
break;
|
||||
}
|
||||
|
||||
switch(argv[k][1])
|
||||
{
|
||||
case 'h':
|
||||
@@ -328,11 +375,15 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// new data extraction
|
||||
std::string newData;
|
||||
|
||||
{
|
||||
RawData data;
|
||||
|
||||
bool res = false;
|
||||
|
||||
if(svn_prefered)
|
||||
{
|
||||
/// SVN data
|
||||
@@ -385,6 +436,7 @@ int main(int argc, char **argv)
|
||||
if (!res)
|
||||
res = extractDataFromArchive(path+"_hg_archival.txt",path,use_url,data);
|
||||
}
|
||||
|
||||
else if(hg_prefered)
|
||||
{
|
||||
// HG data
|
||||
@@ -411,13 +463,16 @@ int main(int argc, char **argv)
|
||||
if (!res)
|
||||
res = extractDataFromArchive(path+"_hg_archival.txt",path,use_url,data);
|
||||
}
|
||||
|
||||
if(res)
|
||||
newData = generateHeader(data.rev_str,data.date_str,data.time_str,data.hash_str);
|
||||
else
|
||||
newData = generateHeader("*", "*", "*", "*");
|
||||
}
|
||||
|
||||
/// get existed header data for compare
|
||||
std::string oldData;
|
||||
|
||||
if(FILE* HeaderFile = fopen("revision.h","rb"))
|
||||
{
|
||||
while(!feof(HeaderFile))
|
||||
@@ -427,8 +482,10 @@ int main(int argc, char **argv)
|
||||
break;
|
||||
oldData += (char)c;
|
||||
}
|
||||
|
||||
fclose(HeaderFile);
|
||||
}
|
||||
|
||||
/// update header only if different data
|
||||
if(newData != oldData)
|
||||
{
|
||||
@@ -438,6 +495,7 @@ int main(int argc, char **argv)
|
||||
fclose(OutputFile);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user