From: Konrad Rosenbaum Date: Mon, 19 Dec 2011 12:34:24 +0000 (+0100) Subject: version info for git X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=3db90a688131dd4ca58a858bd0d6a95e7bf203e0;p=web%2Fkonrad%2Fpack.git version info for git --- diff --git a/qtbase/include/wob.h b/qtbase/include/wob.h index 85db756..7d8c6e3 100644 --- a/qtbase/include/wob.h +++ b/qtbase/include/wob.h @@ -34,6 +34,8 @@ enum VersionInfo{ VersionAuthor, ///contains "modified" if the source tree contained local modifications, "unmodified" if it was pristine, "local" if it was not under source control, depending on the source control system and circumstances this can also contain other values VersionLocallyModified, + ///the time at which source files were generated by woc + VersionGenTime, }; diff --git a/woc/proc/processor.cpp b/woc/proc/processor.cpp index 096ac46..f2e5ac5 100644 --- a/woc/proc/processor.cpp +++ b/woc/proc/processor.cpp @@ -226,6 +226,7 @@ bool WocProcessor::processFile(QString fn) m_verInfo.insert("Comm",m_verComm); m_verInfo.insert("NeedComm",m_verNeedComm); m_verInfo.insert("HR",m_verHR); + m_verInfo.insert("GenTime",QDateTime::currentDateTime().toString(Qt::ISODate)); }else if(tn=="Doc"){ QString s=el.text().trimmed(); @@ -367,11 +368,129 @@ bool WocProcessor::callSvn() return true; } +class GP{ + public: + GP(const QString&s){par<3)lrev=lst[3]; + break; + } + //remember + lbranch=lst[1]; + lrev=lst[2]; + break; + } + } + //low level version info + if(!procGit(gp+"log"+"-1"+"--format=raw",res,tgt,m_gitExe))return false; + QString rev,date; + foreach(QString line,res){ + QStringList lst=line.split(" ",QString::SkipEmptyParts); + if(lst.size()<2)continue; + if(lst[0]=="commit")rev=lst[1];else + if(lst[0]=="author"){ + if(lst.size()<4)continue; + QString tz=lst[lst.size()-1]; + date=lst[lst.size()-2]; + QDateTime tm=QDateTime::fromTime_t(date.toLongLong()).toUTC(); + if(tz.size()==5){ + int f=0; + if(tz[0]=='+')f=1;else + if(tz[0]=='-')f=-1; + tm=tm.addSecs(tz.mid(1,2).toInt(0,10)*3600*f+ + tz.mid(3,2).toInt(0,10)*60*f); + }else tz=""; + date=tm.toString("yyyy-MM-dd hh:mm:ss ")+tz; + m_verInfo.insert("Author",lst[1]); + m_verInfo.insert("Time",date); + } + } + if(rev.isEmpty())rev=lrev; + //get remote info + QString remote,remurl; + if(!lbranch.isEmpty() && procGit(gp+"config"+"-l",res,tgt,m_gitExe)){ + //find the remote of the local branch + QString key="branch."+lbranch+".remote"; + foreach(QString line,res){ + QStringList lst=line.trimmed().split("="); + if(lst.size()!=2)continue; + if(lst[0]==key){ + remote=lst[1]; + break; + } + } + key="remote."+remote+".url"; + if(!remote.isEmpty()) + foreach(QString line,res){ + QStringList lst=line.trimmed().split("="); + if(lst.size()!=2)continue; + if(lst[0]==key){ + remurl=lst[1]; + break; + } + } + if(!remurl.isEmpty()) + m_verInfo.insert("RootURL",remurl); + } + //find path + QDir tdir(QDir(tgt).absolutePath()); + QString path; + do{ + if(tdir.entryList(QDir::Dirs|QDir::AllDirs|QDir::Hidden|QDir::System).contains(".git")){ + break; + }else{ + path=tdir.dirName()+(path.isEmpty()?"":"/"+path); + } + }while(tdir.cdUp()); + //modification state + if(!procGit(gp+"status"+"-s"+".",res,tgt,m_gitExe))return false; + int mctr=0; + foreach(QString line,res){ + if(!line.trimmed().isEmpty())mctr++; + } + //done: add to version info + m_verInfo.insert("System","git"); + m_verInfo.insert("Path",path); + m_verInfo.insert("Number",rev); + m_verInfo.insert("LocallyModified",mctr?"modified":"unmodified"); + return true; } static inline QString getLocalUser() diff --git a/woc/qt/qtout.cpp b/woc/qt/qtout.cpp index ec37dd1..b368f77 100644 --- a/woc/qt/qtout.cpp +++ b/woc/qt/qtout.cpp @@ -296,7 +296,7 @@ void WocQtOut::initVersionH() } vhf.write(QByteArray(HDRSTART).replace("%",m_prefix.toAscii()+"STATIC_VERSION_H")); //generate functions for project's own values - QString data="#include \n#include \n\n" + QString data="#include \n#include \n#include \n\n" "static inline QString WOCgenerated_versionInfo(WOb::VersionInfo vi){\nswitch(vi){\n"; QString data2; QMap vm=WocProcessor::instance()->versionInfo();