~ubuntu-branches/debian/sid/loggerhead/sid

« back to all changes in this revision

Viewing changes to loggerhead/history.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2011-06-02 14:11:55 UTC
  • mto: (13.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: james.westby@ubuntu.com-20110602141155-1pya25vmwztblmbq
Tags: upstream-1.18.1+bzr447
ImportĀ upstreamĀ versionĀ 1.18.1+bzr447

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Copyright (C) 2008, 2009 Canonical Ltd.
 
1
# Copyright (C) 2006-2011 Canonical Ltd.
3
2
#                     (Authored by Martin Albisetti <argentina@gmail.com>)
4
3
# Copyright (C) 2006  Robey Pointer <robey@lag.net>
5
4
# Copyright (C) 2006  Goffredo Baroncelli <kreijack@inwind.it>
35
34
import textwrap
36
35
import threading
37
36
 
 
37
from bzrlib import tag
38
38
import bzrlib.branch
39
39
import bzrlib.delta
40
40
import bzrlib.errors
327
327
        revid in revid_list.
328
328
        """
329
329
        if revid_list is None:
330
 
            revid_list = [r[0][1] for r in self._rev_info]
 
330
            # Just yield the mainline, starting at start_revid
 
331
            revid = start_revid
 
332
            is_null = bzrlib.revision.is_null
 
333
            while not is_null(revid):
 
334
                yield revid
 
335
                parents = self._rev_info[self._rev_indices[revid]][2]
 
336
                if not parents:
 
337
                    return
 
338
                revid = parents[0]
 
339
            return
331
340
        revid_set = set(revid_list)
332
341
        revid = start_revid
333
342
 
340
349
                r.add(self._rev_info[i][0][1])
341
350
                i += 1
342
351
            return r
343
 
        while True:
 
352
        while revid_set:
344
353
            if bzrlib.revision.is_null(revid):
345
354
                return
346
 
            if introduced_revisions(revid) & revid_set:
 
355
            rev_introduced = introduced_revisions(revid)
 
356
            matching = rev_introduced.intersection(revid_set)
 
357
            if matching:
 
358
                # We don't need to look for these anymore.
 
359
                revid_set.difference_update(matching)
347
360
                yield revid
348
361
            parents = self._rev_info[self._rev_indices[revid]][2]
349
362
            if len(parents) == 0:
464
477
        if revid is None:
465
478
            revid = self.last_revid
466
479
        if file_id is not None:
467
 
            # since revid is 'start_revid', possibly should start the path
468
 
            # tracing from revid... FIXME
469
 
            revlist = list(self.get_short_revision_history_by_fileid(file_id))
470
 
            revlist = list(self.get_revids_from(revlist, revid))
 
480
            revlist = list(
 
481
                self.get_short_revision_history_by_fileid(file_id))
 
482
            revlist = self.get_revids_from(revlist, revid)
471
483
        else:
472
 
            revlist = list(self.get_revids_from(None, revid))
 
484
            revlist = self.get_revids_from(None, revid)
473
485
        return revlist
474
486
 
475
 
    def get_view(self, revid, start_revid, file_id, query=None):
 
487
    @staticmethod
 
488
    def _iterate_sufficiently(iterable, stop_at, extra_rev_count):
 
489
        """Return a list of iterable.
 
490
 
 
491
        If extra_rev_count is None, fully consume iterable.
 
492
        Otherwise, stop at 'stop_at' + extra_rev_count.
 
493
 
 
494
        Example:
 
495
          iterate until you find stop_at, then iterate 10 more times.
 
496
        """
 
497
        if extra_rev_count is None:
 
498
            return list(iterable)
 
499
        result = []
 
500
        found = False
 
501
        for n in iterable:
 
502
            result.append(n)
 
503
            if n == stop_at:
 
504
                found = True
 
505
                break
 
506
        if found:
 
507
            for count, n in enumerate(iterable):
 
508
                if count >= extra_rev_count:
 
509
                    break
 
510
                result.append(n)
 
511
        return result
 
512
 
 
513
    def get_view(self, revid, start_revid, file_id, query=None,
 
514
                 extra_rev_count=None):
476
515
        """
477
516
        use the URL parameters (revid, start_revid, file_id, and query) to
478
517
        determine the revision list we're viewing (start_revid, file_id, query)
483
522
              file.
484
523
            - if a start_revid is given, we're viewing the branch from a
485
524
              specific revision up the tree.
 
525
            - if extra_rev_count is given, find the view from start_revid =>
 
526
              revid, and continue an additional 'extra_rev_count'. If not
 
527
              given, then revid_list will contain the full history of
 
528
              start_revid
486
529
 
487
530
        these may be combined to view revisions for a specific file, from
488
531
        a specific revision, with a specific search query.
501
544
 
502
545
        if query is None:
503
546
            revid_list = self.get_file_view(start_revid, file_id)
 
547
            revid_list = self._iterate_sufficiently(revid_list, revid,
 
548
                                                    extra_rev_count)
504
549
            if revid is None:
505
550
                revid = start_revid
506
551
            if revid not in revid_list:
507
552
                # if the given revid is not in the revlist, use a revlist that
508
553
                # starts at the given revid.
509
554
                revid_list = self.get_file_view(revid, file_id)
 
555
                revid_list = self._iterate_sufficiently(revid_list, revid,
 
556
                                                        extra_rev_count)
510
557
                start_revid = revid
511
558
            return revid, start_revid, revid_list
512
559
 
670
717
 
671
718
        revtags = None
672
719
        if revision.revision_id in self._branch_tags:
673
 
          revtags = ', '.join(self._branch_tags[revision.revision_id])
 
720
          # tag.sort_* functions expect (tag, data) pairs, so we generate them,
 
721
          # and then strip them
 
722
          tags = [(t, None) for t in self._branch_tags[revision.revision_id]]
 
723
          sort_func = getattr(tag, 'sort_natural', None)
 
724
          if sort_func is None:
 
725
              tags.sort()
 
726
          else:
 
727
              sort_func(self._branch, tags)
 
728
          revtags = u', '.join([t[0] for t in tags])
674
729
 
675
730
        entry = {
676
731
            'revid': revision.revision_id,
677
732
            'date': datetime.datetime.fromtimestamp(revision.timestamp),
678
733
            'utc_date': datetime.datetime.utcfromtimestamp(revision.timestamp),
 
734
            'committer': revision.committer,
679
735
            'authors': revision.get_apparent_authors(),
680
736
            'branch_nick': revision.properties.get('branch-nick', None),
681
737
            'short_comment': short_message,
686
742
            'tags': revtags,
687
743
        }
688
744
        if isinstance(revision, bzrlib.foreign.ForeignRevision):
689
 
            foreign_revid, mapping = (rev.foreign_revid, rev.mapping)
 
745
            foreign_revid, mapping = (
 
746
                revision.foreign_revid, revision.mapping)
690
747
        elif ":" in revision.revision_id:
691
748
            try:
692
749
                foreign_revid, mapping = \