~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

[merge] improved 'missing' command from aaron

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
import bzrlib.trace
40
40
from bzrlib.trace import mutter, note, log_error, warning, is_quiet
41
41
from bzrlib.workingtree import WorkingTree
 
42
from bzrlib.log import show_one_log
42
43
 
43
44
 
44
45
def tree_files(file_list, default_branch=u'.'):
882
883
                            help='show from oldest to newest'),
883
884
                     'timezone', 'verbose', 
884
885
                     'show-ids', 'revision',
885
 
                     Option('line', help='format with one line per revision'),
886
 
                     'long', 
 
886
                     'line', 'long', 
887
887
                     Option('message',
888
888
                            help='show revisions whose message matches this regexp',
889
889
                            type=str),
890
 
                     Option('short', help='use moderately short format'),
 
890
                     'short',
891
891
                     ]
892
892
    @display_command
893
893
    def run(self, filename=None, timezone='original',
951
951
        # in e.g. the default C locale.
952
952
        outf = codecs.getwriter(bzrlib.user_encoding)(sys.stdout, errors='replace')
953
953
 
954
 
        log_format = 'long'
955
 
        if short:
956
 
            log_format = 'short'
957
 
        if line:
958
 
            log_format = 'line'
 
954
        log_format = get_log_format(long=long, short=short, line=line)
959
955
        lf = log_formatter(log_format,
960
956
                           show_ids=show_ids,
961
957
                           to_file=outf,
970
966
                 end_revision=rev2,
971
967
                 search=message)
972
968
 
 
969
def get_log_format(long=False, short=False, line=False, default='long'):
 
970
    log_format = default
 
971
    if long:
 
972
        log_format = 'long'
 
973
    if short:
 
974
        log_format = 'short'
 
975
    if line:
 
976
        log_format = 'line'
 
977
    return log_format
973
978
 
974
979
 
975
980
class cmd_touching_revisions(Command):
1749
1754
 
1750
1755
 
1751
1756
class cmd_missing(Command):
1752
 
    """What is missing in this branch relative to other branch.
1753
 
    """
1754
 
    # TODO: rewrite this in terms of ancestry so that it shows only
1755
 
    # unmerged things
1756
 
    
1757
 
    takes_args = ['remote?']
1758
 
    aliases = ['mis', 'miss']
1759
 
    takes_options = ['verbose']
1760
 
 
1761
 
    @display_command
1762
 
    def run(self, remote=None, verbose=False):
1763
 
        from bzrlib.errors import BzrCommandError
1764
 
        from bzrlib.missing import show_missing
1765
 
 
1766
 
        if verbose and is_quiet():
1767
 
            raise BzrCommandError('Cannot pass both quiet and verbose')
1768
 
 
1769
 
        tree = WorkingTree.open_containing(u'.')[0]
1770
 
        parent = tree.branch.get_parent()
1771
 
        if remote is None:
1772
 
            if parent is None:
 
1757
    """Show unmerged/unpulled revisions between two branches.
 
1758
 
 
1759
    OTHER_BRANCH may be local or remote."""
 
1760
    takes_args = ['other_branch?']
 
1761
    takes_options = [Option('reverse', 'Reverse the order of revisions'),
 
1762
                     Option('mine-only', 
 
1763
                            'Display changes in the local branch only'),
 
1764
                     Option('theirs-only', 
 
1765
                            'Display changes in the remote branch only'), 
 
1766
                     'line',
 
1767
                     'long', 
 
1768
                     'short',
 
1769
                     'show-ids',
 
1770
                     'verbose'
 
1771
                     ]
 
1772
 
 
1773
    def run(self, other_branch=None, reverse=False, mine_only=False,
 
1774
            theirs_only=False, long=True, short=False, line=False, 
 
1775
            show_ids=False, verbose=False):
 
1776
        from bzrlib.missing import find_unmerged, iter_log_data
 
1777
        from bzrlib.log import log_formatter
 
1778
        local_branch = bzrlib.branch.Branch.open_containing(".")[0]
 
1779
        parent = local_branch.get_parent()
 
1780
        if other_branch is None:
 
1781
            other_branch = parent
 
1782
            if other_branch is None:
1773
1783
                raise BzrCommandError("No missing location known or specified.")
1774
 
            else:
1775
 
                if not is_quiet():
1776
 
                    print "Using last location: %s" % parent
1777
 
                remote = parent
1778
 
        elif parent is None:
1779
 
            # We only update parent if it did not exist, missing
1780
 
            # should not change the parent
1781
 
            tree.branch.set_parent(remote)
1782
 
        br_remote = Branch.open_containing(remote)[0]
1783
 
        return show_missing(tree.branch, br_remote, verbose=verbose, 
1784
 
                            quiet=is_quiet())
 
1784
            print "Using last location: " + local_branch.get_parent()
 
1785
        remote_branch = bzrlib.branch.Branch.open(other_branch)
 
1786
        local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
 
1787
        log_format = get_log_format(long=long, short=short, line=line)
 
1788
        lf = log_formatter(log_format, sys.stdout,
 
1789
                           show_ids=show_ids,
 
1790
                           show_timezone='original')
 
1791
        if reverse is False:
 
1792
            local_extra.reverse()
 
1793
            remote_extra.reverse()
 
1794
        if local_extra and not theirs_only:
 
1795
            print "You have %d extra revision(s):" % len(local_extra)
 
1796
            for data in iter_log_data(local_extra, local_branch, verbose):
 
1797
                lf.show(*data)
 
1798
            printed_local = True
 
1799
        else:
 
1800
            printed_local = False
 
1801
        if remote_extra and not mine_only:
 
1802
            if printed_local is True:
 
1803
                print "\n\n"
 
1804
            print "You are missing %d revision(s):" % len(remote_extra)
 
1805
            for data in iter_log_data(remote_extra, remote_branch, verbose):
 
1806
                lf.show(*data)
 
1807
        if not remote_extra and not local_extra:
 
1808
            status_code = 0
 
1809
            print "Branches are up to date."
 
1810
        else:
 
1811
            status_code = 1
 
1812
        if parent is None and other_branch is not None:
 
1813
            local_branch.set_parent(other_branch)
 
1814
        return status_code
1785
1815
 
1786
1816
 
1787
1817
class cmd_plugins(Command):