Diff
Not logged in

Differences From:

File tools/cvs2fossil/lib/c2f_integrity.tcl part of check-in [c4003e7b93] - The handling of detached lines of development (floating branches) still had some bugs regarding the linkage to their revisions, especially the first revision on such branches. Fixed the relevant places, added early integrity checks and updated the main checks to handle the situation. by aku on 2007-12-05 02:22:52. [view]

To:

File tools/cvs2fossil/lib/c2f_integrity.tcl part of check-in [727f370c29] - Added comments to the sql commands in the integrity checks. by aku on 2008-01-27 20:38:17. [view]

@@ -79,11 +79,11 @@
 	    {Revisions and their LODs have to be in the same project} \
 	    {disagrees with its LOD about owning project} {
 		SELECT F.name, R.rev
 		FROM revision R, file F, symbol S
-		WHERE R.fid = F.fid
-		AND   R.lod = S.sid
-		AND   F.pid != S.pid
+		WHERE R.fid = F.fid   -- get file of rev
+		AND   R.lod = S.sid   -- get symbol of its lod
+		AND   F.pid != S.pid  -- disagreement about the owning project
 		;
 	    }
 	# Find all revisions which disgree with their meta data about
 	# the project they are owned by.
@@ -91,11 +91,11 @@
 	    {Revisions and their meta data have to be in the same project} \
 	    {disagrees with its meta data about owning project} {
 		SELECT F.name, R.rev
 		FROM revision R, file F, meta M
-		WHERE R.fid = F.fid
-		AND   R.mid = M.mid
-		AND   F.pid != M.pid
+		WHERE R.fid = F.fid   -- get file of rev
+		AND   R.mid = M.mid   -- get meta of rev
+		AND   F.pid != M.pid  -- disagreement about owning project
 		;
 	    }
 	# Find all revisions with a primary child which disagrees
 	# about the file they belong to.
@@ -103,12 +103,12 @@
 	    {Revisions and their primary children have to be in the same file} \
 	    {disagrees with its primary child about the owning file} {
 		SELECT F.name, R.rev
 		FROM revision R, revision C, file F
-		WHERE R.fid = F.fid
-		AND   R.child IS NOT NULL
-		AND   R.child = C.rid
-		AND   C.fid != R.fid
+		WHERE R.fid = F.fid       -- get file of rev
+		AND   R.child IS NOT NULL -- get all with primary children
+		AND   R.child = C.rid     -- get primary child
+		AND   C.fid != R.fid      -- wrongly in different file
 		;
 	    }
 
 	# Find all revisions with a branch parent symbol whose parent
@@ -117,12 +117,12 @@
 	    {Revisions and their branch children have to be in the same file} \
 	    {at the beginning of its branch and its parent disagree about the owning file} {
 		SELECT F.name, R.rev
 		FROM revision R, revision P, file F
-		WHERE R.fid = F.fid
-		AND   R.bparent IS NOT NULL
-		AND   R.parent = P.rid
-		AND   R.fid != P.fid
+		WHERE R.fid = F.fid         -- get file of rev
+		AND   R.bparent IS NOT NULL -- get first-of-branch revisions
+		AND   R.parent = P.rid      -- get out-of-branch parent
+		AND   R.fid != P.fid        -- wrongly in different file
 		;
 	    }
 	# Find all revisions with a non-NTDB child which disagrees
 	# about the file they belong to.
@@ -130,12 +130,12 @@
 	    {Revisions and their non-NTDB children have to be in the same file} \
 	    {disagrees with its non-NTDB child about the owning file} {
 		SELECT F.name, R.rev
 		FROM revision R, revision C, file F
-		WHERE R.fid = F.fid
-		AND   R.dbchild IS NOT NULL
-		AND   R.dbchild = C.rid
-		AND   C.fid != R.fid
+		WHERE R.fid = F.fid         -- get file of rev
+		AND   R.dbchild IS NOT NULL -- get last NTDB revisions
+		AND   R.dbchild = C.rid     -- get their child
+		AND   C.fid != R.fid        -- wrongly in different file
 		;
 	    }
 	# Find all revisions which have a primary child, but the child
 	# does not have them as parent.
