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 |
"""Import command classes."""
|
|
18 |
||
19 |
||
20 |
# Lists of command names
|
|
21 |
COMMAND_NAMES = ['blob', 'checkpoint', 'commit', 'progress', 'reset', 'tag'] |
|
|
0.64.19
by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format |
22 |
FILE_COMMAND_NAMES = ['filemodify', 'filedelete', 'filecopy', 'filerename', |
23 |
'filedeleteall'] |
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
24 |
|
|
0.64.2
by Ian Clatworthy
use Bazaar file kinds |
25 |
# Bazaar file kinds
|
26 |
FILE_KIND = 'file' |
|
27 |
SYMLINK_KIND = 'symlink' |
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
28 |
|
29 |
||
30 |
class ImportCommand(object): |
|
31 |
"""Base class for import commands.""" |
|
32 |
||
33 |
def __init__(self, name): |
|
34 |
self.name = name |
|
|
0.64.9
by Ian Clatworthy
dump parameter for info processor |
35 |
# List of field names not to display
|
36 |
self._binary = [] |
|
37 |
||
|
0.64.19
by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format |
38 |
def dump_str(self, names=None, child_lists=None, verbose=False): |
39 |
"""Dump fields as a string. |
|
40 |
||
41 |
:param names: the list of fields to include or
|
|
42 |
None for all public fields
|
|
43 |
:param child_lists: dictionary of child command names to
|
|
44 |
fields for that child command to include
|
|
45 |
:param verbose: if True, prefix each line with the command class and
|
|
46 |
display fields as a dictionary; if False, dump just the field
|
|
47 |
values with tabs between them
|
|
48 |
"""
|
|
|
0.64.9
by Ian Clatworthy
dump parameter for info processor |
49 |
interesting = {} |
|
0.64.19
by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format |
50 |
if names is None: |
51 |
fields = [k for k in self.__dict__.keys() if not k.startswith('_')] |
|
52 |
else: |
|
53 |
fields = names |
|
54 |
for field in fields: |
|
55 |
value = self.__dict__.get(field) |
|
56 |
if field in self._binary and value is not None: |
|
57 |
value = '(...)' |
|
|
0.64.9
by Ian Clatworthy
dump parameter for info processor |
58 |
interesting[field] = value |
|
0.64.19
by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format |
59 |
if verbose: |
60 |
return "%s: %s" % (self.__class__.__name__, interesting) |
|
61 |
else: |
|
|
0.64.112
by Ian Clatworthy
fix unicode-related exception in fast-import-query |
62 |
return "\t".join([repr(interesting[k]) for k in fields]) |
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
63 |
|
64 |
||
65 |
class BlobCommand(ImportCommand): |
|
66 |
||
|
0.64.35
by Ian Clatworthy
identify unmarked blobs and commits by line numbers |
67 |
def __init__(self, mark, data, lineno=0): |
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
68 |
ImportCommand.__init__(self, 'blob') |
69 |
self.mark = mark |
|
70 |
self.data = data |
|
|
0.64.35
by Ian Clatworthy
identify unmarked blobs and commits by line numbers |
71 |
self.lineno = lineno |
72 |
# Provide a unique id in case the mark is missing
|
|
73 |
if mark is None: |
|
74 |
self.id = '@%d' % lineno |
|
75 |
else: |
|
76 |
self.id = ':' + mark |
|
|
0.64.9
by Ian Clatworthy
dump parameter for info processor |
77 |
self._binary = ['data'] |
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
78 |
|
|
0.77.2
by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings |
79 |
def __repr__(self): |
80 |
if self.mark is None: |
|
81 |
mark_line = "" |
|
82 |
else: |
|
83 |
mark_line = "\nmark :%s" % self.mark |
|
84 |
return "blob%s\ndata %d\n%s" % (mark_line, len(self.data), self.data) |
|
85 |
||
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
86 |
|
87 |
class CheckpointCommand(ImportCommand): |
|
88 |
||
89 |
def __init__(self): |
|
90 |
ImportCommand.__init__(self, 'checkpoint') |
|
91 |
||
|
0.77.2
by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings |
92 |
def __repr__(self): |
93 |
return "checkpoint" |
|
94 |
||
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
95 |
|
96 |
class CommitCommand(ImportCommand): |
|
97 |
||
|
0.64.60
by Ian Clatworthy
support merges when from clause implicit |
98 |
def __init__(self, ref, mark, author, committer, message, from_, |
99 |
merges, file_iter, lineno=0): |
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
100 |
ImportCommand.__init__(self, 'commit') |
101 |
self.ref = ref |
|
102 |
self.mark = mark |
|
103 |
self.author = author |
|
104 |
self.committer = committer |
|
105 |
self.message = message |
|
|
0.64.60
by Ian Clatworthy
support merges when from clause implicit |
106 |
self.from_ = from_ |
107 |
self.merges = merges |
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
108 |
self.file_iter = file_iter |
|
0.64.35
by Ian Clatworthy
identify unmarked blobs and commits by line numbers |
109 |
self.lineno = lineno |
|
0.64.9
by Ian Clatworthy
dump parameter for info processor |
110 |
self._binary = ['file_iter'] |
|
0.64.35
by Ian Clatworthy
identify unmarked blobs and commits by line numbers |
111 |
# Provide a unique id in case the mark is missing
|
112 |
if mark is None: |
|
113 |
self.id = '@%d' % lineno |
|
114 |
else: |
|
115 |
self.id = ':' + mark |
|
|
0.64.9
by Ian Clatworthy
dump parameter for info processor |
116 |
|
|
0.77.2
by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings |
117 |
def __repr__(self): |
118 |
if self.mark is None: |
|
119 |
mark_line = "" |
|
120 |
else: |
|
121 |
mark_line = "\nmark :%s" % self.mark |
|
122 |
if self.author is None: |
|
123 |
author_line = "" |
|
124 |
else: |
|
125 |
author_line = "\nauthor %s" % _format_who_when(self.author) |
|
126 |
committer = "committer %s" % _format_who_when(self.committer) |
|
127 |
if self.message is None: |
|
128 |
msg = "" |
|
129 |
else: |
|
130 |
msg = "\ndata %d\n%s" % (len(self.message), self.message) |
|
131 |
if self.from_ is None: |
|
132 |
from_line = "" |
|
133 |
else: |
|
134 |
from_line = "\nfrom :%s" % self.from_ |
|
135 |
if self.merges is None: |
|
136 |
merge_lines = "" |
|
137 |
else: |
|
138 |
merge_lines = "\n" + "\n".join(["merge :%s" % m |
|
139 |
for m in self.merges]) |
|
140 |
if self.file_iter is None: |
|
141 |
filecommands = "" |
|
142 |
else: |
|
143 |
filecommands = "\n" + "\n".join([repr(c) |
|
144 |
for c in self.file_iter]) |
|
145 |
return "commit %s%s%s\n%s%s%s%s%s" % (self.ref, mark_line, author_line, |
|
146 |
committer, msg, from_line, merge_lines, filecommands) |
|
147 |
||
|
0.64.19
by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format |
148 |
def dump_str(self, names=None, child_lists=None, verbose=False): |
149 |
result = [ImportCommand.dump_str(self, names, verbose=verbose)] |
|
|
0.64.9
by Ian Clatworthy
dump parameter for info processor |
150 |
for f in self.file_iter(): |
|
0.64.19
by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format |
151 |
if child_lists is None: |
152 |
continue
|
|
153 |
try: |
|
154 |
child_names = child_lists[f.name] |
|
155 |
except KeyError: |
|
156 |
continue
|
|
157 |
result.append("\t%s" % f.dump_str(child_names, verbose=verbose)) |
|
|
0.64.9
by Ian Clatworthy
dump parameter for info processor |
158 |
return '\n'.join(result) |
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
159 |
|
160 |
||
161 |
class ProgressCommand(ImportCommand): |
|
162 |
||
163 |
def __init__(self, message): |
|
164 |
ImportCommand.__init__(self, 'progress') |
|
165 |
self.message = message |
|
166 |
||
|
0.77.2
by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings |
167 |
def __repr__(self): |
168 |
return "progress %s" % (self.message,) |
|
169 |
||
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
170 |
|
171 |
class ResetCommand(ImportCommand): |
|
172 |
||
173 |
def __init__(self, ref, from_): |
|
174 |
ImportCommand.__init__(self, 'reset') |
|
175 |
self.ref = ref |
|
176 |
self.from_ = from_ |
|
177 |
||
|
0.77.2
by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings |
178 |
def __repr__(self): |
179 |
if self.from_ is None: |
|
180 |
from_line = "" |
|
181 |
else: |
|
182 |
from_line = "\nfrom :%s" % self.from_ |
|
183 |
return "reset %s%s" % (self.ref, from_line) |
|
184 |
||
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
185 |
|
186 |
class TagCommand(ImportCommand): |
|
187 |
||
188 |
def __init__(self, id, from_, tagger, message): |
|
189 |
ImportCommand.__init__(self, 'tag') |
|
190 |
self.id = id |
|
191 |
self.from_ = from_ |
|
192 |
self.tagger = tagger |
|
193 |
self.message = message |
|
194 |
||
|
0.77.2
by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings |
195 |
def __repr__(self): |
196 |
if self.from_ is None: |
|
197 |
from_line = "" |
|
198 |
else: |
|
199 |
from_line = "\nfrom :%s" % self.from_ |
|
200 |
if self.tagger is None: |
|
201 |
tagger_line = "" |
|
202 |
else: |
|
203 |
tagger_line = "\ntagger %s" % _format_who_when(self.tagger) |
|
204 |
if self.message is None: |
|
205 |
msg = "" |
|
206 |
else: |
|
207 |
msg = "\ndata %d\n%s" % (len(self.message), self.message) |
|
208 |
return "tag %s%s%s%s" % (self.id, from_line, tagger_line, msg) |
|
209 |
||
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
210 |
|
211 |
class FileCommand(ImportCommand): |
|
212 |
"""Base class for file commands.""" |
|
213 |
pass
|
|
214 |
||
215 |
||
216 |
class FileModifyCommand(FileCommand): |
|
217 |
||
218 |
def __init__(self, path, kind, is_executable, dataref, data): |
|
219 |
# Either dataref or data should be null
|
|
|
0.64.19
by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format |
220 |
FileCommand.__init__(self, 'filemodify') |
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
221 |
self.path = path |
222 |
self.kind = kind |
|
223 |
self.is_executable = is_executable |
|
224 |
self.dataref = dataref |
|
225 |
self.data = data |
|
|
0.64.9
by Ian Clatworthy
dump parameter for info processor |
226 |
self._binary = ['data'] |
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
227 |
|
|
0.77.2
by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings |
228 |
def __repr__(self): |
229 |
if self.kind == 'symlink': |
|
230 |
mode = "120000" |
|
231 |
elif self.is_executable: |
|
232 |
mode = "755" |
|
233 |
else: |
|
234 |
mode = "644" |
|
235 |
if self.dataref is None: |
|
236 |
dataref = "inline" |
|
237 |
datastr = "\ndata %d\n%s" % (len(self.data), self.data) |
|
238 |
else: |
|
239 |
dataref = ":%s" % (self.dataref,) |
|
240 |
datastr = "" |
|
241 |
return "M %s %s %s%s" % (mode, dataref, self.path, datastr) |
|
242 |
||
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
243 |
|
244 |
class FileDeleteCommand(FileCommand): |
|
245 |
||
246 |
def __init__(self, path): |
|
|
0.64.19
by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format |
247 |
FileCommand.__init__(self, 'filedelete') |
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
248 |
self.path = path |
249 |
||
|
0.77.2
by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings |
250 |
def __repr__(self): |
251 |
return "D %s" % (self.path,) |
|
252 |
||
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
253 |
|
254 |
class FileCopyCommand(FileCommand): |
|
255 |
||
256 |
def __init__(self, src_path, dest_path): |
|
|
0.64.19
by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format |
257 |
FileCommand.__init__(self, 'filecopy') |
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
258 |
self.src_path = src_path |
259 |
self.dest_path = dest_path |
|
260 |
||
|
0.77.2
by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings |
261 |
def __repr__(self): |
262 |
return "C %s %s" % (_quote_path(self.src_path), self.dest_path) |
|
263 |
||
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
264 |
|
265 |
class FileRenameCommand(FileCommand): |
|
266 |
||
|
0.64.2
by Ian Clatworthy
use Bazaar file kinds |
267 |
def __init__(self, old_path, new_path): |
|
0.64.19
by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format |
268 |
FileCommand.__init__(self, 'filerename') |
|
0.64.2
by Ian Clatworthy
use Bazaar file kinds |
269 |
self.old_path = old_path |
270 |
self.new_path = new_path |
|
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
271 |
|
|
0.77.2
by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings |
272 |
def __repr__(self): |
273 |
return "R %s %s" % (_quote_path(self.old_path), self.new_path) |
|
274 |
||
|
0.64.1
by Ian Clatworthy
1st cut: gfi parser + --info processing method |
275 |
|
276 |
class FileDeleteAllCommand(FileCommand): |
|
277 |
||
|
0.64.2
by Ian Clatworthy
use Bazaar file kinds |
278 |
def __init__(self): |
|
0.64.19
by Ian Clatworthy
filtering enhancements: selected fields, filecommands, non-verbose format |
279 |
FileCommand.__init__(self, 'filedeleteall') |
|
0.77.2
by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings |
280 |
|
281 |
def __repr__(self): |
|
282 |
return "deleteall" |
|
283 |
||
284 |
||
285 |
def _quote_path(s): |
|
286 |
"""Surround a path with quotes if it contains spaces.""" |
|
287 |
if ' ' in s: |
|
288 |
return '"%s"' % (s,) |
|
289 |
else: |
|
290 |
return s |
|
291 |
||
292 |
||
293 |
def _format_who_when(fields): |
|
294 |
"""Format a tuple of name,email,secs-since-epoch,utc-offset-secs as a string.""" |
|
295 |
offset = fields[3] |
|
296 |
if offset < 0: |
|
297 |
offset_sign = '-' |
|
298 |
offset = abs(offset) |
|
299 |
else: |
|
300 |
offset_sign = '+' |
|
301 |
offset_hours = offset / 3600 |
|
302 |
offset_minutes = offset / 60 - offset_hours * 60 |
|
303 |
offset_str = "%s%02d%02d" % (offset_sign, offset_hours, offset_minutes) |
|
304 |
return "%s <%s> %d %s" % (fields[0], fields[1], fields[2], offset_str) |