Limit the maximum number of files open at a time.
[cvs2svn.git] / cvs2svn_lib / cvs_revision_manager.py
blob6f5de3b9412bd7e8cd3179b7e0cb1631e2b018d3
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 """Access the CVS repository via CVS's 'cvs' command."""
20 from cvs2svn_lib.common import FatalError
21 from cvs2svn_lib.process import check_command_runs
22 from cvs2svn_lib.process import PipeStream
23 from cvs2svn_lib.process import CommandFailedException
24 from cvs2svn_lib.revision_manager import RevisionReader
27 class CVSRevisionReader(RevisionReader):
28 """A RevisionReader that reads the contents via CVS."""
30 # Different versions of CVS support different global arguments.
31 # Here are the global arguments that we try to use, in order of
32 # decreasing preference:
33 _possible_global_arguments = [
34 ['-q', '-R', '-f'],
35 ['-q', '-R'],
36 ['-q', '-f'],
37 ['-q'],
40 def __init__(self, cvs_executable):
41 self.cvs_executable = cvs_executable
43 for global_arguments in self._possible_global_arguments:
44 try:
45 self._check_cvs_runs(global_arguments)
46 except CommandFailedException, e:
47 pass
48 else:
49 # Those global arguments were OK; use them for all CVS invocations.
50 self.global_arguments = global_arguments
51 break
52 else:
53 raise FatalError(
54 '%s\n'
55 'Please check that cvs is installed and in your PATH.' % (e,)
58 def _check_cvs_runs(self, global_arguments):
59 """Check that CVS can be started.
61 Try running 'cvs --version' with the current setting for
62 self.cvs_executable and the specified global_arguments. If not
63 successful, raise a CommandFailedException."""
65 check_command_runs(
66 [self.cvs_executable] + global_arguments + ['--version'],
67 self.cvs_executable,
70 def get_content_stream(self, cvs_rev, suppress_keyword_substitution=False):
71 project = cvs_rev.cvs_file.project
72 pipe_cmd = [
73 self.cvs_executable
74 ] + self.global_arguments + [
75 '-d', project.cvs_repository_root,
76 'co',
77 '-r' + cvs_rev.rev,
78 '-p'
80 if suppress_keyword_substitution:
81 pipe_cmd.append('-kk')
82 pipe_cmd.append(project.cvs_module + cvs_rev.cvs_path)
83 return PipeStream(pipe_cmd)