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.
41 import cPickle
as pickle
44 from cvs2svn_lib
.common
import FatalError
45 from cvs2svn_lib
.log
import Log
46 from cvs2svn_lib
.symbol
import Trunk
47 from cvs2svn_lib
.cvs_item
import CVSRevisionDelete
48 from cvs2svn_lib
.cvs_item
import CVSSymbol
49 from cvs2svn_lib
.revision_manager
import RevisionCollector
50 from cvs2svn_lib
.key_generator
import KeyGenerator
53 class ExternalBlobGenerator(RevisionCollector
):
54 """Have generate_blobs.py output file revisions to a blob file."""
56 def __init__(self
, blob_filename
):
57 self
.blob_filename
= blob_filename
60 self
._mark
_generator
= KeyGenerator()
61 Log().normal('Starting generate_blobs.py...')
62 self
._popen
= subprocess
.Popen(
65 os
.path
.join(os
.path
.dirname(__file__
), 'generate_blobs.py'),
68 stdin
=subprocess
.PIPE
,
71 def _process_symbol(self
, cvs_symbol
, cvs_file_items
):
72 """Record the original source of CVS_SYMBOL.
74 Determine the original revision source of CVS_SYMBOL, and store it
75 as the symbol's revision_reader_token."""
77 cvs_source
= cvs_symbol
.get_cvs_revision_source(cvs_file_items
)
78 cvs_symbol
.revision_reader_token
= cvs_source
.revision_reader_token
80 def process_file(self
, cvs_file_items
):
82 for lod_items
in cvs_file_items
.iter_lods():
83 for cvs_rev
in lod_items
.cvs_revisions
:
84 if not isinstance(cvs_rev
, CVSRevisionDelete
):
85 mark
= self
._mark
_generator
.gen_id()
86 cvs_rev
.revision_reader_token
= mark
87 marks
[cvs_rev
.rev
] = mark
89 # A separate pickler is used for each dump(), so that its memo
90 # doesn't grow very large. The default ASCII protocol is used so
91 # that this works without changes on systems that distinguish
92 # between text and binary files.
93 pickle
.dump((cvs_file_items
.cvs_file
.filename
, marks
), self
._popen
.stdin
)
94 self
._popen
.stdin
.flush()
96 # Now that all CVSRevisions' revision_reader_tokens are set,
97 # iterate through symbols and set their tokens to those of their
98 # original source revisions:
99 for lod_items
in cvs_file_items
.iter_lods():
100 if lod_items
.cvs_branch
is not None:
101 self
._process
_symbol
(lod_items
.cvs_branch
, cvs_file_items
)
102 for cvs_tag
in lod_items
.cvs_tags
:
103 self
._process
_symbol
(cvs_tag
, cvs_file_items
)
106 self
._popen
.stdin
.close()
107 Log().normal('Waiting for generate_blobs.py to finish...')
108 returncode
= self
._popen
.wait()
111 'generate_blobs.py failed with return code %s.' % (returncode
,)
114 Log().normal('generate_blobs.py is done.')