~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/history.py

  • Committer: John Arbash Meinel
  • Date: 2008-07-26 14:52:44 UTC
  • mto: This revision was merged to the branch mainline in revision 185.
  • Revision ID: john@arbash-meinel.com-20080726145244-l7h1ndtlu5mnm9tg
Add Copyright information to most files.

Fix the documentation for start/stop in the README.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
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:
95
93
        line_list = []
96
 
        wrap_char = '<wbr/>'
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)
103
 
 
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, 
107
 
                                                  insert_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,
113
 
                                                old_type=line.type, 
114
 
                                                new_type=line.type))
 
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,))
204
191
 
205
192
        self.last_revid = branch.last_revision()
213
200
         self._revno_revid, self._merge_sort, self._where_merged
214
201
         ) = whole_history_data
215
202
 
216
 
 
217
203
    def use_file_cache(self, cache):
218
204
        self._file_change_cache = cache
219
205
 
259
245
            revid = parents[0]
260
246
 
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
264
 
        try:
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()]
274
 
        return revids
 
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()]
275
255
 
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,
341
321
            return revid
342
322
        if revid == 'head:':
343
323
            return self.last_revid
344
 
        try:
345
 
            if self.revno_re.match(revid):
346
 
                revid = self._revno_revid[revid]
347
 
        except KeyError:
348
 
            raise bzrlib.errors.NoSuchRevision(self._branch.nick, revid)
 
324
        if self.revno_re.match(revid):
 
325
            revid = self._revno_revid[revid]
349
326
        return revid
350
327
 
351
328
    def get_file_view(self, revid, file_id):
422
399
            return None, None, []
423
400
 
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)
429
403
 
430
404
    def get_path(self, revid, file_id):
431
405
        if (file_id is None) or (file_id == ''):
432
406
            return ''
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
436
410
        return 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)
442
416
 
443
417
    def get_merge_point_list(self, revid):
444
418
        """
567
541
        trees = dict((t.get_revision_id(), t) for
568
542
                     t in self._branch.repository.revision_trees(required_trees))
569
543
        ret = []
570
 
        for revision in revisions:
571
 
            if not revision.parents:
572
 
                old_tree = self._branch.repository.revision_tree(
573
 
                    bzrlib.revision.NULL_REVISION)
574
 
            else:
575
 
                old_tree = trees[revision.parents[0].revid]
576
 
            tree = trees[revision.revid]
577
 
            ret.append(tree.changes_from(old_tree))
578
 
        return ret
 
544
        self._branch.repository.lock_read()
 
545
        try:
 
546
            for revision in revisions:
 
547
                if not revision.parents:
 
548
                    old_tree = self._branch.repository.revision_tree(
 
549
                        bzrlib.revision.NULL_REVISION)
 
550
                else:
 
551
                    old_tree = trees[revision.parents[0].revid]
 
552
                tree = trees[revision.revid]
 
553
                ret.append(tree.changes_from(old_tree))
 
554
            return ret
 
555
        finally:
 
556
            self._branch.repository.unlock()
579
557
 
580
558
    def _change_from_revision(self, revision):
581
559
        """
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,
713
 
                                                 type='context', 
714
 
                                                 line=line[1:]))
 
689
                chunk.diff.append(util.Container(old_lineno=old_lineno, new_lineno=new_lineno,
 
690
                                                 type='context', line=util.fixed_width(line[1:])))
715
691
                old_lineno += 1
716
692
                new_lineno += 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:])))
721
696
                new_lineno += 1
722
697
            elif line.startswith('-'):
723
 
                chunk.diff.append(util.Container(old_lineno=old_lineno, 
724
 
                                                 new_lineno=None,
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:])))
726
700
                old_lineno += 1
727
701
            else:
728
 
                chunk.diff.append(util.Container(old_lineno=None, 
729
 
                                                 new_lineno=None,
730
 
                                                 type='unknown', 
731
 
                                                 line=repr(line)))
 
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)
734
706
        return chunks