/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/log.py

  • Committer: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
    last_path = None
110
110
    revno = 1
111
111
    for revision_id in branch.revision_history():
112
 
        this_inv = branch.repository.get_revision_inventory(revision_id)
 
112
        this_inv = branch.repository.get_inventory(revision_id)
113
113
        if file_id in this_inv:
114
114
            this_ie = this_inv[file_id]
115
115
            this_path = this_inv.id2path(file_id)
220
220
    'direction': 'reverse',
221
221
    'levels': 1,
222
222
    'generate_tags': True,
 
223
    'exclude_common_ancestry': False,
223
224
    '_match_using_deltas': True,
224
225
    }
225
226
 
226
227
 
227
228
def make_log_request_dict(direction='reverse', specific_fileids=None,
228
 
    start_revision=None, end_revision=None, limit=None,
229
 
    message_search=None, levels=1, generate_tags=True, delta_type=None,
230
 
    diff_type=None, _match_using_deltas=True):
 
229
                          start_revision=None, end_revision=None, limit=None,
 
230
                          message_search=None, levels=1, generate_tags=True,
 
231
                          delta_type=None,
 
232
                          diff_type=None, _match_using_deltas=True,
 
233
                          exclude_common_ancestry=False,
 
234
                          ):
231
235
    """Convenience function for making a logging request dictionary.
232
236
 
233
237
    Using this function may make code slightly safer by ensuring
271
275
      algorithm used for matching specific_fileids. This parameter
272
276
      may be removed in the future so bzrlib client code should NOT
273
277
      use it.
 
278
 
 
279
    :param exclude_common_ancestry: Whether -rX..Y should be interpreted as a
 
280
      range operator or as a graph difference.
274
281
    """
275
282
    return {
276
283
        'direction': direction,
283
290
        'generate_tags': generate_tags,
284
291
        'delta_type': delta_type,
285
292
        'diff_type': diff_type,
 
293
        'exclude_common_ancestry': exclude_common_ancestry,
286
294
        # Add 'private' attributes for features that may be deprecated
287
295
        '_match_using_deltas': _match_using_deltas,
288
296
    }
455
463
        generate_merge_revisions = rqst.get('levels') != 1
456
464
        delayed_graph_generation = not rqst.get('specific_fileids') and (
457
465
                rqst.get('limit') or self.start_rev_id or self.end_rev_id)
458
 
        view_revisions = _calc_view_revisions(self.branch, self.start_rev_id,
459
 
            self.end_rev_id, rqst.get('direction'), generate_merge_revisions,
460
 
            delayed_graph_generation=delayed_graph_generation)
 
466
        view_revisions = _calc_view_revisions(
 
467
            self.branch, self.start_rev_id, self.end_rev_id,
 
468
            rqst.get('direction'),
 
469
            generate_merge_revisions=generate_merge_revisions,
 
470
            delayed_graph_generation=delayed_graph_generation,
 
471
            exclude_common_ancestry=rqst.get('exclude_common_ancestry'))
461
472
 
462
473
        # Apply the other filters
