Exemplo n.º 1
0
  def __init__(self, *args, **kwargs):
    # Override some default values
    ctx = Ctx()
    ctx.username = "******"
    ctx.symbol_commit_message = (
      "artificial changeset to create "
      "%(symbol_type)s '%(symbol_name)s'")
    ctx.post_commit_message = (
      "artificial changeset: compensate for changes in %(revnum)s "
      "(on non-trunk default branch in CVS)")

    super(HgRunOptions, self).__init__(*args, **kwargs)
Exemplo n.º 2
0
    def process_remaining_options(self):
        """Process the options that are not compatible with --options."""

        # Convenience var, so we don't have to keep instantiating this Borg.
        ctx = Ctx()

        target = None
        existing_svnrepos = False
        fs_type = None
        bdb_txn_nosync = False
        dump_only = False
        dumpfile = None
        use_rcs = False
        use_cvs = False
        use_internal_co = False
        symbol_strategy_default = 'heuristic'
        mime_types_file = None
        auto_props_file = None
        auto_props_ignore_case = True
        eol_from_mime_type = False
        default_eol = None
        keywords_off = False
        co_executable = config.CO_EXECUTABLE
        cvs_executable = config.CVS_EXECUTABLE
        trunk_base = config.DEFAULT_TRUNK_BASE
        branches_base = config.DEFAULT_BRANCHES_BASE
        tags_base = config.DEFAULT_TAGS_BASE
        encodings = ['ascii']
        fallback_encoding = None
        force_branch = False
        force_tag = False
        symbol_transforms = []
        symbol_strategy_rules = []

        for opt, value in self.opts:
            if opt in ['-s', '--svnrepos']:
                target = value
            elif opt == '--existing-svnrepos':
                existing_svnrepos = True
            elif opt == '--dumpfile':
                dumpfile = value
            elif opt == '--use-rcs':
                use_rcs = True
            elif opt == '--use-cvs':
                use_cvs = True
            elif opt == '--use-internal-co':
                use_internal_co = True
            elif opt == '--trunk-only':
                ctx.trunk_only = True
            elif opt == '--trunk':
                trunk_base = value
            elif opt == '--branches':
                branches_base = value
            elif opt == '--tags':
                tags_base = value
            elif opt == '--no-prune':
                ctx.prune = False
            elif opt == '--encoding':
                encodings.insert(-1, value)
            elif opt == '--fallback-encoding':
                fallback_encoding = value
            elif opt == '--symbol-hints':
                symbol_strategy_rules.append(SymbolHintsFileRule(value))
            elif opt == '--force-branch':
                symbol_strategy_rules.append(
                    ForceBranchRegexpStrategyRule(value))
                force_branch = True
            elif opt == '--force-tag':
                symbol_strategy_rules.append(ForceTagRegexpStrategyRule(value))
                force_tag = True
            elif opt == '--exclude':
                symbol_strategy_rules.append(ExcludeRegexpStrategyRule(value))
            elif opt == '--symbol-default':
                if value not in ['branch', 'tag', 'heuristic', 'strict']:
                    raise FatalError(
                        '%r is not a valid option for --symbol_default.' %
                        (value, ))
                symbol_strategy_default = value
            elif opt == '--no-cross-branch-commits':
                ctx.cross_branch_commits = False
            elif opt == '--retain-conflicting-attic-files':
                ctx.retain_conflicting_attic_files = True
            elif opt == '--symbol-transform':
                [pattern, replacement] = value.split(":")
                try:
                    symbol_transforms.append(
                        RegexpSymbolTransform(pattern, replacement))
                except re.error:
                    raise FatalError("'%s' is not a valid regexp." %
                                     (pattern, ))
            elif opt == '--username':
                ctx.username = value
            elif opt == '--fs-type':
                fs_type = value
            elif opt == '--bdb-txn-nosync':
                bdb_txn_nosync = True
            elif opt == '--cvs-revnums':
                ctx.svn_property_setters.append(CVSRevisionNumberSetter())
            elif opt == '--mime-types':
                mime_types_file = value
            elif opt == '--auto-props':
                auto_props_file = value
            elif opt == '--auto-props-ignore-case':
                # "ignore case" is now the default, so this option doesn't
                # affect anything.
                auto_props_ignore_case = True
            elif opt == '--eol-from-mime-type':
                eol_from_mime_type = True
            elif opt == '--default-eol':
                try:
                    # Check that value is valid, and translate it to the proper case
                    default_eol = {
                        'binary': None,
                        'native': 'native',
                        'crlf': 'CRLF',
                        'lf': 'LF',
                        'cr': 'CR',
                    }[value.lower()]
                except KeyError:
                    raise FatalError(
                        'Illegal value specified for --default-eol: %s' %
                        (value, ))
            elif opt == '--no-default-eol':
                # For backwards compatibility:
                default_eol = None
            elif opt == '--keywords-off':
                keywords_off = True
            elif opt == '--tmpdir':
                ctx.tmpdir = value
            elif opt == '--write-symbol-info':
                ctx.symbol_info_filename = value
            elif opt == '--skip-cleanup':
                ctx.skip_cleanup = True
            elif opt == '--svnadmin':
                ctx.svnadmin_executable = value
            elif opt == '--co':
                co_executable = value
            elif opt == '--cvs':
                cvs_executable = value
            elif opt == '--sort':
                ctx.sort_executable = value
            elif opt == '--dump-only':
                dump_only = True
                Log().error(
                    warning_prefix +
                    ': The --dump-only option is deprecated (it is implied\n'
                    'by --dumpfile).\n')
            elif opt == '--create':
                Log().error(
                    warning_prefix +
                    ': The behaviour produced by the --create option is now the '
                    'default,\nand passing the option is deprecated.\n')

        # Consistency check for options and arguments.
        if len(self.args) == 0:
            self.usage()
            sys.exit(1)

        if len(self.args) > 1:
            Log().error(error_prefix +
                        ": must pass only one CVS repository.\n")
            self.usage()
            sys.exit(1)

        cvsroot = self.args[0]

        if dump_only and not dumpfile:
            raise FatalError(
                "'--dump-only' requires '--dumpfile' to be specified.")

        if (not target) and (not dumpfile) and (not ctx.dry_run):
            raise FatalError("must pass one of '-s' or '--dumpfile'.")

        def not_both(opt1val, opt1name, opt2val, opt2name):
            if opt1val and opt2val:
                raise FatalError("cannot pass both '%s' and '%s'." % (
                    opt1name,
                    opt2name,
                ))

        not_both(target, '-s', dumpfile, '--dumpfile')

        not_both(dumpfile, '--dumpfile', existing_svnrepos,
                 '--existing-svnrepos')

        not_both(bdb_txn_nosync, '--bdb-txn-nosync', existing_svnrepos,
                 '--existing-svnrepos')

        not_both(dumpfile, '--dumpfile', bdb_txn_nosync, '--bdb-txn-nosync')

        not_both(fs_type, '--fs-type', existing_svnrepos,
                 '--existing-svnrepos')

        not_both(use_rcs, '--use-rcs', use_cvs, '--use-cvs')

        not_both(use_rcs, '--use-rcs', use_internal_co, '--use-internal-co')

        not_both(use_cvs, '--use-cvs', use_internal_co, '--use-internal-co')

        not_both(ctx.trunk_only, '--trunk-only', force_branch,
                 '--force-branch')

        not_both(ctx.trunk_only, '--trunk-only', force_tag, '--force-tag')

        if fs_type and fs_type != 'bdb' and bdb_txn_nosync:
            raise FatalError(
                "cannot pass --bdb-txn-nosync with --fs-type=%s." % fs_type)

        if target:
            if existing_svnrepos:
                ctx.output_option = ExistingRepositoryOutputOption(target)
            else:
                ctx.output_option = NewRepositoryOutputOption(
                    target, fs_type=fs_type, bdb_txn_nosync=bdb_txn_nosync)
        else:
            ctx.output_option = DumpfileOutputOption(dumpfile)

        if use_rcs:
            ctx.revision_recorder = NullRevisionRecorder()
            ctx.revision_excluder = NullRevisionExcluder()
            ctx.revision_reader = RCSRevisionReader(co_executable)
        elif use_cvs:
            ctx.revision_recorder = NullRevisionRecorder()
            ctx.revision_excluder = NullRevisionExcluder()
            ctx.revision_reader = CVSRevisionReader(cvs_executable)
        else:
            # --use-internal-co is the default:
            ctx.revision_recorder = InternalRevisionRecorder(compress=True)
            ctx.revision_excluder = InternalRevisionExcluder()
            ctx.revision_reader = InternalRevisionReader(compress=True)

        try:
            ctx.cvs_author_decoder = CVSTextDecoder(encodings,
                                                    fallback_encoding)
            ctx.cvs_log_decoder = CVSTextDecoder(encodings, fallback_encoding)
            # Don't use fallback_encoding for filenames:
            ctx.cvs_filename_decoder = CVSTextDecoder(encodings)
        except LookupError, e:
            raise FatalError(str(e))
