/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: Andrew Bennetts
  • Date: 2009-01-27 05:04:43 UTC
  • mfrom: (3960 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3981.
  • Revision ID: andrew.bennetts@canonical.com-20090127050443-3yw5hhk10ss23hzu
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
251
251
            raise errors.BzrCommandError('Selected log formatter only supports'
252
252
                ' mainline revisions.')
253
253
        generate_merge_revisions = generate_single_revision
 
254
    include_merges = generate_merge_revisions or specific_fileid
254
255
    view_revs_iter = get_view_revisions(mainline_revs, rev_nos, branch,
255
 
                          direction, include_merges=generate_merge_revisions)
 
256
                          direction, include_merges=include_merges)
256
257
 
257
258
    if direction == 'reverse':
258
259
        start_rev_id, end_rev_id = end_rev_id, start_rev_id
263
264
        view_revisions = view_revisions[0:1]
264
265
    if specific_fileid:
265
266
        view_revisions = _filter_revisions_touching_file_id(branch,
266
 
                                                            specific_fileid,
267
 
                                                            view_revisions)
 
267
            specific_fileid, view_revisions,
 
268
            include_merges=generate_merge_revisions)
268
269
 
269
270
    # rebase merge_depth - unless there are no revisions or 
270
271
    # either the first or last revision have merge_depth = 0.
532
533
    return view_revisions
533
534
 
534
535
 
535
 
def _filter_revisions_touching_file_id(branch, file_id, view_revisions):
 
536
def _filter_revisions_touching_file_id(branch, file_id, view_revisions,
 
537
    include_merges=True):
536
538
    r"""Return the list of revision ids which touch a given file id.
537
539
 
538
540
    The function filters view_revisions and returns a subset.
565
567
        assumed that view_revisions is in merge_sort order (i.e. newest
566
568
        revision first ).
567
569
 
 
570
    :param include_merges: include merge revisions in the result or not
 
571
 
568
572
    :return: A list of (revision_id, dotted_revno, merge_depth) tuples.
569
573
    """
570
574
    # Lookup all possible text keys to determine which ones actually modified
604
608
            for idx in xrange(len(current_merge_stack)):
605
609
                node = current_merge_stack[idx]
606
610
                if node is not None:
607
 
                    result.append(node)
608
 
                    current_merge_stack[idx] = None
 
611
                    if include_merges or node[2] == 0:
 
612
                        result.append(node)
 
613
                        current_merge_stack[idx] = None
609
614
    return result
610
615
 
611
616
 
615
620
    :return: an iterator of (revision_id, revno, merge_depth)
616
621
    (if there is no revno for a revision, None is supplied)
617
622
    """
618
 
    if include_merges is False:
 
623
    if not include_merges:
619
624
        revision_ids = mainline_revs[1:]
620
625
        if direction == 'reverse':
621
626
            revision_ids.reverse()
825
830
class ShortLogFormatter(LogFormatter):
826
831
 
827
832
    supports_delta = True
 
833
    supports_tags = True
828
834
    supports_single_merge_revision = True
829
835
 
830
836
    def log_revision(self, revision):
832
838
        is_merge = ''
833
839
        if len(revision.rev.parent_ids) > 1:
834
840
            is_merge = ' [merge]'
835
 
        to_file.write("%5s %s\t%s%s\n" % (revision.revno,
 
841
        tags = ''
 
842
        if revision.tags:
 
843
            tags = ' {%s}' % (', '.join(revision.tags))
 
844
 
 
845
        to_file.write("%5s %s\t%s%s%s\n" % (revision.revno,
836
846
                self.short_author(revision.rev),
837
847
                format_date(revision.rev.timestamp,
838
848
                            revision.rev.timezone or 0,
839
849
                            self.show_timezone, date_fmt="%Y-%m-%d",
840
850
                            show_offset=False),
841
 
                is_merge))
 
851
                tags, is_merge))
842
852
        if self.show_ids:
843
853
            to_file.write('      revision-id:%s\n'
844
854
                          % (revision.rev.revision_id,))
857
867
 
858
868
class LineLogFormatter(LogFormatter):
859
869
 
 
870
    supports_tags = True
860
871
    supports_single_merge_revision = True
861
872
 
862
873
    def __init__(self, *args, **kwargs):
881
892
 
882
893
    def log_revision(self, revision):
883
894
        self.to_file.write(self.log_string(revision.revno, revision.rev,
884
 
                                              self._max_chars))
 
895
            self._max_chars, revision.tags))
885
896
        self.to_file.write('\n')
886
897
 
887
 
    def log_string(self, revno, rev, max_chars):
 
898
    def log_string(self, revno, rev, max_chars, tags=None):
888
899
        """Format log info into one string. Truncate tail of string
889
900
        :param  revno:      revision number or None.
890
901
                            Revision numbers counts from 1.
891
 
        :param  rev:        revision info object
 
902
        :param  rev:        revision object
892
903
        :param  max_chars:  maximum length of resulting string
 
904
        :param  tags:       list of tags or None
