;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Copyright (c) 2000, Perforce Software, All rights reserved. ; ; This software was originally developed by Silicon Graphics, Inc (SGI). ; ; Redistribution and use in source and binary forms, with or ; without modification, are permitted provided that the following ; conditions are met: ; ; Redistributions of source code must retain the above copyright notice, ; this list of conditions and the following disclaimer. ; ; Redistributions in binary form must reproduce the above copyright ; notice, this list of conditions and the following disclaimer in the ; documentation and/or other materials provided with the distribution. ; ; Neither name of Perforce Software nor SGI nor the names of its ; contributors may be used to endorse or promote products derived from ; this software without specific prior written permission. ; ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ; ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR ; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, ; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, ; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR ; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. procedure(CDS_P4RevertLib(libname) ;_Aug 30 00 sikand 779 ; library revert prog((ldd client cont status syncspec command sfile sfilep data depotfile del delfilep delfile cnum dfile dfilenovers lin tmpFile) unless( hiGraphicMode() error("Graphic command!") ) ;; first sync the library to the user sync-spec ;; handle files that are opened for edit by either skipping ;; them or aborting ldd = ddGetObj(libname) unless( libname error("No such lib!\n") ) printf("Disabling auto sync") CDS_P4StopAutoSync() printf("Please wait.....checks are in progress\n") client = CDS_P4GetClient(ldd) CDS_P4CurrentClient = client tmpFile = strcat("/tmp/p4open." CDS_P4UserFileName) CDS_P4IPCDirectCommand(strcat("opened -a //depot/" CDS_P4CurrentBranch "/..." "|grep " client ">" tmpFile)) while( fileLength(tmpFile) > 0 ;; files were opened warn("Cells opened for edit will not be reverted!") cont = CDS_WarnDialogBox("P4 Interface" "Library has cells opened for edit, continue ?") unless( cont warn("Revert Lib Aborted") return(nil) ) ) ; ** while fileLength ** syncspec = CDS_P4GetSyncSpec(ldd) when( syncspec == "" error("Bad sync spec!") ) ;; sync it to current first sprintf(command "sync") status = CDS_P4IPCCommand(command) unless( status error("Sync1 failed") ) warn("Reverting library %s to %s\n",libname syncspec) sfile = sprintf(nil "/tmp/p4synclog1.%s" CDS_P4UserFileName) sprintf(command "-o %s sync %s" sfile syncspec) status = CDS_P4IPCCommand(command) unless( status error("Sync failed") ) cont = CDS_WarnDialogBox("P4 Interface" "Make current sync head of tree ?") unless( cont printf("Don't forget to sync the lib back to current\n") return(t) ) ;; read the sync log ;; call revert file appropriately sfilep = infile(sfile) while( gets(lin sfilep) data = parseString(lin) ;; foo#1 - added/deleted/updated as clientroot/foo when( nthelem(3 data) != "deleted" ;; reject deleted files dfile = car(data) dfilenovers = car(parseString(dfile "#")) printf("Recovering %s\n" dfilenovers) CDS_P4RevertDepotFile(dfilenovers libname syncspec) ) ) ; ** while gets ** close(sfilep) ;; now having restored all the files, we have to get rid ;; of all the excess files that were checked in after the ;; sync date. ;; do a p4 sync ;; but capture the output ;; then parse the output for 'added' files ;; and delete them sfile = sprintf(nil "/tmp/p4synclog2.%s" CDS_P4UserFileName) sprintf(command "-o %s sync" sfile) status = CDS_P4IPCCommand(command) unless( status error("Sync failed") ) sfilep = infile(sfile) delfile = sprintf(nil "/tmp/p4del.%s" CDS_P4UserFileName) delfilep = outfile(delfile) while( gets(lin sfilep) data = parseString(lin) ;; foo#1 - added as clientroot/foo when( nthelem(3 data) == "added" del = t depotfile = car(parseString(car(data) "#")) ;; print it into a file for later -x use ;; into a numbered changelist fprintf(delfilep "%s\n" depotfile) ) ; ** when nthelem ** ) ; ** while gets ** close(sfilep) close(delfilep) when( del ;; create a numbered change cnum = CDS_P4CreateChange(CDS_P4CurrentClient strcat("cds:library re-sync " syncspec)) sprintf(command "-x %s delete -c %s" delfile cnum) status = CDS_P4IPCCommand(command) unless( status error("delete failed") ) ;; now submit it status = CDS_P4IPCCommand(strcat("submit -c " cnum)) unless( status error("submit failed") ) ) ; ** when del ** printf("Library re-sync complete!\n") CDS_P4StartAutoSync() return(t) ) ; ** prog ** ) ; ** procedure CDS_P4RevertLib ** procedure(CDS_P4GetSyncSpec(ldd) ;_Aug 30 00 sikand 121 ; get a user-specified sync spec let(( ssform ss monthf) ss = hiCreateStringField(?name 'ss ?prompt "Sync spec" ?value "" ) ssform = hiCreateAppForm(?name 'ssform ?fields '(ss) ?formTitle strcat("Sync spec for " ldd~>name) ) hiDisplayForm(ssform) ssform->ss->value ) ; ** let ** ) ; ** procedure CDS_P4GetSyncSpec ** procedure(CDS_P4RevertDepotFile(dfile libname changenum) ;_Apr 15 00 sikand 340 let(( fstable filelist status different cmd ddid reject) ;; do a fstat ;; need to get the ddid from depot file ddid = CDS_P4GetDdid(dfile libname) ;; need to check the type ;; we don't want to mess with non-master objects if(ddid~>type == 'ddViewFileType then ;; reject non cdb objects ;; to be completely pure: reject anything except the master ;; for the current master.tag entry ;; when's the last time you ever saw a master.tag switcheroo ? ;; I'll give you $50 for your test-case if you send it to me unless(rexMatchp("\\.cdb" ddid~>writePath) reject=t ) ) unless(reject fstable = CDS_P4Fstat(dfile) if( fstable~>action == 'unbound || fstable~>otherAction0 == 'unbound then ;; not checked out if( fstable~>headAction == "delete" then ;; resurrection printf("Resurrecting file %s\n", dfile) ;; flush and then add ;; get the atomics of the current version ;; since the previous version may have been a multi ;; file integrate ;;version = fstable~>haveRev filelist = parseString(CDS_P4GetAtomicFiles(ddid)) foreach( file filelist status = CDS_P4IPCBufferProcess(strcat("flush " file)) unless( status error("Flush failed!") ) ) ; ** foreach file ** ddCheckin(ddid strcat("cds:Checkin re-sync " changenum) "f") else ;; checkout the files from a specific version ;; ie the atoms must come from the head rev ;; but first make sure that the synced revision ;; is different from the current depot revision ;; running p4 verify will generate faster diffs different = nil ;;version = fstable~>haveRev ;; unbound versions are don't cares if( fstable~>haveRev != 'unbound then filelist = parseString(CDS_P4GetAtomicFiles(ddid)) foreach( file filelist ;; get the new fstat fstable = CDS_P4Fstat(file) if( fstable~>headRev != fstable~>haveRev then printf("Running p4 diff -se %s#%s\n" file fstable~>headRev) sprintf(cmd "diff -se %s#%s" file fstable~>headRev) status = CDS_P4IPCBufferProcess(cmd) if( zerop(status) then if( CDS_IPCBuffer then if( rexMatchp("up-to-date" CDS_IPCBuffer) then error("Up to date diff error for %s" file) ) if( CDS_IPCBuffer != "" different = t ) ) ; ** if CDS_IPCBuffer ** ) ; ** if zerop ** ) ; ** if fstable ** ) ; ** foreach file ** ) ; ** if fstable ** if( different then ;; checkout printf("Making file current: %s\n" ddid~>writePath) CDS_P4PreCheckout(list(ddid) nil nil t) foreach( file filelist ;; sync status = CDS_P4IPCBufferProcess(strcat("sync " file)) unless( status error("sync failed!") ) ;; resolve ;;printf("Resolving file %s\n" file) status = CDS_P4IPCBufferProcess(strcat("resolve -ay" file)) unless( status error("resolve failed!") ) ) ; ** foreach file ** ddCheckin(ddid strcat("cds:Checkin re-sync " changenum)) else ;; this sync is crucial of course status = CDS_P4IPCBufferProcess(strcat("sync " dfile)) unless( zerop(status) error("sync failed!") ) ;;warn("File(s) are consistent for %s" dfile) ) ; ** if different ** ) ; ** if fstable ** else hiGetAttention() status = CDS_P4IPCBufferProcess(strcat("sync ")) warn("File is checked out, ignored\n" ddid~>writePath) error("Aborting entire re-sync operation\n") ) ) ; ** if fstable ** ) ; ** let ** ) ; ** procedure CDS_P4RevertDepotFile ** procedure(CDS_P4GetAtomicDifferences(ddid @key v1 v2) ;_Dec 6 99 sikand 0 ; get the differences between v1 and v2 let(( v1list v2list delist) if( v1 == "head" then v1list = CDS_P4GetAtomicFiles(ddid) else v1list = CDS_P4GetAtomicFiles(ddid ?version v1) ) v1list = parseString(v1list) v2list = parseString(CDS_P4GetAtomicFiles(ddid ?version v2)) delist = nil foreach( el v1list unless( member(el v2list) delist = cons(el delist) ) ) delist ) ; ** let ** ) ; ** procedure CDS_P4GetAtomicDifferences **