RE: [PATCH] Default-exclude symbol strategy
Jon Foster <[email protected]> Mon, 29 Mar 2010 16:17:30 +0100
| Newsgroups | gmane.comp.version-control.subversion.cvs2svn.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, Michael Haggerty wrote: > Jon Foster wrote: > > When migrating a large CVS repository, there are many branches > > to consider migrating. One option is to say "we'll migrate > > everything except [some list of branches]". Cvs2svn has good > > support for that, with "--exclude" and it's options-file > > equivalents. But I want to do something a bit different - by > > default I want to exclude everything, and only include what's > > specifically asked for. > > This makes a lot of sense. > > I noticed that the code for ExcludeRemainingStrategyRule is almost > identical to that for AllBranchRule and AllTagRule, and indeed it > has a similar purpose. What do you think we derive these three > classes from a common base class like _CatchAllRule(action), where > action is one of the constructors Branch, Tag, or ExcludedSymbol > (similar to what is done for _RegexpStrategyRule and the derived > classes ForceBranchRegexpStrategyRule, ForceTagRegexpStrategyRule, > and ExcludeRegexpStrategyRule)? Can do. I also renamed the new rule to AllExcludedRule, for consistency with the exisiting AllBranchRule and AllTagRule. > It would also be logical (and trivial) to allow this option to be > selected via "--symbol-default=exclude". Yep. Having a command-line option also makes it much easier to write a test case. > Let me know if you like this idea and would like to work on a new > version of the patch (that would be great!). If not, I will commit > your patch as-is and home some day to get around to making the > suggested change myself. Updated patch is attached. 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=2466712 To unsubscribe from this discussion, e-mail: [[email protected]].
cvs2svn_symbol_strategy_exclude_2_patch.txt
(text/plain, 6 KB)
Index: cvs2svn_lib/run_options.py
===================================================================
--- cvs2svn_lib/run_options.py (revision 5089)
+++ cvs2svn_lib/run_options.py (working copy)
@@ -41,6 +41,7 @@
from cvs2svn_lib.checkout_internal import InternalRevisionCollector
from cvs2svn_lib.checkout_internal import InternalRevisionReader
from cvs2svn_lib.symbol_strategy import AllBranchRule
+from cvs2svn_lib.symbol_strategy import AllExcludedRule
from cvs2svn_lib.symbol_strategy import AllTagRule
from cvs2svn_lib.symbol_strategy import BranchIfCommitsRule
from cvs2svn_lib.symbol_strategy import ExcludeRegexpStrategyRule
@@ -426,12 +427,12 @@
self.parser.set_default('symbol_default', 'heuristic')
group.add_option(IncompatibleOption(
'--symbol-default', type='choice',
- choices=['heuristic', 'strict', 'branch', 'tag'],
+ choices=['heuristic', 'strict', 'branch', 'tag', 'exclude'],
action='store',
help=(
'specify how ambiguous symbols are converted. '
'OPT is "heuristic" (default), "strict", "branch", '
- 'or "tag"'
+ '"tag" or "exclude"'
),
man_help=(
'Specify how to convert ambiguous symbols (those that appear in '
@@ -441,8 +442,9 @@
'CVS), \'strict\' (no default; every ambiguous symbol has to be '
'resolved manually using \\fB--force-branch\\fR, '
'\\fB--force-tag\\fR, or \\fB--exclude\\fR), \'branch\' (treat '
- 'every ambiguous symbol as a branch), or \'tag\' (treat every '
- 'ambiguous symbol as a tag). The default is \'heuristic\'.'
+ 'every ambiguous symbol as a branch), \'tag\' (treat every '
+ 'ambiguous symbol as a tag), or \'exclude\' (do not convert '
+ 'ambiguous symbols). The default is \'heuristic\'.'
),
metavar='OPT',
))
@@ -1004,6 +1006,8 @@
elif options.symbol_default == 'heuristic':
options.symbol_strategy_rules.append(BranchIfCommitsRule())
options.symbol_strategy_rules.append(HeuristicStrategyRule())
+ elif options.symbol_default == 'exclude':
+ options.symbol_strategy_rules.append(AllExcludedRule())
else:
assert False
Index: cvs2svn_lib/symbol_strategy.py
===================================================================
--- cvs2svn_lib/symbol_strategy.py (revision 5089)
+++ cvs2svn_lib/symbol_strategy.py (working copy)
@@ -257,25 +257,45 @@
return Branch(symbol)
-class AllBranchRule(StrategyRule):
- """Convert all symbols as branches.
+class _CatchAllRule(StrategyRule):
+ """Base class for catch-all rules.
Usually this rule will appear after a list of more careful rules
(including a general rule like UnambiguousUsageRule) and will
therefore only apply to the symbols not handled earlier."""
+ def __init__(self, action):
+ self._action = action
+
+ def log(self, symbol):
+ raise NotImplementedError()
+
def get_symbol(self, symbol, stats):
if isinstance(symbol, (Trunk, TypedSymbol)):
return symbol
else:
- Log().verbose(
- 'Converting symbol %s as a branch because no other rules applied.'
- % (symbol,)
- )
- return Branch(symbol)
+ self.log(symbol)
+ return self._action(symbol)
-class AllTagRule(StrategyRule):
+class AllBranchRule(_CatchAllRule):
+ """Convert all symbols as branches.
+
+ Usually this rule will appear after a list of more careful rules
+ (including a general rule like UnambiguousUsageRule) and will
+ therefore only apply to the symbols not handled earlier."""
+
+ def __init__(self):
+ _CatchAllRule.__init__(self, Branch)
+
+ def log(self, symbol):
+ Log().verbose(
+ 'Converting symbol %s as a branch because no other rules applied.'
+ % (symbol,)
+ )
+
+
+class AllTagRule(_CatchAllRule):
"""Convert all symbols as tags.
We don't worry about conflicts here; they will be caught later by
@@ -285,17 +305,32 @@
(including a general rule like UnambiguousUsageRule) and will
therefore only apply to the symbols not handled earlier."""
- def get_symbol(self, symbol, stats):
- if isinstance(symbol, (Trunk, TypedSymbol)):
- return symbol
- else:
- Log().verbose(
- 'Converting symbol %s as a tag because no other rules applied.'
- % (symbol,)
- )
- return Tag(symbol)
+ def __init__(self):
+ _CatchAllRule.__init__(self, Tag)
+ def log(self, symbol):
+ Log().verbose(
+ 'Converting symbol %s as a tag because no other rules applied.'
+ % (symbol,)
+ )
+
+class AllExcludedRule(_CatchAllRule):
+ """Exclude all symbols.
+
+ Usually this rule will appear after a list of more careful rules
+ (including a SymbolHintsFileRule or several ManualSymbolRules)
+ and will therefore only apply to the symbols not handled earlier."""
+
+ def __init__(self):
+ _CatchAllRule.__init__(self, ExcludedSymbol)
+
+ def log(self, symbol):
+ Log().verbose(
+ 'Excluding symbol %s by catch-all rule.' % (symbol,)
+ )
+
+
class TrunkPathRule(StrategyRule):
"""Set the base path for Trunk."""
Index: run-tests.py
===================================================================
--- run-tests.py (revision 5089)
+++ run-tests.py (working copy)
@@ -3826,6 +3826,20 @@
))
+@Cvs2SvnTestFunction
+def exclude_symbol_default():
+ "test 'exclude' symbol default"
+
+ conv = ensure_conversion(
+ 'symbol-mess', args=['--symbol-default=exclude'])
+ if conv.path_exists('tags', 'MOSTLY_BRANCH') \
+ or conv.path_exists('branches', 'MOSTLY_BRANCH'):
+ raise Failure()
+ if conv.path_exists('tags', 'MOSTLY_TAG') \
+ or conv.path_exists('branches', 'MOSTLY_TAG'):
+ raise Failure()
+
+
########################################################################
# Run the tests
@@ -4030,6 +4044,7 @@
include_empty_directories,
# 170:
include_empty_directories_no_prune,
+ exclude_symbol_default,
]
if __name__ == '__main__':