@@ -143,12 +143,12 @@
 	    {Revisions have to be parents of their primary children} \
 	    {is not the parent of its primary child} {
 		SELECT F.name, R.rev
 		FROM revision R, revision C, file F
-		WHERE R.fid = F.fid
-		AND   R.child IS NOT NULL
-		AND   R.child = C.rid
-		AND   C.parent != R.rid
+		WHERE R.fid = F.fid         -- get file of rev
+		AND   R.child IS NOT NULL   -- get all with primary children
+		AND   R.child = C.rid       -- get primary child
+		AND   C.parent != R.rid     -- child's parent wrongly not us
 		;
 	    }
 	# Find all revisions which have a primrary child, but the
 	# child has a branch parent symbol making them brach starters.
@@ -156,12 +156,12 @@
 	    {Primary children of revisions must not start branches} \
 	    {is parent of a primary child which is the beginning of a branch} {
 		SELECT F.name, R.rev
 		FROM revision R, revision C, file F
-		WHERE R.fid = F.fid
-		AND   R.child IS NOT NULL
-		AND   R.child = C.rid
-		AND   C.bparent IS NOT NULL
+		WHERE R.fid = F.fid         -- get file of rev
+		AND   R.child IS NOT NULL   -- get all with primary children
+		AND   R.child = C.rid       -- get primary child
+		AND   C.bparent IS NOT NULL -- but indicates to be on branch
 		;
 	    }
 	# Find all revisions without branch parent symbol which have a
 	# parent, but the parent does not have them as primary child.
@@ -169,13 +169,13 @@
 	    {Revisions have to be primary children of their parents, if any} \
 	    {is not the child of its parent} {
 		SELECT F.name, R.rev
 		FROM revision R, revision P, file F
-		WHERE R.fid = F.fid
-		AND   R.bparent IS NULL
-		AND   R.parent IS NOT NULL
-		AND   R.parent = P.rid
-		AND   P.child != R.rid
+		WHERE R.fid = F.fid        -- get file of revision
+		AND   R.bparent IS NULL    -- exclude all first-on-branch revisions
+		AND   R.parent IS NOT NULL -- which are not root of their line
+		AND   R.parent = P.rid     -- get in-lod parent
+		AND   P.child != R.rid     -- but does not have rev as primary child
 		;
 	    }
 	# Find all revisions with a branch parent symbol which do not
 	# have a parent.
@@ -183,14 +183,14 @@
 	    {Branch starting revisions have to have a parent, if not detached} \
 	    {at the beginning of its branch has no parent, but its branch has} {
 		SELECT F.name, R.rev
 		FROM revision R, file F, branch B
-		WHERE R.fid = F.fid
-		AND   R.bparent IS NOT NULL
-		AND   R.parent  IS NULL
-		AND   B.sid = R.bparent
-		AND   B.fid = R.fid
-		AND   B.root    IS NOT NULL
+		WHERE R.fid = F.fid         -- get file of revision
+		AND   R.bparent IS NOT NULL -- limit to first-on-branch revisions
+		AND   R.parent  IS NULL     -- which are detached
+		AND   B.sid = R.bparent     -- get branch governing the rev
+		AND   B.fid = R.fid         -- in the revision's file
+		AND   B.root    IS NOT NULL -- but says that branch is attached
 		;
 	    }
 	# Find all revisions with a branch parent symbol whose parent
 	# has them as primary child.
@@ -198,13 +198,13 @@
 	    {Branch starting revisions must not be primary children of their parents} \
 	    {at the beginning of its branch is the primary child of its parent} {
 		SELECT F.name, R.rev
 		FROM revision R, revision P, file F
-		WHERE R.fid = F.fid
-		AND   R.bparent IS NOT NULL
-		AND   R.parent IS NOT NULL
-		AND   R.parent = P.rid
-		AND   P.child = R.rid
+		WHERE R.fid = F.fid         -- get file of revision
+		AND   R.bparent IS NOT NULL -- limit to first-on-branch revisions
+		AND   R.parent IS NOT NULL  -- which are attached
+		AND   R.parent = P.rid      -- get out-of-branch parent
+		AND   P.child = R.rid       -- wrongly has rev as primary child
 		;
 	    }
 	# Find all revisions with a non-NTDB child which are not on
 	# the NTDB.
