git-migration: cvs2git.options, pld-git.sh, revoutput.py (NEW) - initial ve...

draenog draenog at pld-linux.org
Wed Feb 16 16:37:00 CET 2011


Author: draenog                      Date: Wed Feb 16 15:37:00 2011 GMT
Module: git-migration                 Tag: HEAD
---- Log message:
- initial version of new class for output to git fast-import format;
  two subroutines that will be changed copied from cvs2svn sources
  (cvs2svn_lib/git_output_option.py)

---- Files affected:
git-migration:
   cvs2git.options (1.1 -> 1.2) , pld-git.sh (1.29 -> 1.30) , revoutput.py (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: git-migration/cvs2git.options
diff -u git-migration/cvs2git.options:1.1 git-migration/cvs2git.options:1.2
--- git-migration/cvs2git.options:1.1	Wed Feb  9 08:46:47 2011
+++ git-migration/cvs2git.options	Wed Feb 16 16:36:55 2011
@@ -82,7 +82,7 @@
 from cvs2svn_lib.git_revision_collector import GitRevisionCollector
 from cvs2svn_lib.external_blob_generator import ExternalBlobGenerator
 from cvs2svn_lib.git_output_option import GitRevisionMarkWriter
-from cvs2svn_lib.git_output_option import GitOutputOption
+from revoutput import GitOutputRev
 from cvs2svn_lib.dvcs_common import KeywordHandlingPropertySetter
 from cvs2svn_lib.revision_manager import NullRevisionCollector
 from cvs2svn_lib.rcs_revision_manager import RCSRevisionReader
@@ -511,7 +511,7 @@
 
 # This is the main option that causes cvs2svn to output to a
 # "fastimport"-format dumpfile rather than to Subversion:
-ctx.output_option = GitOutputOption(
+ctx.output_option = GitOutputRev(
     # The file in which to write the git-fast-import stream that
     # contains the changesets and branch/tag information:
     os.path.join(ctx.tmpdir, 'git-dump.dat'),

================================================================
Index: git-migration/pld-git.sh
diff -u git-migration/pld-git.sh:1.29 git-migration/pld-git.sh:1.30
--- git-migration/pld-git.sh:1.29	Mon Feb 14 18:28:32 2011
+++ git-migration/pld-git.sh	Wed Feb 16 16:36:55 2011
@@ -115,7 +115,7 @@
 
 		export GIT_DIR=$gitdir/$pkg
 		git init
-		CVS_REPO=packages/$pkg cvs2git --options=cvs2git.options || {
+		PYTHONPATH=$(pwd) CVS_REPO=packages/$pkg cvs2git --options=cvs2git.options || {
 			rm -rf $GIT_DIR
 			exit 1
 		}

================================================================
Index: git-migration/revoutput.py
diff -u /dev/null git-migration/revoutput.py:1.1
--- /dev/null	Wed Feb 16 16:37:00 2011
+++ git-migration/revoutput.py	Wed Feb 16 16:36:55 2011
@@ -0,0 +1,131 @@
+from cvs2svn_lib.context import Ctx
+from cvs2svn_lib.symbol import Trunk
+from cvs2svn_lib.git_output_option import GitOutputOption
+
+class GitOutputRev(GitOutputOption):
+
+  def __init__(self, dump_filename, revision_writer,
+        author_transforms=None,
+        tie_tag_fixup_branches=False,
+        ):
+    GitOutputOption.__init__(self, dump_filename, revision_writer, author_transforms, tie_tag_fixup_branches)
+  
+  def process_primary_commit(self, svn_commit):
+    author = self._get_author(svn_commit)
+    log_msg = self._get_log_msg(svn_commit)
+
+    lods = set()
+    for cvs_rev in svn_commit.get_cvs_items():
+      lods.add(cvs_rev.lod)
+    if len(lods) != 1:
+      raise InternalError('Commit affects %d LODs' % (len(lods),))
+    lod = lods.pop()
+
+    self._mirror.start_commit(svn_commit.revnum)
+    if isinstance(lod, Trunk):
+      # FIXME: is this correct?:
+      self.f.write('commit refs/heads/master\n')
+    else:
+      self.f.write('commit refs/heads/%s\n' % (lod.name,))
+    self.f.write(
+        'mark :%d\n'
+        % (self._create_commit_mark(lod, svn_commit.revnum),)
+        )
+    self.f.write(
+        'committer %s %d +0000\n' % (author, svn_commit.date,)
+        )
+    self.f.write('data %d\n' % (len(log_msg),))
+    self.f.write('%s\n' % (log_msg,))
+    for cvs_rev in svn_commit.get_cvs_items():
+      self.revision_writer.process_revision(cvs_rev, post_commit=False)
+
+    self.f.write('\n')
+    self._mirror.end_commit()
+
+  def _process_symbol_commit(self, svn_commit, git_branch, source_groups):
+    author = self._get_author(svn_commit)
+    log_msg = self._get_log_msg(svn_commit)
+
+    # There are two distinct cases we need to care for here:
+    #  1. initial creation of a LOD
+    #  2. fixup of an existing LOD to include more files, because the LOD in
+    #     CVS was created piecemeal over time, with intervening commits
+
+    # We look at _marks here, but self._mirror._get_lod_history(lod).exists()
+    # might be technically more correct (though _get_lod_history is currently
+    # underscore-private)
+    is_initial_lod_creation = svn_commit.symbol not in self._marks
+
+    # Create the mark, only after the check above
+    mark = self._create_commit_mark(svn_commit.symbol, svn_commit.revnum)
+
+    if is_initial_lod_creation:
+      # Get the primary parent
+      p_source_revnum, p_source_lod, p_cvs_symbols = source_groups[0]
+      try:
+        p_source_node = self._mirror.get_old_lod_directory(
+            p_source_lod, p_source_revnum
+            )
+      except KeyError:
+        raise InternalError('Source %r does not exist' % (p_source_lod,))
+      cvs_files_to_delete = set(self._get_all_files(p_source_node))
+
+      for (source_revnum, source_lod, cvs_symbols,) in source_groups:
+        for cvs_symbol in cvs_symbols:
+          cvs_files_to_delete.discard(cvs_symbol.cvs_file)
+
+    # Write a trailer to the log message which describes the cherrypicks that
+    # make up this symbol creation.
+    log_msg += "\n"
+    if is_initial_lod_creation:
+      log_msg += "\nSprout from %s" % (
+          self._describe_commit(
+              Ctx()._persistence_manager.get_svn_commit(p_source_revnum),
+              p_source_lod
+              ),
+          )
+    for (source_revnum, source_lod, cvs_symbols,) \
+            in source_groups[(is_initial_lod_creation and 1 or 0):]:
+      log_msg += "\nCherrypick from %s:" % (
+          self._describe_commit(
+              Ctx()._persistence_manager.get_svn_commit(source_revnum),
+              source_lod
+              ),
+          )
+      for cvs_path in sorted(
+            cvs_symbol.cvs_file.cvs_path for cvs_symbol in cvs_symbols
+            ):
+        log_msg += "\n    %s" % (cvs_path,)
+    if is_initial_lod_creation:
+      if cvs_files_to_delete:
+        log_msg += "\nDelete:"
+        for cvs_path in sorted(
+              cvs_file.cvs_path for cvs_file in cvs_files_to_delete
+              ):
+          log_msg += "\n    %s" % (cvs_path,)
+
+    self.f.write('commit %s\n' % (git_branch,))
+    self.f.write('mark :%d\n' % (mark,))
+    self.f.write('committer %s %d +0000\n' % (author, svn_commit.date,))
+    self.f.write('data %d\n' % (len(log_msg),))
+    self.f.write('%s\n' % (log_msg,))
+
+    # Only record actual DVCS ancestry for the primary sprout parent,
+    # all the rest are effectively cherrypicks.
+    if is_initial_lod_creation:
+      self.f.write(
+          'from :%d\n'
+          % (self._get_source_mark(p_source_lod, p_source_revnum),)
+          )
+
+    for (source_revnum, source_lod, cvs_symbols,) in source_groups:
+      for cvs_symbol in cvs_symbols:
+        self.revision_writer.branch_file(cvs_symbol)
+
+    if is_initial_lod_creation:
+      for cvs_file in cvs_files_to_delete:
+        self.f.write('D %s\n' % (cvs_file.cvs_path,))
+
+    self.f.write('\n')
+    return mark
+
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/git-migration/cvs2git.options?r1=1.1&r2=1.2&f=u
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/git-migration/pld-git.sh?r1=1.29&r2=1.30&f=u



More information about the pld-cvs-commit mailing list