Update CHANGES file.
[cvs2svn.git] / cvs2svn_lib / abstract_rcs_revision_manager.py
blob1d085aa7c4f0d31aacccfcbdefb5c183b481ee0d
1 # (Be in -*- python -*- mode.)
3 # ====================================================================
4 # Copyright (c) 2000-2010 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 """Base class for RCSRevisionReader and CVSRevisionReader."""
20 from cvs2svn_lib.common import canonicalize_eol
21 from cvs2svn_lib.common import FatalError
22 from cvs2svn_lib.process import get_command_output
23 from cvs2svn_lib.context import Ctx
24 from cvs2svn_lib.revision_manager import RevisionReader
25 from cvs2svn_lib.keyword_expander import expand_keywords
26 from cvs2svn_lib.keyword_expander import collapse_keywords
27 from cvs2svn_lib.apple_single_filter import get_maybe_apple_single
30 class AbstractRCSRevisionReader(RevisionReader):
31 """A base class for RCSRevisionReader and CVSRevisionReader."""
33 # A map from (eol_fix, keyword_handling) to ('-k' option needed for
34 # RCS/CVS, explicit_keyword_handling). The preference is to allow
35 # CVS/RCS to handle keyword expansion itself whenever possible. But
36 # it is not possible in combination with eol_fix==False, because the
37 # only option that CVS/RCS has that leaves the EOLs alone is '-kb'
38 # mode, which leaves the keywords untouched. Therefore, whenever
39 # eol_fix is False, we need to use '-kb' mode and then (if
40 # necessary) expand or collapse the keywords ourselves.
41 _text_options = {
42 (False, 'collapsed') : (['-kb'], 'collapsed'),
43 (False, 'expanded') : (['-kb'], 'expanded'),
44 (False, 'untouched') : (['-kb'], None),
46 (True, 'collapsed') : (['-kk'], None),
47 (True, 'expanded') : (['-kkv'], None),
48 (True, 'untouched') : (['-ko'], None),
51 def get_pipe_command(self, cvs_rev, k_option):
52 """Return the command that is needed to get the contents for CVS_REV.
54 K_OPTION is a list containing the '-k' option that is needed, if
55 any."""
57 raise NotImplementedError()
59 def get_content(self, cvs_rev):
60 # Is EOL fixing requested?
61 eol_fix = cvs_rev.get_property('_eol_fix') or None
63 # How do we want keywords to be handled?
64 keyword_handling = cvs_rev.get_property('_keyword_handling') or None
66 try:
67 (k_option, explicit_keyword_handling) = self._text_options[
68 bool(eol_fix), keyword_handling
70 except KeyError:
71 raise FatalError(
72 'Undefined _keyword_handling property (%r) for %s'
73 % (keyword_handling, cvs_rev,)
76 data = get_command_output(self.get_pipe_command(cvs_rev, k_option))
78 if Ctx().decode_apple_single:
79 # Insert a filter to decode any files that are in AppleSingle
80 # format:
81 data = get_maybe_apple_single(data)
83 if explicit_keyword_handling == 'expanded':
84 data = expand_keywords(data, cvs_rev)
85 elif explicit_keyword_handling == 'collapsed':
86 data = collapse_keywords(data)
88 if eol_fix:
89 data = canonicalize_eol(data, eol_fix)
91 return data