Update copyright dates through whole project based on date of last commit.
[cvs2svn.git] / cvs2svn_lib / fulltext_revision_recorder.py
blobad057b77acec8cb53842f1957aa04f33172dc490
1 # (Be in -*- python -*- mode.)
3 # ====================================================================
4 # Copyright (c) 2007-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 """An abstract class that contructs file contents during CollectRevsPass.
19 It calls its record_fulltext() method with the full text of every
20 revision. This method should be overridden to do something with the
21 fulltext and possibly return a revision_recorder_token."""
24 from cvs2svn_lib.revision_manager import RevisionRecorder
27 class FulltextRevisionRecorder:
28 """Similar to a RevisionRecorder, but it requires the fulltext."""
30 def register_artifacts(self, which_pass):
31 pass
33 def start(self):
34 pass
36 def start_file(self, cvs_file_items):
37 pass
39 def record_fulltext(self, cvs_rev, log, fulltext):
40 """Record the fulltext for CVS_REV.
42 CVS_REV has the log message LOG and the fulltext FULLTEXT. This
43 method should be overridden to do something sensible with them."""
45 raise NotImplementedError()
47 def finish_file(self, cvs_file_items):
48 pass
50 def finish(self):
51 pass
54 class FulltextRevisionRecorderAdapter(RevisionRecorder):
55 """Reconstruct the fulltext and pass it to a FulltextRevisionRecorder.
57 This class implements RevisionRecorder (so it can be passed directly
58 to CollectRevsPass). But it doesn't actually record anything.
59 Instead, it reconstructs the fulltext of each revision, and passes
60 the fulltext to a fulltext_revision_recorder."""
62 def __init__(self, fulltext_revision_recorder):
63 RevisionRecorder.__init__(self)
64 self.fulltext_revision_recorder = fulltext_revision_recorder
66 def register_artifacts(self, which_pass):
67 self.fulltext_revision_recorder.register_artifacts(which_pass)
69 def start(self):
70 self.fulltext_revision_recorder.start()
72 def start_file(self, cvs_file_items):
73 self.fulltext_revision_recorder.start_file(cvs_file_items)
75 def record_text(self, cvs_rev, log, text):
76 """This method should be overwridden.
78 It should determine the fulltext of CVS_REV, then pass it to
79 self.fulltext_revision_recorder.record_fulltext() and return the
80 result."""
82 raise NotImplementedError()
84 def finish_file(self, cvs_file_items):
85 self.fulltext_revision_recorder.finish_file(cvs_file_items)
87 def finish(self):
88 self.fulltext_revision_recorder.finish()
91 class SimpleFulltextRevisionRecorderAdapter(FulltextRevisionRecorderAdapter):
92 """Reconstruct the fulltext using a RevisionReader.
94 To create the fulltext, this class simply uses a RevisionReader (for
95 example, RCSRevisionReader or CVSRevisionReader). This is not quite
96 as wasteful as using one of these RevisionReaders in OutputPass,
97 because the same RCS file will be read over and over (and so
98 presumably stay in the disk cache). But it is still pretty silly,
99 considering that we have all the RCS deltas available to us."""
101 def __init__(self, revision_reader, fulltext_revision_recorder):
102 FulltextRevisionRecorderAdapter.__init__(self, fulltext_revision_recorder)
103 self.revision_reader = revision_reader
105 def register_artifacts(self, which_pass):
106 FulltextRevisionRecorderAdapter.register_artifacts(self, which_pass)
107 self.revision_reader.register_artifacts(which_pass)
109 def start(self):
110 FulltextRevisionRecorderAdapter.start(self)
111 self.revision_reader.start()
113 def record_text(self, cvs_rev, log, text):
114 # FIXME: We have to decide what to do about keyword substitution
115 # and eol_style here:
116 fulltext = self.revision_reader.get_content_stream(
117 cvs_rev, suppress_keyword_substitution=False
118 ).read()
119 return self.fulltext_revision_recorder.record_fulltext(
120 cvs_rev, log, fulltext
123 def finish(self):
124 FulltextRevisionRecorderAdapter.finish(self)
125 self.revision_reader.finish()