1 # (Be in -*- python -*- mode.)
3 # ====================================================================
4 # Copyright (c) 2000-2008 CollabNet. All rights reserved.
6 # This software is licensed as described in the file COPYING, which
7 # you should have received as part of this distribution. The terms
8 # are also available at http://subversion.tigris.org/license-1.html.
9 # If newer versions of this license are posted there, you may use a
10 # newer version instead, at your option.
12 # This software consists of voluntary contributions made by many
13 # individuals. For exact contribution history, see the revision
14 # history and logs, available at http://cvs2svn.tigris.org/.
15 # ====================================================================
17 """This module defines some passes that can be used for debugging cv2svn."""
20 from cvs2svn_lib
import config
21 from cvs2svn_lib
.context
import Ctx
22 from cvs2svn_lib
.common
import FatalException
23 from cvs2svn_lib
.common
import DB_OPEN_READ
24 from cvs2svn_lib
.log
import logger
25 from cvs2svn_lib
.pass_manager
import Pass
26 from cvs2svn_lib
.project
import read_projects
27 from cvs2svn_lib
.artifact_manager
import artifact_manager
28 from cvs2svn_lib
.cvs_path_database
import CVSPathDatabase
29 from cvs2svn_lib
.symbol_database
import SymbolDatabase
30 from cvs2svn_lib
.cvs_item_database
import OldCVSItemStore
31 from cvs2svn_lib
.cvs_item_database
import IndexedCVSItemStore
34 class CheckDependenciesPass(Pass
):
35 """Check that the dependencies are self-consistent."""
40 def register_artifacts(self
):
41 self
._register
_temp
_file
_needed
(config
.PROJECTS
)
42 self
._register
_temp
_file
_needed
(config
.SYMBOL_DB
)
43 self
._register
_temp
_file
_needed
(config
.CVS_PATHS_DB
)
45 def iter_cvs_items(self
):
46 raise NotImplementedError()
48 def get_cvs_item(self
, item_id
):
49 raise NotImplementedError()
51 def run(self
, run_options
, stats_keeper
):
52 Ctx()._projects
= read_projects(
53 artifact_manager
.get_temp_file(config
.PROJECTS
)
55 Ctx()._cvs
_path
_db
= CVSPathDatabase(DB_OPEN_READ
)
56 self
.symbol_db
= SymbolDatabase()
57 Ctx()._symbol
_db
= self
.symbol_db
59 logger
.quiet("Checking dependency consistency...")
62 for cvs_item
in self
.iter_cvs_items():
63 # Check that the pred_ids and succ_ids are mutually consistent:
64 for pred_id
in cvs_item
.get_pred_ids():
65 pred
= self
.get_cvs_item(pred_id
)
66 if not cvs_item
.id in pred
.get_succ_ids():
68 '%s lists pred=%s, but not vice versa.' % (cvs_item
, pred
,))
70 for succ_id
in cvs_item
.get_succ_ids():
71 succ
= self
.get_cvs_item(succ_id
)
72 if not cvs_item
.id in succ
.get_pred_ids():
74 '%s lists succ=%s, but not vice versa.' % (cvs_item
, succ
,))
78 'Dependencies inconsistent:\n'
80 'Exited due to fatal error(s).'
81 % ('\n'.join(fatal_errors
),)
84 self
.symbol_db
.close()
86 Ctx()._cvs
_path
_db
.close()
90 class CheckItemStoreDependenciesPass(CheckDependenciesPass
):
91 def __init__(self
, cvs_items_store_file
):
92 CheckDependenciesPass
.__init
__(self
)
93 self
.cvs_items_store_file
= cvs_items_store_file
95 def register_artifacts(self
):
96 CheckDependenciesPass
.register_artifacts(self
)
97 self
._register
_temp
_file
_needed
(self
.cvs_items_store_file
)
99 def iter_cvs_items(self
):
100 cvs_item_store
= OldCVSItemStore(
101 artifact_manager
.get_temp_file(self
.cvs_items_store_file
))
103 for cvs_file_items
in cvs_item_store
.iter_cvs_file_items():
104 self
.current_cvs_file_items
= cvs_file_items
105 for cvs_item
in cvs_file_items
.values():
108 del self
.current_cvs_file_items
110 cvs_item_store
.close()
112 def get_cvs_item(self
, item_id
):
113 return self
.current_cvs_file_items
[item_id
]
116 class CheckIndexedItemStoreDependenciesPass(CheckDependenciesPass
):
117 def __init__(self
, cvs_items_store_file
, cvs_items_store_index_file
):
118 CheckDependenciesPass
.__init
__(self
)
119 self
.cvs_items_store_file
= cvs_items_store_file
120 self
.cvs_items_store_index_file
= cvs_items_store_index_file
122 def register_artifacts(self
):
123 CheckDependenciesPass
.register_artifacts(self
)
124 self
._register
_temp
_file
_needed
(self
.cvs_items_store_file
)
125 self
._register
_temp
_file
_needed
(self
.cvs_items_store_index_file
)
127 def iter_cvs_items(self
):
128 return self
.cvs_item_store
.itervalues()
130 def get_cvs_item(self
, item_id
):
131 return self
.cvs_item_store
[item_id
]
133 def run(self
, run_options
, stats_keeper
):
134 self
.cvs_item_store
= IndexedCVSItemStore(
135 artifact_manager
.get_temp_file(self
.cvs_items_store_file
),
136 artifact_manager
.get_temp_file(self
.cvs_items_store_index_file
),
139 CheckDependenciesPass
.run(self
, run_options
, stats_keeper
)
141 self
.cvs_item_store
.close()
142 self
.cvs_item_store
= None