463
474
        return make_log_rev_iterator(self.branch, view_revisions,
470
481
        # Note that we always generate the merge revisions because
471
482
        # filter_revisions_touching_file_id() requires them ...
472
483
        rqst = self.rqst
473
 
        view_revisions = _calc_view_revisions(self.branch, self.start_rev_id,
474
 
            self.end_rev_id, rqst.get('direction'), True)
 
484
        view_revisions = _calc_view_revisions(
 
485
            self.branch, self.start_rev_id, self.end_rev_id,
 
486
            rqst.get('direction'), generate_merge_revisions=True,
 
487
            exclude_common_ancestry=rqst.get('exclude_common_ancestry'))
475
488
        if not isinstance(view_revisions, list):
476
489
            view_revisions = list(view_revisions)
477
490
        view_revisions = _filter_revisions_touching_file_id(self.branch,
482
495
 
483
496
 
484
497
def _calc_view_revisions(branch, start_rev_id, end_rev_id, direction,
485
 
    generate_merge_revisions, delayed_graph_generation=False):
 
498
                         generate_merge_revisions,
 
499
                         delayed_graph_generation=False,
 
500
                         exclude_common_ancestry=False,
 
501
                         ):
486
502
    """Calculate the revisions to view.
487
503
 
488
504
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples OR
489
505
             a list of the same tuples.
490
506
    """
 
507
    if (exclude_common_ancestry and start_rev_id == end_rev_id):
 
508
        raise errors.BzrCommandError(
 
509
            '--exclude-common-ancestry requires two different revisions')
 
510
    if direction not in ('reverse', 'forward'):
 
511
        raise ValueError('invalid direction %r' % direction)
491
512
    br_revno, br_rev_id = branch.last_revision_info()
492
513
    if br_revno == 0:
493
514
        return []
494
515
 
495
 
    # If a single revision is requested, check we can handle it
496
 
    generate_single_revision = (end_rev_id and start_rev_id == end_rev_id and
497
 
        (not generate_merge_revisions or not _has_merges(branch, end_rev_id)))
498
 
    if generate_single_revision:
499
 
        return _generate_one_revision(branch, end_rev_id, br_rev_id, br_revno)
500
 
 
501
 
    # If we only want to see linear revisions, we can iterate ...
502
 
    if not generate_merge_revisions:
503
 
        return _generate_flat_revisions(branch, start_rev_id, end_rev_id,
504
 
            direction)
 
516
    if (end_rev_id and start_rev_id == end_rev_id
 
517
        and (not generate_merge_revisions
 
518
             or not _has_merges(branch, end_rev_id))):
 
519
        # If a single revision is requested, check we can handle it
 
520
        iter_revs = _generate_one_revision(branch, end_rev_id, br_rev_id,
 
521
                                           br_revno)
 
522
    elif not generate_merge_revisions:
 
523
        # If we only want to see linear revisions, we can iterate ...
 
524
        iter_revs = _generate_flat_revisions(branch, start_rev_id, end_rev_id,
 
525
                                             direction)
 
526
        if direction == 'forward':
 
527
            iter_revs = reversed(iter_revs)
505
528
    else:
506
 
        return _generate_all_revisions(branch, start_rev_id, end_rev_id,
507
 
            direction, delayed_graph_generation)
 
529
        iter_revs = _generate_all_revisions(branch, start_rev_id, end_rev_id,
 
530
                                            direction, delayed_graph_generation,
 
531
                                            exclude_common_ancestry)
 
532
        if direction == 'forward':
 
533
            iter_revs = _rebase_merge_depth(reverse_by_depth(list(iter_revs)))
 
534
    return iter_revs
508
535
 
509
536
 
510
537
def _generate_one_revision(branch, rev_id, br_rev_id, br_revno):
528
555
        except _StartNotLinearAncestor:
529
556
            raise errors.BzrCommandError('Start revision not found in'
530
557
                ' left-hand history of end revision.')
531
 
    if direction == 'forward':
532
 
        result = reversed(result)
533
558
    return result
534
559
 
535
560
 
536
561
def _generate_all_revisions(branch, start_rev_id, end_rev_id, direction,
537
 
                            delayed_graph_generation):
 
562
                            delayed_graph_generation,
 
563
                            exclude_common_ancestry=False):
538
564
    # On large trees, generating the merge graph can take 30-60 seconds
539
565
    # so we delay doing it until a merge is detected, incrementally
540
566
    # returning initial (non-merge) revisions while we can.
553
579
                    # may not raise _StartNotLinearAncestor for a revision that
554
580
                    # is an ancestor but not a *linear* one. But since we have
555
581
                    # loaded the graph to do the check (or calculate a dotted
556
 
                    # revno), we may as well accept to show the log... 
557
 
                    # -- vila 100201
 
582
                    # revno), we may as well accept to show the log...  We need
 
583
                    # the check only if start_rev_id is not None as all
 
584
                    # revisions have _mod_revision.NULL_REVISION as an ancestor
 
585
                    # -- vila 20100319
558
586
                    graph = branch.repository.get_graph()
559
 
                    if not graph.is_ancestor(start_rev_id, end_rev_id):
 
587
                    if (start_rev_id is not None
 
588
                        and not graph.is_ancestor(start_rev_id, end_rev_id)):
560
589
                        raise _StartNotLinearAncestor()
 
590
                    # Since we collected the revisions so far, we need to
 
591
                    # adjust end_rev_id.
561
592
                    end_rev_id = rev_id
562
593
                    break
563
594
                else:
564
595
                    initial_revisions.append((rev_id, revno, depth))
565
596
            else:
566
597
                # No merged revisions found
567
 
                if direction == 'reverse':
568
 
                    return initial_revisions
569
 
                elif direction == 'forward':
570
 
                    return reversed(initial_revisions)
571
 
                else:
572
 
                    raise ValueError('invalid direction %r' % direction)
 
598
                return initial_revisions
573
599
        except _StartNotLinearAncestor:
574
600
            # A merge was never detected so the lower revision limit can't
575
601
            # be nested down somewhere
576
602
            raise errors.BzrCommandError('Start revision not found in'
577
603
                ' history of end revision.')
578
604
 
 
605
    # We exit the loop above because we encounter a revision with merges, from
 
606
    # this revision, we need to switch to _graph_view_revisions.
 
607
 
579
608
    # A log including nested merges is required. If the direction is reverse,
580
609
    # we rebase the initial merge depths so that the development line is
581
610
    # shown naturally, i.e. just like it is for linear logging. We can easily
583
612
    # indented at the end seems slightly nicer in that case.
