run-tests.py: Only pass the --svnadmin option to cvs2svn when needed.
[cvs2svn.git] / cvs2svn_lib / external_blob_generator.py
blob10a75e02c5dbd8b786868b0505316813779629d2
1 # (Be in -*- python -*- mode.)
3 # ====================================================================
4 # Copyright (c) 2009-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 """Use the generate_blobs.py script to generate git blobs.
19 Use a separate program, generate_blobs.py, to generate a git blob file
20 directly from the RCS files, setting blob marks that we choose. This
21 method is very much faster then generating the blobs from within the
22 main program for several reasons:
24 * The revision fulltexts are generated using internal code (rather
25 than spawning rcs or cvs once per revision). This gain is analogous
26 to the benefit of using --use-internal-co rather than --use-cvs or
27 --use-rcs for cvs2svn.
29 * Intermediate revisions' fulltext can usually be held in RAM rather
30 than being written to temporary storage, and output as they are
31 generated (git-fast-import doesn't care about their order).
33 * The generate_blobs.py script runs in parallel to the main cvs2git
34 script, allowing benefits to be had from multiple CPUs.
36 """
38 import sys
39 import os
40 import subprocess
41 import cPickle as pickle
43 from cvs2svn_lib.common import FatalError
44 from cvs2svn_lib.log import logger
45 from cvs2svn_lib.cvs_item import CVSRevisionDelete
46 from cvs2svn_lib.revision_manager import RevisionCollector
47 from cvs2svn_lib.key_generator import KeyGenerator
50 class ExternalBlobGenerator(RevisionCollector):
51 """Have generate_blobs.py output file revisions to a blob file."""
53 def __init__(self, blob_filename):
54 self.blob_filename = blob_filename
56 def start(self):
57 self._mark_generator = KeyGenerator()
58 logger.normal('Starting generate_blobs.py...')
59 self._pipe = subprocess.Popen(
61 sys.executable,
62 os.path.join(os.path.dirname(__file__), 'generate_blobs.py'),
63 self.blob_filename,
65 stdin=subprocess.PIPE,
68 def _process_symbol(self, cvs_symbol, cvs_file_items):
69 """Record the original source of CVS_SYMBOL.
71 Determine the original revision source of CVS_SYMBOL, and store it
72 as the symbol's revision_reader_token."""
74 cvs_source = cvs_symbol.get_cvs_revision_source(cvs_file_items)
75 cvs_symbol.revision_reader_token = cvs_source.revision_reader_token
77 def process_file(self, cvs_file_items):
78 marks = {}
79 for lod_items in cvs_file_items.iter_lods():
80 for cvs_rev in lod_items.cvs_revisions:
81 if not isinstance(cvs_rev, CVSRevisionDelete):
82 mark = self._mark_generator.gen_id()
83 cvs_rev.revision_reader_token = mark
84 marks[cvs_rev.rev] = mark
86 if marks:
87 # A separate pickler is used for each dump(), so that its memo
88 # doesn't grow very large. The default ASCII protocol is used so
89 # that this works without changes on systems that distinguish
90 # between text and binary files.
91 pickle.dump((cvs_file_items.cvs_file.rcs_path, marks), self._pipe.stdin)
92 self._pipe.stdin.flush()
94 # Now that all CVSRevisions' revision_reader_tokens are set,
95 # iterate through symbols and set their tokens to those of their
96 # original source revisions:
97 for lod_items in cvs_file_items.iter_lods():
98 if lod_items.cvs_branch is not None:
99 self._process_symbol(lod_items.cvs_branch, cvs_file_items)
100 for cvs_tag in lod_items.cvs_tags:
101 self._process_symbol(cvs_tag, cvs_file_items)
103 def finish(self):
104 self._pipe.stdin.close()
105 logger.normal('Waiting for generate_blobs.py to finish...')
106 returncode = self._pipe.wait()
107 if returncode:
108 raise FatalError(
109 'generate_blobs.py failed with return code %s.' % (returncode,)
111 else:
112 logger.normal('generate_blobs.py is done.')