131f051880 2007-11-09 aku: ## -*- tcl -*- 131f051880 2007-11-09 aku: # # ## ### ##### ######## ############# ##################### 131f051880 2007-11-09 aku: ## Copyright (c) 2007 Andreas Kupries. 131f051880 2007-11-09 aku: # 131f051880 2007-11-09 aku: # This software is licensed as described in the file LICENSE, which 131f051880 2007-11-09 aku: # you should have received as part of this distribution. 131f051880 2007-11-09 aku: # 131f051880 2007-11-09 aku: # This software consists of voluntary contributions made by many 131f051880 2007-11-09 aku: # individuals. For exact contribution history, see the revision 131f051880 2007-11-09 aku: # history and logs, available at http://fossil-scm.hwaci.com/fossil 131f051880 2007-11-09 aku: # # ## ### ##### ######## ############# ##################### 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: ## This package holds a number of integrity checks done on the 131f051880 2007-11-09 aku: ## persistent state. This is used by the passes II and IV. 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: # # ## ### ##### ######## ############# ##################### 131f051880 2007-11-09 aku: ## Requirements 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: package require Tcl 8.4 ; # Required runtime. 131f051880 2007-11-09 aku: package require snit ; # OO system. 131f051880 2007-11-09 aku: package require vc::tools::trouble ; # Error reporting. 131f051880 2007-11-09 aku: package require vc::tools::log ; # User feedback. 131f051880 2007-11-09 aku: package require vc::fossil::import::cvs::state ; # State storage. 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: # # ## ### ##### ######## ############# ##################### 131f051880 2007-11-09 aku: ## 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: snit::type ::vc::fossil::import::cvs::integrity { 131f051880 2007-11-09 aku: # # ## ### ##### ######## ############# 131f051880 2007-11-09 aku: ## Public API 131f051880 2007-11-09 aku: 47d52d1efd 2007-11-28 aku: typemethod assert {expression failmessage} { 47d52d1efd 2007-11-28 aku: set ok [uplevel 1 [list ::expr $expression]] 47d52d1efd 2007-11-28 aku: if {$ok} return 47d52d1efd 2007-11-28 aku: trouble internal [uplevel 1 [list ::subst $failmessage]] 47d52d1efd 2007-11-28 aku: return 47d52d1efd 2007-11-28 aku: } 47d52d1efd 2007-11-28 aku: 131f051880 2007-11-09 aku: typemethod strict {} { 8c6488ded2 2007-11-27 aku: log write 4 integrity {Check database consistency} 8c6488ded2 2007-11-27 aku: 131f051880 2007-11-09 aku: set n 0 131f051880 2007-11-09 aku: AllButMeta 131f051880 2007-11-09 aku: Meta 131f051880 2007-11-09 aku: return 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: typemethod metarelaxed {} { 8c6488ded2 2007-11-27 aku: log write 4 integrity {Check database consistency} 8c6488ded2 2007-11-27 aku: 131f051880 2007-11-09 aku: set n 0 131f051880 2007-11-09 aku: AllButMeta b679ca3356 2007-11-25 aku: return b679ca3356 2007-11-25 aku: } b679ca3356 2007-11-25 aku: b679ca3356 2007-11-25 aku: typemethod changesets {} { 8c6488ded2 2007-11-27 aku: log write 4 integrity {Check database consistency} 8c6488ded2 2007-11-27 aku: b679ca3356 2007-11-25 aku: set n 0 b679ca3356 2007-11-25 aku: RevisionChangesets 7c28fe1312 2007-11-29 aku: TagChangesets 7c28fe1312 2007-11-29 aku: BranchChangesets 131f051880 2007-11-09 aku: return 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: # # ## ### ##### ######## ############# 131f051880 2007-11-09 aku: ## Internal methods 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: proc AllButMeta {} { 131f051880 2007-11-09 aku: # This code performs a number of paranoid checks of the 131f051880 2007-11-09 aku: # database, searching for inconsistent cross-references. 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: upvar 1 n n ; # Counter for the checks (we print an id before 131f051880 2007-11-09 aku: # the main label). 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: # Find all revisions which disagree with their line of 131f051880 2007-11-09 aku: # development about the project they are owned by. 7c28fe1312 2007-11-29 aku: CheckRev \ 131f051880 2007-11-09 aku: {Revisions and their LODs have to be in the same project} \ 131f051880 2007-11-09 aku: {disagrees with its LOD about owning project} { 131f051880 2007-11-09 aku: SELECT F.name, R.rev 131f051880 2007-11-09 aku: FROM revision R, file F, symbol S 727f370c29 2008-01-27 aku: WHERE R.fid = F.fid -- get file of rev 727f370c29 2008-01-27 aku: AND R.lod = S.sid -- get symbol of its lod 727f370c29 2008-01-27 aku: AND F.pid != S.pid -- disagreement about the owning project 131f051880 2007-11-09 aku: ; 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: # Find all revisions which disgree with their meta data about 131f051880 2007-11-09 aku: # the project they are owned by. 7c28fe1312 2007-11-29 aku: CheckRev \ 131f051880 2007-11-09 aku: {Revisions and their meta data have to be in the same project} \ 131f051880 2007-11-09 aku: {disagrees with its meta data about owning project} { 131f051880 2007-11-09 aku: SELECT F.name, R.rev 131f051880 2007-11-09 aku: FROM revision R, file F, meta M 727f370c29 2008-01-27 aku: WHERE R.fid = F.fid -- get file of rev 727f370c29 2008-01-27 aku: AND R.mid = M.mid -- get meta of rev 727f370c29 2008-01-27 aku: AND F.pid != M.pid -- disagreement about owning project 131f051880 2007-11-09 aku: ; 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: # Find all revisions with a primary child which disagrees 131f051880 2007-11-09 aku: # about the file they belong to. 7c28fe1312 2007-11-29 aku: CheckRev \ 131f051880 2007-11-09 aku: {Revisions and their primary children have to be in the same file} \ 131f051880 2007-11-09 aku: {disagrees with its primary child about the owning file} { 131f051880 2007-11-09 aku: SELECT F.name, R.rev 131f051880 2007-11-09 aku: FROM revision R, revision C, file F 727f370c29 2008-01-27 aku: WHERE R.fid = F.fid -- get file of rev 727f370c29 2008-01-27 aku: AND R.child IS NOT NULL -- get all with primary children 727f370c29 2008-01-27 aku: AND R.child = C.rid -- get primary child 727f370c29 2008-01-27 aku: AND C.fid != R.fid -- wrongly in different file 131f051880 2007-11-09 aku: ; 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: # Find all revisions with a branch parent symbol whose parent 131f051880 2007-11-09 aku: # disagrees about the file they belong to. 7c28fe1312 2007-11-29 aku: CheckRev \ 131f051880 2007-11-09 aku: {Revisions and their branch children have to be in the same file} \ 131f051880 2007-11-09 aku: {at the beginning of its branch and its parent disagree about the owning file} { 131f051880 2007-11-09 aku: SELECT F.name, R.rev 131f051880 2007-11-09 aku: FROM revision R, revision P, file F 727f370c29 2008-01-27 aku: WHERE R.fid = F.fid -- get file of rev 727f370c29 2008-01-27 aku: AND R.bparent IS NOT NULL -- get first-of-branch revisions 727f370c29 2008-01-27 aku: AND R.parent = P.rid -- get out-of-branch parent 727f370c29 2008-01-27 aku: AND R.fid != P.fid -- wrongly in different file 131f051880 2007-11-09 aku: ; 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: # Find all revisions with a non-NTDB child which disagrees 131f051880 2007-11-09 aku: # about the file they belong to. 7c28fe1312 2007-11-29 aku: CheckRev \ 131f051880 2007-11-09 aku: {Revisions and their non-NTDB children have to be in the same file} \ 131f051880 2007-11-09 aku: {disagrees with its non-NTDB child about the owning file} { 131f051880 2007-11-09 aku: SELECT F.name, R.rev 131f051880 2007-11-09 aku: FROM revision R, revision C, file F 727f370c29 2008-01-27 aku: WHERE R.fid = F.fid -- get file of rev 727f370c29 2008-01-27 aku: AND R.dbchild IS NOT NULL -- get last NTDB revisions 727f370c29 2008-01-27 aku: AND R.dbchild = C.rid -- get their child 727f370c29 2008-01-27 aku: AND C.fid != R.fid -- wrongly in different file 131f051880 2007-11-09 aku: ; 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: # Find all revisions which have a primary child, but the child 131f051880 2007-11-09 aku: # does not have them as parent. 7c28fe1312 2007-11-29 aku: CheckRev \ 131f051880 2007-11-09 aku: {Revisions have to be parents of their primary children} \ 131f051880 2007-11-09 aku: {is not the parent of its primary child} { 131f051880 2007-11-09 aku: SELECT F.name, R.rev 131f051880 2007-11-09 aku: FROM revision R, revision C, file F 727f370c29 2008-01-27 aku: WHERE R.fid = F.fid -- get file of rev 727f370c29 2008-01-27 aku: AND R.child IS NOT NULL -- get all with primary children 727f370c29 2008-01-27 aku: AND R.child = C.rid -- get primary child 727f370c29 2008-01-27 aku: AND C.parent != R.rid -- child's parent wrongly not us 131f051880 2007-11-09 aku: ; 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: # Find all revisions which have a primrary child, but the 131f051880 2007-11-09 aku: # child has a branch parent symbol making them brach starters. 7c28fe1312 2007-11-29 aku: CheckRev \ 131f051880 2007-11-09 aku: {Primary children of revisions must not start branches} \ 131f051880 2007-11-09 aku: {is parent of a primary child which is the beginning of a branch} { 131f051880 2007-11-09 aku: SELECT F.name, R.rev 131f051880 2007-11-09 aku: FROM revision R, revision C, file F 727f370c29 2008-01-27 aku: WHERE R.fid = F.fid -- get file of rev 727f370c29 2008-01-27 aku: AND R.child IS NOT NULL -- get all with primary children 727f370c29 2008-01-27 aku: AND R.child = C.rid -- get primary child 727f370c29 2008-01-27 aku: AND C.bparent IS NOT NULL -- but indicates to be on branch 131f051880 2007-11-09 aku: ; 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: # Find all revisions without branch parent symbol which have a 131f051880 2007-11-09 aku: # parent, but the parent does not have them as primary child. 7c28fe1312 2007-11-29 aku: CheckRev \ 131f051880 2007-11-09 aku: {Revisions have to be primary children of their parents, if any} \ 131f051880 2007-11-09 aku: {is not the child of its parent} { 131f051880 2007-11-09 aku: SELECT F.name, R.rev 131f051880 2007-11-09 aku: FROM revision R, revision P, file F 727f370c29 2008-01-27 aku: WHERE R.fid = F.fid -- get file of revision 727f370c29 2008-01-27 aku: AND R.bparent IS NULL -- exclude all first-on-branch revisions 727f370c29 2008-01-27 aku: AND R.parent IS NOT NULL -- which are not root of their line 727f370c29 2008-01-27 aku: AND R.parent = P.rid -- get in-lod parent 727f370c29 2008-01-27 aku: AND P.child != R.rid -- but does not have rev as primary child 131f051880 2007-11-09 aku: ; 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: # Find all revisions with a branch parent symbol which do not 131f051880 2007-11-09 aku: # have a parent. 7c28fe1312 2007-11-29 aku: CheckRev \ c4003e7b93 2007-12-05 aku: {Branch starting revisions have to have a parent, if not detached} \ c4003e7b93 2007-12-05 aku: {at the beginning of its branch has no parent, but its branch has} { c4003e7b93 2007-12-05 aku: SELECT F.name, R.rev c4003e7b93 2007-12-05 aku: FROM revision R, file F, branch B 727f370c29 2008-01-27 aku: WHERE R.fid = F.fid -- get file of revision 727f370c29 2008-01-27 aku: AND R.bparent IS NOT NULL -- limit to first-on-branch revisions 727f370c29 2008-01-27 aku: AND R.parent IS NULL -- which are detached 727f370c29 2008-01-27 aku: AND B.sid = R.bparent -- get branch governing the rev 727f370c29 2008-01-27 aku: AND B.fid = R.fid -- in the revision's file 727f370c29 2008-01-27 aku: AND B.root IS NOT NULL -- but says that branch is attached 131f051880 2007-11-09 aku: ; 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: # Find all revisions with a branch parent symbol whose parent 131f051880 2007-11-09 aku: # has them as primary child. 7c28fe1312 2007-11-29 aku: CheckRev \ 131f051880 2007-11-09 aku: {Branch starting revisions must not be primary children of their parents} \ 131f051880 2007-11-09 aku: {at the beginning of its branch is the primary child of its parent} { 131f051880 2007-11-09 aku: SELECT F.name, R.rev 131f051880 2007-11-09 aku: FROM revision R, revision P, file F 727f370c29 2008-01-27 aku: WHERE R.fid = F.fid -- get file of revision 727f370c29 2008-01-27 aku: AND R.bparent IS NOT NULL -- limit to first-on-branch revisions 727f370c29 2008-01-27 aku: AND R.parent IS NOT NULL -- which are attached 727f370c29 2008-01-27 aku: AND R.parent = P.rid -- get out-of-branch parent 727f370c29 2008-01-27 aku: AND P.child = R.rid -- wrongly has rev as primary child 131f051880 2007-11-09 aku: ; 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: # Find all revisions with a non-NTDB child which are not on 131f051880 2007-11-09 aku: # the NTDB. 7c28fe1312 2007-11-29 aku: CheckRev \ 131f051880 2007-11-09 aku: {NTDB to trunk transition has to begin on NTDB} \ 131f051880 2007-11-09 aku: {has a non-NTDB child, yet is not on the NTDB} { 131f051880 2007-11-09 aku: SELECT F.name, R.rev 131f051880 2007-11-09 aku: FROM revision R, file F 727f370c29 2008-01-27 aku: WHERE R.fid = F.fid -- get file of revision 727f370c29 2008-01-27 aku: AND R.dbchild IS NOT NULL -- limit to last NTDB revision 727f370c29 2008-01-27 aku: AND NOT R.isdefault -- but signals not-NTDB 131f051880 2007-11-09 aku: ; 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: # Find all revisions with a NTDB parent which are on the NTDB. 7c28fe1312 2007-11-29 aku: CheckRev \ 131f051880 2007-11-09 aku: {NTDB to trunk transition has to end on non-NTDB} \ 131f051880 2007-11-09 aku: {has a NTDB parent, yet is on the NTDB} { 131f051880 2007-11-09 aku: SELECT F.name, R.rev 131f051880 2007-11-09 aku: FROM revision R, file F 727f370c29 2008-01-27 aku: WHERE R.fid = F.fid -- get file of revision 727f370c29 2008-01-27 aku: AND R.dbparent IS NOT NULL -- limit to roots of non-NTDB 727f370c29 2008-01-27 aku: AND R.isdefault -- but signals to be NTDB 131f051880 2007-11-09 aku: ; 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: # Find all revisions with a child which disagrees about the 131f051880 2007-11-09 aku: # line of development they belong to. 7c28fe1312 2007-11-29 aku: CheckRev \ 131f051880 2007-11-09 aku: {Revisions and their primary children have to be in the same LOD} \ 131f051880 2007-11-09 aku: {and its primary child disagree about their LOD} { 131f051880 2007-11-09 aku: SELECT F.name, R.rev 131f051880 2007-11-09 aku: FROM revision R, revision C, file F 727f370c29 2008-01-27 aku: WHERE R.fid = F.fid -- get file of revision 727f370c29 2008-01-27 aku: AND R.child IS NOT NULL -- revision has a primary child 727f370c29 2008-01-27 aku: AND R.child = C.rid -- get that child 727f370c29 2008-01-27 aku: AND C.lod != R.lod -- child wrongly disagrees with lod 131f051880 2007-11-09 aku: ; 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: # Find all revisions with a non-NTDB child which agrees about 131f051880 2007-11-09 aku: # the line of development they belong to. 7c28fe1312 2007-11-29 aku: CheckRev \ 131f051880 2007-11-09 aku: {NTDB and trunk revisions have to be in different LODs} \ 131f051880 2007-11-09 aku: {on NTDB and its non-NTDB child wrongly agree about their LOD} { 131f051880 2007-11-09 aku: SELECT F.name, R.rev 131f051880 2007-11-09 aku: FROM revision R, revision C, file F 727f370c29 2008-01-27 aku: WHERE R.fid = F.fid -- get file of revision 727f370c29 2008-01-27 aku: AND R.dbchild IS NOT NULL -- limit to last NTDB revision 727f370c29 2008-01-27 aku: AND R.dbchild = C.rid -- get non-NTDB child 727f370c29 2008-01-27 aku: AND C.lod = R.lod -- child wrongly has same lod 131f051880 2007-11-09 aku: ; 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: # Find all revisions with a branch parent symbol which is not 131f051880 2007-11-09 aku: # their LOD. 7c28fe1312 2007-11-29 aku: CheckRev \ 131f051880 2007-11-09 aku: {Branch starting revisions have to have their LOD as branch parent symbol} \ 131f051880 2007-11-09 aku: {at the beginning of its branch does not have the branch symbol as its LOD} { 131f051880 2007-11-09 aku: SELECT F.name, R.rev 131f051880 2007-11-09 aku: FROM revision R, file F 727f370c29 2008-01-27 aku: WHERE R.fid = F.fid -- get file of revision 727f370c29 2008-01-27 aku: AND R.bparent IS NOT NULL -- limit to branch-first revisions 727f370c29 2008-01-27 aku: AND R.lod != R.bparent -- out-of-branch parent wrongly is not the lod 131f051880 2007-11-09 aku: ; 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: # Find all revisions with a branch parent symbol whose parent 131f051880 2007-11-09 aku: # is in the same line of development. 7c28fe1312 2007-11-29 aku: CheckRev \ 131f051880 2007-11-09 aku: {Revisions and their branch children have to be in different LODs} \ 131f051880 2007-11-09 aku: {at the beginning of its branch and its parent wrongly agree about their LOD} { 131f051880 2007-11-09 aku: SELECT F.name, R.rev 131f051880 2007-11-09 aku: FROM revision R, revision P, file F 727f370c29 2008-01-27 aku: WHERE R.fid = F.fid -- get file of revision 727f370c29 2008-01-27 aku: AND R.bparent IS NOT NULL -- limit to branch-first revisions 727f370c29 2008-01-27 aku: AND R.parent = P.rid -- get out-of-branch parent of revision 727f370c29 2008-01-27 aku: AND R.lod = P.lod -- rev and parent wrongly agree on lod 131f051880 2007-11-09 aku: ; 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: return 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: proc Meta {} { 131f051880 2007-11-09 aku: # This code performs a number of paranoid checks of the 131f051880 2007-11-09 aku: # database, searching for inconsistent cross-references. 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: upvar 1 n n ; # Counter for the checks (we print an id before 131f051880 2007-11-09 aku: # the main label). 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: # Find all revisions which disgree with their meta data about 131f051880 2007-11-09 aku: # the branch/line of development they belong to. 7c28fe1312 2007-11-29 aku: CheckRev \ 131f051880 2007-11-09 aku: {Revisions and their meta data have to be in the same LOD} \ 131f051880 2007-11-09 aku: {disagrees with its meta data about owning LOD} { 131f051880 2007-11-09 aku: SELECT F.name, R.rev 131f051880 2007-11-09 aku: FROM revision R, meta M, file F 727f370c29 2008-01-27 aku: WHERE R.mid = M.mid -- get meta data of revision 727f370c29 2008-01-27 aku: AND R.lod != M.bid -- rev wrongly disagrees with meta about lod 727f370c29 2008-01-27 aku: AND R.fid = F.fid -- get file of revision 131f051880 2007-11-09 aku: ; 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: return 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: bf83201c7f 2007-11-27 aku: proc RevisionChangesets {} { 8c6488ded2 2007-11-27 aku: # This code performs a number of paranoid checks of the 8c6488ded2 2007-11-27 aku: # database, searching for inconsistent changeset/revision 8c6488ded2 2007-11-27 aku: # information. 8c6488ded2 2007-11-27 aku: 8c6488ded2 2007-11-27 aku: upvar 1 n n ; # Counter for the checks (we print an id before 8c6488ded2 2007-11-27 aku: # the main label). 8c6488ded2 2007-11-27 aku: 8c6488ded2 2007-11-27 aku: # Find all revisions which are not used by at least one de10b2301e 2007-11-29 aku: # changeset. 7c28fe1312 2007-11-29 aku: CheckRev \ de10b2301e 2007-11-29 aku: {All revisions have to be used by least one changeset} \ de10b2301e 2007-11-29 aku: {is not used by a changeset} { 8c6488ded2 2007-11-27 aku: -- Unused revisions = All revisions 8c6488ded2 2007-11-27 aku: -- - revisions used by revision changesets. 8c6488ded2 2007-11-27 aku: -- 8c6488ded2 2007-11-27 aku: -- Both sets can be computed easily, and subtracted 8c6488ded2 2007-11-27 aku: -- from each other. Then we can get the associated 8c6488ded2 2007-11-27 aku: -- file (name) for display. 8c6488ded2 2007-11-27 aku: 8c6488ded2 2007-11-27 aku: SELECT F.name, R.rev 8c6488ded2 2007-11-27 aku: FROM revision R, file F de10b2301e 2007-11-29 aku: WHERE R.rid IN (SELECT rid de10b2301e 2007-11-29 aku: FROM revision -- All revisions de10b2301e 2007-11-29 aku: EXCEPT -- subtract 80b1e8936f 2007-11-29 aku: SELECT CI.iid 80b1e8936f 2007-11-29 aku: FROM csitem CI, changeset C -- revisions used 80b1e8936f 2007-11-29 aku: WHERE C.cid = CI.cid -- by any revision de10b2301e 2007-11-29 aku: AND C.type = 0) -- changeset 8c6488ded2 2007-11-27 aku: AND R.fid = F.fid -- get file of unused revision 8c6488ded2 2007-11-27 aku: } de10b2301e 2007-11-29 aku: # Find all revisions which are used by more than one 8c6488ded2 2007-11-27 aku: # changeset. 7c28fe1312 2007-11-29 aku: CheckRev \ de10b2301e 2007-11-29 aku: {All revisions have to be used by at most one changeset} \ de10b2301e 2007-11-29 aku: {is used by multiple changesets} { 8c6488ded2 2007-11-27 aku: -- Principle of operation: Get all revision/changeset 8c6488ded2 2007-11-27 aku: -- pairs for all revision changesets, group by 8c6488ded2 2007-11-27 aku: -- revision to aggregate the changeset, counting 8c6488ded2 2007-11-27 aku: -- them. From the resulting revision/count table 8c6488ded2 2007-11-27 aku: -- select those with more than one user, and get their 8c6488ded2 2007-11-27 aku: -- associated file (name) for display. 8c6488ded2 2007-11-27 aku: 8c6488ded2 2007-11-27 aku: SELECT F.name, R.rev 8c6488ded2 2007-11-27 aku: FROM revision R, file F, 727f370c29 2008-01-27 aku: (SELECT CI.iid AS rid, -- revision item 727f370c29 2008-01-27 aku: count(CI.cid) AS count -- number of csets using item 80b1e8936f 2007-11-29 aku: FROM csitem CI, changeset C 727f370c29 2008-01-27 aku: WHERE C.type = 0 -- limit to revision csets 727f370c29 2008-01-27 aku: AND C.cid = CI.cid -- get item in changeset 727f370c29 2008-01-27 aku: GROUP BY CI.iid -- aggregate by item, count csets/item 727f370c29 2008-01-27 aku: ) AS U 727f370c29 2008-01-27 aku: WHERE U.count > 1 -- limit to item with multiple users 727f370c29 2008-01-27 aku: AND R.rid = U.rid -- get revision of item 727f370c29 2008-01-27 aku: AND R.fid = F.fid -- get file of revision de10b2301e 2007-11-29 aku: } de10b2301e 2007-11-29 aku: # All revisions have to refer to the same meta information as de10b2301e 2007-11-29 aku: # their changeset. de10b2301e 2007-11-29 aku: CheckRevCS \ de10b2301e 2007-11-29 aku: {All revisions have to agree with their changeset about the used meta information} \ de10b2301e 2007-11-29 aku: {disagrees with its changeset @ about the meta information} { de10b2301e 2007-11-29 aku: SELECT CT.name, C.cid, F.name, R.rev 80b1e8936f 2007-11-29 aku: FROM changeset C, cstype CT, revision R, file F, csitem CI de10b2301e 2007-11-29 aku: WHERE C.type = 0 -- revision changesets only 80b1e8936f 2007-11-29 aku: AND C.cid = CI.cid -- changeset --> its revisions 80b1e8936f 2007-11-29 aku: AND R.rid = CI.iid -- look at them de10b2301e 2007-11-29 aku: AND R.mid != C.src -- Only those which disagree with changeset about the meta de10b2301e 2007-11-29 aku: AND R.fid = F.fid -- get file of the revision de10b2301e 2007-11-29 aku: AND CT.tid = C.type -- get changeset type, for labeling de10b2301e 2007-11-29 aku: } de10b2301e 2007-11-29 aku: # All revisions have to agree on the LOD their changeset de10b2301e 2007-11-29 aku: # belongs to. In other words, all revisions in a changeset de10b2301e 2007-11-29 aku: # have to refer to the same line of development. 8c6488ded2 2007-11-27 aku: # 8c6488ded2 2007-11-27 aku: # Instead of looking at all pairs of revisions in all 8c6488ded2 2007-11-27 aku: # changesets we generate the distinct set of all LODs 8c6488ded2 2007-11-27 aku: # referenced by the revisions of a changeset, look for those 8c6488ded2 2007-11-27 aku: # with cardinality > 1, and get the identifying information 8c6488ded2 2007-11-27 aku: # for the changesets found thusly. 8c6488ded2 2007-11-27 aku: CheckCS \ 8c6488ded2 2007-11-27 aku: {All revisions in a changeset have to belong to the same LOD} \ 8c6488ded2 2007-11-27 aku: {: Its revisions disagree about the LOD they belong to} { 8c6488ded2 2007-11-27 aku: SELECT T.name, C.cid 8c6488ded2 2007-11-27 aku: FROM changeset C, cstype T 8c6488ded2 2007-11-27 aku: WHERE C.cid IN (SELECT U.cid 727f370c29 2008-01-27 aku: FROM (SELECT DISTINCT -- unique cset/lod pairs 727f370c29 2008-01-27 aku: CI.cid AS cid, -- revision cset 727f370c29 2008-01-27 aku: R.lod AS lod -- lod of item in cset 80b1e8936f 2007-11-29 aku: FROM csitem CI, changeset C, revision R 727f370c29 2008-01-27 aku: WHERE CI.iid = R.rid -- get rev of item in cset 727f370c29 2008-01-27 aku: AND C.cid = CI.cid -- get changeset of item 727f370c29 2008-01-27 aku: AND C.type = 0 -- limit to rev csets 727f370c29 2008-01-27 aku: ) AS U 727f370c29 2008-01-27 aku: GROUP BY U.cid -- aggregate by cset, count lods/cset 727f370c29 2008-01-27 aku: HAVING COUNT(U.lod) > 1 -- find csets with multiple lods 727f370c29 2008-01-27 aku: ) 8c6488ded2 2007-11-27 aku: AND T.tid = C.type 8c6488ded2 2007-11-27 aku: } de10b2301e 2007-11-29 aku: # All revisions have to agree on the project their changeset de10b2301e 2007-11-29 aku: # belongs to. In other words, all revisions in a changeset de10b2301e 2007-11-29 aku: # have to refer to the same project. 8c6488ded2 2007-11-27 aku: # 8c6488ded2 2007-11-27 aku: # Instead of looking at all pairs of revisions in all 8c6488ded2 2007-11-27 aku: # changesets we generate the distinct set of all projects 8c6488ded2 2007-11-27 aku: # referenced by the revisions of a changeset, look for those 8c6488ded2 2007-11-27 aku: # with cardinality > 1, and get the identifying information 8c6488ded2 2007-11-27 aku: # for the changesets found thusly. 8c6488ded2 2007-11-27 aku: CheckCS \ 8c6488ded2 2007-11-27 aku: {All revisions in a changeset have to belong to the same project} \ 8c6488ded2 2007-11-27 aku: {: Its revisions disagree about the project they belong to} { 8c6488ded2 2007-11-27 aku: SELECT T.name, C.cid 8c6488ded2 2007-11-27 aku: FROM changeset C, cstype T 8c6488ded2 2007-11-27 aku: WHERE C.cid IN (SELECT U.cid 727f370c29 2008-01-27 aku: FROM (SELECT DISTINCT -- unique cset/proj pairs 727f370c29 2008-01-27 aku: CI.cid AS cid, -- rev cset 727f370c29 2008-01-27 aku: F.pid AS pid -- project of item in cset 80b1e8936f 2007-11-29 aku: FROM csitem CI, changeset C, revision R, file F 727f370c29 2008-01-27 aku: WHERE CI.iid = R.rid -- get rev of item in cset 727f370c29 2008-01-27 aku: AND C.cid = CI.cid -- get changeset of item 727f370c29 2008-01-27 aku: AND C.type = 0 -- limit to rev changesets 727f370c29 2008-01-27 aku: AND F.fid = R.fid -- get file of revision 727f370c29 2008-01-27 aku: ) AS U 727f370c29 2008-01-27 aku: GROUP BY U.cid -- aggregate by csets, count proj/cset 727f370c29 2008-01-27 aku: HAVING COUNT(U.pid) > 1 -- find csets with multiple projects 727f370c29 2008-01-27 aku: ) 727f370c29 2008-01-27 aku: AND T.tid = C.type -- get readable changeset type 8c6488ded2 2007-11-27 aku: } 8c6488ded2 2007-11-27 aku: # All revisions in a single changeset have to belong to 8c6488ded2 2007-11-27 aku: # different files. Conversely: No two revisions of a single 8c6488ded2 2007-11-27 aku: # file are allowed to be in the same changeset. 8c6488ded2 2007-11-27 aku: # 8c6488ded2 2007-11-27 aku: # Instead of looking at all pairs of revisions in all 8c6488ded2 2007-11-27 aku: # changesets we generate the distinct set of all files 8c6488ded2 2007-11-27 aku: # referenced by the revisions of a changeset, and look for 8c6488ded2 2007-11-27 aku: # those with cardinality < the cardinality of the set of 8c6488ded2 2007-11-27 aku: # revisions, and get the identifying information for the 8c6488ded2 2007-11-27 aku: # changesets found thusly. 8c6488ded2 2007-11-27 aku: CheckCS \ 8c6488ded2 2007-11-27 aku: {All revisions in a changeset have to belong to different files} \ 8c6488ded2 2007-11-27 aku: {: Its revisions share files} { 8c6488ded2 2007-11-27 aku: SELECT T.name, C.cid 8c6488ded2 2007-11-27 aku: FROM changeset C, cstype T 8c6488ded2 2007-11-27 aku: WHERE C.cid IN (SELECT VV.cid 727f370c29 2008-01-27 aku: FROM (SELECT U.cid AS cid, -- rev changeset 727f370c29 2008-01-27 aku: COUNT (U.fid) AS fcount -- number of files by items 727f370c29 2008-01-27 aku: FROM (SELECT DISTINCT -- unique cset/file pairs 727f370c29 2008-01-27 aku: CI.cid AS cid, -- rev changeset 727f370c29 2008-01-27 aku: R.fid AS fid -- file of item in changeset 80b1e8936f 2007-11-29 aku: FROM csitem CI, changeset C, revision R 727f370c29 2008-01-27 aku: WHERE CI.iid = R.rid -- get rev of item in changeset 727f370c29 2008-01-27 aku: AND C.cid = CI.cid -- get changeset of item 727f370c29 2008-01-27 aku: AND C.type = 0 -- limit to rev csets de10b2301e 2007-11-29 aku: ) AS U 727f370c29 2008-01-27 aku: GROUP BY U.cid -- aggregate by csets, count files/cset 727f370c29 2008-01-27 aku: ) AS UU, 727f370c29 2008-01-27 aku: (SELECT V.cid AS cid, -- rev changeset 727f370c29 2008-01-27 aku: COUNT (V.iid) AS rcount -- number of items 80b1e8936f 2007-11-29 aku: FROM csitem V, changeset X 727f370c29 2008-01-27 aku: WHERE X.cid = V.cid -- get changeset of item 727f370c29 2008-01-27 aku: AND X.type = 0 -- limit to rev csets 727f370c29 2008-01-27 aku: GROUP BY V.cid -- aggregate by csets, count items/cset 727f370c29 2008-01-27 aku: ) AS VV 727f370c29 2008-01-27 aku: WHERE VV.cid = UU.cid -- sync #items/cset with #files/cset 727f370c29 2008-01-27 aku: AND UU.fcount < VV.rcount -- less files than items 727f370c29 2008-01-27 aku: -- => items belong to the same file. 727f370c29 2008-01-27 aku: ) 727f370c29 2008-01-27 aku: AND T.tid = C.type -- get readable changeset type 7c28fe1312 2007-11-29 aku: } 7c28fe1312 2007-11-29 aku: return 7c28fe1312 2007-11-29 aku: } 7c28fe1312 2007-11-29 aku: 7c28fe1312 2007-11-29 aku: proc TagChangesets {} { 7c28fe1312 2007-11-29 aku: # This code performs a number of paranoid checks of the 7c28fe1312 2007-11-29 aku: # database, searching for inconsistent changeset/revision 7c28fe1312 2007-11-29 aku: # information. 7c28fe1312 2007-11-29 aku: 7c28fe1312 2007-11-29 aku: upvar 1 n n ; # Counter for the checks (we print an id before 7c28fe1312 2007-11-29 aku: # the main label). 4b15fa348d 2007-11-29 aku: 4b15fa348d 2007-11-29 aku: # Find all tags which are not used by at least one changeset. 4b15fa348d 2007-11-29 aku: CheckTag \ 4b15fa348d 2007-11-29 aku: {All tags have to be used by least one changeset} \ 4b15fa348d 2007-11-29 aku: {is not used by a changeset} { 4b15fa348d 2007-11-29 aku: -- Unused tags = All tags 4b15fa348d 2007-11-29 aku: -- - revisions used by tag changesets. 4b15fa348d 2007-11-29 aku: -- 4b15fa348d 2007-11-29 aku: -- Both sets can be computed easily, and subtracted 4b15fa348d 2007-11-29 aku: -- from each other. Then we can get the associated 4b15fa348d 2007-11-29 aku: -- file (name) for display. 4b15fa348d 2007-11-29 aku: 4b15fa348d 2007-11-29 aku: SELECT P.name, S.name 4b15fa348d 2007-11-29 aku: FROM project P, tag T, symbol S 4b15fa348d 2007-11-29 aku: WHERE T.tid IN (SELECT tid -- All tags 4b15fa348d 2007-11-29 aku: FROM tag 4b15fa348d 2007-11-29 aku: EXCEPT -- subtract 80b1e8936f 2007-11-29 aku: SELECT CI.iid -- tags used 80b1e8936f 2007-11-29 aku: FROM csitem CI, changeset C 80b1e8936f 2007-11-29 aku: WHERE C.cid = CI.cid -- by any tag 4b15fa348d 2007-11-29 aku: AND C.type = 1) -- changeset 4b15fa348d 2007-11-29 aku: AND S.sid = T.sid -- get symbol of tag 4b15fa348d 2007-11-29 aku: AND P.pid = S.pid -- get project of symbol 4b15fa348d 2007-11-29 aku: } 4b15fa348d 2007-11-29 aku: # Find all tags which are used by more than one changeset. 4b15fa348d 2007-11-29 aku: CheckRev \ 4b15fa348d 2007-11-29 aku: {All tags have to be used by at most one changeset} \ 4b15fa348d 2007-11-29 aku: {is used by multiple changesets} { 4b15fa348d 2007-11-29 aku: -- Principle of operation: Get all tag/changeset pairs 4b15fa348d 2007-11-29 aku: -- for all tag changesets, group by tag to aggregate 4b15fa348d 2007-11-29 aku: -- the changeset, counting them. From the resulting 4b15fa348d 2007-11-29 aku: -- tag/count table select those with more than one 4b15fa348d 2007-11-29 aku: -- user, and get their associated file (name) for 4b15fa348d 2007-11-29 aku: -- display. 4b15fa348d 2007-11-29 aku: 4b15fa348d 2007-11-29 aku: SELECT P.name, S.name 4b15fa348d 2007-11-29 aku: FROM tag T, project P, symbol S, 727f370c29 2008-01-27 aku: (SELECT CI.iid AS iid, -- item 727f370c29 2008-01-27 aku: count(CI.cid) AS count -- number of csets using item 80b1e8936f 2007-11-29 aku: FROM csitem CI, changeset C 727f370c29 2008-01-27 aku: WHERE C.type = 1 -- limit to tag csets 727f370c29 2008-01-27 aku: AND C.cid = CI.cid -- get items of cset 727f370c29 2008-01-27 aku: GROUP BY CI.iid -- aggregate by item, count csets/item 727f370c29 2008-01-27 aku: ) AS U 727f370c29 2008-01-27 aku: WHERE U.count > 1 -- find tag item used multiple times 727f370c29 2008-01-27 aku: AND T.tid = U.iid -- get tag of item 727f370c29 2008-01-27 aku: AND S.sid = T.sid -- get symbol of tag 727f370c29 2008-01-27 aku: AND P.pid = S.pid -- get project of symbol 4b15fa348d 2007-11-29 aku: } 4b15fa348d 2007-11-29 aku: if 0 { 4b15fa348d 2007-11-29 aku: # This check is disabled for the moment. Apparently tags 4b15fa348d 2007-11-29 aku: # can cross lines of development, at least if the involved 4b15fa348d 2007-11-29 aku: # LODs are the trunk, and the NTDB. That makes sense, as 4b15fa348d 2007-11-29 aku: # the NTDB revisions are initially logically a part of the 4b15fa348d 2007-11-29 aku: # trunk. The standard check below however does not capture 4b15fa348d 2007-11-29 aku: # this. When I manage to rephrase it to accept this type 4b15fa348d 2007-11-29 aku: # of cross-over it will be re-activated. 4b15fa348d 2007-11-29 aku: 4b15fa348d 2007-11-29 aku: # All tags have to agree on the LOD their changeset 4b15fa348d 2007-11-29 aku: # belongs to. In other words, all tags in a changeset have 4b15fa348d 2007-11-29 aku: # to refer to the same line of development. 4b15fa348d 2007-11-29 aku: # 4b15fa348d 2007-11-29 aku: # Instead of looking at all pairs of tags in all 4b15fa348d 2007-11-29 aku: # changesets we generate the distinct set of all LODs 4b15fa348d 2007-11-29 aku: # referenced by the tags of a changeset, look for those 4b15fa348d 2007-11-29 aku: # with cardinality > 1, and get the identifying 4b15fa348d 2007-11-29 aku: # information for the changesets found thusly. 4b15fa348d 2007-11-29 aku: CheckCS \ 4b15fa348d 2007-11-29 aku: {All tags in a changeset have to belong to the same LOD} \ 4b15fa348d 2007-11-29 aku: {: Its tags disagree about the LOD they belong to} { 4b15fa348d 2007-11-29 aku: SELECT T.name, C.cid 4b15fa348d 2007-11-29 aku: FROM changeset C, cstype T 4b15fa348d 2007-11-29 aku: WHERE C.cid IN (SELECT U.cid 80b1e8936f 2007-11-29 aku: FROM (SELECT DISTINCT CI.cid AS cid, T.lod AS lod 80b1e8936f 2007-11-29 aku: FROM csitem CI, changeset C, tag T 80b1e8936f 2007-11-29 aku: WHERE CI.iid = T.tid 80b1e8936f 2007-11-29 aku: AND C.cid = CI.cid 4b15fa348d 2007-11-29 aku: AND C.type = 1) AS U 4b15fa348d 2007-11-29 aku: GROUP BY U.cid HAVING COUNT(U.lod) > 1) 4b15fa348d 2007-11-29 aku: AND T.tid = C.type 4b15fa348d 2007-11-29 aku: } 4b15fa348d 2007-11-29 aku: } 4b15fa348d 2007-11-29 aku: # All tags have to agree on the project their changeset 4b15fa348d 2007-11-29 aku: # belongs to. In other words, all tags in a changeset have to 4b15fa348d 2007-11-29 aku: # refer to the same project. 4b15fa348d 2007-11-29 aku: # 4b15fa348d 2007-11-29 aku: # Instead of looking at all pairs of tags in all changesets we 4b15fa348d 2007-11-29 aku: # generate the distinct set of all projects referenced by the 4b15fa348d 2007-11-29 aku: # tags of a changeset, look for those with cardinality > 1, 4b15fa348d 2007-11-29 aku: # and get the identifying information for the changesets found 4b15fa348d 2007-11-29 aku: # thusly. 4b15fa348d 2007-11-29 aku: CheckCS \ 4b15fa348d 2007-11-29 aku: {All tags in a changeset have to belong to the same project} \ 4b15fa348d 2007-11-29 aku: {: Its tags disagree about the project they belong to} { 4b15fa348d 2007-11-29 aku: SELECT T.name, C.cid 4b15fa348d 2007-11-29 aku: FROM changeset C, cstype T 4b15fa348d 2007-11-29 aku: WHERE C.cid IN (SELECT U.cid 727f370c29 2008-01-27 aku: FROM (SELECT DISTINCT -- unique cset/proj pairs 727f370c29 2008-01-27 aku: CI.cid AS cid, -- tag cset 727f370c29 2008-01-27 aku: F.pid AS pid -- project of item in cset 80b1e8936f 2007-11-29 aku: FROM csitem CI, changeset C, tag T, file F 727f370c29 2008-01-27 aku: WHERE CI.iid = T.tid -- get tag of item in cset 727f370c29 2008-01-27 aku: AND C.cid = CI.cid -- get changeset of item 727f370c29 2008-01-27 aku: AND C.type = 1 -- limit to tag changesets 727f370c29 2008-01-27 aku: AND F.fid = T.fid -- get file of tag 727f370c29 2008-01-27 aku: ) AS U 727f370c29 2008-01-27 aku: GROUP BY U.cid -- aggregate by csets, count proj/cset 727f370c29 2008-01-27 aku: HAVING COUNT(U.pid) > 1 -- find csets with multiple projects 727f370c29 2008-01-27 aku: ) 727f370c29 2008-01-27 aku: AND T.tid = C.type -- get readable changeset type 4b15fa348d 2007-11-29 aku: } 4b15fa348d 2007-11-29 aku: # All tags in a single changeset have to belong to different 4b15fa348d 2007-11-29 aku: # files. Conversely: No two tags of a single file are allowed 4b15fa348d 2007-11-29 aku: # to be in the same changeset. 4b15fa348d 2007-11-29 aku: # 4b15fa348d 2007-11-29 aku: # Instead of looking at all pairs of tags in all changesets we 4b15fa348d 2007-11-29 aku: # generate the distinct set of all files referenced by the 4b15fa348d 2007-11-29 aku: # tags of a changeset, and look for those with cardinality < 4b15fa348d 2007-11-29 aku: # the cardinality of the set of tags, and get the identifying 4b15fa348d 2007-11-29 aku: # information for the changesets found thusly. 4b15fa348d 2007-11-29 aku: CheckCS \ 4b15fa348d 2007-11-29 aku: {All tags in a changeset have to belong to different files} \ 4b15fa348d 2007-11-29 aku: {: Its tags share files} { 4b15fa348d 2007-11-29 aku: SELECT T.name, C.cid 4b15fa348d 2007-11-29 aku: FROM changeset C, cstype T 4b15fa348d 2007-11-29 aku: WHERE C.cid IN (SELECT VV.cid 727f370c29 2008-01-27 aku: FROM (SELECT U.cid AS cid, -- changeset 727f370c29 2008-01-27 aku: COUNT (U.fid) AS fcount -- number of files by items 727f370c29 2008-01-27 aku: FROM (SELECT DISTINCT -- unique cset/file pairs 727f370c29 2008-01-27 aku: CI.cid AS cid, -- tag changeset 727f370c29 2008-01-27 aku: T.fid AS fid -- file of item in changeset 80b1e8936f 2007-11-29 aku: FROM csitem CI, changeset C, tag T 727f370c29 2008-01-27 aku: WHERE CI.iid = T.tid -- get tag of item in changeset 727f370c29 2008-01-27 aku: AND C.cid = CI.cid -- get changeset of item 727f370c29 2008-01-27 aku: AND C.type = 1 -- limit to tag changesets 4b15fa348d 2007-11-29 aku: ) AS U 727f370c29 2008-01-27 aku: GROUP BY U.cid -- aggregate by csets, count files/cset 727f370c29 2008-01-27 aku: ) AS UU, 727f370c29 2008-01-27 aku: (SELECT V.cid AS cid, -- changeset 727f370c29 2008-01-27 aku: COUNT (V.iid) AS rcount -- number of items in cset 80b1e8936f 2007-11-29 aku: FROM csitem V, changeset X 727f370c29 2008-01-27 aku: WHERE X.cid = V.cid -- get changeset of item 727f370c29 2008-01-27 aku: AND X.type = 1 -- limit to tag changesets 727f370c29 2008-01-27 aku: GROUP BY V.cid -- aggregate by csets, count items/cset 727f370c29 2008-01-27 aku: ) AS VV 727f370c29 2008-01-27 aku: WHERE VV.cid = UU.cid -- sync #items/cset with #files/cset 727f370c29 2008-01-27 aku: AND UU.fcount < VV.rcount -- less files than items 727f370c29 2008-01-27 aku: -- => items belong to the same file. 727f370c29 2008-01-27 aku: ) 727f370c29 2008-01-27 aku: AND T.tid = C.type -- get readable changeset type 8c6488ded2 2007-11-27 aku: } 8c6488ded2 2007-11-27 aku: return 8c6488ded2 2007-11-27 aku: } 8c6488ded2 2007-11-27 aku: 7c28fe1312 2007-11-29 aku: proc BranchChangesets {} { 8c6488ded2 2007-11-27 aku: # This code performs a number of paranoid checks of the 8c6488ded2 2007-11-27 aku: # database, searching for inconsistent changeset/revision 8c6488ded2 2007-11-27 aku: # information. 8c6488ded2 2007-11-27 aku: 8c6488ded2 2007-11-27 aku: upvar 1 n n ; # Counter for the checks (we print an id before 8c6488ded2 2007-11-27 aku: # the main label). 8c6488ded2 2007-11-27 aku: 4b15fa348d 2007-11-29 aku: # Find all branches which are not used by at least one 4b15fa348d 2007-11-29 aku: # changeset. 4b15fa348d 2007-11-29 aku: CheckBranch \ 4b15fa348d 2007-11-29 aku: {All branches have to be used by least one changeset} \ 4b15fa348d 2007-11-29 aku: {is not used by a changeset} { 4b15fa348d 2007-11-29 aku: -- Unused branches = All branches 4b15fa348d 2007-11-29 aku: -- - branches used by branch changesets. 4b15fa348d 2007-11-29 aku: -- 4b15fa348d 2007-11-29 aku: -- Both sets can be computed easily, and subtracted 4b15fa348d 2007-11-29 aku: -- from each other. Then we can get the associated 4b15fa348d 2007-11-29 aku: -- file (name) for display. 4b15fa348d 2007-11-29 aku: 4b15fa348d 2007-11-29 aku: SELECT P.name, S.name 4b15fa348d 2007-11-29 aku: FROM project P, branch B, symbol S 4b15fa348d 2007-11-29 aku: WHERE B.bid IN (SELECT bid -- All branches 4b15fa348d 2007-11-29 aku: FROM branch 4b15fa348d 2007-11-29 aku: EXCEPT -- subtract 80b1e8936f 2007-11-29 aku: SELECT CI.iid -- branches used 80b1e8936f 2007-11-29 aku: FROM csitem CI, changeset C 80b1e8936f 2007-11-29 aku: WHERE C.cid = CI.cid -- by any branch 727f370c29 2008-01-27 aku: AND C.type = 2 -- changeset 727f370c29 2008-01-27 aku: ) 4b15fa348d 2007-11-29 aku: AND S.sid = B.sid -- get symbol of branch 4b15fa348d 2007-11-29 aku: AND P.pid = S.pid -- get project of symbol 4b15fa348d 2007-11-29 aku: } 4b15fa348d 2007-11-29 aku: # Find all branches which are used by more than one changeset. 4b15fa348d 2007-11-29 aku: CheckRev \ 4b15fa348d 2007-11-29 aku: {All branches have to be used by at most one changeset} \ 4b15fa348d 2007-11-29 aku: {is used by multiple changesets} { 4b15fa348d 2007-11-29 aku: -- Principle of operation: Get all branch/changeset 4b15fa348d 2007-11-29 aku: -- pairs for all branch changesets, group by tag to 4b15fa348d 2007-11-29 aku: -- aggregate the changeset, counting them. From the 4b15fa348d 2007-11-29 aku: -- resulting branch/count table select those with more 4b15fa348d 2007-11-29 aku: -- than one user, and get their associated file (name) 4b15fa348d 2007-11-29 aku: -- for display. 4b15fa348d 2007-11-29 aku: 4b15fa348d 2007-11-29 aku: SELECT P.name, S.name 4b15fa348d 2007-11-29 aku: FROM branch B, project P, symbol S, 727f370c29 2008-01-27 aku: (SELECT CI.iid AS iid, -- item 727f370c29 2008-01-27 aku: count(CI.cid) AS count -- number of csets for item 80b1e8936f 2007-11-29 aku: FROM csitem CI, changeset C 727f370c29 2008-01-27 aku: WHERE C.type = 2 -- limit to branch changesets, 727f370c29 2008-01-27 aku: AND C.cid = CI.cid -- get the items they contain, 727f370c29 2008-01-27 aku: GROUP BY CI.iid -- aggregate by items, count csets/item (x) 727f370c29 2008-01-27 aku: ) AS U 727f370c29 2008-01-27 aku: WHERE U.count > 1 -- find items used multiple times 727f370c29 2008-01-27 aku: AND B.bid = U.iid -- get the users (branch changesets) 727f370c29 2008-01-27 aku: AND S.sid = B.sid -- get symbol of branch 727f370c29 2008-01-27 aku: AND P.pid = S.pid -- get project of symbol 4b15fa348d 2007-11-29 aku: } fd93aa26a6 2007-12-02 aku: if 0 { fd93aa26a6 2007-12-02 aku: # This check has been disabled. When the converter was run fd93aa26a6 2007-12-02 aku: # on the Tcl CVS several branches tripped this fd93aa26a6 2007-12-02 aku: # constraint. One of them was a free-floating branch, and fd93aa26a6 2007-12-02 aku: # its handling has been fixed by now. The others however fd93aa26a6 2007-12-02 aku: # seem semi-legitimate, in the sense that they show fd93aa26a6 2007-12-02 aku: # inconsistencies in the CVS history the user is not fd93aa26a6 2007-12-02 aku: # really able to solve, but it might be possible to simply fd93aa26a6 2007-12-02 aku: # ignore them. fd93aa26a6 2007-12-02 aku: fd93aa26a6 2007-12-02 aku: # For example in Tcl we have a branch X with a prefered fd93aa26a6 2007-12-02 aku: # parent Y, except for a single file where the prefered fd93aa26a6 2007-12-02 aku: # parent seems to be created after its current parent, fd93aa26a6 2007-12-02 aku: # making re-parenting impossible. However we may be able fd93aa26a6 2007-12-02 aku: # to ignore this, it should only cause the branch to have fd93aa26a6 2007-12-02 aku: # more than one predecessor, and shifting it around in the fd93aa26a6 2007-12-02 aku: # commit order. The backend would still use the prefered fd93aa26a6 2007-12-02 aku: # parent for the attachment point in fossil. fd93aa26a6 2007-12-02 aku: fd93aa26a6 2007-12-02 aku: # So, for now I have decided to disable this and press fd93aa26a6 2007-12-02 aku: # forward. Of course, if we run into actual trouble we fd93aa26a6 2007-12-02 aku: # will have to go back here see what can be done to fix fd93aa26a6 2007-12-02 aku: # this. Even if only giving the user the instruction how fd93aa26a6 2007-12-02 aku: # to edit the CVS repository to remove the inconsistency. fd93aa26a6 2007-12-02 aku: fd93aa26a6 2007-12-02 aku: # All branches have to agree on the LOD their changeset fd93aa26a6 2007-12-02 aku: # belongs to. In other words, all branches in a changeset fd93aa26a6 2007-12-02 aku: # have to refer to the same line of development. fd93aa26a6 2007-12-02 aku: # fd93aa26a6 2007-12-02 aku: # Instead of looking at all pairs of branches in all fd93aa26a6 2007-12-02 aku: # changesets we generate the distinct set of all LODs fd93aa26a6 2007-12-02 aku: # referenced by the branches of a changeset, look for fd93aa26a6 2007-12-02 aku: # those with cardinality > 1, and get the identifying fd93aa26a6 2007-12-02 aku: # information for the changesets found thusly. fd93aa26a6 2007-12-02 aku: CheckCS \ fd93aa26a6 2007-12-02 aku: {All branches in a changeset have to belong to the same LOD} \ fd93aa26a6 2007-12-02 aku: {: Its branches disagree about the LOD they belong to} { fd93aa26a6 2007-12-02 aku: SELECT T.name, C.cid fd93aa26a6 2007-12-02 aku: FROM changeset C, cstype T fd93aa26a6 2007-12-02 aku: WHERE C.cid IN (SELECT U.cid fd93aa26a6 2007-12-02 aku: FROM (SELECT DISTINCT CI.cid AS cid, B.lod AS lod fd93aa26a6 2007-12-02 aku: FROM csitem CI, changeset C, branch B fd93aa26a6 2007-12-02 aku: WHERE CI.iid = B.bid fd93aa26a6 2007-12-02 aku: AND C.cid = CI.cid fd93aa26a6 2007-12-02 aku: AND C.type = 2) AS U fd93aa26a6 2007-12-02 aku: GROUP BY U.cid HAVING COUNT(U.lod) > 1) fd93aa26a6 2007-12-02 aku: AND T.tid = C.type fd93aa26a6 2007-12-02 aku: } fd93aa26a6 2007-12-02 aku: } 4b15fa348d 2007-11-29 aku: # All branches have to agree on the project their changeset 4b15fa348d 2007-11-29 aku: # belongs to. In other words, all branches in a changeset have 4b15fa348d 2007-11-29 aku: # to refer to the same project. 4b15fa348d 2007-11-29 aku: # 4b15fa348d 2007-11-29 aku: # Instead of looking at all pairs of branches in all 4b15fa348d 2007-11-29 aku: # changesets we generate the distinct set of all projects 4b15fa348d 2007-11-29 aku: # referenced by the branches of a changeset, look for those 4b15fa348d 2007-11-29 aku: # with cardinality > 1, and get the identifying information 4b15fa348d 2007-11-29 aku: # for the changesets found thusly. 4b15fa348d 2007-11-29 aku: CheckCS \ 4b15fa348d 2007-11-29 aku: {All branches in a changeset have to belong to the same project} \ 4b15fa348d 2007-11-29 aku: {: Its branches disagree about the project they belong to} { 4b15fa348d 2007-11-29 aku: SELECT T.name, C.cid 4b15fa348d 2007-11-29 aku: FROM changeset C, cstype T 4b15fa348d 2007-11-29 aku: WHERE C.cid IN (SELECT U.cid 727f370c29 2008-01-27 aku: FROM (SELECT DISTINCT -- Unique cset/proj pairs 727f370c29 2008-01-27 aku: CI.cid AS cid, -- Branch cset 727f370c29 2008-01-27 aku: F.pid AS pid -- Project of item in cset 80b1e8936f 2007-11-29 aku: FROM csitem CI, changeset C, branch B, file F 727f370c29 2008-01-27 aku: WHERE CI.iid = B.bid -- get branch of item in cset 727f370c29 2008-01-27 aku: AND C.cid = CI.cid -- get changeset of item 727f370c29 2008-01-27 aku: AND C.type = 2 -- limit to branch changesets 727f370c29 2008-01-27 aku: AND F.fid = B.fid -- get file of branch 727f370c29 2008-01-27 aku: ) AS U 727f370c29 2008-01-27 aku: GROUP BY U.cid -- aggregate by csets, count proj/cset 727f370c29 2008-01-27 aku: HAVING COUNT(U.pid) > 1 -- find cset with multiple projects 727f370c29 2008-01-27 aku: ) 727f370c29 2008-01-27 aku: AND T.tid = C.type -- get readable changeset type 4b15fa348d 2007-11-29 aku: } 4b15fa348d 2007-11-29 aku: # All branches in a single changeset have to belong to 4b15fa348d 2007-11-29 aku: # different files. Conversely: No two branches of a single 4b15fa348d 2007-11-29 aku: # file are allowed to be in the same changeset. 4b15fa348d 2007-11-29 aku: # 4b15fa348d 2007-11-29 aku: # Instead of looking at all pairs of branches in all 4b15fa348d 2007-11-29 aku: # changesets we generate the distinct set of all files 4b15fa348d 2007-11-29 aku: # referenced by the branches of a changeset, and look for 4b15fa348d 2007-11-29 aku: # those with cardinality < the cardinality of the set of 4b15fa348d 2007-11-29 aku: # branches, and get the identifying information for the 4b15fa348d 2007-11-29 aku: # changesets found thusly. 4b15fa348d 2007-11-29 aku: CheckCS \ 4b15fa348d 2007-11-29 aku: {All branches in a changeset have to belong to different files} \ 4b15fa348d 2007-11-29 aku: {: Its branches share files} { 4b15fa348d 2007-11-29 aku: SELECT T.name, C.cid 4b15fa348d 2007-11-29 aku: FROM changeset C, cstype T 4b15fa348d 2007-11-29 aku: WHERE C.cid IN (SELECT VV.cid 727f370c29 2008-01-27 aku: FROM (SELECT U.cid AS cid, -- changeset 727f370c29 2008-01-27 aku: COUNT (U.fid) AS fcount -- number of files by items 727f370c29 2008-01-27 aku: FROM (SELECT DISTINCT -- unique cset/file pairs 727f370c29 2008-01-27 aku: CI.cid AS cid, -- Branch changeset 727f370c29 2008-01-27 aku: B.fid AS fid -- File of item in changeset 80b1e8936f 2007-11-29 aku: FROM csitem CI, changeset C, branch B 727f370c29 2008-01-27 aku: WHERE CI.iid = B.bid -- get tag of item in changeset 727f370c29 2008-01-27 aku: AND C.cid = CI.cid -- get changeset of item 727f370c29 2008-01-27 aku: AND C.type = 2 -- limit to branch changesets 4b15fa348d 2007-11-29 aku: ) AS U 727f370c29 2008-01-27 aku: GROUP BY U.cid -- aggregate by csets, count files/cset 727f370c29 2008-01-27 aku: ) AS UU, 727f370c29 2008-01-27 aku: (SELECT V.cid AS cid, -- changeset 727f370c29 2008-01-27 aku: COUNT (V.iid) AS rcount -- number of items in cset 80b1e8936f 2007-11-29 aku: FROM csitem V, changeset X 727f370c29 2008-01-27 aku: WHERE X.cid = V.cid -- get changeset of item 727f370c29 2008-01-27 aku: AND X.type = 2 -- limit to branch changesets 727f370c29 2008-01-27 aku: GROUP BY V.cid -- aggregate by csets, count items/cset 727f370c29 2008-01-27 aku: ) AS VV 727f370c29 2008-01-27 aku: WHERE VV.cid = UU.cid -- sync #items/cset with #files/cset 727f370c29 2008-01-27 aku: AND UU.fcount < VV.rcount -- less files than items 727f370c29 2008-01-27 aku: -- => items belong to the same file. 727f370c29 2008-01-27 aku: ) 727f370c29 2008-01-27 aku: AND T.tid = C.type -- get readable changeset type 8c6488ded2 2007-11-27 aku: } 8c6488ded2 2007-11-27 aku: return bf83201c7f 2007-11-27 aku: } bf83201c7f 2007-11-27 aku: de10b2301e 2007-11-29 aku: proc ___UnusedChangesetChecks___ {} { 8c6488ded2 2007-11-27 aku: # This code performs a number of paranoid checks of the 8c6488ded2 2007-11-27 aku: # database, searching for inconsistent changeset/revision 8c6488ded2 2007-11-27 aku: # information. 8c6488ded2 2007-11-27 aku: 8c6488ded2 2007-11-27 aku: return ; # Disabled for now, bottlenecks ... 8c6488ded2 2007-11-27 aku: 8c6488ded2 2007-11-27 aku: upvar 1 n n ; # Counter for the checks (we print an id before 8c6488ded2 2007-11-27 aku: # the main label). 8c6488ded2 2007-11-27 aku: 8c6488ded2 2007-11-27 aku: # The next two checks are BOTTLENECKS. In essence we are 8c6488ded2 2007-11-27 aku: # checking each symbol changeset one by one. 8c6488ded2 2007-11-27 aku: 8c6488ded2 2007-11-27 aku: # TODO: Try to rephrase the checks to make more use of 8c6488ded2 2007-11-27 aku: # indices, set and stream operations. 8c6488ded2 2007-11-27 aku: 8c6488ded2 2007-11-27 aku: # All revisions used by tag symbol changesets have to have the 8c6488ded2 2007-11-27 aku: # changeset's tag associated with them. de10b2301e 2007-11-29 aku: CheckRevCS \ 8c6488ded2 2007-11-27 aku: {All revisions used by tag symbol changesets have to have the changeset's tag attached to them} \ 8c6488ded2 2007-11-27 aku: {does not have the tag of its symbol changeset @ attached to it} { 8c6488ded2 2007-11-27 aku: SELECT CT.name, C.cid, F.name, R.rev 80b1e8936f 2007-11-29 aku: FROM changeset C, cstype CT, revision R, file F, csitem CI, tag T 8c6488ded2 2007-11-27 aku: WHERE C.type = 1 -- symbol changesets only 8c6488ded2 2007-11-27 aku: AND C.src = T.sid -- tag only, linked by symbol id 80b1e8936f 2007-11-29 aku: AND C.cid = CI.cid -- changeset --> its revisions 80b1e8936f 2007-11-29 aku: AND R.rid = CI.iid -- look at the revisions 8c6488ded2 2007-11-27 aku: -- and look for the tag among the attached ones. 8c6488ded2 2007-11-27 aku: AND T.sid NOT IN (SELECT TB.sid 8c6488ded2 2007-11-27 aku: FROM tag TB 8c6488ded2 2007-11-27 aku: WHERE TB.rev = R.rid) 8c6488ded2 2007-11-27 aku: AND R.fid = F.fid -- get file of revision 8c6488ded2 2007-11-27 aku: } 8c6488ded2 2007-11-27 aku: 8c6488ded2 2007-11-27 aku: # All revisions used by branch symbol changesets have to have 8c6488ded2 2007-11-27 aku: # the changeset's branch associated with them. 8c6488ded2 2007-11-27 aku: de10b2301e 2007-11-29 aku: CheckRevCS \ 8c6488ded2 2007-11-27 aku: {All revisions used by branch symbol changesets have to have the changeset's branch attached to them} \ 8c6488ded2 2007-11-27 aku: {does not have the branch of its symbol changeset @ attached to it} { 8c6488ded2 2007-11-27 aku: SELECT CT.name, C.cid, F.name, R.rev, C.cid 80b1e8936f 2007-11-29 aku: FROM changeset C, cstype CT, revision R, file F, csitem CI, branch B 8c6488ded2 2007-11-27 aku: WHERE C.type = 1 -- symbol changesets only 8c6488ded2 2007-11-27 aku: AND C.src = B.sid -- branches only 80b1e8936f 2007-11-29 aku: AND C.cid = CI.cid -- changeset --> its revisions 80b1e8936f 2007-11-29 aku: AND R.rid = CI.iid -- look at the revisions 8c6488ded2 2007-11-27 aku: -- and look for the branch among the attached ones. 8c6488ded2 2007-11-27 aku: AND B.sid NOT IN (SELECT BB.sid 8c6488ded2 2007-11-27 aku: FROM branch BB 8c6488ded2 2007-11-27 aku: WHERE BB.root = R.rid) 8c6488ded2 2007-11-27 aku: AND R.fid = F.fid -- get file of revision 8c6488ded2 2007-11-27 aku: } 8c6488ded2 2007-11-27 aku: 8c6488ded2 2007-11-27 aku: # TODO 8c6488ded2 2007-11-27 aku: # The state has to contain at least one tag symbol changeset 8c6488ded2 2007-11-27 aku: # for all known tags. 8c6488ded2 2007-11-27 aku: 8c6488ded2 2007-11-27 aku: # TODO 8c6488ded2 2007-11-27 aku: # The state has to contain at least one branch symbol changeset 8c6488ded2 2007-11-27 aku: # for all known branches. 8c6488ded2 2007-11-27 aku: return bf83201c7f 2007-11-27 aku: } bf83201c7f 2007-11-27 aku: bf83201c7f 2007-11-27 aku: 7c28fe1312 2007-11-29 aku: proc CheckRev {header label sql} { 131f051880 2007-11-09 aku: upvar 1 n n 131f051880 2007-11-09 aku: set ok 1 131f051880 2007-11-09 aku: foreach {fname revnr} [state run $sql] { 131f051880 2007-11-09 aku: set ok 0 de10b2301e 2007-11-29 aku: trouble fatal "${revnr}::$fname $label" 7c28fe1312 2007-11-29 aku: } 7c28fe1312 2007-11-29 aku: log write 5 integrity {\[[format %02d [incr n]]\] [expr {$ok ? "Ok " : "Failed"}] ... $header} 7c28fe1312 2007-11-29 aku: return 7c28fe1312 2007-11-29 aku: } 7c28fe1312 2007-11-29 aku: 7c28fe1312 2007-11-29 aku: proc CheckTag {header label sql} { 7c28fe1312 2007-11-29 aku: upvar 1 n n 7c28fe1312 2007-11-29 aku: set ok 1 7c28fe1312 2007-11-29 aku: foreach {pname sname} [state run $sql] { 7c28fe1312 2007-11-29 aku: set ok 0 7c28fe1312 2007-11-29 aku: trouble fatal "<$pname tag '$sname'> $label" 7c28fe1312 2007-11-29 aku: } 7c28fe1312 2007-11-29 aku: log write 5 integrity {\[[format %02d [incr n]]\] [expr {$ok ? "Ok " : "Failed"}] ... $header} 7c28fe1312 2007-11-29 aku: return 7c28fe1312 2007-11-29 aku: } 7c28fe1312 2007-11-29 aku: 7c28fe1312 2007-11-29 aku: proc CheckBranch {header label sql} { 7c28fe1312 2007-11-29 aku: upvar 1 n n 7c28fe1312 2007-11-29 aku: set ok 1 7c28fe1312 2007-11-29 aku: foreach {pname sname} [state run $sql] { 7c28fe1312 2007-11-29 aku: set ok 0 7c28fe1312 2007-11-29 aku: trouble fatal "<$pname branch '$sname'> $label" 8c6488ded2 2007-11-27 aku: } 47d52d1efd 2007-11-28 aku: log write 5 integrity {\[[format %02d [incr n]]\] [expr {$ok ? "Ok " : "Failed"}] ... $header} 8c6488ded2 2007-11-27 aku: return 8c6488ded2 2007-11-27 aku: } 8c6488ded2 2007-11-27 aku: 8c6488ded2 2007-11-27 aku: proc CheckCS {header label sql} { 8c6488ded2 2007-11-27 aku: upvar 1 n n 8c6488ded2 2007-11-27 aku: set ok 1 8c6488ded2 2007-11-27 aku: foreach {ctype cid} [state run $sql] { 8c6488ded2 2007-11-27 aku: set ok 0 8c6488ded2 2007-11-27 aku: trouble fatal "<$ctype $cid> $label" 8c6488ded2 2007-11-27 aku: } 47d52d1efd 2007-11-28 aku: log write 5 integrity {\[[format %02d [incr n]]\] [expr {$ok ? "Ok " : "Failed"}] ... $header} 8c6488ded2 2007-11-27 aku: return 8c6488ded2 2007-11-27 aku: } 8c6488ded2 2007-11-27 aku: de10b2301e 2007-11-29 aku: proc CheckRevCS {header label sql} { 8c6488ded2 2007-11-27 aku: upvar 1 n n 8c6488ded2 2007-11-27 aku: set ok 1 8c6488ded2 2007-11-27 aku: foreach {cstype csid fname revnr} [state run $sql] { 8c6488ded2 2007-11-27 aku: set ok 0 8c6488ded2 2007-11-27 aku: set b "<$cstype $csid>" 8c6488ded2 2007-11-27 aku: trouble fatal "$fname <$revnr> [string map [list @ $b] $label]" 131f051880 2007-11-09 aku: } 47d52d1efd 2007-11-28 aku: log write 5 integrity {\[[format %02d [incr n]]\] [expr {$ok ? "Ok " : "Failed"}] ... $header} 131f051880 2007-11-09 aku: return 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: # # ## ### ##### ######## ############# 131f051880 2007-11-09 aku: ## Configuration 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: pragma -hasinstances no ; # singleton 131f051880 2007-11-09 aku: pragma -hastypeinfo no ; # no introspection 131f051880 2007-11-09 aku: pragma -hastypedestroy no ; # immortal 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: # # ## ### ##### ######## ############# 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: namespace eval ::vc::fossil::import::cvs { 131f051880 2007-11-09 aku: namespace export integrity 131f051880 2007-11-09 aku: namespace eval integrity { 131f051880 2007-11-09 aku: namespace import ::vc::fossil::import::cvs::state 131f051880 2007-11-09 aku: namespace import ::vc::tools::trouble 131f051880 2007-11-09 aku: namespace import ::vc::tools::log 131f051880 2007-11-09 aku: log register integrity 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: } 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: # # ## ### ##### ######## ############# ##################### 131f051880 2007-11-09 aku: ## Ready 131f051880 2007-11-09 aku: 131f051880 2007-11-09 aku: package provide vc::fossil::import::cvs::integrity 1.0 131f051880 2007-11-09 aku: return