1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# Copyright (C) 2008 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Import processor that queries the input (and doesn't import)."""
from __future__ import print_function
from .. import (
commands,
processor,
)
class QueryProcessor(processor.ImportProcessor):
"""An import processor that queries the input.
No changes to the current repository are made.
"""
known_params = (
commands.COMMAND_NAMES +
commands.FILE_COMMAND_NAMES +
[b'commit-mark']
)
def __init__(self, params=None, verbose=False):
processor.ImportProcessor.__init__(self, params, verbose)
self.parsed_params = {}
self.interesting_commit = None
self._finished = False
if params:
if 'commit-mark' in params:
self.interesting_commit = params['commit-mark']
del params['commit-mark']
for name, value in params.items():
if value == 1:
# All fields
fields = None
else:
fields = value.split(',')
self.parsed_params[name] = fields
def pre_handler(self, cmd):
"""Hook for logic before each handler starts."""
if self._finished:
return
if self.interesting_commit and cmd.name == 'commit':
if cmd.mark == self.interesting_commit:
print(cmd.to_string())
self._finished = True
return
if cmd.name in self.parsed_params:
fields = self.parsed_params[cmd.name]
str = cmd.dump_str(fields, self.parsed_params, self.verbose)
print("%s" % (str,))
def progress_handler(self, cmd):
"""Process a ProgressCommand."""
pass
def blob_handler(self, cmd):
"""Process a BlobCommand."""
pass
def checkpoint_handler(self, cmd):
"""Process a CheckpointCommand."""
pass
def commit_handler(self, cmd):
"""Process a CommitCommand."""
pass
def reset_handler(self, cmd):
"""Process a ResetCommand."""
pass
def tag_handler(self, cmd):
"""Process a TagCommand."""
pass
def feature_handler(self, cmd):
"""Process a FeatureCommand."""
feature = cmd.feature_name
if feature not in commands.FEATURE_NAMES:
self.warning(
"feature %s is not supported - parsing may fail"
% (feature,))
|