~vmiklos/bzr-fastimport/darcs

12 by Ian Clatworthy
lightweight tags, filter processor and param validation
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
111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
17
"""Import processor that queries the input (and doesn't import)."""
12 by Ian Clatworthy
lightweight tags, filter processor and param validation
18
19
20
from bzrlib.plugins.fastimport import (
21
    commands,
22
    processor,
23
    )
24
25
111 by Ian Clatworthy
rename fast-import-filter to fast-import-query
26
class QueryProcessor(processor.ImportProcessor):
27
    """An import processor that queries the input.
12 by Ian Clatworthy
lightweight tags, filter processor and param validation
28
29
    No changes to the current repository are made.
30
    """
31
224 by Ian Clatworthy
add --commit-mark option to fast-import-query to show just one commit (without file contents)
32
    known_params = commands.COMMAND_NAMES + commands.FILE_COMMAND_NAMES + \
33
        ['commit-mark']
12 by Ian Clatworthy
lightweight tags, filter processor and param validation
34
35
    def __init__(self, target=None, params=None, verbose=False):
36
        # Allow creation without a target
37
        processor.ImportProcessor.__init__(self, target, params, verbose)
19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
38
        self.parsed_params = {}
224 by Ian Clatworthy
add --commit-mark option to fast-import-query to show just one commit (without file contents)
39
        self.interesting_commit = None
40
        self._finished = False
19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
41
        if params:
224 by Ian Clatworthy
add --commit-mark option to fast-import-query to show just one commit (without file contents)
42
            if 'commit-mark' in params:
43
                self.interesting_commit = params['commit-mark']
44
                del params['commit-mark']
19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
45
            for name, value in params.iteritems():
46
                if value == 1:
47
                    # All fields
48
                    fields = None
49
                else:
50
                    fields = value.split(',')
51
                self.parsed_params[name] = fields
12 by Ian Clatworthy
lightweight tags, filter processor and param validation
52
53
    def pre_handler(self, cmd):
54
        """Hook for logic before each handler starts."""
224 by Ian Clatworthy
add --commit-mark option to fast-import-query to show just one commit (without file contents)
55
        if self._finished:
56
            return
57
        if self.interesting_commit and cmd.name == 'commit':
58
            if cmd.mark == self.interesting_commit:
59
                print cmd.to_string()
60
                self._finished = True
61
            return
19 by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format
62
        if self.parsed_params.has_key(cmd.name):
63
            fields = self.parsed_params[cmd.name]
64
            str = cmd.dump_str(fields, self.parsed_params, self.verbose)
65
            print "%s" % (str,)
12 by Ian Clatworthy
lightweight tags, filter processor and param validation
66
67
    def progress_handler(self, cmd):
68
        """Process a ProgressCommand."""
69
        pass
70
71
    def blob_handler(self, cmd):
72
        """Process a BlobCommand."""
73
        pass
74
75
    def checkpoint_handler(self, cmd):
76
        """Process a CheckpointCommand."""
77
        pass
78
79
    def commit_handler(self, cmd):
80
        """Process a CommitCommand."""
81
        for fc in cmd.file_iter():
82
            pass
83
84
    def reset_handler(self, cmd):
85
        """Process a ResetCommand."""
86
        pass
87
88
    def tag_handler(self, cmd):
89
        """Process a TagCommand."""
90
        pass