From 9d35b5be0fb77cc5ffc9c6722449c7bc9a36cec5 Mon Sep 17 00:00:00 2001 From: mhagger Date: Mon, 15 Feb 2010 03:51:07 +0000 Subject: [PATCH] Change GitRevisionRecorder into GitRevisionCollector. It now runs in FilterSymbolsPass via the revision_excluder mechanism. git-svn-id: http://cvs2svn.tigris.org/svn/cvs2svn/trunk@5058 be7e6eca-30d4-0310-a8e5-ac0d63af7087 --- cvs2bzr-example.options | 3 -- cvs2git-example.options | 42 ++++++++++++++-------------- cvs2hg-example.options | 1 - cvs2svn_lib/git_revision_recorder.py | 53 ++++++++++++++++++++++++++++-------- cvs2svn_lib/git_run_options.py | 13 ++++----- 5 files changed, 66 insertions(+), 46 deletions(-) diff --git a/cvs2bzr-example.options b/cvs2bzr-example.options index 5d26b890..b4405bb3 100644 --- a/cvs2bzr-example.options +++ b/cvs2bzr-example.options @@ -79,13 +79,10 @@ from cvs2svn_lib import changeset_database from cvs2svn_lib.common import CVSTextDecoder from cvs2svn_lib.log import Log from cvs2svn_lib.project import Project -from cvs2svn_lib.git_revision_recorder import GitRevisionRecorder from cvs2svn_lib.git_output_option import GitRevisionInlineWriter from cvs2svn_lib.bzr_output_option import BzrOutputOption from cvs2svn_lib.revision_manager import NullRevisionRecorder from cvs2svn_lib.revision_manager import NullRevisionExcluder -from cvs2svn_lib.fulltext_revision_recorder \ - import SimpleFulltextRevisionRecorderAdapter from cvs2svn_lib.rcs_revision_manager import RCSRevisionReader from cvs2svn_lib.cvs_revision_manager import CVSRevisionReader from cvs2svn_lib.checkout_internal import InternalRevisionRecorder diff --git a/cvs2git-example.options b/cvs2git-example.options index df2c3154..7ad39f4c 100644 --- a/cvs2git-example.options +++ b/cvs2git-example.options @@ -79,13 +79,11 @@ from cvs2svn_lib import changeset_database from cvs2svn_lib.common import CVSTextDecoder from cvs2svn_lib.log import Log from cvs2svn_lib.project import Project -from cvs2svn_lib.git_revision_recorder import GitRevisionRecorder +from cvs2svn_lib.git_revision_recorder import GitRevisionCollector from cvs2svn_lib.git_output_option import GitRevisionMarkWriter from cvs2svn_lib.git_output_option import GitOutputOption from cvs2svn_lib.revision_manager import NullRevisionRecorder from cvs2svn_lib.revision_manager import NullRevisionExcluder -from cvs2svn_lib.fulltext_revision_recorder \ - import SimpleFulltextRevisionRecorderAdapter from cvs2svn_lib.rcs_revision_manager import RCSRevisionReader from cvs2svn_lib.cvs_revision_manager import CVSRevisionReader from cvs2svn_lib.checkout_internal import InternalRevisionRecorder @@ -129,38 +127,38 @@ Log().log_level = Log.NORMAL # The directory to use for temporary files: ctx.tmpdir = r'cvs2svn-tmp' -# During CollectRevsPass, cvs2git records the contents of file +ctx.revision_recorder = NullRevisionRecorder() + +# During FilterSymbolsPass, cvs2git records the contents of file # revisions into a "blob" file in git-fast-import format. This option # configures that process: -ctx.revision_recorder = SimpleFulltextRevisionRecorderAdapter( - # The following option specifies how the revision contents of the RCS - # files should be read. +ctx.revision_excluder = GitRevisionCollector( + # The file in which to write the git-fast-import stream that + # contains the file revision contents: + 'cvs2svn-tmp/git-blob.dat', + + # The following option specifies how the revision contents of the + # RCS files should be read. # - # RCSRevisionReader uses RCS's "co" program to extract the revision - # contents of the RCS files during CollectRevsPass. The constructor - # argument specifies how to invoke the "co" executable. + # RCSRevisionReader uses RCS's "co" program to extract the + # revision contents of the RCS files during CollectRevsPass. The + # constructor argument specifies how to invoke the "co" + # executable. # # CVSRevisionReader uses the "cvs" program to extract the revision # contents out of the RCS files during OutputPass. This option is # considerably slower than RCSRevisionReader because "cvs" is - # considerably slower than "co". However, it works in some situations - # where RCSRevisionReader fails; see the HTML documentation of the - # "--use-cvs" option for details. The constructor argument specifies - # how to invoke the "co" executable. + # considerably slower than "co". However, it works in some + # situations where RCSRevisionReader fails; see the HTML + # documentation of the "--use-cvs" option for details. The + # constructor argument specifies how to invoke the "co" + # executable. # # Uncomment one of the two following lines: #RCSRevisionReader(co_executable=r'co'), CVSRevisionReader(cvs_executable=r'cvs'), - - # The file in which to write the git-fast-import stream that - # contains the file revision contents: - GitRevisionRecorder(os.path.join(ctx.tmpdir, 'git-blob.dat')), ) -# cvs2git does not need to keep track of what revisions will be -# excluded, so leave this option unchanged: -ctx.revision_excluder = NullRevisionExcluder() - # cvs2git doesn't need a revision reader because OutputPass only # refers to blobs that were output during CollectRevsPass, so leave # this option set to None. diff --git a/cvs2hg-example.options b/cvs2hg-example.options index 754c5afa..7c5b41df 100644 --- a/cvs2hg-example.options +++ b/cvs2hg-example.options @@ -85,7 +85,6 @@ from cvs2svn_lib import changeset_database from cvs2svn_lib.common import CVSTextDecoder from cvs2svn_lib.log import Log from cvs2svn_lib.project import Project -from cvs2svn_lib.git_revision_recorder import GitRevisionRecorder from cvs2svn_lib.git_output_option import GitRevisionInlineWriter from cvs2svn_lib.git_output_option import GitOutputOption from cvs2svn_lib.revision_manager import NullRevisionRecorder diff --git a/cvs2svn_lib/git_revision_recorder.py b/cvs2svn_lib/git_revision_recorder.py index 5a7d938f..f1698a2a 100644 --- a/cvs2svn_lib/git_revision_recorder.py +++ b/cvs2svn_lib/git_revision_recorder.py @@ -21,21 +21,26 @@ import itertools from cvs2svn_lib.symbol import Trunk from cvs2svn_lib.cvs_item import CVSRevisionDelete from cvs2svn_lib.cvs_item import CVSSymbol -from cvs2svn_lib.fulltext_revision_recorder import FulltextRevisionRecorder +from cvs2svn_lib.revision_manager import RevisionCollector from cvs2svn_lib.key_generator import KeyGenerator -class GitRevisionRecorder(FulltextRevisionRecorder): +class GitRevisionCollector(RevisionCollector): """Output file revisions to git-fast-import.""" - def __init__(self, blob_filename): + def __init__(self, blob_filename, revision_reader): self.blob_filename = blob_filename + self.revision_reader = revision_reader + + def register_artifacts(self, which_pass): + self.revision_reader.register_artifacts(which_pass) def start(self): + self.revision_reader.start() self.dump_file = open(self.blob_filename, 'wb') self._mark_generator = KeyGenerator() - def record_fulltext(self, cvs_rev, log, fulltext): + def _process_revision(self, cvs_rev): """Write the revision fulltext to a blob if it is not dead.""" if isinstance(cvs_rev, CVSRevisionDelete): @@ -43,23 +48,47 @@ class GitRevisionRecorder(FulltextRevisionRecorder): # will never be needed: return None + # FIXME: We have to decide what to do about keyword substitution + # and eol_style here: + stream = self.revision_reader.get_content_stream( + cvs_rev, suppress_keyword_substitution=False, + ) + fulltext = stream.read() + stream.close() + mark = self._mark_generator.gen_id() self.dump_file.write('blob\n') self.dump_file.write('mark :%d\n' % (mark,)) self.dump_file.write('data %d\n' % (len(fulltext),)) self.dump_file.write(fulltext) self.dump_file.write('\n') - return mark + cvs_rev.revision_recorder_token = mark + + def _process_symbol(self, cvs_symbol, cvs_file_items): + """Record the original source of CVS_SYMBOL. + + Determine the original revision source of CVS_SYMBOL, and store it + as the symbol's revision_recorder_token.""" + + cvs_source = cvs_symbol.get_cvs_revision_source(cvs_file_items) + cvs_symbol.revision_recorder_token = cvs_source.revision_recorder_token + + def process_file(self, cvs_file_items): + for lod_items in cvs_file_items.iter_lods(): + for cvs_rev in lod_items.cvs_revisions: + self._process_revision(cvs_rev) - def finish_file(self, cvs_file_items): - # Determine the original source of each CVSSymbol, and store it as - # the symbol's revision_recorder_token. - for cvs_item in cvs_file_items.values(): - if isinstance(cvs_item, CVSSymbol): - cvs_source = cvs_item.get_cvs_revision_source(cvs_file_items) - cvs_item.revision_recorder_token = cvs_source.revision_recorder_token + # Now that all CVSRevisions' revision_recorder_tokens are set, + # iterate through symbols and set their tokens to those of their + # original source revisions: + for lod_items in cvs_file_items.iter_lods(): + if lod_items.cvs_branch is not None: + self._process_symbol(lod_items.cvs_branch, cvs_file_items) + for cvs_tag in lod_items.cvs_tags: + self._process_symbol(cvs_tag, cvs_file_items) def finish(self): + self.revision_reader.finish() self.dump_file.close() diff --git a/cvs2svn_lib/git_run_options.py b/cvs2svn_lib/git_run_options.py index e2355f16..f60fcc08 100644 --- a/cvs2svn_lib/git_run_options.py +++ b/cvs2svn_lib/git_run_options.py @@ -35,11 +35,9 @@ from cvs2svn_lib.revision_manager import NullRevisionRecorder from cvs2svn_lib.revision_manager import NullRevisionExcluder from cvs2svn_lib.rcs_revision_manager import RCSRevisionReader from cvs2svn_lib.cvs_revision_manager import CVSRevisionReader -from cvs2svn_lib.git_revision_recorder import GitRevisionRecorder +from cvs2svn_lib.git_revision_recorder import GitRevisionCollector from cvs2svn_lib.git_output_option import GitRevisionMarkWriter from cvs2svn_lib.git_output_option import GitOutputOption -from cvs2svn_lib.fulltext_revision_recorder \ - import SimpleFulltextRevisionRecorderAdapter class GitRunOptions(DVCSRunOptions): @@ -150,17 +148,16 @@ A directory called \\fIcvs2svn-tmp\\fR (or the directory specified by cvs_executable=options.cvs_executable ) + ctx.revision_recorder = NullRevisionRecorder() if ctx.dry_run: - ctx.revision_recorder = NullRevisionRecorder() + ctx.revision_excluder = NullRevisionExcluder() else: if not (options.blobfile and options.dumpfile): raise FatalError("must pass '--blobfile' and '--dumpfile' options.") - ctx.revision_recorder = SimpleFulltextRevisionRecorderAdapter( - revision_reader, - GitRevisionRecorder(options.blobfile), + ctx.revision_excluder = GitRevisionCollector( + options.blobfile, revision_reader, ) - ctx.revision_excluder = NullRevisionExcluder() ctx.revision_reader = None def process_output_options(self): -- 2.11.4.GIT