@@ -212,11 +212,11 @@
 	    {NTDB to trunk transition has to begin on NTDB} \
 	    {has a non-NTDB child, yet is not on the NTDB} {
 		SELECT F.name, R.rev
 		FROM revision R, file F
-		WHERE R.fid = F.fid
-		AND   R.dbchild IS NOT NULL
-		AND   NOT R.isdefault
+		WHERE R.fid = F.fid         -- get file of revision
+		AND   R.dbchild IS NOT NULL -- limit to last NTDB revision
+		AND   NOT R.isdefault       -- but signals not-NTDB
 		;
 	    }
 	# Find all revisions with a NTDB parent which are on the NTDB.
 	CheckRev \
@@ -223,11 +223,11 @@
 	    {NTDB to trunk transition has to end on non-NTDB} \
 	    {has a NTDB parent, yet is on the NTDB} {
 		SELECT F.name, R.rev
 		FROM revision R, file F
-		WHERE R.fid = F.fid
-		AND   R.dbparent IS NOT NULL
-		AND   R.isdefault
+		WHERE R.fid = F.fid          -- get file of revision
+		AND   R.dbparent IS NOT NULL -- limit to roots of non-NTDB
+		AND   R.isdefault            -- but signals to be NTDB
 		;
 	    }
 	# Find all revisions with a child which disagrees about the
 	# line of development they belong to.
@@ -235,12 +235,12 @@
 	    {Revisions and their primary children have to be in the same LOD} \
 	    {and its primary child disagree about their LOD} {
 		SELECT F.name, R.rev
 		FROM revision R, revision C, file F
-		WHERE R.fid = F.fid
-		AND   R.child IS NOT NULL
-		AND   R.child = C.rid
-		AND   C.lod != R.lod
+		WHERE R.fid = F.fid       -- get file of revision
+		AND   R.child IS NOT NULL -- revision has a primary child
+		AND   R.child = C.rid     -- get that child
+		AND   C.lod != R.lod      -- child wrongly disagrees with lod
 		;
 	    }
 	# Find all revisions with a non-NTDB child which agrees about
 	# the line of development they belong to.
@@ -248,12 +248,12 @@
 	    {NTDB and trunk revisions have to be in different LODs} \
 	    {on NTDB and its non-NTDB child wrongly agree about their LOD} {
 		SELECT F.name, R.rev
 		FROM revision R, revision C, file F
-		WHERE R.fid = F.fid
-		AND   R.dbchild IS NOT NULL
-		AND   R.dbchild = C.rid
-		AND   C.lod = R.lod
+		WHERE R.fid = F.fid         -- get file of revision
+		AND   R.dbchild IS NOT NULL -- limit to last NTDB revision
+		AND   R.dbchild = C.rid     -- get non-NTDB child
+		AND   C.lod = R.lod         -- child wrongly has same lod
 		;
 	    }
 	# Find all revisions with a branch parent symbol which is not
 	# their LOD.
@@ -261,11 +261,11 @@
 	    {Branch starting revisions have to have their LOD as branch parent symbol} \
 	    {at the beginning of its branch does not have the branch symbol as its LOD} {
 		SELECT F.name, R.rev
 		FROM revision R, file F
-		WHERE R.fid = F.fid
-		AND   R.bparent IS NOT NULL
-		AND   R.lod != R.bparent
+		WHERE R.fid = F.fid         -- get file of revision
+		AND   R.bparent IS NOT NULL -- limit to branch-first revisions
+		AND   R.lod != R.bparent    -- out-of-branch parent wrongly is not the lod
 		;
 	    }
 	# Find all revisions with a branch parent symbol whose parent
 	# is in the same line of development.
@@ -273,12 +273,12 @@
 	    {Revisions and their branch children have to be in different LODs} \
 	    {at the beginning of its branch and its parent wrongly agree about their LOD} {
 		SELECT F.name, R.rev
 		FROM revision R, revision P, file F
-		WHERE R.fid = F.fid
-		AND   R.bparent IS NOT NULL
-		AND   R.parent = P.rid
-		AND   R.lod = P.lod
+		WHERE R.fid = F.fid          -- get file of revision
+		AND   R.bparent IS NOT NULL  -- limit to branch-first revisions
+		AND   R.parent = P.rid       -- get out-of-branch parent of revision
+		AND   R.lod = P.lod          -- rev and parent wrongly agree on lod
 		;
 	    }
 	return
     }
