[PATCH] Exclude vendor branches

Jon Foster <[email protected]> Fri, 5 Mar 2010 18:28:11 -0000
Newsgroups gmane.comp.version-control.subversion.cvs2svn.devel
Message-ID <[email protected]>
Hi,

Sorry for sending so many patches all at once.  If there's anything I
can do to make reviewing easier, please let me know.

This patch adds an --exclude-vendor-branches option to cvs2svn.
There are a several reasons for wanting to exclude vendor branches:

- People often think of "cvs import" as "a way to add a new
  file/directory" without understanding vendor branches at all.
  So they don't expect the vendor branch to be a real SVN branch.
  And there's no value in the vendor branch name and release name
  they choose, which are often "avendor" and "arelease".

- They complicate the SVN history due to the automatically
  generated merges from vendor branch to trunk.

- I've got another cvs2svn patch (to follow), where handling vendor
  branches would be extremely complex; it's easier to just exclude
  them.

This patch applies on top of the "remove no-op revisions" patch I
sent earlier today.  The feature is completely independent, but
it touches the same parts of the code.

I'd welcome any feedback or review of this patch.

Kind regards,

Jon


**********************************************************************
This email and its attachments may be confidential and are intended solely for the use of the individual to whom it is addressed. Any views or opinions expressed are solely those of the author and do not necessarily represent those of Cabot Communications Ltd.

If you are not the intended recipient of this email and its attachments, you must take no action based upon them, nor must you copy or show them to anyone.

Cabot Communications Limited
Verona House, Filwood Road, Bristol BS16 3RY, UK
+44 (0) 1179584232

Co. Registered in England number 02817269

Please contact the sender if you believe you have received this email in error.

**********************************************************************


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

------------------------------------------------------
http://cvs2svn.tigris.org/ds/viewMessage.do?dsForumId=1667&dsMessageId=2455559

To unsubscribe from this discussion, e-mail: [[email protected]].
cvs2svn_exclude_vendor_patch.txt (text/plain, 8.3 KB)
diff -uprN --exclude=.svn -x cvs2svn-tmp -x '*.pyc' cvs2svn-trunk-noop/cvs2bzr-example.options cvs2svn-trunk-exclude-vendor/cvs2bzr-example.options
--- cvs2svn-trunk-noop/cvs2bzr-example.options	2010-03-05 13:28:25.000000000 +0000
+++ cvs2svn-trunk-exclude-vendor/cvs2bzr-example.options	2010-03-05 17:25:36.000000000 +0000
@@ -137,6 +137,16 @@ ctx.revision_reader = None
 # should be omitted from the conversion):
 ctx.trunk_only = False
 
+# Change the following line to True if the conversion should exclude
+# all vendor branches.  Notes:
+# - You cannot do this if you have a branch that branches from a
+#   vendor branch _after_ the trunk and vendor branch have diverged.
+# - If you have any tags on a vendor branch _after_ the trunk and
+#   vendor branch have diverged, then you must exclude them using
+#   a SymbolTransform.  (SymbolStrategyRules cannot be used as
+#   they are applied too late).
+ctx.exclude_vendor_branches = False
+
 # How to convert CVS author names, log messages, and filenames to
 # Unicode.  The first argument to CVSTextDecoder is a list of encoders
 # that are tried in order in 'strict' mode until one of them succeeds.
diff -uprN --exclude=.svn -x cvs2svn-tmp -x '*.pyc' cvs2svn-trunk-noop/cvs2git-example.options cvs2svn-trunk-exclude-vendor/cvs2git-example.options
--- cvs2svn-trunk-noop/cvs2git-example.options	2010-03-05 13:28:19.000000000 +0000
+++ cvs2svn-trunk-exclude-vendor/cvs2git-example.options	2010-03-05 17:25:41.000000000 +0000
@@ -165,6 +165,16 @@ ctx.revision_reader = None
 # should be omitted from the conversion):
 ctx.trunk_only = False
 