Exemplo n.º 3
0
  def process_remaining_options(self):
    """Process the options that are not compatible with --options."""

    # Convenience var, so we don't have to keep instantiating this Borg.
    ctx = Ctx()

    target = None
    existing_svnrepos = False
    fs_type = None
    bdb_txn_nosync = False
    dump_only = False
    dumpfile = None
    use_rcs = False
    use_cvs = False
    use_internal_co = False
    symbol_strategy_default = 'heuristic'
    mime_types_file = None
    auto_props_file = None
    auto_props_ignore_case = True
    eol_from_mime_type = False
    default_eol = None
    keywords_off = False
    co_executable = config.CO_EXECUTABLE
    cvs_executable = config.CVS_EXECUTABLE
    trunk_base = config.DEFAULT_TRUNK_BASE
    branches_base = config.DEFAULT_BRANCHES_BASE
    tags_base = config.DEFAULT_TAGS_BASE
    encodings = ['ascii']
    fallback_encoding = None
    force_branch = False
    force_tag = False
    symbol_transforms = []
    symbol_strategy_rules = []

    for opt, value in self.opts:
      if opt  in ['-s', '--svnrepos']:
        target = value
      elif opt == '--existing-svnrepos':
        existing_svnrepos = True
      elif opt == '--dumpfile':
        dumpfile = value
      elif opt == '--use-rcs':
        use_rcs = True
      elif opt == '--use-cvs':
        use_cvs = True
      elif opt == '--use-internal-co':
        use_internal_co = True
      elif opt == '--trunk-only':
        ctx.trunk_only = True
      elif opt == '--trunk':
        trunk_base = value
      elif opt == '--branches':
        branches_base = value
      elif opt == '--tags':
        tags_base = value
      elif opt == '--no-prune':
        ctx.prune = False
      elif opt == '--encoding':
        encodings.insert(-1, value)
      elif opt == '--fallback-encoding':
        fallback_encoding = value
      elif opt == '--symbol-hints':
        symbol_strategy_rules.append(SymbolHintsFileRule(value))
      elif opt == '--force-branch':
        symbol_strategy_rules.append(ForceBranchRegexpStrategyRule(value))
        force_branch = True
      elif opt == '--force-tag':
        symbol_strategy_rules.append(ForceTagRegexpStrategyRule(value))
        force_tag = True
      elif opt == '--exclude':
        symbol_strategy_rules.append(ExcludeRegexpStrategyRule(value))
      elif opt == '--symbol-default':
        if value not in ['branch', 'tag', 'heuristic', 'strict']:
          raise FatalError(
              '%r is not a valid option for --symbol_default.' % (value,))
        symbol_strategy_default = value
      elif opt == '--no-cross-branch-commits':
        ctx.cross_branch_commits = False
      elif opt == '--retain-conflicting-attic-files':
        ctx.retain_conflicting_attic_files = True
      elif opt == '--symbol-transform':
        [pattern, replacement] = value.split(":")
        try:
          symbol_transforms.append(
              RegexpSymbolTransform(pattern, replacement))
        except re.error:
          raise FatalError("'%s' is not a valid regexp." % (pattern,))
      elif opt == '--username':
        ctx.username = value
      elif opt == '--fs-type':
        fs_type = value
      elif opt == '--bdb-txn-nosync':
        bdb_txn_nosync = True
      elif opt == '--cvs-revnums':
        ctx.svn_property_setters.append(CVSRevisionNumberSetter())
      elif opt == '--mime-types':
        mime_types_file = value
      elif opt == '--auto-props':
        auto_props_file = value
      elif opt == '--auto-props-ignore-case':
        # "ignore case" is now the default, so this option doesn't
        # affect anything.
        auto_props_ignore_case = True
      elif opt == '--eol-from-mime-type':
        eol_from_mime_type = True
      elif opt == '--default-eol':
        try:
          # Check that value is valid, and translate it to the proper case
          default_eol = {
              'binary' : None, 'native' : 'native',
              'crlf' : 'CRLF', 'lf' : 'LF', 'cr' : 'CR',
              }[value.lower()]
        except KeyError:
          raise FatalError(
              'Illegal value specified for --default-eol: %s' % (value,)
              )
      elif opt == '--no-default-eol':
        # For backwards compatibility:
        default_eol = None
      elif opt == '--keywords-off':
        keywords_off = True
      elif opt == '--tmpdir':
        ctx.tmpdir = value
      elif opt == '--write-symbol-info':
        ctx.symbol_info_filename = value
      elif opt == '--skip-cleanup':
        ctx.skip_cleanup = True
      elif opt == '--svnadmin':
        ctx.svnadmin_executable = value
      elif opt == '--co':
        co_executable = value
      elif opt == '--cvs':
        cvs_executable = value
      elif opt == '--sort':
        ctx.sort_executable = value
      elif opt == '--dump-only':
        dump_only = True
        Log().error(
            warning_prefix +
            ': The --dump-only option is deprecated (it is implied\n'
            'by --dumpfile).\n'
            )
      elif opt == '--create':
        Log().error(
            warning_prefix +
            ': The behaviour produced by the --create option is now the '
            'default,\nand passing the option is deprecated.\n'
            )

    # Consistency check for options and arguments.
    if len(self.args) == 0:
      self.usage()
      sys.exit(1)

    if len(self.args) > 1:
      Log().error(error_prefix + ": must pass only one CVS repository.\n")
      self.usage()
      sys.exit(1)

    cvsroot = self.args[0]

    if dump_only and not dumpfile:
      raise FatalError("'--dump-only' requires '--dumpfile' to be specified.")

    if (not target) and (not dumpfile) and (not ctx.dry_run):
      raise FatalError("must pass one of '-s' or '--dumpfile'.")

    def not_both(opt1val, opt1name, opt2val, opt2name):
      if opt1val and opt2val:
        raise FatalError("cannot pass both '%s' and '%s'."
                         % (opt1name, opt2name,))

    not_both(target, '-s',
             dumpfile, '--dumpfile')

    not_both(dumpfile, '--dumpfile',
             existing_svnrepos, '--existing-svnrepos')

    not_both(bdb_txn_nosync, '--bdb-txn-nosync',
             existing_svnrepos, '--existing-svnrepos')

    not_both(dumpfile, '--dumpfile',
             bdb_txn_nosync, '--bdb-txn-nosync')

    not_both(fs_type, '--fs-type',
             existing_svnrepos, '--existing-svnrepos')

    not_both(use_rcs, '--use-rcs',
             use_cvs, '--use-cvs')

    not_both(use_rcs, '--use-rcs',
             use_internal_co, '--use-internal-co')

    not_both(use_cvs, '--use-cvs',
             use_internal_co, '--use-internal-co')

    not_both(ctx.trunk_only, '--trunk-only',
             force_branch, '--force-branch')

    not_both(ctx.trunk_only, '--trunk-only',
             force_tag, '--force-tag')

    if fs_type and fs_type != 'bdb' and bdb_txn_nosync:
      raise FatalError("cannot pass --bdb-txn-nosync with --fs-type=%s."
                       % fs_type)

    if target:
      if existing_svnrepos:
        ctx.output_option = ExistingRepositoryOutputOption(target)
      else:
        ctx.output_option = NewRepositoryOutputOption(
            target, fs_type=fs_type, bdb_txn_nosync=bdb_txn_nosync)
    else:
      ctx.output_option = DumpfileOutputOption(dumpfile)

    if use_rcs:
      ctx.revision_recorder = NullRevisionRecorder()
      ctx.revision_excluder = NullRevisionExcluder()
      ctx.revision_reader = RCSRevisionReader(co_executable)
    elif use_cvs:
      ctx.revision_recorder = NullRevisionRecorder()
      ctx.revision_excluder = NullRevisionExcluder()
      ctx.revision_reader = CVSRevisionReader(cvs_executable)
    else:
      # --use-internal-co is the default:
      ctx.revision_recorder = InternalRevisionRecorder(compress=True)
      ctx.revision_excluder = InternalRevisionExcluder()
      ctx.revision_reader = InternalRevisionReader(compress=True)

    try:
      ctx.cvs_author_decoder = CVSTextDecoder(encodings, fallback_encoding)
      ctx.cvs_log_decoder = CVSTextDecoder(encodings, fallback_encoding)
      # Don't use fallback_encoding for filenames:
      ctx.cvs_filename_decoder = CVSTextDecoder(encodings)
    except LookupError, e:
      raise FatalError(str(e))