584
613
    view_revisions = chain(iter(initial_revisions),
585
614
        _graph_view_revisions(branch, start_rev_id, end_rev_id,
586
 
        rebase_initial_depths=direction == 'reverse'))
587
 
    if direction == 'reverse':
588
 
        return view_revisions
589
 
    elif direction == 'forward':
590
 
        # Forward means oldest first, adjusting for depth.
591
 
        view_revisions = reverse_by_depth(list(view_revisions))
592
 
        return _rebase_merge_depth(view_revisions)
593
 
    else:
594
 
        raise ValueError('invalid direction %r' % direction)
 
615
                              rebase_initial_depths=(direction == 'reverse'),
 
616
                              exclude_common_ancestry=exclude_common_ancestry))
 
617
    return view_revisions
595
618
 
596
619
 
597
620
def _has_merges(branch, rev_id):
655
678
 
656
679
 
657
680
def _graph_view_revisions(branch, start_rev_id, end_rev_id,
658
 
    rebase_initial_depths=True):
 
681
                          rebase_initial_depths=True,
 
682
                          exclude_common_ancestry=False):
659
683
    """Calculate revisions to view including merges, newest to oldest.
660
684
 
661
685
    :param branch: the branch
665
689
      revision is found?
666
690
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples.
667
691
    """
 
692
    if exclude_common_ancestry:
 
693
        stop_rule = 'with-merges-without-common-ancestry'
 
694
    else:
 
695
        stop_rule = 'with-merges'
668
696
    view_revisions = branch.iter_merge_sorted_revisions(
669
697
        start_revision_id=end_rev_id, stop_revision_id=start_rev_id,
670
 
        stop_rule="with-merges")
 
698
        stop_rule=stop_rule)
671
699
    if not rebase_initial_depths:
672
700
        for (rev_id, merge_depth, revno, end_of_merge
673
701
             ) in view_revisions:
1424
1452
        """
1425
1453
        # Revision comes directly from a foreign repository
1426
1454
        if isinstance(rev, foreign.ForeignRevision):
1427
 
            return rev.mapping.vcs.show_foreign_revid(rev.foreign_revid)
 
1455
            return self._format_properties(
 
1456
                rev.mapping.vcs.show_foreign_revid(rev.foreign_revid))
1428
1457
 
1429
1458
        # Imported foreign revision revision ids always contain :
1430
1459
        if not ":" in rev.revision_id:
1517
1546
        to_file = self.to_file
1518
1547
        to_file.write("%s%s\n" % (indent, ('\n' + indent).join(lines)))
1519
1548
        if revision.delta is not None:
1520
 
            # We don't respect delta_format for compatibility
1521
 
            revision.delta.show(to_file, self.show_ids, indent=indent,
1522
 
                                short_status=False)
 
1549
            # Use the standard status output to display changes
 
1550
            from bzrlib.delta import report_delta
 
1551
            report_delta(to_file, revision.delta, short_status=False, 
 
1552
                         show_ids=self.show_ids, indent=indent)
1523
1553
        if revision.diff is not None:
1524
1554
            to_file.write(indent + 'diff:\n')
1525
1555
            to_file.flush()
1588
1618
                to_file.write(indent + offset + '%s\n' % (l,))
1589
1619
 
1590
1620
        if revision.delta is not None:
1591
 
            revision.delta.show(to_file, self.show_ids, indent=indent + offset,
1592
 
                                short_status=self.delta_format==1)
 
1621
            # Use the standard status output to display changes
 
1622
            from bzrlib.delta import report_delta
 
1623
            report_delta(to_file, revision.delta, 
 
1624
                         short_status=self.delta_format==1, 
 
1625
                         show_ids=self.show_ids, indent=indent + offset)
1593
1626
        if revision.diff is not None:
1594
1627
            self.show_diff(self.to_exact_file, revision.diff, '      ')
1595
1628
        to_file.write('\n')
1670
1703
                               self.show_timezone,
1671
1704
                               date_fmt='%Y-%m-%d',
1672
1705
                               show_offset=False)
1673
 
        committer_str = revision.rev.committer.replace (' <', '  <')
 
1706
        committer_str = revision.rev.get_apparent_authors()[0].replace (' <', '  <')
1674
1707
        to_file.write('%s  %s\n\n' % (date_str,committer_str))
1675
1708
 
1676
1709
        if revision.delta is not None and revision.delta.has_changed():
2006
2039
        bug_rows = [line.split(' ', 1) for line in bug_lines]
2007
2040
        fixed_bug_urls = [row[0] for row in bug_rows if
2008
2041
                          len(row) > 1 and row[1] == 'fixed']
2009
 
        
 
2042
 
2010
2043
        if fixed_bug_urls:
2011
2044
            return {'fixes bug(s)': ' '.join(fixed_bug_urls)}
2012
2045
    return {}