File Annotation
Not logged in
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: 
b42cff97e3 2007-11-30       aku:     typemethod changesets {csets} {
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
b42cff97e3 2007-11-30       aku: 	Selfreferentiality $csets
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
131f051880 2007-11-09       aku: 		WHERE R.fid = F.fid
131f051880 2007-11-09       aku: 		AND   R.lod = S.sid
131f051880 2007-11-09       aku: 		AND   F.pid != S.pid
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
131f051880 2007-11-09       aku: 		WHERE R.fid = F.fid
131f051880 2007-11-09       aku: 		AND   R.mid = M.mid
131f051880 2007-11-09       aku: 		AND   F.pid != M.pid
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
131f051880 2007-11-09       aku: 		WHERE R.fid = F.fid
131f051880 2007-11-09       aku: 		AND   R.child IS NOT NULL
131f051880 2007-11-09       aku: 		AND   R.child = C.rid
131f051880 2007-11-09       aku: 		AND   C.fid != R.fid
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
131f051880 2007-11-09       aku: 		WHERE R.fid = F.fid
131f051880 2007-11-09       aku: 		AND   R.bparent IS NOT NULL
131f051880 2007-11-09       aku: 		AND   R.parent = P.rid
131f051880 2007-11-09       aku: 		AND   R.fid != P.fid
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
131f051880 2007-11-09       aku: 		WHERE R.fid = F.fid
131f051880 2007-11-09       aku: 		AND   R.dbchild IS NOT NULL
131f051880 2007-11-09       aku: 		AND   R.dbchild = C.rid
131f051880 2007-11-09       aku: 		AND   C.fid != R.fid
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
131f051880 2007-11-09       aku: 		WHERE R.fid = F.fid
131f051880 2007-11-09       aku: 		AND   R.child IS NOT NULL
131f051880 2007-11-09       aku: 		AND   R.child = C.rid
131f051880 2007-11-09       aku: 		AND   C.parent != R.rid
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
131f051880 2007-11-09       aku: 		WHERE R.fid = F.fid
131f051880 2007-11-09       aku: 		AND   R.child IS NOT NULL
131f051880 2007-11-09       aku: 		AND   R.child = C.rid
131f051880 2007-11-09       aku: 		AND   C.bparent IS NOT NULL
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
131f051880 2007-11-09       aku: 		WHERE R.fid = F.fid
131f051880 2007-11-09       aku: 		AND   R.bparent IS NULL
131f051880 2007-11-09       aku: 		AND   R.parent IS NOT NULL
131f051880 2007-11-09       aku: 		AND   R.parent = P.rid
131f051880 2007-11-09       aku: 		AND   P.child != R.rid
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 \
131f051880 2007-11-09       aku: 	    {Branch starting revisions have to have a parent} \
131f051880 2007-11-09       aku: 	    {at the beginning of its branch has no parent} {
131f051880 2007-11-09       aku: 		SELECT F.name, R.rev
131f051880 2007-11-09       aku: 		FROM revision R, file F
131f051880 2007-11-09       aku: 		WHERE R.fid = F.fid
131f051880 2007-11-09       aku: 		AND   R.bparent IS NOT NULL
131f051880 2007-11-09       aku: 		AND   R.parent IS NULL
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
131f051880 2007-11-09       aku: 		WHERE R.fid = F.fid
131f051880 2007-11-09       aku: 		AND   R.bparent IS NOT NULL
131f051880 2007-11-09       aku: 		AND   R.parent IS NOT NULL
131f051880 2007-11-09       aku: 		AND   R.parent = P.rid
131f051880 2007-11-09       aku: 		AND   P.child = R.rid
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
131f051880 2007-11-09       aku: 		WHERE R.fid = F.fid
131f051880 2007-11-09       aku: 		AND   R.dbchild IS NOT NULL
131f051880 2007-11-09       aku: 		AND   NOT R.isdefault
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
131f051880 2007-11-09       aku: 		WHERE R.fid = F.fid
131f051880 2007-11-09       aku: 		AND   R.dbparent IS NOT NULL
131f051880 2007-11-09       aku: 		AND   R.isdefault
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
131f051880 2007-11-09       aku: 		WHERE R.fid = F.fid
131f051880 2007-11-09       aku: 		AND   R.child IS NOT NULL
131f051880 2007-11-09       aku: 		AND   R.child = C.rid
131f051880 2007-11-09       aku: 		AND   C.lod != R.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
131f051880 2007-11-09       aku: 		WHERE R.fid = F.fid
131f051880 2007-11-09       aku: 		AND   R.dbchild IS NOT NULL
131f051880 2007-11-09       aku: 		AND   R.dbchild = C.rid
131f051880 2007-11-09       aku: 		AND   C.lod = R.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
131f051880 2007-11-09       aku: 		WHERE R.fid = F.fid
131f051880 2007-11-09       aku: 		AND   R.bparent IS NOT NULL
131f051880 2007-11-09       aku: 		AND   R.lod != R.bparent
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
131f051880 2007-11-09       aku: 		WHERE R.fid = F.fid
131f051880 2007-11-09       aku: 		AND   R.bparent IS NOT NULL
131f051880 2007-11-09       aku: 		AND   R.parent = P.rid
131f051880 2007-11-09       aku: 		AND   R.lod = P.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
131f051880 2007-11-09       aku: 		WHERE R.mid = M.mid
131f051880 2007-11-09       aku: 		AND   R.lod != M.bid
131f051880 2007-11-09       aku: 		AND   R.fid = F.fid
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,
80b1e8936f 2007-11-29       aku: 		     (SELECT CI.iid AS rid, count(CI.cid) AS count
80b1e8936f 2007-11-29       aku: 		      FROM csitem CI, changeset C
8c6488ded2 2007-11-27       aku: 		      WHERE C.type = 0
80b1e8936f 2007-11-29       aku: 		      AND   C.cid = CI.cid
80b1e8936f 2007-11-29       aku: 		      GROUP BY CI.iid) AS U
8c6488ded2 2007-11-27       aku: 		WHERE U.count > 1
8c6488ded2 2007-11-27       aku: 		AND R.rid = U.rid
8c6488ded2 2007-11-27       aku: 		AND R.fid = F.fid
8c6488ded2 2007-11-27       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
80b1e8936f 2007-11-29       aku: 				 FROM (SELECT DISTINCT CI.cid AS cid, R.lod AS lod
80b1e8936f 2007-11-29       aku: 				       FROM   csitem CI, changeset C, revision R
80b1e8936f 2007-11-29       aku: 				       WHERE  CI.iid = R.rid
80b1e8936f 2007-11-29       aku: 				       AND    C.cid = CI.cid
de10b2301e 2007-11-29       aku: 				       AND    C.type = 0) AS U
8c6488ded2 2007-11-27       aku: 				 GROUP BY U.cid HAVING COUNT(U.lod) > 1)
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
80b1e8936f 2007-11-29       aku: 				 FROM (SELECT DISTINCT CI.cid AS cid, F.pid AS pid
80b1e8936f 2007-11-29       aku: 				       FROM   csitem CI, changeset C, revision R, file F
80b1e8936f 2007-11-29       aku: 				       WHERE  CI.iid = R.rid
80b1e8936f 2007-11-29       aku: 				       AND    C.cid = CI.cid
de10b2301e 2007-11-29       aku: 				       AND    C.type = 0
8c6488ded2 2007-11-27       aku: 				       AND    F.fid  = R.fid) AS U
8c6488ded2 2007-11-27       aku: 				 GROUP BY U.cid HAVING COUNT(U.pid) > 1)
8c6488ded2 2007-11-27       aku: 		AND    T.tid = C.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
8c6488ded2 2007-11-27       aku: 				 FROM (SELECT U.cid as cid, COUNT (U.fid) AS fcount
80b1e8936f 2007-11-29       aku: 				       FROM (SELECT DISTINCT CI.cid AS cid, R.fid AS fid
80b1e8936f 2007-11-29       aku: 					     FROM   csitem CI, changeset C, revision R
80b1e8936f 2007-11-29       aku: 					     WHERE  CI.iid = R.rid
80b1e8936f 2007-11-29       aku: 					     AND    C.cid = CI.cid
de10b2301e 2007-11-29       aku: 					     AND    C.type = 0
de10b2301e 2007-11-29       aku: 					     ) AS U
7c28fe1312 2007-11-29       aku: 				       GROUP BY U.cid) AS UU,
80b1e8936f 2007-11-29       aku: 				      (SELECT V.cid AS cid, COUNT (V.iid) AS rcount
80b1e8936f 2007-11-29       aku: 				       FROM   csitem V, changeset X
de10b2301e 2007-11-29       aku: 				       WHERE  X.cid = V.cid
de10b2301e 2007-11-29       aku: 				       AND    X.type = 0
7c28fe1312 2007-11-29       aku: 				       GROUP BY V.cid) AS VV
7c28fe1312 2007-11-29       aku: 				 WHERE VV.cid = UU.cid
7c28fe1312 2007-11-29       aku: 				 AND   UU.fcount < VV.rcount)
7c28fe1312 2007-11-29       aku: 		AND    T.tid = C.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,
80b1e8936f 2007-11-29       aku: 		     (SELECT CI.iid AS iid, count(CI.cid) AS count
80b1e8936f 2007-11-29       aku: 		      FROM csitem CI, changeset C
4b15fa348d 2007-11-29       aku: 		      WHERE C.type = 1
80b1e8936f 2007-11-29       aku: 		      AND   C.cid = CI.cid
80b1e8936f 2007-11-29       aku: 		      GROUP BY CI.iid) AS U
4b15fa348d 2007-11-29       aku: 		WHERE U.count > 1
80b1e8936f 2007-11-29       aku: 		AND   T.tid = U.iid
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: 	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
80b1e8936f 2007-11-29       aku: 				 FROM (SELECT DISTINCT CI.cid AS cid, F.pid AS pid
80b1e8936f 2007-11-29       aku: 				       FROM   csitem CI, changeset C, tag T, file F
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
4b15fa348d 2007-11-29       aku: 				       AND    F.fid  = T.fid) AS U
4b15fa348d 2007-11-29       aku: 				 GROUP BY U.cid HAVING COUNT(U.pid) > 1)
4b15fa348d 2007-11-29       aku: 		AND    T.tid = C.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
4b15fa348d 2007-11-29       aku: 				 FROM (SELECT U.cid as cid, COUNT (U.fid) AS fcount
80b1e8936f 2007-11-29       aku: 				       FROM (SELECT DISTINCT CI.cid AS cid, T.fid AS fid
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
4b15fa348d 2007-11-29       aku: 					     ) AS U
8c6488ded2 2007-11-27       aku: 				       GROUP BY U.cid) AS UU,
80b1e8936f 2007-11-29       aku: 				      (SELECT V.cid AS cid, COUNT (V.iid) AS rcount
80b1e8936f 2007-11-29       aku: 				       FROM   csitem V, changeset X
4b15fa348d 2007-11-29       aku: 				       WHERE  X.cid = V.cid
4b15fa348d 2007-11-29       aku: 				       AND    X.type = 1
8c6488ded2 2007-11-27       aku: 				       GROUP BY V.cid) AS VV
8c6488ded2 2007-11-27       aku: 				 WHERE VV.cid = UU.cid
8c6488ded2 2007-11-27       aku: 				 AND   UU.fcount < VV.rcount)
8c6488ded2 2007-11-27       aku: 		AND    T.tid = C.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
4b15fa348d 2007-11-29       aku: 				AND    C.type = 2)            -- changeset
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,
80b1e8936f 2007-11-29       aku: 		     (SELECT CI.iid AS iid, count(CI.cid) AS count
80b1e8936f 2007-11-29       aku: 		      FROM csitem CI, changeset C
4b15fa348d 2007-11-29       aku: 		      WHERE C.type = 2
80b1e8936f 2007-11-29       aku: 		      AND   C.cid = CI.cid
80b1e8936f 2007-11-29       aku: 		      GROUP BY CI.iid ) AS U
4b15fa348d 2007-11-29       aku: 		WHERE U.count > 1
80b1e8936f 2007-11-29       aku: 		AND   B.bid = U.iid
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: 	# All branches have to agree on the LOD 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 line of development.
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 LODs
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 LOD} \
4b15fa348d 2007-11-29       aku: 	    {: Its branches 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, B.lod AS lod
80b1e8936f 2007-11-29       aku: 				       FROM   csitem CI, changeset C, branch B
80b1e8936f 2007-11-29       aku: 				       WHERE  CI.iid = B.bid
80b1e8936f 2007-11-29       aku: 				       AND    C.cid = CI.cid
4b15fa348d 2007-11-29       aku: 				       AND    C.type = 2) 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: 	# 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
80b1e8936f 2007-11-29       aku: 				 FROM (SELECT DISTINCT CI.cid AS cid, F.pid AS pid
80b1e8936f 2007-11-29       aku: 				       FROM   csitem CI, changeset C, branch B, file F
80b1e8936f 2007-11-29       aku: 				       WHERE  CI.iid = B.bid
80b1e8936f 2007-11-29       aku: 				       AND    C.cid = CI.cid
4b15fa348d 2007-11-29       aku: 				       AND    C.type = 2
4b15fa348d 2007-11-29       aku: 				       AND    F.fid  = B.fid) AS U
4b15fa348d 2007-11-29       aku: 				 GROUP BY U.cid HAVING COUNT(U.pid) > 1)
4b15fa348d 2007-11-29       aku: 		AND    T.tid = C.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
4b15fa348d 2007-11-29       aku: 				 FROM (SELECT U.cid as cid, COUNT (U.fid) AS fcount
80b1e8936f 2007-11-29       aku: 				       FROM (SELECT DISTINCT CI.cid AS cid, B.fid AS fid
80b1e8936f 2007-11-29       aku: 					     FROM   csitem CI, changeset C, branch B
80b1e8936f 2007-11-29       aku: 					     WHERE  CI.iid = B.bid
80b1e8936f 2007-11-29       aku: 					     AND    C.cid = CI.cid
4b15fa348d 2007-11-29       aku: 					     AND    C.type = 2
4b15fa348d 2007-11-29       aku: 					     ) AS U
4b15fa348d 2007-11-29       aku: 				       GROUP BY U.cid) AS UU,
80b1e8936f 2007-11-29       aku: 				      (SELECT V.cid AS cid, COUNT (V.iid) AS rcount
80b1e8936f 2007-11-29       aku: 				       FROM   csitem V, changeset X
4b15fa348d 2007-11-29       aku: 				       WHERE  X.cid = V.cid
4b15fa348d 2007-11-29       aku: 				       AND    X.type = 2
4b15fa348d 2007-11-29       aku: 				       GROUP BY V.cid) AS VV
4b15fa348d 2007-11-29       aku: 				 WHERE VV.cid = UU.cid
4b15fa348d 2007-11-29       aku: 				 AND   UU.fcount < VV.rcount)
4b15fa348d 2007-11-29       aku: 		AND    T.tid = C.type
4b15fa348d 2007-11-29       aku: 	    }
b42cff97e3 2007-11-30       aku: 	return
b42cff97e3 2007-11-30       aku:     }
b42cff97e3 2007-11-30       aku: 
b42cff97e3 2007-11-30       aku:     proc Selfreferentiality {csets} {
b42cff97e3 2007-11-30       aku: 	log write 4 integrity {Checking changesets for self-references}
b42cff97e3 2007-11-30       aku: 
b42cff97e3 2007-11-30       aku: 	foreach cset $csets {
b42cff97e3 2007-11-30       aku: 	    if {[$cset selfreferential]} {
b42cff97e3 2007-11-30       aku: 		trouble fatal "[$cset str] depends on itself"
8c6488ded2 2007-11-27       aku: 	    }
b42cff97e3 2007-11-30       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