Skip to content

Commit

Permalink
Detect error when path is out of project root directory
Browse files Browse the repository at this point in the history
git-svn-id: file:///c/Users/zrh535/projects/svn_pbscc-proxy/trunk@50 579805b6-df4a-4a06-8235-6ebdbfd23ff6
  • Loading branch information
[email protected] committed Aug 7, 2010
1 parent 5b5f3af commit 5d486f1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ver:
-SubWCRev . version.hxx tmp\version.h

.cpp.obj:
$(cc) -Ox $(cflags) $(cvarsdll) -DSTRICT -YX -DNODEBUG $<
$(cc) -Ox $(cflags) $(cvarsdll) -DSTRICT -GX -YX -DNODEBUG $<

x_res:
rc $(rcvars) $(rcflags) -r -fo $(PRJNAME).res $(PRJNAME).rc
Expand Down
24 changes: 18 additions & 6 deletions src/pbscc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ bool rememberTarget(THECONTEXT*ctx,LONG nFiles,LPCSTR* lpFileNames){
long len=strlen(lpFileNames[i]);
if( len>4 && !stricmp(".pbt",lpFileNames[i]+len-4) && len<MAXFULLPATH ){
strcpy(ctx->PBTarget,lpFileNames[i]);
log("target: \"%s\"\n",ctx->PBTarget);
//log("target: \"%s\"\n",ctx->PBTarget);
}
}
return true;
Expand Down Expand Up @@ -792,6 +792,8 @@ SCCEXTERNC SCCRTN EXTFUN SccGet(LPVOID pContext, HWND hWnd, LONG nFiles, LPCSTR*
SCCRTN _SccQueryInfo(LPVOID pContext, LONG nFiles, LPCSTR* lpFileNames,LPLONG lpStatus,INFOEXCALLBACK cbFunc,LPVOID cbParm){
INFOEXCALLBACKPARM cbp;
THECONTEXT *ctx=(THECONTEXT *)pContext;
const char* errFile=NULL;
int svniErr;
//ctx->lpComment[0]=0;//guess this is deprecated line
DWORD t=GetTickCount();
if(cbFunc){
Expand All @@ -806,7 +808,7 @@ SCCRTN _SccQueryInfo(LPVOID pContext, LONG nFiles, LPCSTR* lpFileNames,LPLONG lp
lpStatus[i]=SCC_STATUS_NOTCONTROLLED;
SVNINFOITEM * svni;
log("\tsvni->get( \"%s\" , \"%s\" )\n",ctx->lpProjPath,lpFileNames[i]);
if( (svni = ctx->svni->get(ctx->lpProjPath,lpFileNames[i]))!=NULL ){
if( (svni = ctx->svni->get(ctx->lpProjPath,lpFileNames[i], &svniErr))!=NULL ){
lpStatus[i]=SCC_STATUS_CONTROLLED;
if(svni->owner[0]){
if(!stricmp(svni->owner,ctx->lpUser))lpStatus[i]=SCC_STATUS_OUTBYUSER|SCC_STATUS_CONTROLLED;
Expand All @@ -818,6 +820,10 @@ SCCRTN _SccQueryInfo(LPVOID pContext, LONG nFiles, LPCSTR* lpFileNames,LPLONG lp
cbFunc(cbParm,&cbp);
}
}else{
if(svniErr){
if(!errFile)errFile=lpFileNames[i];
log("\tWARN: Path is out of root\n");
}
if(cbFunc){
cbp.object=(char*)lpFileNames[i];
cbp.version="";
Expand All @@ -826,6 +832,12 @@ SCCRTN _SccQueryInfo(LPVOID pContext, LONG nFiles, LPCSTR* lpFileNames,LPLONG lp
}
//log("\tstat=%04X ver=\"%s\" user=\"%s\" \"%s\"\n",lpStatus[i],ver,user,lpFileNames[i]);
}
if(errFile){
mstring s=mstring("WARN: Path is out of root directory: ");
s.append(errFile);
_msg(ctx, s.c_str());
_msg(ctx,"Probably wrong scc parameter \"Local Root Directory\". It must include all subdirectories of your project." );
}
log("_SccQueryInfo: ms=%i\n",GetTickCount()-t);
return SCC_OK;
}
Expand All @@ -848,7 +860,7 @@ SCCEXTERNC SCCRTN EXTFUN SccCheckout(LPVOID pContext, HWND hWnd, LONG nFiles, LP
//do preliminary check
for(i=0;i<nFiles;i++){
SVNINFOITEM * svni;
if( (svni = ctx->svni->get(ctx->lpProjPath,lpFileNames[i]))!=NULL ){
if( (svni = ctx->svni->get(ctx->lpProjPath,lpFileNames[i],NULL))!=NULL ){
if(svni->owner[0])return SCC_E_ALREADYCHECKEDOUT;
}else return SCC_E_FILENOTCONTROLLED;
}
Expand Down Expand Up @@ -887,7 +899,7 @@ SCCEXTERNC SCCRTN EXTFUN SccUncheckout(LPVOID pContext, HWND hWnd, LONG nFiles,
//do preliminary check
for(i=0;i<nFiles;i++){
SVNINFOITEM * svni;
if( (svni = ctx->svni->get(ctx->lpProjPath,lpFileNames[i]))!=NULL ){
if( (svni = ctx->svni->get(ctx->lpProjPath,lpFileNames[i],NULL))!=NULL ){
if( stricmp(svni->owner,ctx->lpUser) ) return SCC_E_NOTCHECKEDOUT;
}else return SCC_E_FILENOTCONTROLLED;
}
Expand Down Expand Up @@ -928,7 +940,7 @@ SCCEXTERNC SCCRTN EXTFUN SccCheckin(LPVOID pContext, HWND hWnd, LONG nFiles, LPC

for(i=0;i<nFiles;i++){
SVNINFOITEM * svni;
if( (svni = ctx->svni->get(ctx->lpProjPath,lpFileNames[i]))!=NULL ){
if( (svni = ctx->svni->get(ctx->lpProjPath,lpFileNames[i],NULL))!=NULL ){
if( stricmp(svni->owner,ctx->lpUser) ) return SCC_E_NOTCHECKEDOUT;
}else return SCC_E_FILENOTCONTROLLED;
if( !_copyfile(ctx,lpFileNames[i],_subst(ctx, (char*)lpFileNames[i])) )goto error;
Expand Down Expand Up @@ -1023,7 +1035,7 @@ SCCEXTERNC SCCRTN EXTFUN SccDiff(LPVOID pContext, HWND hWnd, LPCSTR lpFileName,
log("\tdo visual diff\n");
mstring buf;
SVNINFOITEM * svni;
if( ( svni = ctx->svni->get(ctx->lpProjPath,lpFileName))!=NULL ) {
if( ( svni = ctx->svni->get(ctx->lpProjPath,lpFileName,NULL))!=NULL ) {
if(!stricmp(svni->owner,ctx->lpUser)){
_copyfile(ctx,lpFileName, _subst(ctx,lpFileName) );
buf.sprintf("TortoiseProc.exe /command:diff /path:\"%s\"", _subst(ctx,lpFileName) );
Expand Down
21 changes: 15 additions & 6 deletions src/svninfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
//initial size
#define __SVNINFO_H__INITSIZE 5000

#define __SVNINFO_ERR_PATH 1



typedef struct {
Expand Down Expand Up @@ -61,12 +63,12 @@ class svninfo {
if(len>0) {
if(_root[len-1]=='\\' || _root[len-1]=='/')len--;
if( CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,_root,len,_path,len)==2 ){
if(!_path[len]) return _path+len;
if(_path[len]=='\\' || _path[len]=='/' )return _path+len+1;
if(!_path[len]) return _path+len;
}
}
//just return the full path
return _path;
return NULL;
}


Expand Down Expand Up @@ -98,6 +100,8 @@ class svninfo {
* @param _owner: the lock owner of the element
*/
void add(const char*_root,const char*_path,const char*_name,const char*_rev,const char*_owner){
if( (_path=relativePath(_root,_path))==NULL)return;

if(count+1>=size){
//reallocate
SVNINFOITEM *ptr_old=ptr;
Expand All @@ -108,7 +112,6 @@ class svninfo {
memcpy(ptr, ptr_old, size_old*sizeof(SVNINFOITEM));
delete []ptr_old;
}
_path=relativePath(_root,_path);

ptr[count].path=buf->set(_path)->addPath(_name)->c_copy();
ptr[count].rev=buf->set(_rev)->c_copy();
Expand Down Expand Up @@ -157,9 +160,15 @@ class svninfo {
}
*/

/** returns svn element by absolute path with root specified */
SVNINFOITEM* get(const char*_root, const char*_path){
_path=relativePath(_root,_path);
/** returns svn element by absolute path with root specified
* @param err ptr to get error code. could be NULL
*/
SVNINFOITEM* get(const char*_root, const char*_path,int*err){
if( (_path=relativePath(_root,_path))==NULL ){
if(err)err[0]=__SVNINFO_ERR_PATH;
return NULL;
}
if(err)err[0]=0;
int h=hash(_path);
for(int i=0;i<count;i++) {
if( ptr[i].hash==h ){
Expand Down
19 changes: 10 additions & 9 deletions src/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ long outproc (LPCSTR msg, DWORD len) {
}




int main(int argc, char *argv[]) {
long t=0;
int i;

//printf("copy=%i\n",CopyFileUTF8("in.srw","out.srw") );
//if(1==1)return 0;


LONG lpSccCaps,pnCheckoutCommentLen,pnCommentLen;
logFile=stdout;
t=timer(t,"start");
Expand All @@ -54,22 +53,24 @@ int main(int argc, char *argv[]) {
THECONTEXT*ctx;

SccInitialize( (LPVOID *) &ctx, NULL, "caller","scc", &lpSccCaps, "aux", &pnCheckoutCommentLen, &pnCommentLen);

t=timer(t,"SccInitialize end");
SccOpenProject(ctx, NULL, "root", wc, "pb-workspace", "aux", "comment", outproc,0);
t=timer(t,"SccOpenProject end");


// for(i=0;i<5000;i++){
ScanWC(ctx);
// ScanWC(ctx);
// }
t=timer(t,"end scan");


SVNINFOITEM *svni=ctx->svni->get( "D:\\Home\\Projects\\pbscc-test\\newtest\\pb" , "d:\\home\\projects\\pbscc-test\\newtest\\pb\\tools\\tools.pbt" );
ScanWC(ctx);

SVNINFOITEM *svni;
printf("case 1: \n");
svni=ctx->svni->get( "D:\\Home\\Projects\\pbscc-test\\newtest\\pb\\" , "d:\\home\\projects\\pbscc-test\\newtest\\pb/scc.ini",NULL);
ctx->svni->print(svni);

for(i=0;i<ctx->svni->getCount();i++)ctx->svni->print(ctx->svni->get(i));
printf("count=%i\n\n\n",ctx->svni->getCount());
//for(i=0;i<ctx->svni->getCount();i++)ctx->svni->print(ctx->svni->get(i));
//printf("count=%i\n\n\n",ctx->svni->getCount());

SccUninitialize(ctx);

Expand Down

0 comments on commit 5d486f1

Please sign in to comment.