@@ -296,11 +296,11 @@
 	    {Revisions and their meta data have to be in the same LOD} \
 	    {disagrees with its meta data about owning LOD} {
 		SELECT F.name, R.rev
 		FROM revision R, meta M, file F
-		WHERE R.mid = M.mid
-		AND   R.lod != M.bid
-		AND   R.fid = F.fid
+		WHERE R.mid = M.mid   -- get meta data of revision
+		AND   R.lod != M.bid  -- rev wrongly disagrees with meta about lod
+		AND   R.fid = F.fid   -- get file of revision
 		;
 	    }
 	return
     }
@@ -349,16 +349,18 @@
                 -- associated file (name) for display.
 
 		SELECT F.name, R.rev
 		FROM revision R, file F,
-		     (SELECT CI.iid AS rid, count(CI.cid) AS count
+		     (SELECT CI.iid        AS rid,  -- revision item
+		             count(CI.cid) AS count -- number of csets using item
 		      FROM csitem CI, changeset C
-		      WHERE C.type = 0
-		      AND   C.cid = CI.cid
-		      GROUP BY CI.iid) AS U
-		WHERE U.count > 1
-		AND R.rid = U.rid
-		AND R.fid = F.fid
+		      WHERE C.type = 0            -- limit to revision csets
+		      AND   C.cid  = CI.cid       -- get item in changeset
+		      GROUP BY CI.iid             -- aggregate by item, count csets/item
+		     ) AS U
+		WHERE U.count > 1    -- limit to item with multiple users
+		AND   R.rid = U.rid  -- get revision of item
+		AND   R.fid = F.fid  -- get file of revision
 	    }
 	# All revisions have to refer to the same meta information as
 	# their changeset.
 	CheckRevCS \
@@ -387,14 +389,19 @@
 	    {: Its revisions disagree about the LOD they belong to} {
 		SELECT T.name, C.cid
 		FROM   changeset C, cstype T
 		WHERE  C.cid IN (SELECT U.cid
-				 FROM (SELECT DISTINCT CI.cid AS cid, R.lod AS lod
+				 FROM (SELECT DISTINCT       -- unique cset/lod pairs
+				              CI.cid AS cid, -- revision cset
+				              R.lod  AS lod  -- lod of item in cset
 				       FROM   csitem CI, changeset C, revision R
-				       WHERE  CI.iid = R.rid
-				       AND    C.cid = CI.cid
-				       AND    C.type = 0) AS U
-				 GROUP BY U.cid HAVING COUNT(U.lod) > 1)
+				       WHERE  CI.iid = R.rid  -- get rev of item in cset
+				       AND    C.cid  = CI.cid -- get changeset of item
+				       AND    C.type = 0      -- limit to rev csets
+				      ) AS U
+				 GROUP BY U.cid          -- aggregate by cset, count lods/cset
+				 HAVING COUNT(U.lod) > 1 -- find csets with multiple lods
+				)
 		AND    T.tid = C.type
 	    }
 	# All revisions have to agree on the project their changeset
 	# belongs to. In other words, all revisions in a changeset
@@ -410,16 +417,21 @@
 	    {: Its revisions disagree about the project they belong to} {
 		SELECT T.name, C.cid
 		FROM   changeset C, cstype T
 		WHERE  C.cid IN (SELECT U.cid
-				 FROM (SELECT DISTINCT CI.cid AS cid, F.pid AS pid
+				 FROM (SELECT DISTINCT       -- unique cset/proj pairs
+				              CI.cid AS cid, -- rev cset
+				              F.pid  AS pid  -- project of item in cset
 				       FROM   csitem CI, changeset C, revision R, file F
-				       WHERE  CI.iid = R.rid
-				       AND    C.cid = CI.cid
-				       AND    C.type = 0
-				       AND    F.fid  = R.fid) AS U
-				 GROUP BY U.cid HAVING COUNT(U.pid) > 1)
-		AND    T.tid = C.type
+				       WHERE  CI.iid = R.rid  -- get rev of item in cset
+				       AND    C.cid  = CI.cid -- get changeset of item
+				       AND    C.type = 0      -- limit to rev changesets
+				       AND    F.fid  = R.fid  -- get file of revision
+				      ) AS U
+				 GROUP BY U.cid          -- aggregate by csets, count proj/cset
+				 HAVING COUNT(U.pid) > 1 -- find csets with multiple projects
+				)
+		AND    T.tid = C.type -- get readable changeset type
 	    }
 	# All revisions in a single changeset have to belong to
 	# different files. Conversely: No two revisions of a single
 	# file are allowed to be in the same changeset.