+# Change the following line to True if the conversion should exclude
+# all vendor branches.  Notes:
+# - You cannot do this if you have a branch that branches from a
+#   vendor branch _after_ the trunk and vendor branch have diverged.
+# - If you have any tags on a vendor branch _after_ the trunk and
+#   vendor branch have diverged, then you must exclude them using
+#   a SymbolTransform.  (SymbolStrategyRules cannot be used as
+#   they are applied too late).
+ctx.exclude_vendor_branches = False
+
 # How to convert CVS author names, log messages, and filenames to
 # Unicode.  The first argument to CVSTextDecoder is a list of encoders
 # that are tried in order in 'strict' mode until one of them succeeds.
diff -uprN --exclude=.svn -x cvs2svn-tmp -x '*.pyc' cvs2svn-trunk-noop/cvs2hg-example.options cvs2svn-trunk-exclude-vendor/cvs2hg-example.options
--- cvs2svn-trunk-noop/cvs2hg-example.options	2010-03-05 13:28:13.000000000 +0000
+++ cvs2svn-trunk-exclude-vendor/cvs2hg-example.options	2010-03-05 17:25:46.000000000 +0000
@@ -143,6 +143,16 @@ ctx.revision_reader = None
 # should be omitted from the conversion):
 ctx.trunk_only = False
 
+# Change the following line to True if the conversion should exclude
+# all vendor branches.  Notes:
+# - You cannot do this if you have a branch that branches from a
+#   vendor branch _after_ the trunk and vendor branch have diverged.
+# - If you have any tags on a vendor branch _after_ the trunk and
+#   vendor branch have diverged, then you must exclude them using
+#   a SymbolTransform.  (SymbolStrategyRules cannot be used as
+#   they are applied too late).
+ctx.exclude_vendor_branches = False
+
 # How to convert CVS author names, log messages, and filenames to
 # Unicode.  The first argument to CVSTextDecoder is a list of encoders
 # that are tried in order in 'strict' mode until one of them succeeds.
diff -uprN --exclude=.svn -x cvs2svn-tmp -x '*.pyc' cvs2svn-trunk-noop/cvs2svn-example.options cvs2svn-trunk-exclude-vendor/cvs2svn-example.options
--- cvs2svn-trunk-noop/cvs2svn-example.options	2010-03-05 13:27:53.000000000 +0000
+++ cvs2svn-trunk-exclude-vendor/cvs2svn-example.options	2010-03-05 17:25:51.000000000 +0000
@@ -230,6 +230,16 @@ ctx.svnadmin_executable = r'svnadmin'
 # should be ignored):
 ctx.trunk_only = False
 
+# Change the following line to True if the conversion should exclude
+# all vendor branches.  Notes:
+# - You cannot do this if you have a branch that branches from a
+#   vendor branch _after_ the trunk and vendor branch have diverged.
+# - If you have any tags on a vendor branch _after_ the trunk and
+#   vendor branch have diverged, then you must exclude them using
+#   a SymbolTransform.  (SymbolStrategyRules cannot be used as
+#   they are applied too late).
+ctx.exclude_vendor_branches = False
+
 # Normally, cvs2svn ignores directories within the CVS repository if
 # they do not contain valid RCS files.  This produces a Subversion
 # repository whose behavior imitates that of CVS if CVS is typically
diff -uprN --exclude=.svn -x cvs2svn-tmp -x '*.pyc' cvs2svn-trunk-noop/cvs2svn_lib/collect_data.py cvs2svn-trunk-exclude-vendor/cvs2svn_lib/collect_data.py
--- cvs2svn-trunk-noop/cvs2svn_lib/collect_data.py	2010-03-05 13:17:03.000000000 +0000
+++ cvs2svn-trunk-exclude-vendor/cvs2svn_lib/collect_data.py	2010-03-05 17:55:34.000000000 +0000
@@ -1137,6 +1137,11 @@ class CollectData:
       cvs_file_items.exclude_non_trunk()
       cvs_file_items.check_link_consistency()
 
