2
# Copyright (C) 2008 Canonical Ltd.
3
# (Authored by Martin Albisetti <argentina@gmail.com>)
4
2
# Copyright (C) 2006 Robey Pointer <robey@lag.net>
5
3
# Copyright (C) 2006 Goffredo Baroncelli <kreijack@inwind.it>
6
4
# Copyright (C) 2005 Jake Edge <jake@edge2.net>
93
91
out_chunk_list = []
94
92
for chunk in chunk_list:
97
94
delete_list, insert_list = [], []
98
95
for line in chunk.diff:
99
# Add <wbr/> every X characters so we can wrap properly
100
wrap_line = re.findall(r'.{%d}|.+$' % 78, line.line)
101
wrap_lines = [util.html_clean(_line) for _line in wrap_line]
102
wrapped_line = wrap_char.join(wrap_lines)
104
96
if line.type == 'context':
105
97
if len(delete_list) or len(insert_list):
106
_process_side_by_side_buffers(line_list, delete_list,
98
_process_side_by_side_buffers(line_list, delete_list, insert_list)
108
99
delete_list, insert_list = [], []
109
line_list.append(util.Container(old_lineno=line.old_lineno,
110
new_lineno=line.new_lineno,
111
old_line=wrapped_line,
112
new_line=wrapped_line,
100
line_list.append(util.Container(old_lineno=line.old_lineno, new_lineno=line.new_lineno,
101
old_line=line.line, new_line=line.line,
102
old_type=line.type, new_type=line.type))
115
103
elif line.type == 'delete':
116
delete_list.append((line.old_lineno, wrapped_line, line.type))
104
delete_list.append((line.old_lineno, line.line, line.type))
117
105
elif line.type == 'insert':
118
insert_list.append((line.new_lineno, wrapped_line, line.type))
106
insert_list.append((line.new_lineno, line.line, line.type))
119
107
if len(delete_list) or len(insert_list):
120
108
_process_side_by_side_buffers(line_list, delete_list, insert_list)
121
109
out_chunk_list.append(util.Container(diff=line_list))
199
187
"Can only construct a History object with a read-locked branch.")
200
188
self._file_change_cache = None
201
189
self._branch = branch
202
self._inventory_cache = {}
203
190
self.log = logging.getLogger('loggerhead.%s' % (branch.nick,))
205
192
self.last_revid = branch.last_revision()
213
200
self._revno_revid, self._merge_sort, self._where_merged
214
201
) = whole_history_data
217
203
def use_file_cache(self, cache):
218
204
self._file_change_cache = cache
259
245
revid = parents[0]
261
247
def get_short_revision_history_by_fileid(self, file_id):
248
# wow. is this really the only way we can get this list? by
249
# man-handling the weave store directly? :-0
262
250
# FIXME: would be awesome if we could get, for a folder, the list of
263
# revisions where items within that folder changed.i
265
# FIXME: Workaround for bzr versions prior to 1.6b3.
266
# Remove me eventually pretty please :)
267
w = self._branch.repository.weave_store.get_weave(file_id, self._branch.repository.get_transaction())
268
w_revids = w.versions()
269
revids = [r for r in self._full_history if r in w_revids]
270
except AttributeError:
271
possible_keys = [(file_id, revid) for revid in self._full_history]
272
existing_keys = self._branch.repository.texts.get_parent_map(possible_keys)
273
revids = [revid for _, revid in existing_keys.iterkeys()]
251
# revisions where items within that folder changed.
252
possible_keys = [(file_id, revid) for revid in self._full_history]
253
existing_keys = self._branch.repository.texts.get_parent_map(possible_keys)
254
return [revid for _, revid in existing_keys.iterkeys()]
276
256
def get_revision_history_since(self, revid_list, date):
277
257
# if a user asks for revisions starting at 01-sep, they mean inclusive,
342
322
if revid == 'head:':
343
323
return self.last_revid
345
if self.revno_re.match(revid):
346
revid = self._revno_revid[revid]
348
raise bzrlib.errors.NoSuchRevision(self._branch.nick, revid)
324
if self.revno_re.match(revid):
325
revid = self._revno_revid[revid]
351
328
def get_file_view(self, revid, file_id):
422
399
return None, None, []
424
401
def get_inventory(self, revid):
425
if revid not in self._inventory_cache:
426
self._inventory_cache[revid] = (
427
self._branch.repository.get_revision_inventory(revid))
428
return self._inventory_cache[revid]
402
return self._branch.repository.get_revision_inventory(revid)
430
404
def get_path(self, revid, file_id):
431
405
if (file_id is None) or (file_id == ''):
433
path = self.get_inventory(revid).id2path(file_id)
407
path = self._branch.repository.get_revision_inventory(revid).id2path(file_id)
434
408
if (len(path) > 0) and not path.startswith('/'):
435
409
path = '/' + path
438
412
def get_file_id(self, revid, path):
439
413
if (len(path) > 0) and not path.startswith('/'):
440
414
path = '/' + path
441
return self.get_inventory(revid).path2id(path)
415
return self._branch.repository.get_revision_inventory(revid).path2id(path)
443
417
def get_merge_point_list(self, revid):
567
541
trees = dict((t.get_revision_id(), t) for
568
542
t in self._branch.repository.revision_trees(required_trees))
570
for revision in revisions:
571
if not revision.parents:
572
old_tree = self._branch.repository.revision_tree(
573
bzrlib.revision.NULL_REVISION)
575
old_tree = trees[revision.parents[0].revid]
576
tree = trees[revision.revid]
577
ret.append(tree.changes_from(old_tree))
544
self._branch.repository.lock_read()
546
for revision in revisions:
547
if not revision.parents:
548
old_tree = self._branch.repository.revision_tree(
549
bzrlib.revision.NULL_REVISION)
551
old_tree = trees[revision.parents[0].revid]
552
tree = trees[revision.revid]
553
ret.append(tree.changes_from(old_tree))
556
self._branch.repository.unlock()
580
558
def _change_from_revision(self, revision):
708
686
old_lineno = lines[0]
709
687
new_lineno = lines[1]
710
688
elif line.startswith(' '):
711
chunk.diff.append(util.Container(old_lineno=old_lineno,
712
new_lineno=new_lineno,
689
chunk.diff.append(util.Container(old_lineno=old_lineno, new_lineno=new_lineno,
690
type='context', line=util.fixed_width(line[1:])))
717
693
elif line.startswith('+'):
718
chunk.diff.append(util.Container(old_lineno=None,
719
new_lineno=new_lineno,
720
type='insert', line=line[1:]))
694
chunk.diff.append(util.Container(old_lineno=None, new_lineno=new_lineno,
695
type='insert', line=util.fixed_width(line[1:])))
722
697
elif line.startswith('-'):
723
chunk.diff.append(util.Container(old_lineno=old_lineno,
725
type='delete', line=line[1:]))
698
chunk.diff.append(util.Container(old_lineno=old_lineno, new_lineno=None,
699
type='delete', line=util.fixed_width(line[1:])))
728
chunk.diff.append(util.Container(old_lineno=None,
702
chunk.diff.append(util.Container(old_lineno=None, new_lineno=None,
703
type='unknown', line=util.fixed_width(repr(line))))
732
704
if chunk is not None:
733
705
chunks.append(chunk)