~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/log.py

  • Committer: Martin
  • Date: 2010-05-16 15:18:43 UTC
  • mfrom: (5235 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5239.
  • Revision ID: gzlist@googlemail.com-20100516151843-lu53u7caehm3ie3i
Merge bzr.dev to resolve conflicts in NEWS and _chk_map_pyx

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
    }
459
467
            self.branch, self.start_rev_id, self.end_rev_id,
460
468
            rqst.get('direction'),
461
469
            generate_merge_revisions=generate_merge_revisions,
462
 
            delayed_graph_generation=delayed_graph_generation)
 
470
            delayed_graph_generation=delayed_graph_generation,
 
471
            exclude_common_ancestry=rqst.get('exclude_common_ancestry'))
463
472
 
464
473
        # Apply the other filters
465
474
        return make_log_rev_iterator(self.branch, view_revisions,
474
483
        rqst = self.rqst
475
484
        view_revisions = _calc_view_revisions(
476
485
            self.branch, self.start_rev_id, self.end_rev_id,
477
 
            rqst.get('direction'), generate_merge_revisions=True)
 
486
            rqst.get('direction'), generate_merge_revisions=True,
 
487
            exclude_common_ancestry=rqst.get('exclude_common_ancestry'))
478
488
        if not isinstance(view_revisions, list):
479
489
            view_revisions = list(view_revisions)
480
490
        view_revisions = _filter_revisions_touching_file_id(self.branch,
485
495
 
486
496
 
487
497
def _calc_view_revisions(branch, start_rev_id, end_rev_id, direction,
488
 
    generate_merge_revisions, delayed_graph_generation=False):
 
498
                         generate_merge_revisions,
 
499
                         delayed_graph_generation=False,
 
500
                         exclude_common_ancestry=False,
 
501
                         ):
489
502
    """Calculate the revisions to view.
490
503
 
491
504
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples OR
492
505
             a list of the same tuples.
493
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')
494
510
    if direction not in ('reverse', 'forward'):
495
511
        raise ValueError('invalid direction %r' % direction)
496
512
    br_revno, br_rev_id = branch.last_revision_info()
511
527
            iter_revs = reversed(iter_revs)
512
528
    else:
513
529
        iter_revs = _generate_all_revisions(branch, start_rev_id, end_rev_id,
514
 
                                            direction, delayed_graph_generation)
 
530
                                            direction, delayed_graph_generation,
 
531
                                            exclude_common_ancestry)
515
532
        if direction == 'forward':
516
533
            iter_revs = _rebase_merge_depth(reverse_by_depth(list(iter_revs)))
517
534
    return iter_revs
542
559
 
543
560
 
544
561
def _generate_all_revisions(branch, start_rev_id, end_rev_id, direction,
545
 
                            delayed_graph_generation):
 
562
                            delayed_graph_generation,
 
563
                            exclude_common_ancestry=False):
546
564
    # On large trees, generating the merge graph can take 30-60 seconds
547
565
    # so we delay doing it until a merge is detected, incrementally
548
566
    # returning initial (non-merge) revisions while we can.
594
612
    # indented at the end seems slightly nicer in that case.
595
613
    view_revisions = chain(iter(initial_revisions),
596
614
        _graph_view_revisions(branch, start_rev_id, end_rev_id,
597
 
                              rebase_initial_depths=(direction == 'reverse')))
 
615
                              rebase_initial_depths=(direction == 'reverse'),
 
616
                              exclude_common_ancestry=exclude_common_ancestry))
598
617
    return view_revisions
599
618
 
600
619
 
659
678
 
660
679
 
661
680
def _graph_view_revisions(branch, start_rev_id, end_rev_id,
662
 
                          rebase_initial_depths=True):
 
681
                          rebase_initial_depths=True,
 
682
                          exclude_common_ancestry=False):
663
683
    """Calculate revisions to view including merges, newest to oldest.
664
684
 
665
685
    :param branch: the branch
669
689
      revision is found?
670
690
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples.
671
691
    """
 
692
    if exclude_common_ancestry:
 
693
        stop_rule = 'with-merges-without-common-ancestry'
 
694
    else:
 
695
        stop_rule = 'with-merges'
672
696
    view_revisions = branch.iter_merge_sorted_revisions(
673
697
        start_revision_id=end_rev_id, stop_revision_id=start_rev_id,
674
 
        stop_rule="with-merges")
 
698
        stop_rule=stop_rule)
675
699
    if not rebase_initial_depths:
676
700
        for (rev_id, merge_depth, revno, end_of_merge
677
701
             ) in view_revisions:
1317
1341
 
1318
1342
    def __init__(self, to_file, show_ids=False, show_timezone='original',
1319
1343
                 delta_format=None, levels=None, show_advice=False,
1320
 
                 to_exact_file=None):
 
1344
                 to_exact_file=None, author_list_handler=None):
1321
1345
        """Create a LogFormatter.
1322
1346
 
1323
1347
        :param to_file: the file to output to
1331
1355
          let the log formatter decide.
1332
1356
        :param show_advice: whether to show advice at the end of the
1333
1357
          log or not
 
1358
        :param author_list_handler: callable generating a list of
 
1359
          authors to display for a given revision
