~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/log.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
 
18
 
 
19
17
"""Code to show logs of changes.
20
18
 
21
19
Various flavors of log can be produced:
49
47
all the changes since the previous revision that touched hello.c.
50
48
"""
51
49
 
 
50
from __future__ import absolute_import
 
51
 
52
52
import codecs
53
53
from cStringIO import StringIO
54
54
from itertools import (
65
65
lazy_import(globals(), """
66
66
 
67
67
from bzrlib import (
68
 
    bzrdir,
69
68
    config,
 
69
    controldir,
70
70
    diff,
71
71
    errors,
72
72
    foreign,
105
105
    last_ie = None
106
106
    last_path = None
107
107
    revno = 1
108
 
    for revision_id in branch.revision_history():
 
108
    graph = branch.repository.get_graph()
 
109
    history = list(graph.iter_lefthand_ancestry(branch.last_revision(),
 
110
        [_mod_revision.NULL_REVISION]))
 
111
    for revision_id in reversed(history):
109
112
        this_inv = branch.repository.get_inventory(revision_id)
110
113
        if this_inv.has_id(file_id):
111
114
            this_ie = this_inv[file_id]
135
138
        revno += 1
136
139
 
137
140
 
138
 
def _enumerate_history(branch):
139
 
    rh = []
140
 
    revno = 1
141
 
    for rev_id in branch.revision_history():
142
 
        rh.append((revno, rev_id))
143
 
        revno += 1
144
 
    return rh
145
 
 
146
 
 
147
141
def show_log(branch,
148
142
             lf,
149
143
             specific_fileid=None,
338
332
    from bzrlib import gpg
339
333
 
340
334
    gpg_strategy = gpg.GPGStrategy(None)
341
 
    result = repo.verify_revision(rev_id, gpg_strategy)
 
335
    result = repo.verify_revision_signature(rev_id, gpg_strategy)
342
336
    if result[0] == gpg.SIGNATURE_VALID:
343
 
        return "valid signature from {0}".format(result[1])
 
337
        return u"valid signature from {0}".format(result[1])
344
338
    if result[0] == gpg.SIGNATURE_KEY_MISSING:
345
339
        return "unknown key {0}".format(result[1])
346
340
    if result[0] == gpg.SIGNATURE_NOT_VALID:
577
571
        and (not generate_merge_revisions
578
572
             or not _has_merges(branch, end_rev_id))):
579
573
        # If a single revision is requested, check we can handle it
580
 
        iter_revs = _generate_one_revision(branch, end_rev_id, br_rev_id,
581
 
                                           br_revno)
582
 
    elif not generate_merge_revisions:
583
 
        # If we only want to see linear revisions, we can iterate ...
584
 
        iter_revs = _generate_flat_revisions(branch, start_rev_id, end_rev_id,
585
 
                                             direction, exclude_common_ancestry)
586
 
        if direction == 'forward':
587
 
            iter_revs = reversed(iter_revs)
588
 
    else:
589
 
        iter_revs = _generate_all_revisions(branch, start_rev_id, end_rev_id,
590
 
                                            direction, delayed_graph_generation,
591
 
                                            exclude_common_ancestry)
592
 
        if direction == 'forward':
593
 
            iter_revs = _rebase_merge_depth(reverse_by_depth(list(iter_revs)))
 
574
        return  _generate_one_revision(branch, end_rev_id, br_rev_id,
 
575
                                       br_revno)
 
576
    if not generate_merge_revisions:
 
577
        try:
 
578
            # If we only want to see linear revisions, we can iterate ...
 
579
            iter_revs = _linear_view_revisions(
 
580
                branch, start_rev_id, end_rev_id,
 
581
                exclude_common_ancestry=exclude_common_ancestry)
 
582
            # If a start limit was given and it's not obviously an
 
583
            # ancestor of the end limit, check it before outputting anything
 
584
            if (direction == 'forward'
 
585
                or (start_rev_id and not _is_obvious_ancestor(
 
586
                        branch, start_rev_id, end_rev_id))):
 
587
                    iter_revs = list(iter_revs)
 
588
            if direction == 'forward':
 
589
                iter_revs = reversed(iter_revs)
 
590
            return iter_revs
 
591
        except _StartNotLinearAncestor:
 
592
            # Switch to the slower implementation that may be able to find a
 
593
            # non-obvious ancestor out of the left-hand history.
 
594
            pass
 
595
    iter_revs = _generate_all_revisions(branch, start_rev_id, end_rev_id,
 
596
                                        direction, delayed_graph_generation,
 
597
                                        exclude_common_ancestry)
 
598
    if direction == 'forward':
 
599
        iter_revs = _rebase_merge_depth(reverse_by_depth(list(iter_revs)))
594
600
    return iter_revs
595
601
 
596
602
 
603
609
        return [(rev_id, revno_str, 0)]
604
610
 
605
611
 
606
 
def _generate_flat_revisions(branch, start_rev_id, end_rev_id, direction,
607
 
                             exclude_common_ancestry=False):
608
 
    result = _linear_view_revisions(
609
 
        branch, start_rev_id, end_rev_id,
610
 
        exclude_common_ancestry=exclude_common_ancestry)
611
 
    # If a start limit was given and it's not obviously an
612
 
    # ancestor of the end limit, check it before outputting anything
613
 
    if direction == 'forward' or (start_rev_id
614
 
        and not _is_obvious_ancestor(branch, start_rev_id, end_rev_id)):
615
 
        try:
616
 
            result = list(result)
617
 
        except _StartNotLinearAncestor:
618
 
            raise errors.BzrCommandError(gettext('Start revision not found in'
619
 
                ' left-hand history of end revision.'))
620
 
    return result
621
 
 
622
 
 
623
612
def _generate_all_revisions(branch, start_rev_id, end_rev_id, direction,
624
613
                            delayed_graph_generation,
625
614
                            exclude_common_ancestry=False):
1796
1785
        return self.get(name)(*args, **kwargs)
1797
1786
 
1798
1787
    def get_default(self, branch):
1799
 
        return self.get(branch.get_config().log_format())
 
1788
        c = branch.get_config_stack()
 
1789
        return self.get(c.get('log_format'))
1800
1790
 
1801
1791
 
1802
1792
log_formatter_registry = LogFormatterRegistry()
1803
1793
 
1804
1794
 
1805
1795
log_formatter_registry.register('short', ShortLogFormatter,
1806
 
                                'Moderately short log format')
 
1796
                                'Moderately short log format.')
1807
1797
log_formatter_registry.register('long', LongLogFormatter,
1808
 
                                'Detailed log format')
 
1798
                                'Detailed log format.')
1809
1799
log_formatter_registry.register('line', LineLogFormatter,
1810
 
                                'Log format with one line per revision')
 
1800
                                'Log format with one line per revision.')
1811
1801
log_formatter_registry.register('gnu-changelog', GnuChangelogLogFormatter,
1812
 
                                'Format used by GNU ChangeLog files')
 
1802
                                'Format used by GNU ChangeLog files.')
1813
1803
 
1814
1804
 
1815
1805
def register_formatter(name, formatter):
2024
2014
      kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
2025
2015
      branch will be read-locked.
2026
2016
    """
2027
 
    from builtins import _get_revision_range
2028
 
    tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
 
2017
    from bzrlib.builtins import _get_revision_range
 
2018
    tree, b, path = controldir.ControlDir.open_containing_tree_or_branch(
 
2019
        file_list[0])
2029
2020
    add_cleanup(b.lock_read().unlock)
2030
2021
    # XXX: It's damn messy converting a list of paths to relative paths when
2031
2022
    # those paths might be deleted ones, they might be on a case-insensitive