@@ -435,24 +447,32 @@
 	    {: Its revisions share files} {
 		SELECT T.name, C.cid
 		FROM   changeset C, cstype T
 		WHERE  C.cid IN (SELECT VV.cid
-				 FROM (SELECT U.cid as cid, COUNT (U.fid) AS fcount
-				       FROM (SELECT DISTINCT CI.cid AS cid, R.fid AS fid
+				 FROM (SELECT U.cid         AS cid,   -- rev changeset
+				              COUNT (U.fid) AS fcount -- number of files by items
+				       FROM (SELECT DISTINCT       -- unique cset/file pairs
+					            CI.cid AS cid, -- rev changeset
+					            R.fid AS fid   -- file of item in changeset
 					     FROM   csitem CI, changeset C, revision R
-					     WHERE  CI.iid = R.rid
-					     AND    C.cid = CI.cid
-					     AND    C.type = 0
+					     WHERE  CI.iid = R.rid  -- get rev of item in changeset
+					     AND    C.cid  = CI.cid -- get changeset of item
+					     AND    C.type = 0      -- limit to rev csets
 					     ) AS U
-				       GROUP BY U.cid) AS UU,
-				      (SELECT V.cid AS cid, COUNT (V.iid) AS rcount
+				       GROUP BY U.cid -- aggregate by csets, count files/cset
+				      ) AS UU,
+				      (SELECT V.cid         AS cid,   -- rev changeset
+				              COUNT (V.iid) AS rcount -- number of items
 				       FROM   csitem V, changeset X
-				       WHERE  X.cid = V.cid
-				       AND    X.type = 0
-				       GROUP BY V.cid) AS VV
-				 WHERE VV.cid = UU.cid
-				 AND   UU.fcount < VV.rcount)
-		AND    T.tid = C.type
+				       WHERE  X.cid  = V.cid  -- get changeset of item
+				       AND    X.type = 0      -- limit to rev csets
+				       GROUP BY V.cid         -- aggregate by csets, count items/cset
+				      ) AS VV
+				 WHERE VV.cid = UU.cid        -- sync #items/cset with #files/cset
+				 AND   UU.fcount < VV.rcount  -- less files than items
+				                              -- => items belong to the same file.
+				)
+		AND    T.tid = C.type -- get readable changeset type
 	    }
 	return
     }
 
@@ -499,17 +519,19 @@
                 -- display.
 
 		SELECT P.name, S.name
 		FROM tag T, project P, symbol S,
-		     (SELECT CI.iid AS iid, count(CI.cid) AS count
+		     (SELECT CI.iid        AS iid,  -- item
+		             count(CI.cid) AS count -- number of csets using item
 		      FROM csitem CI, changeset C
-		      WHERE C.type = 1
-		      AND   C.cid = CI.cid
-		      GROUP BY CI.iid) AS U
-		WHERE U.count > 1
-		AND   T.tid = U.iid
-		AND   S.sid = T.sid               -- get symbol of tag
-		AND   P.pid = S.pid               -- get project of symbol
+		      WHERE C.type = 1       -- limit to tag csets
+		      AND   C.cid  = CI.cid  -- get items of cset
+		      GROUP BY CI.iid        -- aggregate by item, count csets/item
+		     ) AS U
+		WHERE U.count > 1            -- find tag item used multiple times
+		AND   T.tid = U.iid          -- get tag of item
+		AND   S.sid = T.sid          -- get symbol of tag
+		AND   P.pid = S.pid          -- get project of symbol
 	    }
 	if 0 {
 	    # This check is disabled for the moment. Apparently tags
 	    # can cross lines of development, at least if the involved
@@ -557,16 +579,21 @@
 	    {: Its tags disagree about the project they belong to} {
 		SELECT T.name, C.cid
 		FROM   changeset C, cstype T
 		WHERE  C.cid IN (SELECT U.cid
-				 FROM (SELECT DISTINCT CI.cid AS cid, F.pid AS pid
+				 FROM (SELECT DISTINCT       -- unique cset/proj pairs
+				              CI.cid AS cid, -- tag cset
+				              F.pid  AS pid  -- project of item in cset
 				       FROM   csitem CI, changeset C, tag T, file F
-				       WHERE  CI.iid = T.tid
-				       AND    C.cid = CI.cid
-				       AND    C.type = 1
-				       AND    F.fid  = T.fid) AS U
-				 GROUP BY U.cid HAVING COUNT(U.pid) > 1)
-		AND    T.tid = C.type
+				       WHERE  CI.iid = T.tid  -- get tag of item in cset
+				       AND    C.cid  = CI.cid -- get changeset of item
+				       AND    C.type = 1      -- limit to tag changesets
+				       AND    F.fid  = T.fid  -- get file of tag
+                                      ) AS U
+				 GROUP BY U.cid           -- aggregate by csets, count proj/cset
+				 HAVING COUNT(U.pid) > 1  -- find csets with multiple projects
+		                )
+		AND    T.tid = C.type -- get readable changeset type
 	    }
 	# All tags in a single changeset have to belong to different
 	# files. Conversely: No two tags of a single file are allowed
 	# to be in the same changeset.
