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();
return true;
}
+class GP{
+ public:
+ GP(const QString&s){par<<s;}
+ GP(){}
+ GP&operator+(const QString&s){par<<s;return *this;}
+ GP operator+(const QString&s)const{return GP(s);}
+ operator QStringList(){return par;}
+ private:
+ QStringList par;
+};
+const GP gp;
+static bool procGit(const QStringList¶m,QStringList&ret,const QString&tgt,const QString&git)
+{
+ QProcess proc;
+ proc.setProcessChannelMode(QProcess::MergedChannels);
+ proc.setWorkingDirectory(tgt);
+ proc.start(git,param);
+ proc.waitForFinished();
+ if(proc.exitCode()!=0){
+ qDebug("Warning: error while calling git %s.",param.value(0).toAscii().data());
+ return false;
+ }
+ ret=QString::fromLocal8Bit(proc.readAllStandardOutput()).split('\n');
+ return true;
+}
+
bool WocProcessor::callGit()
{
- //TODO implement
- qDebug()<<"WARNING: WocProcessor::callGit not implemented!";
- return false;
+ QString tgt=m_baseDir+"/"+m_verTarget;
+ QStringList res;
+ //parse branch info and get current branch
+ QString lbranch,lrev;
+ if(!procGit(gp+"branch"+"-v",res,tgt,m_gitExe))return false;
+ foreach(QString line,res){
+ line=line.trimmed();
+ if(line.size()<3)continue;
+ if(line[0]=='*'){
+ QStringList lst=line.split(' ',QString::SkipEmptyParts);
+ if(lst.size()<3)continue;
+ //check for detached checkout
+ if(lst[1]=="(no"&&lst[2]=="branch)"){
+ if(lst.size()>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()