1334
1360
        """
1335
1361
        self.to_file = to_file
1336
1362
        # 'exact' stream used to show diff, it should print content 'as is'
1351
1377
        self.levels = levels
1352
1378
        self._show_advice = show_advice
1353
1379
        self._merge_count = 0
 
1380
        self._author_list_handler = author_list_handler
1354
1381
 
1355
1382
    def get_levels(self):
1356
1383
        """Get the number of levels to display or 0 for all."""
1388
1415
        return address
1389
1416
 
1390
1417
    def short_author(self, rev):
1391
 
        name, address = config.parse_username(rev.get_apparent_authors()[0])
1392
 
        if name:
1393
 
            return name
1394
 
        return address
 
1418
        return self.authors(rev, 'first', short=True, sep=', ')
 
1419
 
 
1420
    def authors(self, rev, who, short=False, sep=None):
 
1421
        """Generate list of authors, taking --authors option into account.
 
1422
 
 
1423
        The caller has to specify the name of a author list handler,
 
1424
        as provided by the author list registry, using the ``who``
 
1425
        argument.  That name only sets a default, though: when the
 
1426
        user selected a different author list generation using the
 
1427
        ``--authors`` command line switch, as represented by the
 
1428
        ``author_list_handler`` constructor argument, that value takes
 
1429
        precedence.
 
1430
 
 
1431
        :param rev: The revision for which to generate the list of authors.
 
1432
        :param who: Name of the default handler.
 
1433
        :param short: Whether to shorten names to either name or address.
 
1434
        :param sep: What separator to use for automatic concatenation.
 
1435
        """
 
1436
        if self._author_list_handler is not None:
 
1437
            # The user did specify --authors, which overrides the default
 
1438
            author_list_handler = self._author_list_handler
 
1439
        else:
 
1440
            # The user didn't specify --authors, so we use the caller's default
 
1441
            author_list_handler = author_list_registry.get(who)
 
1442
        names = author_list_handler(rev)
 
1443
        if short:
 
1444
            for i in range(len(names)):
 
1445
                name, address = config.parse_username(names[i])
 
1446
                if name:
 
1447
                    names[i] = name
 
1448
                else:
 
1449
                    names[i] = address
 
1450
        if sep is not None:
 
1451
            names = sep.join(names)
 
1452
        return names
1395
1453
 
1396
1454
    def merge_marker(self, revision):
1397
1455
        """Get the merge marker to include in the output or '' if none."""
1499
1557
        lines.extend(self.custom_properties(revision.rev))
1500
1558
 
1501
1559
        committer = revision.rev.committer
1502
 
        authors = revision.rev.get_apparent_authors()
 
1560
        authors = self.authors(revision.rev, 'all')
1503
1561
        if authors != [committer]:
1504
1562
            lines.append('author: %s' % (", ".join(authors),))
1505
1563
        lines.append('committer: %s' % (committer,))
1679
1737
                               self.show_timezone,
1680
1738
                               date_fmt='%Y-%m-%d',
1681
1739
                               show_offset=False)
1682
 
        committer_str = revision.rev.get_apparent_authors()[0].replace (' <', '  <')
 
1740
        committer_str = self.authors(revision.rev, 'first', sep=', ')
 
1741
        committer_str = committer_str.replace(' <', '  <')
1683
1742
        to_file.write('%s  %s\n\n' % (date_str,committer_str))
1684
1743
 
1685
1744
        if revision.delta is not None and revision.delta.has_changed():
1750
1809
        raise errors.BzrCommandError("unknown log formatter: %r" % name)
1751
1810
 
1752
1811
 
 
1812
def author_list_all(rev):
 
1813
    return rev.get_apparent_authors()[:]
 
1814
 
 
1815
 
 
1816
def author_list_first(rev):
 
1817
    lst = rev.get_apparent_authors()
 
1818
    try:
 
1819
        return [lst[0]]
 
1820
    except IndexError:
 
1821
        return []
 
1822
 
 
1823
 
 
1824
def author_list_committer(rev):
 
1825
    return [rev.committer]
 
1826
 
 
1827
 
 
1828
author_list_registry = registry.Registry()
 
1829
 
 
1830
author_list_registry.register('all', author_list_all,
 
1831
                              'All authors')
 
1832
 
 
1833
author_list_registry.register('first', author_list_first,
 
1834
                              'The first author')
 
1835
 
 
1836
author_list_registry.register('committer', author_list_committer,
 
1837
                              'The committer')
 
1838
 
 
1839
 
1753
1840
def show_one_log(revno, rev, delta, verbose, to_file, show_timezone):
1754
1841
    # deprecated; for compatibility
1755
1842
    lf = LongLogFormatter(to_file=to_file, show_timezone=show_timezone)
1906
1993
        lf.log_revision(lr)
1907
1994
 
1908
1995
 
1909
 
def _get_info_for_log_files(revisionspec_list, file_list):
 
1996
def _get_info_for_log_files(revisionspec_list, file_list, add_cleanup):
1910
1997
    """Find file-ids and kinds given a list of files and a revision range.
1911
1998
 
1912
1999
    We search for files at the end of the range. If not found there,
1916
2003
    :param file_list: the list of paths given on the command line;
1917
2004
      the first of these can be a branch location or a file path,
1918
2005
      the remainder must be file paths
 
2006
    :param add_cleanup: When the branch returned is read locked,
 
2007
      an unlock call will be queued to the cleanup.
1919
2008
    :return: (branch, info_list, start_rev_info, end_rev_info) where
1920
2009
      info_list is a list of (relative_path, file_id, kind) tuples where
1921
2010
      kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
1923
2012
    """
1924
2013
    from builtins import _get_revision_range, safe_relpath_files
1925
2014
    tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
1926
 
    b.lock_read()
 
2015
    add_cleanup(b.lock_read().unlock)
1927
2016
    # XXX: It's damn messy converting a list of paths to relative paths when
1928
2017
    # those paths might be deleted ones, they might be on a case-insensitive
1929
2018
    # filesystem and/or they might be in silly locations (like another branch).