Mercurial and Git clients can push and pull from this alias URL to interact with this repository. You can change to which repository an alias points by going to the Aliases link on the project page.
// Copyright (C) 2009 Benjamin Pollack//// This program is free software: you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation, either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program. If not, see <http://www.gnu.org/licenses/>.#include "stdafx.h"#include "dirstate.h"
-#include <stdio.h>-#include <stdlib.h>-#include <stddef.h>-#include <time.h>-#include <sys/types.h>-#include <sys/stat.h>-#include <vector>
#include <list>
#ifdef WIN32
-#ifndef _WINBASE_-#include <windef.h> // needed by winbase.h-#include <stdarg.h> // needed by winbase.h-#include <winbase.h>-#endif--#include <string.h>-#include <_mingw.h>--#define MAX_PATH 260--static __int64 days_between_epochs = 134774; /* days between 1.1.1601 and 1.1.1970 */
static __int64 secs_between_epochs = (__int64)days_between_epochs * 86400;
intlstat(constchar*file,struct_stat&rstat){WIN32_FIND_DATAdata;HANDLEhfind;__int64temp;hfind=FindFirstFile(file,&data);if(hfind==INVALID_HANDLE_VALUE)return-1;FindClose(hfind);rstat.st_mtime=*(__int64*)&data.ftLastWriteTime/10000000-secs_between_epochs;rstat.st_size=(data.nFileSizeHigh<<sizeof(data.nFileSizeHigh))|data.nFileSizeLow;return0;}#endif#define HASH_LENGTH 20structdirentry{unsignedcharstate;unsignedmode;unsignedsize;unsignedmtime;unsignedlength;std::stringname;charstatus(conststruct_stat&stat)const;};chardirentry::status(conststruct_stat&stat)const{switch(this->state){case'n':
if(this->mtime==(unsigned)stat.st_mtime&&this->size==(unsigned)stat.st_size#ifndef WIN32&&this->mode==stat.st_mode#endif)return'C';elsereturn'M';case'm':
return'M';case'r':
return'R';case'a':
return'A';default:return'?';}}classdirstate{typedefstd::vector<direntry>EntriesT;EntriesTentries;public:typedefEntriesT::size_typesize_type;typedefEntriesT::const_iteratorIter;charparent1[HASH_LENGTH];charparent2[HASH_LENGTH];staticstd::auto_ptr<dirstate>read(conststd::string&path);voidadd(constdirentry&e){entries.push_back(e);}Iterbegin()const{returnentries.begin();}Iterend()const{returnentries.end();}size_typesize()const{returnentries.size();}private:staticuint32_tntohl(uint32_tx){return((x&0x000000ffUL)<<24)|((x&0x0000ff00UL)<<8)|((x&0x00ff0000UL)>>8)|((x&0xff000000UL)>>24);}};std::auto_ptr<dirstate>dirstate::read(conststd::string&path){FILE*f=fopen(path.c_str(),"rb");if(!f){TDEBUG_TRACE("dirstate::read: can't open "<<path);returnstd::auto_ptr<dirstate>(0);}std::auto_ptr<dirstate>pd(newdirstate());fread(&pd->parent1,sizeof(char),HASH_LENGTH,f);fread(&pd->parent2,sizeof(char),HASH_LENGTH,f);direntrye;std::vector<char>temp(MAX_PATH+10,0);while(fread(&e.state,sizeof(e.state),1,f)==1){fread(&e.mode,sizeof(e.mode),1,f);fread(&e.size,sizeof(e.size),1,f);fread(&e.mtime,sizeof(e.mtime),1,f);fread(&e.length,sizeof(e.length),1,f);e.mode=ntohl(e.mode);e.size=ntohl(e.size);e.mtime=ntohl(e.mtime);e.length=ntohl(e.length);temp.resize(e.length+1,0);fread(&temp[0],sizeof(char),e.length,f);temp[e.length]=0;e.name=&temp[0];pd->add(e);}fclose(f);returnpd;}classdirstatecache{structentry{constdirstate*dstate;__time64_tmtime;std::stringhgroot;entry():dstate(0),mtime(0){}};typedefstd::list<entry>::iteratorIter;staticstd::list<entry>_cache;public:staticconstdirstate*get(conststd::string&hgroot);};std::list<dirstatecache::entry>dirstatecache::_cache;constdirstate*dirstatecache::get(conststd::string&hgroot){std::stringpath=hgroot;path+="/.hg/dirstate";struct_statstat;if(0!=lstat(path.c_str(),stat)){TDEBUG_TRACE("dirstatecache::get: lstat("<<path<<") fails");return0;}Iteriter=_cache.begin();for(;iter!=_cache.end();++iter){if(hgroot==iter->hgroot)break;}if(iter==_cache.end()){if(_cache.size()>=10){TDEBUG_TRACE("dirstatecache::get: dropping "<<_cache.back().hgroot);delete_cache.back().dstate;_cache.back().dstate=0;_cache.pop_back();}entrye;e.hgroot=hgroot;_cache.push_front(e);iter=_cache.begin();}if(iter->mtime<stat.st_mtime){iter->mtime=stat.st_mtime;if(iter->dstate){deleteiter->dstate;iter->dstate=0;TDEBUG_TRACE("dirstatecache::get: refreshing "<<hgroot);}else{TDEBUG_TRACE("dirstatecache::get: reading "<<hgroot);}iter->dstate=dirstate::read(path).release();TDEBUG_TRACE("dirstatecache::get: "<<iter->dstate->size()<<" entries read. "<<_cache.size()<<" repos in cache");}returniter->dstate;}intHgQueryDirstate(conststd::string&hgroot,conststd::string&abspath,std::string&relpath,constdirstate*&ppd,struct_stat&rstat){if(0!=lstat(abspath.c_str(),rstat)){TDEBUG_TRACE("HgQueryDirstate: lstat("<<abspath<<") fails");return0;}ppd=dirstatecache::get(hgroot);if(!ppd){TDEBUG_TRACE("HgQueryDirstate: dirstatecache::get("<<hgroot<<") returns 0");return0;}for(size_ti=0;i<relpath.size();++i){if(relpath[i]=='\\')relpath[i]='/';}return1;}intHgQueryDirstateDirectory(conststd::string&hgroot,conststd::string&abspath,std::string&relpath,char&outStatus){constdirstate*pd=0;struct_statstat;if(!HgQueryDirstate(hgroot,abspath,relpath,pd,stat)){TDEBUG_TRACE("HgQueryDirstateDirectory: HgQueryDirstate returns 0."<<" hgroot = "<<hgroot<<", abspath = "<<abspath);return0;}booladded=false;boolmodified=false;boolempty=true;size_trootlen=hgroot.size();size_tlen=relpath.size();for(dirstate::Iteriter=pd->begin();iter!=pd->end()&&!modified;++iter){constdirentry&e=*iter;if(e.name.compare(0,len,relpath)!=0)continue;empty=false;switch(e.state){case'n':
if(!modified){std::stringtemp=hgroot;temp+="/";temp+=e.name;if(0==lstat(temp.c_str(),stat))modified=(e.status(stat)=='M');}break;case'm':
modified=true;break;case'a':
added=true;break;}}if(modified)outStatus='M';elseif(added)outStatus='A';elseif(empty)outStatus='?';elseoutStatus='C';return1;}intHgQueryDirstateFile(conststd::string&hgroot,conststd::string&abspath,std::string&relpath,char&outStatus){constdirstate*pd=0;struct_statstat;if(!HgQueryDirstate(hgroot,abspath,relpath,pd,stat)){TDEBUG_TRACE("HgQueryDirstateFile: HgQueryDirstate returns 0."<<" hgroot = "<<hgroot<<", abspath = "<<abspath);return0;}for(dirstate::Iteriter=pd->begin();iter!=pd->end();++iter){constdirentry&e=*iter;if(relpath==e.name){outStatus=e.status(stat);returnoutStatus!='?';}}return0;}staticchar*revhash_string(constcharrevhash[HASH_LENGTH]){unsignedix;staticcharrev_string[HASH_LENGTH*2+1];staticchar*hexval="0123456789abcdef";for(ix=0;ix<HASH_LENGTH;++ix){rev_string[ix*2]=hexval[(revhash[ix]>>4)&0xf];rev_string[ix*2+1]=hexval[revhash[ix]&0xf];}rev_string[sizeof(rev_string)]=0;returnrev_string;}voidtestread(){std::auto_ptr<dirstate>pd=dirstate::read(".hg/dirstate");time_tt;char*s;unsignedix;printf("parent1: %s\n",revhash_string(pd->parent1));printf("parent2: %s\n",revhash_string(pd->parent2));printf("entries: %d\n\n",pd->size());for(dirstate::Iteri=pd->begin();i!=pd->end();++i){t=i->mtime;s=ctime(&t);s[strlen(s)-1]='\0';printf("%s %s\n",s,i->name.c_str());}}#if 0int main(int argc, char *argv[]){ testread(); return 0;}#endif
Attach a Trello Card
Add a tag
Your session has expired
You are no longer logged in. Please log in and try your request again.
Filter RSS Feed
This RSS feed URL allows you to see the contents of your current filter using any feed reader.
This link includes a special authentication token. If you share the URL with anyone else, they can see this RSS feed's activity. You can disable these tokens when needed.
Your current filter is unsaved; changing it won't affect this RSS feed.