/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: Martin Pool
  • Date: 2010-04-28 07:03:38 UTC
  • mfrom: (5188 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5189.
  • Revision ID: mbp@sourcefrog.net-20100428070338-2af8y3takgfkrkyp
merge news

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,
224
223
    '_match_using_deltas': True,
225
224
    }
226
225
 
227
226
 
228
227
def make_log_request_dict(direction='reverse', specific_fileids=None,
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
 
                          ):
 
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):
235
231
    """Convenience function for making a logging request dictionary.
236
232
 
237
233
    Using this function may make code slightly safer by ensuring
275
271
      algorithm used for matching specific_fileids. This parameter
276
272
      may be removed in the future so bzrlib client code should NOT
277
273
      use it.
278
 
 
279
 
    :param exclude_common_ancestry: Whether -rX..Y should be interpreted as a
280
 
      range operator or as a graph difference.
281
274
    """
282
275
    return {
283
276
        'direction': direction,
290
283
        'generate_tags': generate_tags,
291
284
        'delta_type': delta_type,
292
285
        'diff_type': diff_type,
293
 
        'exclude_common_ancestry': exclude_common_ancestry,
294
286
        # Add 'private' attributes for features that may be deprecated
295
287
        '_match_using_deltas': _match_using_deltas,
296
288
    }
467
459
            self.branch, self.start_rev_id, self.end_rev_id,
468
460
            rqst.get('direction'),
469
461
            generate_merge_revisions=generate_merge_revisions,
470
 
            delayed_graph_generation=delayed_graph_generation,
471
 
            exclude_common_ancestry=rqst.get('exclude_common_ancestry'))
 
462
            delayed_graph_generation=delayed_graph_generation)
472
463
 
473
464
        # Apply the other filters
474
465
        return make_log_rev_iterator(self.branch, view_revisions,
483
474
        rqst = self.rqst
484
475
        view_revisions = _calc_view_revisions(
485
476
            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'))
 
477
            rqst.get('direction'), generate_merge_revisions=True)
488
478
        if not isinstance(view_revisions, list):
489
479
            view_revisions = list(view_revisions)
490
480
        view_revisions = _filter_revisions_touching_file_id(self.branch,
495
485
 
496
486
 
497
487
def _calc_view_revisions(branch, start_rev_id, end_rev_id, direction,
498
 
                         generate_merge_revisions,
499
 
                         delayed_graph_generation=False,
500
 
                         exclude_common_ancestry=False,
501
 
                         ):
 
488
    generate_merge_revisions, delayed_graph_generation=False):
502
489
    """Calculate the revisions to view.
503
490
 
504
491
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples OR
505
492
             a list of the same tuples.
506
493
    """
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
494
    if direction not in ('reverse', 'forward'):
511
495
        raise ValueError('invalid direction %r' % direction)
512
496
    br_revno, br_rev_id = branch.last_revision_info()
527
511
            iter_revs = reversed(iter_revs)
528
512
    else:
529
513
        iter_revs = _generate_all_revisions(branch, start_rev_id, end_rev_id,
530
 
                                            direction, delayed_graph_generation,
531
 
                                            exclude_common_ancestry)
 
514
                                            direction, delayed_graph_generation)
532
515
        if direction == 'forward':
533
516
            iter_revs = _rebase_merge_depth(reverse_by_depth(list(iter_revs)))
534
517
    return iter_revs
559
542
 
560
543
 
561
544
def _generate_all_revisions(branch, start_rev_id, end_rev_id, direction,
562
 
                            delayed_graph_generation,
563
 
                            exclude_common_ancestry=False):
 
545
                            delayed_graph_generation):
564
546
    # On large trees, generating the merge graph can take 30-60 seconds
565
547
    # so we delay doing it until a merge is detected, incrementally
566
548
    # returning initial (non-merge) revisions while we can.
612
594
    # indented at the end seems slightly nicer in that case.
613
595
    view_revisions = chain(iter(initial_revisions),
614
596
        _graph_view_revisions(branch, start_rev_id, end_rev_id,
615
 
                              rebase_initial_depths=(direction == 'reverse'),
616
 
                              exclude_common_ancestry=exclude_common_ancestry))
 
597
                              rebase_initial_depths=(direction == 'reverse')))
617
598
    return view_revisions
618
599
 
619
600
 
678
659
 
679
660
 
680
661
def _graph_view_revisions(branch, start_rev_id, end_rev_id,
681
 
                          rebase_initial_depths=True,
682
 
                          exclude_common_ancestry=False):
 
662
                          rebase_initial_depths=True):
683
663
    """Calculate revisions to view including merges, newest to oldest.
684
664
 
685
665
    :param branch: the branch
689
669
      revision is found?
690
670
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples.
691
671
    """
