Make CVSFileItems._sever_branch() a NOOP if the branch is already severed.
[cvs2svn.git] / cvs2svn_lib / collect_data.py
blob160d7b9042a2ed088e0fe69d056603dc1023c043
1 # (Be in -*- python -*- mode.)
3 # ====================================================================
4 # Copyright (c) 2000-2009 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 """Data collection classes.
19 This module contains the code used to collect data from the CVS
20 repository. It parses *,v files, recording all useful information
21 except for the actual file contents (though even the file contents
22 might be recorded by the RevisionRecorder if one is configured).
24 As a *,v file is parsed, the information pertaining to the file is
25 accumulated in memory, mostly in _RevisionData, _BranchData, and
26 _TagData objects. When parsing is complete, a final pass is made over
27 the data to create some final dependency links, collect statistics,
28 etc., then the _*Data objects are converted into CVSItem objects
29 (CVSRevision, CVSBranch, and CVSTag respectively) and the CVSItems are
30 dumped into databases.
32 During the data collection, persistent unique ids are allocated to
33 many types of objects: CVSFile, Symbol, and CVSItems. CVSItems are a
34 special case. CVSItem ids are unique across all CVSItem types, and
35 the ids are carried over from the corresponding data collection
36 objects:
38 _RevisionData -> CVSRevision
40 _BranchData -> CVSBranch
42 _TagData -> CVSTag
44 In a later pass it is possible to convert tags <-> branches. But even
45 if this occurs, the new branch or tag uses the same id as the old tag
46 or branch.
48 """
51 import os
52 import stat
53 import re
55 from cvs2svn_lib import config
56 from cvs2svn_lib.common import DB_OPEN_NEW
57 from cvs2svn_lib.common import FatalError
58 from cvs2svn_lib.common import warning_prefix
59 from cvs2svn_lib.common import error_prefix
60 from cvs2svn_lib.common import IllegalSVNPathError
61 from cvs2svn_lib.common import verify_svn_filename_legal
62 from cvs2svn_lib.log import Log
63 from cvs2svn_lib.context import Ctx
64 from cvs2svn_lib.artifact_manager import artifact_manager
65 from cvs2svn_lib.project import FileInAndOutOfAtticException
66 from cvs2svn_lib.cvs_file import CVSPath
67 from cvs2svn_lib.cvs_file import CVSDirectory
68 from cvs2svn_lib.cvs_file import CVSFile
69 from cvs2svn_lib.symbol import Symbol
70 from cvs2svn_lib.symbol import Trunk
71 from cvs2svn_lib.cvs_item import CVSRevision
72 from cvs2svn_lib.cvs_item import CVSBranch
73 from cvs2svn_lib.cvs_item import CVSTag
74 from cvs2svn_lib.cvs_item import cvs_revision_type_map
75 from cvs2svn_lib.cvs_file_items import VendorBranchError
76 from cvs2svn_lib.cvs_file_items import CVSFileItems
77 from cvs2svn_lib.key_generator import KeyGenerator
78 from cvs2svn_lib.cvs_item_database import NewCVSItemStore
79 from cvs2svn_lib.symbol_statistics import SymbolStatisticsCollector
80 from cvs2svn_lib.metadata_database import MetadataDatabase
81 from cvs2svn_lib.metadata_database import MetadataLogger
83 import cvs2svn_rcsparse
86 # A regular expression defining "valid" revision numbers (used to
87 # check that symbol definitions are reasonable).
88 _valid_revision_re = re.compile(r'''
90 (?:\d+\.)+ # Digit groups with trailing dots
91 \d+ # And the last digit group.
93 ''', re.VERBOSE)
95 _branch_revision_re = re.compile(r'''
97 ((?:\d+\.\d+\.)+) # A nonzero even number of digit groups w/trailing dot
98 (?:0\.)? # CVS sticks an extra 0 here; RCS does not
99 (\d+) # And the last digit group
101 ''', re.VERBOSE)
104 def rev_tuple(rev):
105 """Return a tuple of integers corresponding to revision number REV.
107 For example, if REV is '1.2.3.4', then return (1,2,3,4)."""
109 return tuple([int(x) for x in rev.split('.')])
112 def is_trunk_revision(rev):
113 """Return True iff REV is a trunk revision.
115 REV is a revision number corresponding to a specific revision (i.e.,
116 not a whole branch)."""
118 return rev.count('.') == 1
121 def is_branch_revision_number(rev):
122 """Return True iff REV is a branch revision number.
124 REV is a CVS revision number in canonical form (i.e., with zeros
125 removed). Return True iff it refers to a whole branch, as opposed
126 to a single revision."""
128 return rev.count('.') % 2 == 0
131 def is_same_line_of_development(rev1, rev2):
132 """Return True if rev1 and rev2 are on the same line of
133 development (i.e., both on trunk, or both on the same branch);
134 return False otherwise. Either rev1 or rev2 can be None, in
135 which case automatically return False."""
137 if rev1 is None or rev2 is None:
138 return False
139 if rev1.count('.') == 1 and rev2.count('.') == 1:
140 return True
141 if rev1[0:rev1.rfind('.')] == rev2[0:rev2.rfind('.')]:
142 return True
143 return False
146 class _RevisionData:
147 """We track the state of each revision so that in set_revision_info,
148 we can determine if our op is an add/change/delete. We can do this
149 because in set_revision_info, we'll have all of the _RevisionData
150 for a file at our fingertips, and we need to examine the state of
151 our prev_rev to determine if we're an add or a change. Without the
152 state of the prev_rev, we are unable to distinguish between an add
153 and a change."""
155 def __init__(self, cvs_rev_id, rev, timestamp, author, state):
156 # The id of this revision:
157 self.cvs_rev_id = cvs_rev_id
158 self.rev = rev
159 self.timestamp = timestamp
160 self.author = author
161 self.original_timestamp = timestamp
162 self.state = state
164 # If this is the first revision on a branch, then this is the
165 # branch_data of that branch; otherwise it is None.
166 self.parent_branch_data = None
168 # The revision number of the parent of this revision along the
169 # same line of development, if any. For the first revision R on a
170 # branch, we consider the revision from which R sprouted to be the
171 # 'parent'. If this is the root revision in the file's revision
172 # tree, then this field is None.
174 # Note that this revision can't be determined arithmetically (due
175 # to cvsadmin -o), which is why this field is necessary.
176 self.parent = None
178 # The revision number of the primary child of this revision (the
179 # child along the same line of development), if any; otherwise,
180 # None.
181 self.child = None
183 # The _BranchData instances of branches that sprout from this
184 # revision, sorted in ascending order by branch number. It would
185 # be inconvenient to initialize it here because we would have to
186 # scan through all branches known by the _SymbolDataCollector to
187 # find the ones having us as the parent. Instead, this
188 # information is filled in by
189 # _FileDataCollector._resolve_dependencies() and sorted by
190 # _FileDataCollector._sort_branches().
191 self.branches_data = []
193 # The revision numbers of the first commits on any branches on
194 # which commits occurred. This dependency is kept explicitly
195 # because otherwise a revision-only topological sort would miss
196 # the dependency that exists via branches_data.
197 self.branches_revs_data = []
199 # The _TagData instances of tags that are connected to this
200 # revision.
201 self.tags_data = []
203 # A token that may be returned from
204 # RevisionRecorder.record_text(). It can be used by
205 # RevisionReader to obtain the text again.
206 self.revision_recorder_token = None
208 def get_first_on_branch_id(self):
209 return self.parent_branch_data and self.parent_branch_data.id
212 class _SymbolData:
213 """Collection area for information about a symbol in a single CVSFile.
215 SYMBOL is an instance of Symbol, undifferentiated as a Branch or a
216 Tag regardless of whether self is a _BranchData or a _TagData."""
218 def __init__(self, id, symbol):
219 """Initialize an object for SYMBOL."""
221 # The unique id that will be used for this particular symbol in
222 # this particular file. This same id will be used for the CVSItem
223 # that is derived from this instance.
224 self.id = id
226 # An instance of Symbol.
227 self.symbol = symbol
230 class _BranchData(_SymbolData):
231 """Collection area for information about a Branch in a single CVSFile."""
233 def __init__(self, id, symbol, branch_number):
234 _SymbolData.__init__(self, id, symbol)
236 # The branch number (e.g., '1.5.2') of this branch.
237 self.branch_number = branch_number
239 # The revision number of the revision from which this branch
240 # sprouts (e.g., '1.5').
241 self.parent = self.branch_number[:self.branch_number.rindex(".")]
243 # The revision number of the first commit on this branch, if any
244 # (e.g., '1.5.2.1'); otherwise, None.
245 self.child = None
248 class _TagData(_SymbolData):
249 """Collection area for information about a Tag in a single CVSFile."""
251 def __init__(self, id, symbol, rev):
252 _SymbolData.__init__(self, id, symbol)
254 # The revision number being tagged (e.g., '1.5.2.3').
255 self.rev = rev
258 class _SymbolDataCollector(object):
259 """Collect information about symbols in a single CVSFile."""
261 def __init__(self, fdc, cvs_file):
262 self.fdc = fdc
263 self.cvs_file = cvs_file
265 self.pdc = self.fdc.pdc
266 self.collect_data = self.fdc.collect_data
268 # A list [(name, revision), ...] of symbols defined in the header
269 # of the file. The name has already been transformed using the
270 # symbol transform rules. If the symbol transform rules indicate
271 # that the symbol should be ignored, then it is never added to
272 # this list. This list is processed then deleted in
273 # process_symbols().
274 self._symbol_defs = []
276 # A set containing the transformed names of symbols in this file
277 # (used to detect duplicats during processing of unlabeled
278 # branches):
279 self._defined_symbols = set()
281 # Map { branch_number : _BranchData }, where branch_number has an
282 # odd number of digits.
283 self.branches_data = { }
285 # Map { revision : [ tag_data ] }, where revision has an even
286 # number of digits, and the value is a list of _TagData objects
287 # for tags that apply to that revision.
288 self.tags_data = { }
290 def _add_branch(self, name, branch_number):
291 """Record that BRANCH_NUMBER is the branch number for branch NAME,
292 and derive and record the revision from which NAME sprouts.
293 BRANCH_NUMBER is an RCS branch number with an odd number of
294 components, for example '1.7.2' (never '1.7.0.2'). Return the
295 _BranchData instance (which is usually newly-created)."""
297 branch_data = self.branches_data.get(branch_number)
299 if branch_data is not None:
300 Log().warn(
301 "%s: in '%s':\n"
302 " branch '%s' already has name '%s',\n"
303 " cannot also have name '%s', ignoring the latter\n"
304 % (warning_prefix,
305 self.cvs_file.filename, branch_number,
306 branch_data.symbol.name, name)
308 return branch_data
310 symbol = self.pdc.get_symbol(name)
311 branch_data = _BranchData(
312 self.collect_data.item_key_generator.gen_id(), symbol, branch_number
314 self.branches_data[branch_number] = branch_data
315 return branch_data
317 def _construct_distinct_name(self, name, original_name):
318 """Construct a distinct symbol name from NAME.
320 If NAME is distinct, return it. If it is already used in this
321 file (as determined from its presence in self._defined_symbols),
322 construct and return a new name that is not already used."""
324 if name not in self._defined_symbols:
325 return name
326 else:
327 index = 1
328 while True:
329 dup_name = '%s-DUPLICATE-%d' % (name, index,)
330 if dup_name not in self._defined_symbols:
331 self.collect_data.record_fatal_error(
332 "Symbol name '%s' is already used in '%s'.\n"
333 "The unlabeled branch '%s' must be renamed using "
334 "--symbol-transform."
335 % (name, self.cvs_file.filename, original_name,)
337 return dup_name
339 def _add_unlabeled_branch(self, branch_number):
340 original_name = "unlabeled-" + branch_number
341 name = self.transform_symbol(original_name, branch_number)
342 if name is None:
343 self.collect_data.record_fatal_error(
344 "The unlabeled branch '%s' in '%s' contains commits.\n"
345 "It may not be ignored via a symbol transform. (Use --exclude "
346 "instead.)"
347 % (original_name, self.cvs_file.filename,)
349 # Retain the original name to allow the conversion to continue:
350 name = original_name
352 distinct_name = self._construct_distinct_name(name, original_name)
353 self._defined_symbols.add(distinct_name)
354 return self._add_branch(distinct_name, branch_number)
356 def _add_tag(self, name, revision):
357 """Record that tag NAME refers to the specified REVISION."""
359 symbol = self.pdc.get_symbol(name)
360 tag_data = _TagData(
361 self.collect_data.item_key_generator.gen_id(), symbol, revision
363 self.tags_data.setdefault(revision, []).append(tag_data)
364 return tag_data
366 def transform_symbol(self, name, revision):
367 """Transform a symbol according to the project's symbol transforms.
369 Transform the symbol with the original name NAME and canonicalized
370 revision number REVISION. Return the new symbol name or None if
371 the symbol should be ignored entirely.
373 Log the results of the symbol transform if necessary."""
375 old_name = name
376 # Apply any user-defined symbol transforms to the symbol name:
377 name = self.cvs_file.project.transform_symbol(
378 self.cvs_file, name, revision
381 if name is None:
382 # Ignore symbol:
383 self.pdc.log_symbol_transform(old_name, None)
384 Log().verbose(
385 " symbol '%s'=%s ignored in %s"
386 % (old_name, revision, self.cvs_file.filename,)
388 else:
389 if name != old_name:
390 self.pdc.log_symbol_transform(old_name, name)
391 Log().verbose(
392 " symbol '%s'=%s transformed to '%s' in %s"
393 % (old_name, revision, name, self.cvs_file.filename,)
396 return name
398 def define_symbol(self, name, revision):
399 """Record a symbol definition for later processing."""
401 # Canonicalize the revision number:
402 revision = _branch_revision_re.sub(r'\1\2', revision)
404 # Apply any user-defined symbol transforms to the symbol name:
405 name = self.transform_symbol(name, revision)
407 if name is not None:
408 # Verify that the revision number is valid:
409 if _valid_revision_re.match(revision):
410 # The revision number is valid; record it for later processing:
411 self._symbol_defs.append( (name, revision) )
412 else:
413 Log().warn(
414 'In %r:\n'
415 ' branch %r references invalid revision %s\n'
416 ' and will be ignored.'
417 % (self.cvs_file.filename, name, revision,)
420 def _eliminate_trivial_duplicate_defs(self, symbol_defs):
421 """Iterate through SYMBOL_DEFS, Removing identical duplicate definitions.
423 Duplicate definitions of symbol names have been seen in the wild,
424 and they can also happen when --symbol-transform is used. If a
425 symbol is defined to the same revision number repeatedly, then
426 ignore all but the last definition."""
428 # Make a copy, since we have to iterate through the definitions
429 # twice:
430 symbol_defs = list(symbol_defs)
432 # A map { (name, revision) : [index,...] } of the indexes where
433 # symbol definitions name=revision were found:
434 known_definitions = {}
435 for (i, symbol_def) in enumerate(symbol_defs):
436 known_definitions.setdefault(symbol_def, []).append(i)
438 # A set of the indexes of entries that have to be removed from
439 # symbol_defs:
440 dup_indexes = set()
441 for ((name, revision), indexes) in known_definitions.iteritems():
442 if len(indexes) > 1:
443 Log().verbose(
444 "in %r:\n"
445 " symbol %s:%s defined multiple times; ignoring duplicates\n"
446 % (self.cvs_file.filename, name, revision,)
448 dup_indexes.update(indexes[:-1])
450 for (i, symbol_def) in enumerate(symbol_defs):
451 if i not in dup_indexes:
452 yield symbol_def
454 def _process_duplicate_defs(self, symbol_defs):
455 """Iterate through SYMBOL_DEFS, processing duplicate names.
457 Duplicate definitions of symbol names have been seen in the wild,
458 and they can also happen when --symbol-transform is used. If a
459 symbol is defined multiple times, then it is a fatal error. This
460 method should be called after _eliminate_trivial_duplicate_defs()."""
462 # Make a copy, since we have to access multiple times:
463 symbol_defs = list(symbol_defs)
465 # A map {name : [index,...]} mapping the names of symbols to a
466 # list of their definitions' indexes in symbol_defs:
467 known_symbols = {}
468 for (i, (name, revision)) in enumerate(symbol_defs):
469 known_symbols.setdefault(name, []).append(i)
471 known_symbols = known_symbols.items()
472 known_symbols.sort()
473 dup_indexes = set()
474 for (name, indexes) in known_symbols:
475 if len(indexes) > 1:
476 # This symbol was defined multiple times.
477 self.collect_data.record_fatal_error(
478 "Multiple definitions of the symbol '%s' in '%s': %s" % (
479 name, self.cvs_file.filename,
480 ' '.join([symbol_defs[i][1] for i in indexes]),
483 # Ignore all but the last definition for now, to allow the
484 # conversion to proceed:
485 dup_indexes.update(indexes[:-1])
487 for (i, symbol_def) in enumerate(symbol_defs):
488 if i not in dup_indexes:
489 yield symbol_def
491 def _process_symbol(self, name, revision):
492 """Process a symbol called NAME, which is associated with REVISON.
494 REVISION is a canonical revision number with zeros removed, for
495 example: '1.7', '1.7.2', or '1.1.1' or '1.1.1.1'. NAME is a
496 transformed branch or tag name."""
498 # Add symbol to our records:
499 if is_branch_revision_number(revision):
500 self._add_branch(name, revision)
501 else:
502 self._add_tag(name, revision)
504 def process_symbols(self):
505 """Process the symbol definitions from SELF._symbol_defs."""
507 symbol_defs = self._symbol_defs
508 del self._symbol_defs
510 symbol_defs = self._eliminate_trivial_duplicate_defs(symbol_defs)
511 symbol_defs = self._process_duplicate_defs(symbol_defs)
513 for (name, revision) in symbol_defs:
514 self._defined_symbols.add(name)
515 self._process_symbol(name, revision)
517 @staticmethod
518 def rev_to_branch_number(revision):
519 """Return the branch_number of the branch on which REVISION lies.
521 REVISION is a branch revision number with an even number of
522 components; for example '1.7.2.1' (never '1.7.2' nor '1.7.0.2').
523 The return value is the branch number (for example, '1.7.2').
524 Return none iff REVISION is a trunk revision such as '1.2'."""
526 if is_trunk_revision(revision):
527 return None
528 return revision[:revision.rindex(".")]
530 def rev_to_branch_data(self, revision):
531 """Return the branch_data of the branch on which REVISION lies.
533 REVISION must be a branch revision number with an even number of
534 components; for example '1.7.2.1' (never '1.7.2' nor '1.7.0.2').
535 Raise KeyError iff REVISION is unknown."""
537 assert not is_trunk_revision(revision)
539 return self.branches_data[self.rev_to_branch_number(revision)]
541 def rev_to_lod(self, revision):
542 """Return the line of development on which REVISION lies.
544 REVISION must be a revision number with an even number of
545 components. Raise KeyError iff REVISION is unknown."""
547 if is_trunk_revision(revision):
548 return self.pdc.trunk
549 else:
550 return self.rev_to_branch_data(revision).symbol
553 class _FileDataCollector(cvs2svn_rcsparse.Sink):
554 """Class responsible for collecting RCS data for a particular file.
556 Any collected data that need to be remembered are stored into the
557 referenced CollectData instance."""
559 def __init__(self, pdc, cvs_file):
560 """Create an object that is prepared to receive data for CVS_FILE.
561 CVS_FILE is a CVSFile instance. COLLECT_DATA is used to store the
562 information collected about the file."""
564 self.pdc = pdc
565 self.cvs_file = cvs_file
567 self.collect_data = self.pdc.collect_data
568 self.project = self.cvs_file.project
570 # A place to store information about the symbols in this file:
571 self.sdc = _SymbolDataCollector(self, self.cvs_file)
573 # { revision : _RevisionData instance }
574 self._rev_data = { }
576 # Lists [ (parent, child) ] of revision number pairs indicating
577 # that revision child depends on revision parent along the main
578 # line of development.
579 self._primary_dependencies = []
581 # If set, this is an RCS branch number -- rcsparse calls this the
582 # "principal branch", but CVS and RCS refer to it as the "default
583 # branch", so that's what we call it, even though the rcsparse API
584 # setter method is still 'set_principal_branch'.
585 self.default_branch = None
587 # True iff revision 1.1 of the file appears to have been imported
588 # (as opposed to added normally).
589 self._file_imported = False
591 def _get_rev_id(self, revision):
592 if revision is None:
593 return None
594 return self._rev_data[revision].cvs_rev_id
596 def set_principal_branch(self, branch):
597 """This is a callback method declared in Sink."""
599 if branch.find('.') == -1:
600 # This just sets the default branch to trunk. Normally this
601 # shouldn't occur, but it has been seen in at least one CVS
602 # repository. Just ignore it.
603 pass
604 else:
605 self.default_branch = branch
607 def set_expansion(self, mode):
608 """This is a callback method declared in Sink."""
610 self.cvs_file.mode = mode
612 def define_tag(self, name, revision):
613 """Remember the symbol name and revision, but don't process them yet.
615 This is a callback method declared in Sink."""
617 self.sdc.define_symbol(name, revision)
619 def admin_completed(self):
620 """This is a callback method declared in Sink."""
622 self.sdc.process_symbols()
624 def define_revision(self, revision, timestamp, author, state,
625 branches, next):
626 """This is a callback method declared in Sink."""
628 for branch in branches:
629 try:
630 branch_data = self.sdc.rev_to_branch_data(branch)
631 except KeyError:
632 # Normally we learn about the branches from the branch names
633 # and numbers parsed from the symbolic name header. But this
634 # must have been an unlabeled branch that slipped through the
635 # net. Generate a name for it and create a _BranchData record
636 # for it now.
637 branch_data = self.sdc._add_unlabeled_branch(
638 self.sdc.rev_to_branch_number(branch))
640 assert branch_data.child is None
641 branch_data.child = branch
643 if revision in self._rev_data:
644 # This revision has already been seen.
645 Log().error('File %r contains duplicate definitions of revision %s.'
646 % (self.cvs_file.filename, revision,))
647 raise RuntimeError
649 # Record basic information about the revision:
650 rev_data = _RevisionData(
651 self.collect_data.item_key_generator.gen_id(),
652 revision, int(timestamp), author, state)
653 self._rev_data[revision] = rev_data
655 # When on trunk, the RCS 'next' revision number points to what
656 # humans might consider to be the 'previous' revision number. For
657 # example, 1.3's RCS 'next' is 1.2.
659 # However, on a branch, the RCS 'next' revision number really does
660 # point to what humans would consider to be the 'next' revision
661 # number. For example, 1.1.2.1's RCS 'next' would be 1.1.2.2.
663 # In other words, in RCS, 'next' always means "where to find the next
664 # deltatext that you need this revision to retrieve.
666 # That said, we don't *want* RCS's behavior here, so we determine
667 # whether we're on trunk or a branch and set the dependencies
668 # accordingly.
669 if next:
670 if is_trunk_revision(revision):
671 self._primary_dependencies.append( (next, revision,) )
672 else:
673 self._primary_dependencies.append( (revision, next,) )
675 def _resolve_primary_dependencies(self):
676 """Resolve the dependencies listed in self._primary_dependencies."""
678 for (parent, child,) in self._primary_dependencies:
679 parent_data = self._rev_data[parent]
680 assert parent_data.child is None
681 parent_data.child = child
683 child_data = self._rev_data[child]
684 assert child_data.parent is None
685 child_data.parent = parent
687 def _resolve_branch_dependencies(self):
688 """Resolve dependencies involving branches."""
690 for branch_data in self.sdc.branches_data.values():
691 # The branch_data's parent has the branch as a child regardless
692 # of whether the branch had any subsequent commits:
693 try:
694 parent_data = self._rev_data[branch_data.parent]
695 except KeyError:
696 Log().warn(
697 'In %r:\n'
698 ' branch %r references non-existing revision %s\n'
699 ' and will be ignored.'
700 % (self.cvs_file.filename, branch_data.symbol.name,
701 branch_data.parent,))
702 del self.sdc.branches_data[branch_data.branch_number]
703 else:
704 parent_data.branches_data.append(branch_data)
706 # If the branch has a child (i.e., something was committed on
707 # the branch), then we store a reference to the branch_data
708 # there, define the child's parent to be the branch's parent,
709 # and list the child in the branch parent's branches_revs_data:
710 if branch_data.child is not None:
711 child_data = self._rev_data[branch_data.child]
712 assert child_data.parent_branch_data is None
713 child_data.parent_branch_data = branch_data
714 assert child_data.parent is None
715 child_data.parent = branch_data.parent
716 parent_data.branches_revs_data.append(branch_data.child)
718 def _sort_branches(self):
719 """Sort the branches sprouting from each revision in creation order.
721 Creation order is taken to be the reverse of the order that they
722 are listed in the symbols part of the RCS file. (If a branch is
723 created then deleted, a later branch can be assigned the recycled
724 branch number; therefore branch numbers are not an indication of
725 creation order.)"""
727 for rev_data in self._rev_data.values():
728 rev_data.branches_data.sort(lambda a, b: - cmp(a.id, b.id))
730 def _resolve_tag_dependencies(self):
731 """Resolve dependencies involving tags."""
733 for (rev, tag_data_list) in self.sdc.tags_data.items():
734 try:
735 parent_data = self._rev_data[rev]
736 except KeyError:
737 Log().warn(
738 'In %r:\n'
739 ' the following tag(s) reference non-existing revision %s\n'
740 ' and will be ignored:\n'
741 ' %s' % (
742 self.cvs_file.filename, rev,
743 ', '.join([repr(tag_data.symbol.name)
744 for tag_data in tag_data_list]),))
745 del self.sdc.tags_data[rev]
746 else:
747 for tag_data in tag_data_list:
748 assert tag_data.rev == rev
749 # The tag_data's rev has the tag as a child:
750 parent_data.tags_data.append(tag_data)
752 def _determine_operation(self, rev_data):
753 prev_rev_data = self._rev_data.get(rev_data.parent)
754 return cvs_revision_type_map[(
755 rev_data.state != 'dead',
756 prev_rev_data is not None and prev_rev_data.state != 'dead',
759 def _get_cvs_revision(self, rev_data):
760 """Create and return a CVSRevision for REV_DATA."""
762 branch_ids = [
763 branch_data.id
764 for branch_data in rev_data.branches_data
767 branch_commit_ids = [
768 self._get_rev_id(rev)
769 for rev in rev_data.branches_revs_data
772 tag_ids = [
773 tag_data.id
774 for tag_data in rev_data.tags_data
777 revision_type = self._determine_operation(rev_data)
779 return revision_type(
780 self._get_rev_id(rev_data.rev), self.cvs_file,
781 rev_data.timestamp, None,
782 self._get_rev_id(rev_data.parent),
783 self._get_rev_id(rev_data.child),
784 rev_data.rev,
785 True,
786 self.sdc.rev_to_lod(rev_data.rev),
787 rev_data.get_first_on_branch_id(),
788 False, None, None,
789 tag_ids, branch_ids, branch_commit_ids,
790 rev_data.revision_recorder_token)
792 def _get_cvs_revisions(self):
793 """Generate the CVSRevisions present in this file."""
795 for rev_data in self._rev_data.itervalues():
796 yield self._get_cvs_revision(rev_data)
798 def _get_cvs_branches(self):
799 """Generate the CVSBranches present in this file."""
801 for branch_data in self.sdc.branches_data.values():
802 yield CVSBranch(
803 branch_data.id, self.cvs_file, branch_data.symbol,
804 branch_data.branch_number,
805 self.sdc.rev_to_lod(branch_data.parent),
806 self._get_rev_id(branch_data.parent),
807 self._get_rev_id(branch_data.child),
808 None,
811 def _get_cvs_tags(self):
812 """Generate the CVSTags present in this file."""
814 for tags_data in self.sdc.tags_data.values():
815 for tag_data in tags_data:
816 yield CVSTag(
817 tag_data.id, self.cvs_file, tag_data.symbol,
818 self.sdc.rev_to_lod(tag_data.rev),
819 self._get_rev_id(tag_data.rev),
820 None,
823 def tree_completed(self):
824 """The revision tree has been parsed.
826 Analyze it for consistency and connect some loose ends.
828 This is a callback method declared in Sink."""
830 self._resolve_primary_dependencies()
831 self._resolve_branch_dependencies()
832 self._sort_branches()
833 self._resolve_tag_dependencies()
835 # Compute the preliminary CVSFileItems for this file:
836 cvs_items = []
837 cvs_items.extend(self._get_cvs_revisions())
838 cvs_items.extend(self._get_cvs_branches())
839 cvs_items.extend(self._get_cvs_tags())
840 self._cvs_file_items = CVSFileItems(
841 self.cvs_file, self.pdc.trunk, cvs_items
844 self._cvs_file_items.check_link_consistency()
846 # Tell the revision recorder about the file dependency tree.
847 self.collect_data.revision_recorder.start_file(self._cvs_file_items)
849 def set_revision_info(self, revision, log, text):
850 """This is a callback method declared in Sink."""
852 rev_data = self._rev_data[revision]
853 cvs_rev = self._cvs_file_items[rev_data.cvs_rev_id]
855 if cvs_rev.metadata_id is not None:
856 # Users have reported problems with repositories in which the
857 # deltatext block for revision 1.1 appears twice. It is not
858 # known whether this results from a CVS/RCS bug, or from botched
859 # hand-editing of the repository. In any case, empirically, cvs
860 # and rcs both use the first version when checking out data, so
861 # that's what we will do. (For the record: "cvs log" fails on
862 # such a file; "rlog" prints the log message from the first
863 # block and ignores the second one.)
864 Log().warn(
865 "%s: in '%s':\n"
866 " Deltatext block for revision %s appeared twice;\n"
867 " ignoring the second occurrence.\n"
868 % (warning_prefix, self.cvs_file.filename, revision,)
870 return
872 if is_trunk_revision(revision):
873 branch_name = None
874 else:
875 branch_name = self.sdc.rev_to_branch_data(revision).symbol.name
877 cvs_rev.metadata_id = self.collect_data.metadata_logger.store(
878 self.project, branch_name, rev_data.author, log
880 cvs_rev.deltatext_exists = bool(text)
882 # If this is revision 1.1, determine whether the file appears to
883 # have been created via 'cvs add' instead of 'cvs import'. The
884 # test is that the log message CVS uses for 1.1 in imports is
885 # "Initial revision\n" with no period. (This fact helps determine
886 # whether this file might have had a default branch in the past.)
887 if revision == '1.1':
888 self._file_imported = (log == 'Initial revision\n')
890 cvs_rev.revision_recorder_token = \
891 self.collect_data.revision_recorder.record_text(cvs_rev, log, text)
893 def parse_completed(self):
894 """Finish the processing of this file.
896 This is a callback method declared in Sink."""
898 # Make sure that there was an info section for each revision:
899 for cvs_item in self._cvs_file_items.values():
900 if isinstance(cvs_item, CVSRevision) and cvs_item.metadata_id is None:
901 self.collect_data.record_fatal_error(
902 '%r has no deltatext section for revision %s'
903 % (self.cvs_file.filename, cvs_item.rev,)
906 def _process_ntdbrs(self):
907 """Fix up any non-trunk default branch revisions (if present).
909 If a non-trunk default branch is determined to have existed, yield
910 the _RevisionData.ids for all revisions that were once non-trunk
911 default revisions, in dependency order.
913 There are two cases to handle:
915 One case is simple. The RCS file lists a default branch
916 explicitly in its header, such as '1.1.1'. In this case, we know
917 that every revision on the vendor branch is to be treated as head
918 of trunk at that point in time.
920 But there's also a degenerate case. The RCS file does not
921 currently have a default branch, yet we can deduce that for some
922 period in the past it probably *did* have one. For example, the
923 file has vendor revisions 1.1.1.1 -> 1.1.1.96, all of which are
924 dated before 1.2, and then it has 1.1.1.97 -> 1.1.1.100 dated
925 after 1.2. In this case, we should record 1.1.1.96 as the last
926 vendor revision to have been the head of the default branch.
928 If any non-trunk default branch revisions are found:
930 - Set their ntdbr members to True.
932 - Connect the last one with revision 1.2.
934 - Remove revision 1.1 if it is not needed.
938 try:
939 if self.default_branch:
940 vendor_cvs_branch_id = self.sdc.branches_data[self.default_branch].id
941 vendor_lod_items = self._cvs_file_items.get_lod_items(
942 self._cvs_file_items[vendor_cvs_branch_id]
944 if not self._cvs_file_items.process_live_ntdb(vendor_lod_items):
945 return
946 elif self._file_imported:
947 vendor_branch_data = self.sdc.branches_data.get('1.1.1')
948 if vendor_branch_data is None:
949 return
950 else:
951 vendor_lod_items = self._cvs_file_items.get_lod_items(
952 self._cvs_file_items[vendor_branch_data.id]
954 if not self._cvs_file_items.process_historical_ntdb(
955 vendor_lod_items
957 return
958 else:
959 return
960 except VendorBranchError, e:
961 self.collect_data.record_fatal_error(str(e))
962 return
964 if self._file_imported:
965 self._cvs_file_items.imported_remove_1_1(vendor_lod_items)
967 self._cvs_file_items.check_link_consistency()
969 def get_cvs_file_items(self):
970 """Finish up and return a CVSFileItems instance for this file.
972 This method must only be called once."""
974 self._process_ntdbrs()
976 # Break a circular reference loop, allowing the memory for self
977 # and sdc to be freed.
978 del self.sdc
980 return self._cvs_file_items
983 class _ProjectDataCollector:
984 def __init__(self, collect_data, project):
985 self.collect_data = collect_data
986 self.project = project
987 self.num_files = 0
989 # The Trunk LineOfDevelopment object for this project:
990 self.trunk = Trunk(
991 self.collect_data.symbol_key_generator.gen_id(), self.project
993 self.project.trunk_id = self.trunk.id
995 # This causes a record for self.trunk to spring into existence:
996 self.collect_data.symbol_stats[self.trunk]
998 # A map { name -> Symbol } for all known symbols in this project.
999 # The symbols listed here are undifferentiated into Branches and
1000 # Tags because the same name might appear as a branch in one file
1001 # and a tag in another.
1002 self.symbols = {}
1004 # A map { (old_name, new_name) : count } indicating how many files
1005 # were affected by each each symbol name transformation:
1006 self.symbol_transform_counts = {}
1008 def get_symbol(self, name):
1009 """Return the Symbol object for the symbol named NAME in this project.
1011 If such a symbol does not yet exist, allocate a new symbol_id,
1012 create a Symbol instance, store it in self.symbols, and return it."""
1014 symbol = self.symbols.get(name)
1015 if symbol is None:
1016 symbol = Symbol(
1017 self.collect_data.symbol_key_generator.gen_id(),
1018 self.project, name)
1019 self.symbols[name] = symbol
1020 return symbol
1022 def log_symbol_transform(self, old_name, new_name):
1023 """Record that OLD_NAME was transformed to NEW_NAME in one file.
1025 This information is used to generated a statistical summary of
1026 symbol transforms."""
1028 try:
1029 self.symbol_transform_counts[old_name, new_name] += 1
1030 except KeyError:
1031 self.symbol_transform_counts[old_name, new_name] = 1
1033 def summarize_symbol_transforms(self):
1034 if self.symbol_transform_counts and Log().is_on(Log.NORMAL):
1035 log = Log()
1036 log.normal('Summary of symbol transforms:')
1037 transforms = self.symbol_transform_counts.items()
1038 transforms.sort()
1039 for ((old_name, new_name), count) in transforms:
1040 if new_name is None:
1041 log.normal(' "%s" ignored in %d files' % (old_name, count,))
1042 else:
1043 log.normal(
1044 ' "%s" transformed to "%s" in %d files'
1045 % (old_name, new_name, count,)
1048 def _process_cvs_file_items(self, cvs_file_items):
1049 """Process the CVSFileItems from one CVSFile."""
1051 # Remove CVSRevisionDeletes that are not needed:
1052 cvs_file_items.remove_unneeded_deletes(self.collect_data.metadata_db)
1054 # Remove initial branch deletes that are not needed:
1055 cvs_file_items.remove_initial_branch_deletes(
1056 self.collect_data.metadata_db
1059 # If this is a --trunk-only conversion, discard all branches and
1060 # tags, then draft any non-trunk default branch revisions to
1061 # trunk:
1062 if Ctx().trunk_only:
1063 cvs_file_items.exclude_non_trunk()
1065 self.collect_data.revision_recorder.finish_file(cvs_file_items)
1066 self.collect_data.add_cvs_file_items(cvs_file_items)
1067 self.collect_data.symbol_stats.register(cvs_file_items)
1069 def process_file(self, cvs_file):
1070 Log().normal(cvs_file.filename)
1071 fdc = _FileDataCollector(self, cvs_file)
1072 try:
1073 cvs2svn_rcsparse.parse(open(cvs_file.filename, 'rb'), fdc)
1074 except (cvs2svn_rcsparse.common.RCSParseError, ValueError, RuntimeError):
1075 self.collect_data.record_fatal_error(
1076 "%r is not a valid ,v file" % (cvs_file.filename,)
1078 # Abort the processing of this file, but let the pass continue
1079 # with other files:
1080 return
1081 except:
1082 Log().warn("Exception occurred while parsing %s" % cvs_file.filename)
1083 raise
1084 else:
1085 self.num_files += 1
1087 cvs_file_items = fdc.get_cvs_file_items()
1089 del fdc
1091 self._process_cvs_file_items(cvs_file_items)
1094 class CollectData:
1095 """Repository for data collected by parsing the CVS repository files.
1097 This class manages the databases into which information collected
1098 from the CVS repository is stored. The data are stored into this
1099 class by _FileDataCollector instances, one of which is created for
1100 each file to be parsed."""
1102 def __init__(self, revision_recorder, stats_keeper):
1103 self.revision_recorder = revision_recorder
1104 self._cvs_item_store = NewCVSItemStore(
1105 artifact_manager.get_temp_file(config.CVS_ITEMS_STORE))
1106 self.metadata_db = MetadataDatabase(
1107 artifact_manager.get_temp_file(config.METADATA_STORE),
1108 artifact_manager.get_temp_file(config.METADATA_INDEX_TABLE),
1109 DB_OPEN_NEW,
1111 self.metadata_logger = MetadataLogger(self.metadata_db)
1112 self.fatal_errors = []
1113 self.num_files = 0
1114 self.symbol_stats = SymbolStatisticsCollector()
1115 self.stats_keeper = stats_keeper
1117 # Key generator for CVSFiles:
1118 self.file_key_generator = KeyGenerator()
1120 # Key generator for CVSItems:
1121 self.item_key_generator = KeyGenerator()
1123 # Key generator for Symbols:
1124 self.symbol_key_generator = KeyGenerator()
1126 self.revision_recorder.start()
1128 def record_fatal_error(self, err):
1129 """Record that fatal error ERR was found.
1131 ERR is a string (without trailing newline) describing the error.
1132 Output the error to stderr immediately, and record a copy to be
1133 output again in a summary at the end of CollectRevsPass."""
1135 err = '%s: %s' % (error_prefix, err,)
1136 Log().error(err + '\n')
1137 self.fatal_errors.append(err)
1139 def add_cvs_directory(self, cvs_directory):
1140 """Record CVS_DIRECTORY."""
1142 Ctx()._cvs_file_db.log_file(cvs_directory)
1144 def add_cvs_file_items(self, cvs_file_items):
1145 """Record the information from CVS_FILE_ITEMS.
1147 Store the CVSFile to _cvs_file_db under its persistent id, store
1148 the CVSItems, and record the CVSItems to self.stats_keeper."""
1150 Ctx()._cvs_file_db.log_file(cvs_file_items.cvs_file)
1151 self._cvs_item_store.add(cvs_file_items)
1153 self.stats_keeper.record_cvs_file(cvs_file_items.cvs_file)
1154 for cvs_item in cvs_file_items.values():
1155 self.stats_keeper.record_cvs_item(cvs_item)
1157 def _get_cvs_file(
1158 self, parent_directory, basename, file_in_attic, leave_in_attic=False
1160 """Return a CVSFile describing the file with name BASENAME.
1162 PARENT_DIRECTORY is the CVSDirectory instance describing the
1163 directory that physically holds this file in the filesystem.
1164 BASENAME must be the base name of a *,v file within
1165 PARENT_DIRECTORY.
1167 FILE_IN_ATTIC is a boolean telling whether the specified file is
1168 in an Attic subdirectory. If FILE_IN_ATTIC is True, then:
1170 - If LEAVE_IN_ATTIC is True, then leave the 'Attic' component in
1171 the filename.
1173 - Otherwise, raise FileInAndOutOfAtticException if a file with the
1174 same filename appears outside of Attic.
1176 The CVSFile is assigned a new unique id. All of the CVSFile
1177 information is filled in except mode (which can only be determined
1178 by parsing the file).
1180 Raise FatalError if the resulting filename would not be legal in
1181 SVN."""
1183 filename = os.path.join(parent_directory.filename, basename)
1184 try:
1185 verify_svn_filename_legal(basename[:-2])
1186 except IllegalSVNPathError, e:
1187 raise FatalError(
1188 'File %r would result in an illegal SVN filename: %s'
1189 % (filename, e,)
1192 if file_in_attic and not leave_in_attic:
1193 in_attic = True
1194 logical_parent_directory = parent_directory.parent_directory
1196 # If this file also exists outside of the attic, it's a fatal
1197 # error:
1198 non_attic_filename = os.path.join(
1199 logical_parent_directory.filename, basename,
1201 if os.path.exists(non_attic_filename):
1202 raise FileInAndOutOfAtticException(non_attic_filename, filename)
1203 else:
1204 in_attic = False
1205 logical_parent_directory = parent_directory
1207 file_stat = os.stat(filename)
1209 # The size of the file in bytes:
1210 file_size = file_stat[stat.ST_SIZE]
1212 # Whether or not the executable bit is set:
1213 file_executable = bool(file_stat[0] & stat.S_IXUSR)
1215 # mode is not known, so we temporarily set it to None.
1216 return CVSFile(
1217 self.file_key_generator.gen_id(),
1218 parent_directory.project, logical_parent_directory, basename[:-2],
1219 in_attic, file_executable, file_size, None
1222 def _get_attic_file(self, parent_directory, basename):
1223 """Return a CVSFile object for the Attic file at BASENAME.
1225 PARENT_DIRECTORY is the CVSDirectory that physically contains the
1226 file on the filesystem (i.e., the Attic directory). It is not
1227 necessarily the parent_directory of the CVSFile that will be
1228 returned.
1230 Return CVSFile, whose parent directory is usually
1231 PARENT_DIRECTORY.parent_directory, but might be PARENT_DIRECTORY
1232 iff CVSFile will remain in the Attic directory."""
1234 try:
1235 return self._get_cvs_file(parent_directory, basename, True)
1236 except FileInAndOutOfAtticException, e:
1237 if Ctx().retain_conflicting_attic_files:
1238 Log().warn(
1239 "%s: %s;\n"
1240 " storing the latter into 'Attic' subdirectory.\n"
1241 % (warning_prefix, e)
1243 else:
1244 self.record_fatal_error(str(e))
1246 # Either way, return a CVSFile object so that the rest of the
1247 # file processing can proceed:
1248 return self._get_cvs_file(
1249 parent_directory, basename, True, leave_in_attic=True
1252 def _generate_attic_cvs_files(self, cvs_directory):
1253 """Generate CVSFiles for the files in Attic directory CVS_DIRECTORY.
1255 Also add CVS_DIRECTORY to self if any files are being retained in
1256 that directory."""
1258 retained_attic_file = False
1260 fnames = os.listdir(cvs_directory.filename)
1261 fnames.sort()
1262 for fname in fnames:
1263 pathname = os.path.join(cvs_directory.filename, fname)
1264 if os.path.isdir(pathname):
1265 Log().warn("Directory %s found within Attic; ignoring" % (pathname,))
1266 elif fname.endswith(',v'):
1267 cvs_file = self._get_attic_file(cvs_directory, fname)
1268 if cvs_file.parent_directory == cvs_directory:
1269 # This file will be retained in the Attic directory.
1270 retained_attic_file = True
1271 yield cvs_file
1273 if retained_attic_file:
1274 # If any files were retained in the Attic directory, then write
1275 # the Attic directory to CVSFileDatabase:
1276 self.add_cvs_directory(cvs_directory)
1278 def _get_non_attic_file(self, parent_directory, basename):
1279 """Return a CVSFile object for the non-Attic file at BASENAME."""
1281 return self._get_cvs_file(parent_directory, basename, False)
1283 def _generate_cvs_files(self, cvs_directory):
1284 """Generate the CVSFiles under non-Attic directory CVS_DIRECTORY.
1286 Process directories recursively, including Attic directories.
1287 Also create and register CVSDirectories as they are found, and
1288 look for conflicts between the filenames that will result from
1289 files, attic files, and subdirectories."""
1291 self.add_cvs_directory(cvs_directory)
1293 # Map {cvs_file.basename : cvs_file.filename} for files directly
1294 # in cvs_directory:
1295 rcsfiles = {}
1297 attic_dir = None
1299 # Non-Attic subdirectories of cvs_directory (to be recursed into):
1300 dirs = []
1302 fnames = os.listdir(cvs_directory.filename)
1303 fnames.sort()
1304 for fname in fnames:
1305 pathname = os.path.join(cvs_directory.filename, fname)
1306 if os.path.isdir(pathname):
1307 if fname == 'Attic':
1308 attic_dir = fname
1309 else:
1310 dirs.append(fname)
1311 elif fname.endswith(',v'):
1312 cvs_file = self._get_non_attic_file(cvs_directory, fname)
1313 rcsfiles[cvs_file.basename] = cvs_file.filename
1314 yield cvs_file
1315 else:
1316 # Silently ignore other files:
1317 pass
1319 # Map {cvs_file.basename : cvs_file.filename} for files in an
1320 # Attic directory within cvs_directory:
1321 attic_rcsfiles = {}
1323 if attic_dir is not None:
1324 attic_directory = CVSDirectory(
1325 self.file_key_generator.gen_id(),
1326 cvs_directory.project, cvs_directory, 'Attic',
1329 for cvs_file in self._generate_attic_cvs_files(attic_directory):
1330 if cvs_file.parent_directory == cvs_directory:
1331 attic_rcsfiles[cvs_file.basename] = cvs_file.filename
1332 yield cvs_file
1334 alldirs = dirs + [attic_dir]
1335 else:
1336 alldirs = dirs
1338 # Check for conflicts between directory names and the filenames
1339 # that will result from the rcs files (both in this directory and
1340 # in attic). (We recurse into the subdirectories nevertheless, to
1341 # try to detect more problems.)
1342 for fname in alldirs:
1343 pathname = os.path.join(cvs_directory.filename, fname)
1344 for rcsfile_list in [rcsfiles, attic_rcsfiles]:
1345 if fname in rcsfile_list:
1346 self.record_fatal_error(
1347 'Directory name conflicts with filename. Please remove or '
1348 'rename one\n'
1349 'of the following:\n'
1350 ' "%s"\n'
1351 ' "%s"'
1352 % (pathname, rcsfile_list[fname],)
1355 # Now recurse into the other subdirectories:
1356 for fname in dirs:
1357 dirname = os.path.join(cvs_directory.filename, fname)
1359 # Verify that the directory name does not contain any illegal
1360 # characters:
1361 try:
1362 verify_svn_filename_legal(fname)
1363 except IllegalSVNPathError, e:
1364 raise FatalError(
1365 'Directory %r would result in an illegal SVN path name: %s'
1366 % (dirname, e,)
1369 sub_directory = CVSDirectory(
1370 self.file_key_generator.gen_id(),
1371 cvs_directory.project, cvs_directory, fname,
1374 for cvs_file in self._generate_cvs_files(sub_directory):
1375 yield cvs_file
1377 def process_project(self, project):
1378 Ctx()._projects[project.id] = project
1380 root_cvs_directory = CVSDirectory(
1381 self.file_key_generator.gen_id(), project, None, ''
1383 project.root_cvs_directory_id = root_cvs_directory.id
1384 pdc = _ProjectDataCollector(self, project)
1386 found_rcs_file = False
1387 for cvs_file in self._generate_cvs_files(root_cvs_directory):
1388 pdc.process_file(cvs_file)
1389 found_rcs_file = True
1391 if not found_rcs_file:
1392 self.record_fatal_error(
1393 'No RCS files found under %r!\n'
1394 'Are you absolutely certain you are pointing cvs2svn\n'
1395 'at a CVS repository?\n'
1396 % (project.project_cvs_repos_path,)
1399 pdc.summarize_symbol_transforms()
1401 self.num_files += pdc.num_files
1402 Log().verbose('Processed', self.num_files, 'files')
1404 def _set_cvs_path_ordinals(self):
1405 cvs_files = list(Ctx()._cvs_file_db.itervalues())
1406 cvs_files.sort(CVSPath.slow_compare)
1407 for (i, cvs_file) in enumerate(cvs_files):
1408 cvs_file.ordinal = i
1410 def close(self):
1411 """Close the data structures associated with this instance.
1413 Return a list of fatal errors encountered while processing input.
1414 Each list entry is a string describing one fatal error."""
1416 self.revision_recorder.finish()
1417 self.symbol_stats.purge_ghost_symbols()
1418 self.symbol_stats.close()
1419 self.symbol_stats = None
1420 self.metadata_logger = None
1421 self.metadata_db.close()
1422 self.metadata_db = None
1423 self._cvs_item_store.close()
1424 self._cvs_item_store = None
1425 self._set_cvs_path_ordinals()
1426 self.revision_recorder = None
1427 retval = self.fatal_errors
1428 self.fatal_errors = None
1429 return retval