/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-04-09 03:58:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5146.
  • Revision ID: robertc@robertcollins.net-20100409035814-eqayfeknoncyoctr
``bzrlib.commands.Command.run_direct`` is no longer needed - the pre
2.1 method of calling run() to perform testing or direct use via the API
is now possible again. As part of this, the _operation attribute on
Command is now transient and only exists for the duration of ``run()``.
(Robert Collins)

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
    }
463
455
        generate_merge_revisions = rqst.get('levels') != 1
464
456
        delayed_graph_generation = not rqst.get('specific_fileids') and (
465
457
                rqst.get('limit') or self.start_rev_id or self.end_rev_id)
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'))
 
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)
472
461
 
473
462
        # Apply the other filters
474
463
        return make_log_rev_iterator(self.branch, view_revisions,
481
470
        # Note that we always generate the merge revisions because
482
471
        # filter_revisions_touching_file_id() requires them ...
483
472
        rqst = self.rqst
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'))
 
473
        view_revisions = _calc_view_revisions(self.branch, self.start_rev_id,
 
474
            self.end_rev_id, rqst.get('direction'), True)
488
475
        if not isinstance(view_revisions, list):
489
476
            view_revisions = list(view_revisions)
490
477
        view_revisions = _filter_revisions_touching_file_id(self.branch,
495
482
 
496
483
 
497
484
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
 
                         ):
 
485
    generate_merge_revisions, delayed_graph_generation=False):
502
486
    """Calculate the revisions to view.
503
487
 
504
488
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples OR
505
489
             a list of the same tuples.
506
490
    """
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)
512
491
    br_revno, br_rev_id = branch.last_revision_info()
513
492
    if br_revno == 0:
514
493
        return []
515
494
 
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)
 
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)
528
505
    else:
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
 
506
        return _generate_all_revisions(branch, start_rev_id, end_rev_id,
 
507
            direction, delayed_graph_generation)
535
508
 
536
509
 
537
510
def _generate_one_revision(branch, rev_id, br_rev_id, br_revno):
555
528
        except _StartNotLinearAncestor:
556
529
            raise errors.BzrCommandError('Start revision not found in'
557
530
                ' left-hand history of end revision.')
 
531
    if direction == 'forward':
 
532
        result = reversed(result)
558
533
    return result
559
534
 
560
535
 
561
536
def _generate_all_revisions(branch, start_rev_id, end_rev_id, direction,
562
 
                            delayed_graph_generation,
563
 
                            exclude_common_ancestry=False):
 
537
                            delayed_graph_generation):
564
538
    # On large trees, generating the merge graph can take 30-60 seconds
565
539
    # so we delay doing it until a merge is detected, incrementally
566
540
    # returning initial (non-merge) revisions while we can.
595
569
                    initial_revisions.append((rev_id, revno, depth))
596
570
            else:
597
571
                # No merged revisions found
598
 
                return initial_revisions
 
572
                if direction == 'reverse':
 
573
                    return initial_revisions
 
574
                elif direction == 'forward':
 
575
                    return reversed(initial_revisions)
 
576
                else:
 
577
                    raise ValueError('invalid direction %r' % direction)
599
578
        except _StartNotLinearAncestor:
600
579
            # A merge was never detected so the lower revision limit can't
601
580
            # be nested down somewhere
612
591
    # indented at the end seems slightly nicer in that case.
613
592
    view_revisions = chain(iter(initial_revisions),
614
593
        _graph_view_revisions(branch, start_rev_id, end_rev_id,
615
 
                              rebase_initial_depths=(direction == 'reverse'),
616
 
                              exclude_common_ancestry=exclude_common_ancestry))
617
 
    return view_revisions
 
594
                              rebase_initial_depths=(direction == 'reverse')))
 
595
    if direction == 'reverse':
 
596
        return view_revisions
 
597
    elif direction == 'forward':
 
598
        # Forward means oldest first, adjusting for depth.
 
599
        view_revisions = reverse_by_depth(list(view_revisions))
 
600
        return _rebase_merge_depth(view_revisions)
 
601
    else:
 
602
        raise ValueError('invalid direction %r' % direction)
618
603
 
619
604
 
620
605
def _has_merges(branch, rev_id):
678
663
 
679
664
 
680
665
def _graph_view_revisions(branch, start_rev_id, end_rev_id,
681
 
                          rebase_initial_depths=True,
682
 
                          exclude_common_ancestry=False):
 
666
                          rebase_initial_depths=True):
683
667
    """Calculate revisions to view including merges, newest to oldest.
684
668
 
685
669
    :param branch: the branch
689
673
      revision is found?
690
674
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples.
691
675
    """
