[PATCH] New SymbolTransforms
Jon Foster <[email protected]> Thu, 4 Mar 2010 18:46:36 -0000
| Newsgroups | gmane.comp.version-control.subversion.cvs2svn.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi,
Here are three new SymbolTransforms I've written. I hope these are
generic and useful enough to be accepted into cvs2svn.
* SubtreeSymbolTransform
This wraps another SymbolTransform and limits it to only apply
within a certain directory. E.g.:
SubtreeSymbolTransform('myrepo/some_module',
RegexpSymbolTransform('.*-br', r'\1-branch'))
Will only do the regexp transform within the specified module.
This allows more powerful transforms than the existing
SubtreeSymbolMapper.
* IgnoreTagsExceptSpecifiedOnesSymbolTransform
Sometimes, you want to ignore most -- but not all -- CVS tags.
That's what this does. Typical usage:
IgnoreTagsExceptSpecifiedOnesSymbolTransform([
'release-52', 'release-53'])
* ExcludeBranchesSymbolTransform
I want to ignore all branches in certain modules, but keep those
branches in other modules. This class renames all branches to
"cvs2svn-excluded-br-.*", and then I can exclude those branches
later with a StrategyRule. This class can be wrapped in a
SubtreeSymbolTransform to restrict it to a single CVS module.
E.g.:
SubtreeSymbolTransform('myrepo/never_branch_module',
ExcludeBranchesSymbolTransform())
This class makes sure it doesn't exclude any tags.
I'd welcome any feedback or review of this patch.
Kind regards,
Jon
P.S. It looks like SymbolTransforms have to be defined in the
cvs2svn core - I originally tried to define these in my options.py
file, but that fails with a pickle error.
**********************************************************************
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=2455096
To unsubscribe from this discussion, e-mail: [[email protected]].
cvs2svn_symbol_transforms_patch.txt
(text/plain, 2.7 KB)
Index: cvs2svn_lib/symbol_transform.py
===================================================================
--- cvs2svn_lib/symbol_transform.py (revision 5065)
+++ cvs2svn_lib/symbol_transform.py (working copy)
@@ -234,3 +234,74 @@
return symbol_name
+class SubtreeSymbolTransform(SymbolTransform):
+ '''A wrapper around any other SymbolTransform, that limits it to a
+ specified subtree.'''
+
+ def __init__(self, cvs_path, inner_symbol_transform):
+ '''Constructor.
+ CVS_PATH is the path in the repository.
+ INNER_SYMBOL_TRANSFORM is the SymbolTransform to wrap.'''
+
+ assert type(cvs_path) == str
+ self.__subtree = os.path.normcase(os.path.normpath(cvs_path))
+ self.__inner = inner_symbol_transform
+
+ def __does_rule_apply_to(self, cvs_file):
+ cvs_path = os.path.normcase(os.path.normpath(cvs_file.filename))
+ while cvs_path != self.__subtree:
+ new_cvs_path = os.path.dirname(cvs_path)
+ if new_cvs_path == cvs_path:
+ return False
+ cvs_path = new_cvs_path
+ return True
+
+ def transform(self, cvs_file, symbol_name, revision):
+ if self.__does_rule_apply_to(cvs_file):
+ return self.__inner.transform(cvs_file, symbol_name, revision)
+ else:
+ # Rule does not apply to that path; return symbol name unaltered.
+ return symbol_name
+
+
+class IgnoreTagsExceptSpecifiedOnesSymbolTransform(SymbolTransform):
+ """Ignores tag symbols that are not in a list."""
+
+ def __init__(self, tags_to_keep):
+ """Create an SymbolTransform that ignores tag symbols that are
+ not in the tags_to_keep list.
+
+ TAGS_TO_KEEP is an iterable returning strings."""
+
+ self.__tags_to_keep = frozenset(tags_to_keep)
+ for s in self.__tags_to_keep:
+ assert type(s) == str
+
+ def transform(self, cvs_file, symbol_name, revision):
+ if revision.count('.') % 2 == 0:
+ # SymbolTransforms cannot exclude branches
+ return symbol_name
+ elif symbol_name in self.__tags_to_keep:
+ # It's a tag that was explicitly included
+ return symbol_name
+ else:
+ # It's a tag that should be excluded
+ return None
+
+
+class ExcludeBranchesSymbolTransform(SymbolTransform):
+ """Exclude all branch symbols.
+
+ Note that branches cannot really be filtered out by a
+ SymbolTransform, so they will be renamed to branches
+ of the form "cvs2svn-excluded-br-[original name]". You
+ can then exclude those branches at the SymbolStrategy stage.
+ """
+
+ def transform(self, cvs_file, symbol_name, revision):
+ if revision.count('.') % 2 != 0:
+ # Tag, leave it.
+ return symbol_name
+ else:
+ # Branch, so exclude it
+ return 'cvs2svn-excluded-br-' + symbol_name