~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: John Arbash Meinel
  • Date: 2006-07-13 18:38:58 UTC
  • mfrom: (1863 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1869.
  • Revision ID: john@arbash-meinel.com-20060713183858-ebf4aa1f9ef8bb6e
[merge] bzr.dev 1863

Show diffs side-by-side

added added

removed removed

Lines of Context:
375
375
    encoding_type = 'replace'
376
376
 
377
377
    def run(self, names_list):
 
378
        if names_list is None:
 
379
            names_list = []
 
380
 
378
381
        if len(names_list) < 2:
379
382
            raise BzrCommandError("missing file argument")
380
383
        tree, rel_names = tree_files(names_list)
1075
1078
 
1076
1079
 
1077
1080
class cmd_diff(Command):
1078
 
    """Show differences in working tree.
 
1081
    """Show differences in the working tree or between revisions.
1079
1082
    
1080
1083
    If files are listed, only the changes in those files are listed.
1081
1084
    Otherwise, all changes for the tree are listed.
1085
1088
 
1086
1089
    examples:
1087
1090
        bzr diff
 
1091
            Shows the difference in the working tree versus the last commit
1088
1092
        bzr diff -r1
 
1093
            Difference between the working tree and revision 1
1089
1094
        bzr diff -r1..2
 
1095
            Difference between revision 2 and revision 1
1090
1096
        bzr diff --diff-prefix old/:new/
 
1097
            Same as 'bzr diff' but prefix paths with old/ and new/
1091
1098
        bzr diff bzr.mine bzr.dev
 
1099
            Show the differences between the two working trees
1092
1100
        bzr diff foo.c
 
1101
            Show just the differences for 'foo.c'
1093
1102
    """
1094
1103
    # TODO: Option to use external diff command; could be GNU diff, wdiff,
1095
1104
    #       or a graphical diff.
1139
1148
                # FIXME diff those two files. rbc 20051123
1140
1149
                raise BzrCommandError("Files are in different branches")
1141
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
1142
1155
        if revision is not None:
1143
1156
            if tree2 is not None:
1144
1157
                raise BzrCommandError("Can't specify -r with two branches")
1817
1830
                self.outf.write(c.username() + '\n')
1818
1831
            return
1819
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
        
1820
1840
        # use global config unless --branch given
1821
1841
        if branch:
1822
1842
            c = Branch.open_containing('.')[0].get_config()
2617
2637
    takes_args = ['location?']
2618
2638
    aliases = []
2619
2639
 
2620
 
    def run(self, location=None, 
 
2640
    def run(self, location=None,
2621
2641
            dry_run=False, verbose=False,
2622
2642
            revision=None, force=False):
2623
 
        from bzrlib.log import log_formatter
 
2643
        from bzrlib.log import log_formatter, show_log
2624
2644
        import sys
2625
2645
        from bzrlib.uncommit import uncommit
2626
2646
 
2634
2654
            tree = None
2635
2655
            b = control.open_branch()
2636
2656
 
 
2657
        rev_id = None
2637
2658
        if revision is None:
2638
2659
            revno = b.revno()
2639
 
            rev_id = b.last_revision()
2640
2660
        else:
2641
 
            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)
2642
2670
        if rev_id is None:
2643
 
            print 'No revisions to uncommit.'
2644
 
 
2645
 
        for r in range(revno, b.revno()+1):
2646
 
            rev_id = b.get_rev_id(r)
2647
 
            lf = log_formatter('short', to_file=sys.stdout,show_timezone='original')
2648
 
            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())
2649
2684
 
2650
2685
        if dry_run:
2651
2686
            print 'Dry-run, pretending to remove the above revisions.'