/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: Jelmer Vernooij
  • Date: 2010-03-13 02:49:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5089.
  • Revision ID: jelmer@samba.org-20100313024914-rpuoguinoxpxt05b
Allow merge directives to output multiple patch files. 

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.
579
553
                    # may not raise _StartNotLinearAncestor for a revision that
580
554
                    # is an ancestor but not a *linear* one. But since we have
581
555
                    # loaded the graph to do the check (or calculate a dotted
582
 
                    # revno), we may as well accept to show the log...  We need
583
 
                    # the check only if start_rev_id is not None as all
584
 
                    # revisions have _mod_revision.NULL_REVISION as an ancestor
585
 
                    # -- vila 20100319
 
556
                    # revno), we may as well accept to show the log... 
 
557
                    # -- vila 100201
586
558
                    graph = branch.repository.get_graph()
587
 
                    if (start_rev_id is not None
588
 
                        and not graph.is_ancestor(start_rev_id, end_rev_id)):
 
559
                    if not graph.is_ancestor(start_rev_id, end_rev_id):
589
560
                        raise _StartNotLinearAncestor()
590
 
                    # Since we collected the revisions so far, we need to
591
 
                    # adjust end_rev_id.
592
561
                    end_rev_id = rev_id
593
562
                    break
594
563
                else:
595
564
                    initial_revisions.append((rev_id, revno, depth))
596
565
            else:
597
566
                # No merged revisions found
598
 
                return initial_revisions
 
567
                if direction == 'reverse':
 
568
                    return initial_revisions
 
569
                elif direction == 'forward':
 
570
                    return reversed(initial_revisions)
 
571
                else:
 
572
                    raise ValueError('invalid direction %r' % direction)
599
573
        except _StartNotLinearAncestor:
600
574
            # A merge was never detected so the lower revision limit can't
601
575
            # be nested down somewhere
602
576
            raise errors.BzrCommandError('Start revision not found in'
603
577
                ' history of end revision.')
604
578
 
605
 
    # We exit the loop above because we encounter a revision with merges, from
606
 
    # this revision, we need to switch to _graph_view_revisions.
607
 
 
608
579
    # A log including nested merges is required. If the direction is reverse,
609
580
    # we rebase the initial merge depths so that the development line is
610
581
    # shown naturally, i.e. just like it is for linear logging. We can easily
612
583
    # indented at the end seems slightly nicer in that case.
613
584
    view_revisions = chain(iter(initial_revisions),
614
585
        _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
 
586
        rebase_initial_depths=direction == 'reverse'))
 
587
    if direction == 'reverse':
 
588
        return view_revisions
 
589
    elif direction == 'forward':
 
590
        # Forward means oldest first, adjusting for depth.
 
591
        view_revisions = reverse_by_depth(list(view_revisions))
 
592
        return _rebase_merge_depth(view_revisions)
 
593
    else:
 
594
        raise ValueError('invalid direction %r' % direction)
618
595
 
619
596
 
620
597
def _has_merges(branch, rev_id):
678
655
 
679
656
 
680
657
def _graph_view_revisions(branch, start_rev_id, end_rev_id,
681
 
                          rebase_initial_depths=True,
682
 
                          exclude_common_ancestry=False):
 
658
    rebase_initial_depths=True):
683
659
    """Calculate revisions to view including merges, newest to oldest.
684
660
 
685
661
    :param branch: the branch
689
665
      revision is found?
690
666
    :return: An iterator of (revision_id, dotted_revno, merge_depth) tuples.
691
667
    """
692
 
    if exclude_common_ancestry:
693
 
        stop_rule = 'with-merges-without-common-ancestry'
694
 
    else:
695
 
        stop_rule = 'with-merges'
696
668
    view_revisions = branch.iter_merge_sorted_revisions(
697
669
        start_revision_id=end_rev_id, stop_revision_id=start_rev_id,
698
 
        stop_rule=stop_rule)
 
670
        stop_rule="with-merges")
699
671
    if not rebase_initial_depths:
700
672
        for (rev_id, merge_depth, revno, end_of_merge
701
673
             ) in view_revisions:
1341
1313
 
1342
1314
    def __init__(self, to_file, show_ids=False, show_timezone='original',
1343
1315
                 delta_format=None, levels=None, show_advice=False,
1344
 
                 to_exact_file=None, author_list_handler=None):
 
1316
                 to_exact_file=None):
1345
1317
        """Create a LogFormatter.
1346
1318
 
1347
1319
        :param to_file: the file to output to
1355
1327
          let the log formatter decide.
1356
1328
        :param show_advice: whether to show advice at the end of the
1357
1329
          log or not
1358
 
        :param author_list_handler: callable generating a list of
1359
 
          authors to display for a given revision
1360
1330
        """
1361
1331
        self.to_file = to_file
1362
1332
        # 'exact' stream used to show diff, it should print content 'as is'
1377
1347
        self.levels = levels
1378
1348
        self._show_advice = show_advice
1379
1349
        self._merge_count = 0
1380
 
        self._author_list_handler = author_list_handler
1381
1350
 
1382
1351
    def get_levels(self):
1383
1352
        """Get the number of levels to display or 0 for all."""
1415
1384
        return address
1416
1385
 
1417
1386
    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
 
1387
        name, address = config.parse_username(rev.get_apparent_authors()[0])
 
1388
        if name:
 