@@ -581,24 +608,32 @@
 	    {: Its tags share files} {
 		SELECT T.name, C.cid
 		FROM   changeset C, cstype T
 		WHERE  C.cid IN (SELECT VV.cid
-				 FROM (SELECT U.cid as cid, COUNT (U.fid) AS fcount
-				       FROM (SELECT DISTINCT CI.cid AS cid, T.fid AS fid
+				 FROM (SELECT U.cid         AS cid,   -- changeset
+				              COUNT (U.fid) AS fcount -- number of files by items
+				       FROM (SELECT DISTINCT       -- unique cset/file pairs
+					            CI.cid AS cid, -- tag changeset
+					            T.fid  AS fid  -- file of item in changeset
 					     FROM   csitem CI, changeset C, tag T
-					     WHERE  CI.iid = T.tid
-					     AND    C.cid = CI.cid
-					     AND    C.type = 1
+					     WHERE  CI.iid = T.tid -- get tag of item in changeset
+					     AND    C.cid = CI.cid -- get changeset of item
+					     AND    C.type = 1     -- limit to tag changesets
 					     ) AS U
-				       GROUP BY U.cid) AS UU,
-				      (SELECT V.cid AS cid, COUNT (V.iid) AS rcount
+				       GROUP BY U.cid -- aggregate by csets, count files/cset
+                                      ) AS UU,
+				      (SELECT V.cid         AS cid,   -- changeset
+				              COUNT (V.iid) AS rcount -- number of items in cset
 				       FROM   csitem V, changeset X
-				       WHERE  X.cid = V.cid
-				       AND    X.type = 1
-				       GROUP BY V.cid) AS VV
-				 WHERE VV.cid = UU.cid
-				 AND   UU.fcount < VV.rcount)
-		AND    T.tid = C.type
+				       WHERE  X.cid  = V.cid -- get changeset of item
+				       AND    X.type = 1     -- limit to tag changesets
+				       GROUP BY V.cid        -- aggregate by csets, count items/cset
+                                      ) AS VV
+				 WHERE VV.cid = UU.cid       -- sync #items/cset with #files/cset
+				 AND   UU.fcount < VV.rcount -- less files than items
+				                             -- => items belong to the same file.
+				)
+		AND    T.tid = C.type -- get readable changeset type
 	    }
 	return
     }
 
@@ -629,9 +664,10 @@
 				EXCEPT                        -- subtract
 				SELECT CI.iid                 -- branches used
 				FROM   csitem CI, changeset C
 				WHERE  C.cid = CI.cid         -- by any branch
-				AND    C.type = 2)            -- changeset
+				AND    C.type = 2             -- changeset
+			       )
 		AND   S.sid = B.sid               -- get symbol of branch
 		AND   P.pid = S.pid               -- get project of symbol
 	    }
 	# Find all branches which are used by more than one changeset.
@@ -646,17 +682,19 @@
                 -- for display.
 
 		SELECT P.name, S.name
 		FROM branch B, project P, symbol S,