692
 
    if exclude_common_ancestry:
693
 
        stop_rule = 'with-merges-without-common-ancestry'
694
 
    else:
695
 
        stop_rule = 'with-merges'
696
676
    view_revisions = branch.iter_merge_sorted_revisions(
697
677
        start_revision_id=end_rev_id, stop_revision_id=start_rev_id,
698
 
        stop_rule=stop_rule)
 
678
        stop_rule="with-merges")
699
679
    if not rebase_initial_depths:
700
680
        for (rev_id, merge_depth, revno, end_of_merge
701
681
             ) in view_revisions:
1341
1321
 
1342
1322
    def __init__(self, to_file, show_ids=False, show_timezone='original',
1343
1323
                 delta_format=None, levels=None, show_advice=False,
1344
 
                 to_exact_file=None, author_list_handler=None):
 
1324
                 to_exact_file=None):
1345
1325
        """Create a LogFormatter.
1346
1326
 
1347
1327
        :param to_file: the file to output to
1355
1335
          let the log formatter decide.
1356
1336
        :param show_advice: whether to show advice at the end of the
1357
1337
          log or not
1358
 
        :param author_list_handler: callable generating a list of
1359
 
          authors to display for a given revision
1360
1338
        """
1361
1339
        self.to_file = to_file
1362
1340
        # 'exact' stream used to show diff, it should print content 'as is'
1377
1355
        self.levels = levels
1378
1356
        self._show_advice = show_advice
1379
1357
        self._merge_count = 0
1380
 
        self._author_list_handler = author_list_handler
1381
1358
 
1382
1359
    def get_levels(self):
1383
1360
        """Get the number of levels to display or 0 for all."""
1415
1392
        return address
1416
1393
 
1417
1394
    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
 
1395
        name, address = config.parse_username(rev.get_apparent_authors()[0])
 
1396
        if name:
 
1397
            return name
 
1398
        return address
1453
1399
 
1454
1400
    def merge_marker(self, revision):
1455
1401
        """Get the merge marker to include in the output or '' if none."""
1557
1503
        lines.extend(self.custom_properties(revision.rev))
1558
1504
 
1559
1505
        committer = revision.rev.committer
1560
 
        authors = self.authors(revision.rev, 'all')
 
1506
        authors = revision.rev.get_apparent_authors()
1561
1507
        if authors != [committer]:
1562
1508
            lines.append('author: %s' % (", ".join(authors),))
1563
1509
        lines.append('committer: %s' % (committer,))
1737
1683
                               self.show_timezone,
1738
1684
                               date_fmt='%Y-%m-%d',
1739
1685
                               show_offset=False)
1740
 
        committer_str = self.authors(revision.rev, 'first', sep=', ')
1741
 
        committer_str = committer_str.replace(' <', '  <')
 
1686
        committer_str = revision.rev.get_apparent_authors()[0].replace (' <', '  <')
1742
1687
        to_file.write('%s  %s\n\n' % (date_str,committer_str))
1743
1688
 
1744
1689
        if revision.delta is not None and revision.delta.has_changed():
1809
1754
        raise errors.BzrCommandError("unknown log formatter: %r" % name)
1810
1755
 
1811
1756
 
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
1757
def show_one_log(revno, rev, delta, verbose, to_file, show_timezone):
1841
1758
    # deprecated; for compatibility
1842
1759
    lf = LongLogFormatter(to_file=to_file, show_timezone=show_timezone)
1993
1910
        lf.log_revision(lr)
1994
1911
 
1995
1912
 
1996
 
def _get_info_for_log_files(revisionspec_list, file_list, add_cleanup):
 
1913
def _get_info_for_log_files(revisionspec_list, file_list):
1997
1914
    """Find file-ids and kinds given a list of files and a revision range.
1998
1915
 
1999
1916
    We search for files at the end of the range. If not found there,
2003
1920
    :param file_list: the list of paths given on the command line;
2004
1921
      the first of these can be a branch location or a file path,
2005
1922
      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
1923
    :return: (branch, info_list, start_rev_info, end_rev_info) where
2009
1924
      info_list is a list of (relative_path, file_id, kind) tuples where
2010
1925
      kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
2012
1927
    """
2013
1928
    from builtins import _get_revision_range, safe_relpath_files
2014
1929
    tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
2015
 
    add_cleanup(b.lock_read().unlock)
 
1930
    b.lock_read()
2016
1931
    # XXX: It's damn messy converting a list of paths to relative paths when
2017
1932
    # those paths might be deleted ones, they might be on a case-insensitive
2018
1933
    # filesystem and/or they might be in silly locations (like another branch).