893
905
        :return:            formatted truncated string
894
906
        """
895
907
        out = []
898
910
            out.append("%s:" % revno)
899
911
        out.append(self.truncate(self.short_author(rev), 20))
900
912
        out.append(self.date_string(rev))
 
913
        if tags:
 
914
            tag_str = '{%s}' % (', '.join(tags))
 
915
            out.append(tag_str)
901
916
        out.append(rev.get_summary())
902
917
        return self.truncate(" ".join(out).rstrip('\n'), max_chars)
903
918
 
1010
1025
                 search=None)
1011
1026
 
1012
1027
 
 
1028
def get_history_change(old_revision_id, new_revision_id, repository):
 
1029
    """Calculate the uncommon lefthand history between two revisions.
 
1030
 
 
1031
    :param old_revision_id: The original revision id.
 
1032
    :param new_revision_id: The new revision id.
 
1033
    :param repository: The repository to use for the calculation.
 
1034
 
 
1035
    return old_history, new_history
 
1036
    """
 
1037
    old_history = []
 
1038
    old_revisions = set()
 
1039
    new_history = []
 
1040
    new_revisions = set()
 
1041
    new_iter = repository.iter_reverse_revision_history(new_revision_id)
 
1042
    old_iter = repository.iter_reverse_revision_history(old_revision_id)
 
1043
    stop_revision = None
 
1044
    do_old = True
 
1045
    do_new = True
 
1046
    while do_new or do_old:
 
1047
        if do_new:
 
1048
            try:
 
1049
                new_revision = new_iter.next()
 
1050
            except StopIteration:
 
1051
                do_new = False
 
1052
            else:
 
1053
                new_history.append(new_revision)
 
1054
                new_revisions.add(new_revision)
 
1055
                if new_revision in old_revisions:
 
1056
                    stop_revision = new_revision
 
1057
                    break
 
1058
        if do_old:
 
1059
            try:
 
1060
                old_revision = old_iter.next()
 
1061
            except StopIteration:
 
1062
                do_old = False
 
1063
            else:
 
1064
                old_history.append(old_revision)
 
1065
                old_revisions.add(old_revision)
 
1066
                if old_revision in new_revisions:
 
1067
                    stop_revision = old_revision
 
1068
                    break
 
1069
    new_history.reverse()
 
1070
    old_history.reverse()
 
1071
    if stop_revision is not None:
 
1072
        new_history = new_history[new_history.index(stop_revision) + 1:]
 
1073
        old_history = old_history[old_history.index(stop_revision) + 1:]
 
1074
    return old_history, new_history
 
1075
 
 
1076
 
 
1077
def show_branch_change(branch, output, old_revno, old_revision_id):
 
1078
    """Show the changes made to a branch.
 
1079
 
 
1080
    :param branch: The branch to show changes about.
 
1081
    :param output: A file-like object to write changes to.
 
1082
    :param old_revno: The revno of the old tip.
 
1083
    :param old_revision_id: The revision_id of the old tip.
 
1084
    """
 
1085
    new_revno, new_revision_id = branch.last_revision_info()
 
1086
    old_history, new_history = get_history_change(old_revision_id,
 
1087
                                                  new_revision_id,
 
1088
                                                  branch.repository)
 
1089
    if old_history == [] and new_history == []:
 
1090
        output.write('Nothing seems to have changed\n')
 
1091
        return
 
1092
 
 
1093
    log_format = log_formatter_registry.get_default(branch)
 
1094
    lf = log_format(show_ids=False, to_file=output, show_timezone='original')
 
1095
    if old_history != []:
 
1096
        output.write('*'*60)
 
1097
        output.write('\nRemoved Revisions:\n')
 
1098
        show_flat_log(branch.repository, old_history, old_revno, lf)
 
1099
        output.write('*'*60)
 
1100
        output.write('\n\n')
 
1101
    if new_history != []:
 
1102
        output.write('Added Revisions:\n')
 
1103
        start_revno = new_revno - len(new_history) + 1
 
1104
        show_log(branch, lf, None, verbose=False, direction='forward',
 
1105
                 start_revision=start_revno,)
 
1106
 
 
1107
 
 
1108
def show_flat_log(repository, history, last_revno, lf):
 
1109
    """Show a simple log of the specified history.
 
1110
 
 
1111
    :param repository: The repository to retrieve revisions from.
 
1112
    :param history: A list of revision_ids indicating the lefthand history.
 
1113
    :param last_revno: The revno of the last revision_id in the history.
 
1114
    :param lf: The log formatter to use.
 
1115
    """
 
1116
    start_revno = last_revno - len(history) + 1
 
1117
    revisions = repository.get_revisions(history)
 
1118
    for i, rev in enumerate(revisions):
 
1119
        lr = LogRevision(rev, i + last_revno, 0, None)
 
1120
        lf.log_revision(lr)
 
1121
 
 
1122
 
1013
1123
properties_handler_registry = registry.Registry()
1014
1124
properties_handler_registry.register_lazy("foreign",
1015
1125
                                          "bzrlib.foreign",