comparison hgext3rd/fastimport/vendor/python_fastimport/processors/query_processor.py @ 86:28704a2a7461 vendor/python-fastimport

Import python-fastimport-0.9.8
author Roy Marples <roy@marples.name>
date Tue, 19 Jan 2021 22:56:34 +0000
parents
children 2fc99e3479d9
comparison
equal deleted inserted replaced
85:1f5544a8870b 86:28704a2a7461
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, see <http://www.gnu.org/licenses/>.
15
16 """Import processor that queries the input (and doesn't import)."""
17 from __future__ import print_function
18
19
20 from fastimport import (
21 commands,
22 processor,
23 )
24
25
26 class QueryProcessor(processor.ImportProcessor):
27 """An import processor that queries the input.
28
29 No changes to the current repository are made.
30 """
31
32 known_params = (
33 commands.COMMAND_NAMES +
34 commands.FILE_COMMAND_NAMES +
35 [b'commit-mark']
36 )
37
38 def __init__(self, params=None, verbose=False):
39 processor.ImportProcessor.__init__(self, params, verbose)
40 self.parsed_params = {}
41 self.interesting_commit = None
42 self._finished = False
43 if params:
44 if 'commit-mark' in params:
45 self.interesting_commit = params['commit-mark']
46 del params['commit-mark']
47 for name, value in params.items():
48 if value == 1:
49 # All fields
50 fields = None
51 else:
52 fields = value.split(',')
53 self.parsed_params[name] = fields
54
55 def pre_handler(self, cmd):
56 """Hook for logic before each handler starts."""
57 if self._finished:
58 return
59 if self.interesting_commit and cmd.name == 'commit':
60 if cmd.mark == self.interesting_commit:
61 print(cmd.to_string())
62 self._finished = True
63 return
64 if cmd.name in self.parsed_params:
65 fields = self.parsed_params[cmd.name]
66 str = cmd.dump_str(fields, self.parsed_params, self.verbose)
67 print("%s" % (str,))
68
69 def progress_handler(self, cmd):
70 """Process a ProgressCommand."""
71 pass
72
73 def blob_handler(self, cmd):
74 """Process a BlobCommand."""
75 pass
76
77 def checkpoint_handler(self, cmd):
78 """Process a CheckpointCommand."""
79 pass
80
81 def commit_handler(self, cmd):
82 """Process a CommitCommand."""
83 pass
84
85 def reset_handler(self, cmd):
86 """Process a ResetCommand."""
87 pass
88
89 def tag_handler(self, cmd):
90 """Process a TagCommand."""
91 pass
92
93 def feature_handler(self, cmd):
94 """Process a FeatureCommand."""
95 feature = cmd.feature_name
96 if feature not in commands.FEATURE_NAMES:
97 self.warning("feature %s is not supported - parsing may fail"
98 % (feature,))