1 # (Be in -*- python -*- mode.)
3 # ====================================================================
4 # Copyright (c) 2007-2009 CollabNet. All rights reserved.
6 # This software is licensed as described in the file COPYING, which
7 # you should have received as part of this distribution. The terms
8 # are also available at http://subversion.tigris.org/license-1.html.
9 # If newer versions of this license are posted there, you may use a
10 # newer version instead, at your option.
12 # This software consists of voluntary contributions made by many
13 # individuals. For exact contribution history, see the revision
14 # history and logs, available at http://cvs2svn.tigris.org/.
15 # ====================================================================
17 """Miscellaneous utility code common to DVCS backends (like
18 Git, Mercurial, or Bazaar).
23 from cvs2svn_lib
.common
import FatalError
24 from cvs2svn_lib
.run_options
import RunOptions
25 from cvs2svn_lib
.log
import Log
26 from cvs2svn_lib
.context
import Ctx
27 from cvs2svn_lib
.project
import Project
28 from cvs2svn_lib
.output_option
import OutputOption
31 class DVCSRunOptions(RunOptions
):
32 """Dumping ground for whatever is common to GitRunOptions and
34 def __init__(self
, progname
, cmd_args
, pass_manager
):
35 Ctx().cross_project_commits
= False
36 Ctx().cross_branch_commits
= False
37 RunOptions
.__init
__(self
, progname
, cmd_args
, pass_manager
)
41 project_cvs_repos_path
,
42 symbol_transforms
=None,
43 symbol_strategy_rules
=[],
45 """Set the project to be converted.
47 If a project had already been set, overwrite it.
49 Most arguments are passed straight through to the Project
50 constructor. SYMBOL_STRATEGY_RULES is an iterable of
51 SymbolStrategyRules that will be applied to symbols in this
54 symbol_strategy_rules
= list(symbol_strategy_rules
)
58 project_cvs_repos_path
,
59 symbol_transforms
=symbol_transforms
,
62 self
.projects
= [project
]
63 self
.project_symbol_strategy_rules
= [symbol_strategy_rules
]
65 def process_options(self
):
66 # Consistency check for options and arguments.
67 if len(self
.args
) == 0:
71 if len(self
.args
) > 1:
72 Log().error(error_prefix
+ ": must pass only one CVS repository.\n")
76 cvsroot
= self
.args
[0]
78 self
.process_extraction_options()
79 self
.process_output_options()
80 self
.process_symbol_strategy_options()
81 self
.process_property_setter_options()
86 symbol_transforms
=self
.options
.symbol_transforms
,
87 symbol_strategy_rules
=self
.options
.symbol_strategy_rules
,
91 class DVCSOutputOption(OutputOption
):
92 # name of output format (for error messages); must be set by
96 def normalize_author_transforms(self
, author_transforms
):
97 """Return a new dict with the same content as author_transforms, but all
98 strings encoded to UTF-8. Also turns None into the empty dict."""
100 if author_transforms
is not None:
101 for (cvsauthor
, (name
, email
,)) in author_transforms
.iteritems():
102 cvsauthor
= to_utf8(cvsauthor
)
104 email
= to_utf8(email
)
105 result
[cvsauthor
] = (name
, email
,)
109 if Ctx().cross_project_commits
:
111 '%s output is not supported with cross-project commits' % self
.name
113 if Ctx().cross_branch_commits
:
115 '%s output is not supported with cross-branch commits' % self
.name
117 if Ctx().username
is None:
119 '%s output requires a default commit username' % self
.name
124 if isinstance(s
, unicode):
125 return s
.encode('utf8')