692
 
    if exclude_common_ancestry:
693
 
        stop_rule = 'with-merges-without-common-ancestry'
694
 
    else:
695
 
        stop_rule = 'with-merges'
696
672
    view_revisions = branch.iter_merge_sorted_revisions(
697
673
        start_revision_id=end_rev_id, stop_revision_id=start_rev_id,
698
 
        stop_rule=stop_rule)
 
674
        stop_rule="with-merges")
699
675
    if not rebase_initial_depths:
700
676
        for (rev_id, merge_depth, revno, end_of_merge
701
677
             ) in view_revisions:
1341
1317
 
1342
1318
    def __init__(self, to_file, show_ids=False, show_timezone='original',
1343
1319
                 delta_format=None, levels=None, show_advice=False,
1344
 
                 to_exact_file=None, author_list_handler=None):
 
1320
                 to_exact_file=None):
1345
1321
        """Create a LogFormatter.
1346
1322
 
1347
1323
        :param to_file: the file to output to
1355
1331
          let the log formatter decide.
1356
1332
        :param show_advice: whether to show advice at the end of the
1357
1333
          log or not
1358
 
        :param author_list_handler: callable generating a list of
1359
 
          authors to display for a given revision
1360
1334
        """
1361
1335
        self.to_file = to_file
1362
1336
        # 'exact' stream used to show diff, it should print content 'as is'
1377
1351
        self.levels = levels
1378
1352
        self._show_advice = show_advice
1379
1353
        self._merge_count = 0
1380
 
        self._author_list_handler = author_list_handler
1381
1354
 
1382
1355
    def get_levels(self):
1383
1356
        """Get the number of levels to display or 0 for all."""
1415
1388
        return address
1416
1389
 
1417
1390
    def short_author(self, rev):
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
 
1391
        name, address = config.parse_username(rev.get_apparent_authors()[0])
 
1392
        if name:
 
1393
            return name
 
1394
        return address
1453
1395
 
1454
1396
    def merge_marker(self, revision):
1455
1397
        """Get the merge marker to include in the output or '' if none."""
1557
1499
        lines.extend(self.custom_properties(revision.rev))
1558
1500
 
1559
1501
        committer = revision.rev.committer
1560
 
        authors = self.authors(revision.rev, 'all')
 
1502
        authors = revision.rev.get_apparent_authors()
1561
1503
        if authors != [committer]:
1562
1504
            lines.append('author: %s' % (", ".join(authors),))
1563
1505
        lines.append('committer: %s' % (committer,))
1737
1679
                               self.show_timezone,
1738
1680
                               date_fmt='%Y-%m-%d',
1739
1681
                               show_offset=False)
1740
 
        committer_str = self.authors(revision.rev, 'first', sep=', ')
1741
 
        committer_str = committer_str.replace(' <', '  <')
 
1682
        committer_str = revision.rev.get_apparent_authors()[0].replace (' <', '  <')
1742
1683
        to_file.write('%s  %s\n\n' % (date_str,committer_str))
1743
1684
 
1744
1685
        if revision.delta is not None and revision.delta.has_changed():
1809
1750
        raise errors.BzrCommandError("unknown log formatter: %r" % name)
1810
1751
 
1811
1752
 
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
 
 
1840
1753
def show_one_log(revno, rev, delta, verbose, to_file, show_timezone):
1841
1754
    # deprecated; for compatibility
1842
1755
    lf = LongLogFormatter(to_file=to_file, show_timezone=show_timezone)
1993
1906
        lf.log_revision(lr)
1994
1907
 
1995
1908
 
1996
 
def _get_info_for_log_files(revisionspec_list, file_list, add_cleanup):
 
1909
def _get_info_for_log_files(revisionspec_list, file_list):
1997
1910
    """Find file-ids and kinds given a list of files and a revision range.
1998
1911
 
1999
1912
    We search for files at the end of the range. If not found there,
2003
1916
    :param file_list: the list of paths given on the command line;
2004
1917
      the first of these can be a branch location or a file path,
2005
1918
      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.
2008
1919
    :return: (branch, info_list, start_rev_info, end_rev_info) where
2009
1920
      info_list is a list of (relative_path, file_id, kind) tuples where
2010
1921
      kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
2012
1923
    """
2013
1924
    from builtins import _get_revision_range, safe_relpath_files
2014
1925
    tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
2015
 
    add_cleanup(b.lock_read().unlock)
 
1926
    b.lock_read()
2016
1927
    # XXX: It's damn messy converting a list of paths to relative paths when
2017
1928
    # those paths might be deleted ones, they might be on a case-insensitive
2018
1929
    # filesystem and/or they might be in silly locations (like another branch).