-		     (SELECT CI.iid AS iid, count(CI.cid) AS count
+		     (SELECT CI.iid        AS iid,  -- item
+                             count(CI.cid) AS count -- number of csets for item
 		      FROM csitem CI, changeset C
-		      WHERE C.type = 2
-		      AND   C.cid = CI.cid
-		      GROUP BY CI.iid ) AS U
-		WHERE U.count > 1
-		AND   B.bid = U.iid
-		AND   S.sid = B.sid               -- get symbol of branch
-		AND   P.pid = S.pid               -- get project of symbol
+		      WHERE C.type = 2        -- limit to branch changesets,
+		      AND   C.cid = CI.cid    -- get the items they contain,
+		      GROUP BY CI.iid         -- aggregate by items, count csets/item (x)
+                     ) AS U
+		WHERE U.count > 1             -- find items used multiple times
+		AND   B.bid = U.iid           -- get the users (branch changesets)
+		AND   S.sid = B.sid           -- get symbol of branch
+		AND   P.pid = S.pid           -- get project of symbol
 	    }
 	if 0 {
 	    # This check has been disabled. When the converter was run
 	    # on the Tcl CVS several branches tripped this
@@ -720,16 +758,21 @@
 	    {: Its branches disagree about the project they belong to} {
 		SELECT T.name, C.cid
 		FROM   changeset C, cstype T
 		WHERE  C.cid IN (SELECT U.cid
-				 FROM (SELECT DISTINCT CI.cid AS cid, F.pid AS pid
+				 FROM (SELECT DISTINCT        -- Unique cset/proj pairs
+				              CI.cid AS cid,  -- Branch cset
+				              F.pid  AS pid   -- Project of item in cset
 				       FROM   csitem CI, changeset C, branch B, file F
-				       WHERE  CI.iid = B.bid
-				       AND    C.cid = CI.cid
-				       AND    C.type = 2
-				       AND    F.fid  = B.fid) AS U
-				 GROUP BY U.cid HAVING COUNT(U.pid) > 1)
-		AND    T.tid = C.type
+				       WHERE  CI.iid = B.bid  -- get branch of item in cset
+				       AND    C.cid  = CI.cid -- get changeset of item
+				       AND    C.type = 2      -- limit to branch changesets
+				       AND    F.fid  = B.fid  -- get file of branch
+                                      ) AS U
+				 GROUP BY U.cid          -- aggregate by csets, count proj/cset
+				 HAVING COUNT(U.pid) > 1 -- find cset with multiple projects
+				)
+		AND    T.tid = C.type -- get readable changeset type
 	    }
 	# All branches in a single changeset have to belong to
 	# different files. Conversely: No two branches of a single
 	# file are allowed to be in the same changeset.
@@ -745,24 +788,32 @@
 	    {: Its branches share files} {
 		SELECT T.name, C.cid
 		FROM   changeset C, cstype T
 		WHERE  C.cid IN (SELECT VV.cid
-				 FROM (SELECT U.cid as cid, COUNT (U.fid) AS fcount
-				       FROM (SELECT DISTINCT CI.cid AS cid, B.fid AS fid
+				 FROM (SELECT U.cid         AS cid,   -- changeset
+				              COUNT (U.fid) AS fcount -- number of files by items
+				       FROM (SELECT DISTINCT       -- unique cset/file pairs
+					            CI.cid AS cid, -- Branch changeset
+					            B.fid  AS fid  -- File of item in changeset
 					     FROM   csitem CI, changeset C, branch B
-					     WHERE  CI.iid = B.bid
-					     AND    C.cid = CI.cid
-					     AND    C.type = 2
+					     WHERE  CI.iid = B.bid  -- get tag of item in changeset
+					     AND    C.cid  = CI.cid -- get changeset of item
+					     AND    C.type = 2      -- limit to branch changesets
 					     ) AS U
-				       GROUP BY U.cid) AS UU,
-				      (SELECT V.cid AS cid, COUNT (V.iid) AS rcount
+				       GROUP BY U.cid -- aggregate by csets, count files/cset
+				      ) AS UU,
+				      (SELECT V.cid         AS cid,   -- changeset
+				              COUNT (V.iid) AS rcount -- number of items in cset
 				       FROM   csitem V, changeset X
-				       WHERE  X.cid = V.cid
-				       AND    X.type = 2
-				       GROUP BY V.cid) AS VV
-				 WHERE VV.cid = UU.cid
-				 AND   UU.fcount < VV.rcount)
-		AND    T.tid = C.type
+				       WHERE  X.cid  = V.cid -- get changeset of item
+				       AND    X.type = 2     -- limit to branch changesets
+				       GROUP BY V.cid	     -- aggregate by csets, count items/cset
+				      ) AS VV
+				 WHERE VV.cid = UU.cid       -- sync #items/cset with #files/cset
+				 AND   UU.fcount < VV.rcount -- less files than items
+							     -- => items belong to the same file.
+				)
+		AND    T.tid = C.type -- get readable changeset type
 	    }
 	return
     }