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 """Write file contents to a stream of git-fast-import blobs."""
21 from cvs2svn_lib
.symbol
import Trunk
22 from cvs2svn_lib
.cvs_item
import CVSRevisionDelete
23 from cvs2svn_lib
.cvs_item
import CVSSymbol
24 from cvs2svn_lib
.revision_manager
import RevisionCollector
25 from cvs2svn_lib
.key_generator
import KeyGenerator
28 class GitRevisionCollector(RevisionCollector
):
29 """Output file revisions to git-fast-import."""
31 def __init__(self
, blob_filename
, revision_reader
):
32 self
.blob_filename
= blob_filename
33 self
.revision_reader
= revision_reader
35 def register_artifacts(self
, which_pass
):
36 self
.revision_reader
.register_artifacts(which_pass
)
39 self
.revision_reader
.start()
40 self
.dump_file
= open(self
.blob_filename
, 'wb')
41 self
._mark
_generator
= KeyGenerator()
43 def _process_revision(self
, cvs_rev
):
44 """Write the revision fulltext to a blob if it is not dead."""
46 if isinstance(cvs_rev
, CVSRevisionDelete
):
47 # There is no need to record a delete revision, and its token
48 # will never be needed:
51 # FIXME: We have to decide what to do about keyword substitution
53 stream
= self
.revision_reader
.get_content_stream(
54 cvs_rev
, suppress_keyword_substitution
=False,
56 fulltext
= stream
.read()
59 mark
= self
._mark
_generator
.gen_id()
60 self
.dump_file
.write('blob\n')
61 self
.dump_file
.write('mark :%d\n' % (mark
,))
62 self
.dump_file
.write('data %d\n' % (len(fulltext
),))
63 self
.dump_file
.write(fulltext
)
64 self
.dump_file
.write('\n')
65 cvs_rev
.revision_reader_token
= mark
67 def _process_symbol(self
, cvs_symbol
, cvs_file_items
):
68 """Record the original source of CVS_SYMBOL.
70 Determine the original revision source of CVS_SYMBOL, and store it
71 as the symbol's revision_reader_token."""
73 cvs_source
= cvs_symbol
.get_cvs_revision_source(cvs_file_items
)
74 cvs_symbol
.revision_reader_token
= cvs_source
.revision_reader_token
76 def process_file(self
, cvs_file_items
):
77 for lod_items
in cvs_file_items
.iter_lods():
78 for cvs_rev
in lod_items
.cvs_revisions
:
79 self
._process
_revision
(cvs_rev
)
81 # Now that all CVSRevisions' revision_reader_tokens are set,
82 # iterate through symbols and set their tokens to those of their
83 # original source revisions:
84 for lod_items
in cvs_file_items
.iter_lods():
85 if lod_items
.cvs_branch
is not None:
86 self
._process
_symbol
(lod_items
.cvs_branch
, cvs_file_items
)
87 for cvs_tag
in lod_items
.cvs_tags
:
88 self
._process
_symbol
(cvs_tag
, cvs_file_items
)
91 self
.revision_reader
.finish()
92 self
.dump_file
.close()