~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1078
1078
 
1079
1079
 
1080
1080
class cmd_diff(Command):
1081
 
    """Show differences in working tree.
 
1081
    """Show differences in the working tree or between revisions.
1082
1082
    
1083
1083
    If files are listed, only the changes in those files are listed.
1084
1084
    Otherwise, all changes for the tree are listed.
1088
1088
 
1089
1089
    examples:
1090
1090
        bzr diff
 
1091
            Shows the difference in the working tree versus the last commit
1091
1092
        bzr diff -r1
 
1093
            Difference between the working tree and revision 1
1092
1094
        bzr diff -r1..2
 
1095
            Difference between revision 2 and revision 1
1093
1096
        bzr diff --diff-prefix old/:new/
 
1097
            Same as 'bzr diff' but prefix paths with old/ and new/
1094
1098
        bzr diff bzr.mine bzr.dev
 
1099
            Show the differences between the two working trees
1095
1100
        bzr diff foo.c
 
1101
            Show just the differences for 'foo.c'
1096
1102
    """
1097
1103
    # TODO: Option to use external diff command; could be GNU diff, wdiff,
1098
1104
    #       or a graphical diff.
1142
1148
                # FIXME diff those two files. rbc 20051123
1143
1149
                raise BzrCommandError("Files are in different branches")
1144
1150
            file_list = None
 
1151
        except NotBranchError:
 
1152
            # Don't raise an error when bzr diff is called from
 
1153
            # outside a working tree.
 
1154
            tree1, tree2 = None, None
1145
1155
        if revision is not None:
1146
1156
            if tree2 is not None:
1147
1157
                raise BzrCommandError("Can't specify -r with two branches")
1820
1830
                self.outf.write(c.username() + '\n')
1821
1831
            return
1822
1832
 
 
1833
        # display a warning if an email address isn't included in the given name.
 
1834
        try:
 
1835
            config.extract_email_address(name)
 
1836
        except BzrError, e:
 
1837
            warning('"%s" does not seem to contain an email address.  '
 
1838
                    'This is allowed, but not recommended.', name)
 
1839
        
1823
1840
        # use global config unless --branch given
1824
1841
        if branch:
1825
1842
            c = Branch.open_containing('.')[0].get_config()
2620
2637
    takes_args = ['location?']
2621
2638
    aliases = []
2622
2639
 
2623
 
    def run(self, location=None, 
 
2640
    def run(self, location=None,
2624
2641
            dry_run=False, verbose=False,
2625
2642
            revision=None, force=False):
2626
 
        from bzrlib.log import log_formatter
 
2643
        from bzrlib.log import log_formatter, show_log
2627
2644
        import sys
2628
2645
        from bzrlib.uncommit import uncommit
2629
2646
 
2637
2654
            tree = None
2638
2655
            b = control.open_branch()
2639
2656
 
 
2657
        rev_id = None
2640
2658
        if revision is None:
2641
2659
            revno = b.revno()
2642
 
            rev_id = b.last_revision()
2643
2660
        else:
2644
 
            revno, rev_id = revision[0].in_history(b)
 
2661
            # 'bzr uncommit -r 10' actually means uncommit
 
2662
            # so that the final tree is at revno 10.
 
2663
            # but bzrlib.uncommit.uncommit() actually uncommits
 
2664
            # the revisions that are supplied.
 
2665
            # So we need to offset it by one
 
2666
            revno = revision[0].in_history(b).revno+1
 
2667
 
 
2668
        if revno <= b.revno():
 
2669
            rev_id = b.get_rev_id(revno)
2645
2670
        if rev_id is None:
2646
 
            print 'No revisions to uncommit.'
2647
 
 
2648
 
        for r in range(revno, b.revno()+1):
2649
 
            rev_id = b.get_rev_id(r)
2650
 
            lf = log_formatter('short', to_file=sys.stdout,show_timezone='original')
2651
 
            lf.show(r, b.repository.get_revision(rev_id), None)
 
2671
            self.outf.write('No revisions to uncommit.\n')
 
2672
            return 1
 
2673
 
 
2674
        lf = log_formatter('short',
 
2675
                           to_file=self.outf,
 
2676
                           show_timezone='original')
 
2677
 
 
2678
        show_log(b,
 
2679
                 lf,
 
2680
                 verbose=False,
 
2681
                 direction='forward',
 
2682
                 start_revision=revno,
 
2683
                 end_revision=b.revno())
2652
2684
 
2653
2685
        if dry_run:
2654
2686
            print 'Dry-run, pretending to remove the above revisions.'