/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
1
# Copyright (C) 2008 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Fast, stream-based importing of data into Bazaar."""
18
19
20
from bzrlib.commands import Command, register_command
0.64.8 by Ian Clatworthy
custom parameters for processors
21
from bzrlib.option import RegistryOption, ListOption
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
22
23
24
def test_suite():
25
    import tests
26
    return tests.test_suite()
27
28
0.64.8 by Ian Clatworthy
custom parameters for processors
29
def _defines_to_dict(defines):
30
    """Convert a list of definition strings to a dictionary."""
31
    if defines is None:
32
        return None
33
    result = {}
34
    for define in defines:
35
        kv = define.split('=', 1)
36
        if len(kv) == 1:
37
            result[define.strip()] = 1
38
        else:
39
            result[kv[0].strip()] = kv[1].strip()
40
    return result
41
42
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
43
class cmd_fast_import(Command):
44
    """Backend for fast Bazaar data importers.
45
46
    This command reads a mixed command/data stream from standard
47
    input and creates branches in the current repository. It is
48
    designed to be stream compatible with git-fast-import so that
49
    existing front-ends can be reused with a minimum of modifications.
50
    Git 1.5.4 includes git-fast-export enabling conversion from git.
51
    See http://git.or.cz/gitwiki/InterfacesFrontendsAndTools for
52
    other front-ends including converters from Subversion, CVS,
53
    Mercurial, Darcs, Perforce and SCCS. See
54
    http://www.kernel.org/pub/software/scm/git/docs/git-fast-import.html
55
    for the protocol specification. See the documentation shipped
56
    with the bzr-fastimport plugin for the known limitations and
57
    Bazaar-specific enhancements.
58
59
    Examples::
60
61
     cd /git/repo/path
62
     git-fast-export --signed-tags=warn | bzr fast-import
63
64
        Import a Git repository into Bazaar.
65
66
     svn-fast-export.py /svn/repo/path | bzr fast-import
67
68
        Import a Subversion repository into Bazaar.
69
70
     hg-fast-export.py -r /hg/repo/path | bzr fast-import
71
72
        Import a Mercurial repository into Bazaar.
73
    """
74
    hidden = True
75
    takes_args = []
76
    takes_options = ['verbose',
77
                    RegistryOption.from_kwargs('method',
78
                        'The way to process the data.',
0.64.8 by Ian Clatworthy
custom parameters for processors
79
                        title='Processing Method',
80
                        value_switches=True, enum_switch=False,
81
                        safe="Import the data into any format (default).",
82
                        info="Display information only - don't import it.",
0.64.12 by Ian Clatworthy
lightweight tags, filter processor and param validation
83
                        filter="Filter commands only - don't import it.",
0.64.8 by Ian Clatworthy
custom parameters for processors
84
                        ),
85
                    ListOption('params', short_name='P', type=str,
86
                        help="Define processing specific parameters.",
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
87
                        ),
88
                     ]
89
    aliases = ['fastimport']
0.64.8 by Ian Clatworthy
custom parameters for processors
90
    def run(self, verbose=False, method='safe', params=None):
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
91
        import sys
92
        from bzrlib import bzrdir
93
        import parser
94
0.64.8 by Ian Clatworthy
custom parameters for processors
95
        params = _defines_to_dict(params)
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
96
        if method == 'info':
97
            from bzrlib.plugins.fastimport.processors import info_processor
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
98
            proc = info_processor.InfoProcessor(params=params,
99
                verbose=verbose)
0.64.12 by Ian Clatworthy
lightweight tags, filter processor and param validation
100
        elif method == 'filter':
101
            from bzrlib.plugins.fastimport.processors import filter_processor
0.64.19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
102
            proc = filter_processor.FilterProcessor(params=params,
103
                verbose=verbose)
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
104
        else:
105
            from bzrlib.plugins.fastimport.processors import generic_processor
106
            control, relpath = bzrdir.BzrDir.open_containing('.')
0.64.8 by Ian Clatworthy
custom parameters for processors
107
            proc = generic_processor.GenericProcessor(control, params=params)
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
108
109
        # Note: might need to pass the parser to the processor so that the
110
        # processor can be it's error reporting with source context
111
        p = parser.ImportParser(sys.stdin, verbose=verbose)
112
        return proc.process(p.iter_commands)
113
114
115
register_command(cmd_fast_import)