+    # If asked, exclude vendor branches.
+    if Ctx().exclude_vendor_branches and not Ctx().trunk_only:
+      cvs_file_items.exclude_vendor_branch()
+      cvs_file_items.check_link_consistency()
+
     self.add_cvs_file_items(cvs_file_items)
     self.symbol_stats.register(cvs_file_items)
 
diff -uprN --exclude=.svn -x cvs2svn-tmp -x '*.pyc' cvs2svn-trunk-noop/cvs2svn_lib/context.py cvs2svn-trunk-exclude-vendor/cvs2svn_lib/context.py
--- cvs2svn-trunk-noop/cvs2svn_lib/context.py	2010-03-05 13:17:37.000000000 +0000
+++ cvs2svn-trunk-exclude-vendor/cvs2svn_lib/context.py	2010-03-05 17:55:34.000000000 +0000
@@ -47,6 +47,7 @@ class Ctx:
     self.revision_reader = None
     self.svnadmin_executable = config.SVNADMIN_EXECUTABLE
     self.trunk_only = False
+    self.exclude_vendor_branches = False
     self.remove_noop_revisions = False
     self.include_empty_directories = False
     self.prune = True
diff -uprN --exclude=.svn -x cvs2svn-tmp -x '*.pyc' cvs2svn-trunk-noop/cvs2svn_lib/cvs_file_items.py cvs2svn-trunk-exclude-vendor/cvs2svn_lib/cvs_file_items.py
--- cvs2svn-trunk-noop/cvs2svn_lib/cvs_file_items.py	2010-03-05 15:00:41.000000000 +0000
+++ cvs2svn-trunk-exclude-vendor/cvs2svn_lib/cvs_file_items.py	2010-03-05 18:16:43.000000000 +0000
@@ -983,6 +983,33 @@ class CVSFileItems(object):
     if ntdbr_excluded:
       self.graft_ntdbr_to_trunk()
 
+  def exclude_vendor_branch(self):
+    """Delete the vendor branch (if present), grafting it
+    onto the trunk.
+
+    This does not work if there were any imports to the vendor branch
+    after the file was modified on trunk, AND that version of the
+    vendor branch was EITHER branched from OR tagged with a
+    non-excluded tag.
+    """
+
+    ntdbr_excluded = False
+    for lod_items in self.iter_lods():
+      if (not isinstance(lod_items.lod, Trunk) and \
+          lod_items.cvs_revisions and \
+          lod_items.cvs_revisions[0].ntdbr):
+        # A symbol can only be excluded if no other symbols spring
+        # from it.
+        blockers = list(lod_items.iter_blockers())
+        if blockers:
+            raise RuntimeError('Cannot exclude vendor branch %r in %r as it is needed by these symbols: %r'
+                               % (lod_items.lod, self.cvs_file.filename, blockers))
+
+        ntdbr_excluded |= self._exclude_branch(lod_items)
+
+    if ntdbr_excluded:
+      self.graft_ntdbr_to_trunk()
+
   def filter_excluded_symbols(self):
     """Delete any excluded symbols and references to them."""
 
diff -uprN --exclude=.svn -x cvs2svn-tmp -x '*.pyc' cvs2svn-trunk-noop/cvs2svn_lib/run_options.py cvs2svn-trunk-exclude-vendor/cvs2svn_lib/run_options.py
--- cvs2svn-trunk-noop/cvs2svn_lib/run_options.py	2010-03-05 13:26:55.000000000 +0000
+++ cvs2svn-trunk-exclude-vendor/cvs2svn_lib/run_options.py	2010-03-05 17:55:34.000000000 +0000
@@ -489,6 +489,16 @@ class RunOptions(object):
             ),
         metavar='REGEXP',
         ))
+    group.add_option(ContextOption(
+        '--exclude-vendor-branches',
+        action='store_true',
+        help=(
+            'exclude all vendor branches'
+            ),
+        man_help=(
+            'exclude all vendor branches'
+            ),
+        ))
     self.parser.set_default('keep_trivial_imports', False)
     group.add_option(IncompatibleOption(
         '--keep-trivial-imports',