1389
            return name
 
1390
        return address
1453
1391
 
1454
1392
    def merge_marker(self, revision):
1455
1393
        """Get the merge marker to include in the output or '' if none."""
1486
1424
        """
1487
1425
        # Revision comes directly from a foreign repository
1488
1426
        if isinstance(rev, foreign.ForeignRevision):
1489
 
            return self._format_properties(
1490
 
                rev.mapping.vcs.show_foreign_revid(rev.foreign_revid))
 
1427
            return self._format_properties(rev.mapping.vcs.show_foreign_revid(rev.foreign_revid))
1491
1428
 
1492
1429
        # Imported foreign revision revision ids always contain :
1493
1430
        if not ":" in rev.revision_id:
1557
1494
        lines.extend(self.custom_properties(revision.rev))
1558
1495
 
1559
1496
        committer = revision.rev.committer
1560
 
        authors = self.authors(revision.rev, 'all')
 
1497
        authors = revision.rev.get_apparent_authors()
1561
1498
        if authors != [committer]:
1562
1499
            lines.append('author: %s' % (", ".join(authors),))
1563
1500
        lines.append('committer: %s' % (committer,))
1580
1517
        to_file = self.to_file
1581
1518
        to_file.write("%s%s\n" % (indent, ('\n' + indent).join(lines)))
1582
1519
        if revision.delta is not None:
1583
 
            # Use the standard status output to display changes
1584
 
            from bzrlib.delta import report_delta
1585
 
            report_delta(to_file, revision.delta, short_status=False, 
1586
 
                         show_ids=self.show_ids, indent=indent)
 
1520
            # We don't respect delta_format for compatibility
 
1521
            revision.delta.show(to_file, self.show_ids, indent=indent,
 
1522
                                short_status=False)
1587
1523
        if revision.diff is not None:
1588
1524
            to_file.write(indent + 'diff:\n')
1589
1525
            to_file.flush()
1652
1588
                to_file.write(indent + offset + '%s\n' % (l,))
1653
1589
 
1654
1590
        if revision.delta is not None:
1655
 
            # Use the standard status output to display changes
1656
 
            from bzrlib.delta import report_delta
1657
 
            report_delta(to_file, revision.delta, 
1658
 
                         short_status=self.delta_format==1, 
1659
 
                         show_ids=self.show_ids, indent=indent + offset)
 
1591
            revision.delta.show(to_file, self.show_ids, indent=indent + offset,
 
1592
                                short_status=self.delta_format==1)
1660
1593
        if revision.diff is not None:
1661
1594
            self.show_diff(self.to_exact_file, revision.diff, '      ')
1662
1595
        to_file.write('\n')
1737
1670
                               self.show_timezone,
1738
1671
                               date_fmt='%Y-%m-%d',
1739
1672
                               show_offset=False)
1740
 
        committer_str = self.authors(revision.rev, 'first', sep=', ')
1741
 
        committer_str = committer_str.replace(' <', '  <')
 
1673
        committer_str = revision.rev.committer.replace (' <', '  <')
1742
1674
        to_file.write('%s  %s\n\n' % (date_str,committer_str))
1743
1675
 
1744
1676
        if revision.delta is not None and revision.delta.has_changed():
1809
1741
        raise errors.BzrCommandError("unknown log formatter: %r" % name)
1810
1742
 
1811
1743
 
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
1744
def show_one_log(revno, rev, delta, verbose, to_file, show_timezone):
1841
1745
    # deprecated; for compatibility
1842
1746
    lf = LongLogFormatter(to_file=to_file, show_timezone=show_timezone)
1993
1897
        lf.log_revision(lr)
1994
1898
 
1995
1899
 
1996
 
def _get_info_for_log_files(revisionspec_list, file_list, add_cleanup):
 
1900
def _get_info_for_log_files(revisionspec_list, file_list):
1997
1901
    """Find file-ids and kinds given a list of files and a revision range.
1998
1902
 
1999
1903
    We search for files at the end of the range. If not found there,
2003
1907
    :param file_list: the list of paths given on the command line;
2004
1908
      the first of these can be a branch location or a file path,
2005
1909
      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
1910
    :return: (branch, info_list, start_rev_info, end_rev_info) where
2009
1911
      info_list is a list of (relative_path, file_id, kind) tuples where
2010
1912
      kind is one of values 'directory', 'file', 'symlink', 'tree-reference'.
2012
1914
    """
2013
1915
    from builtins import _get_revision_range, safe_relpath_files
2014
1916
    tree, b, path = bzrdir.BzrDir.open_containing_tree_or_branch(file_list[0])
2015
 
    add_cleanup(b.lock_read().unlock)
 
1917
    b.lock_read()
2016
1918
    # XXX: It's damn messy converting a list of paths to relative paths when
2017
1919
    # those paths might be deleted ones, they might be on a case-insensitive
2018
1920
    # filesystem and/or they might be in silly locations (like another branch).
2104
2006
        bug_rows = [line.split(' ', 1) for line in bug_lines]
2105
2007
        fixed_bug_urls = [row[0] for row in bug_rows if
2106
2008
                          len(row) > 1 and row[1] == 'fixed']
2107
 
 
 
2009
        
2108
2010
        if fixed_bug_urls:
2109
2011
            return {'fixes bug(s)': ' '.join(fixed_bug_urls)}
2110
2012
    return {}