~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Mark Hammond
  • Date: 2008-12-28 05:21:23 UTC
  • mfrom: (3920 +trunk)
  • mto: (3932.1.1 prepare-1.11)
  • mto: This revision was merged to the branch mainline in revision 3937.
  • Revision ID: mhammond@skippinet.com.au-20081228052123-f78xs5sbdkotshwf
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
 
57
57
from bzrlib.commands import Command, display_command
58
58
from bzrlib.option import ListOption, Option, RegistryOption, custom_help
59
 
from bzrlib.trace import mutter, note, warning, is_quiet
 
59
from bzrlib.trace import mutter, note, warning, is_quiet, get_verbosity_level
60
60
 
61
61
 
62
62
def tree_files(file_list, default_branch=u'.'):
392
392
    """
393
393
    hidden = True
394
394
    takes_args = ['revision_info*']
395
 
    takes_options = ['revision']
 
395
    takes_options = [
 
396
        'revision',
 
397
        Option('directory',
 
398
            help='Branch to examine, '
 
399
                 'rather than the one containing the working directory.',
 
400
            short_name='d',
 
401
            type=unicode,
 
402
            ),
 
403
        ]
396
404
 
397
405
    @display_command
398
 
    def run(self, revision=None, revision_info_list=[]):
 
406
    def run(self, revision=None, directory=u'.', revision_info_list=[]):
399
407
 
400
408
        revs = []
401
409
        if revision is not None:
404
412
            for rev in revision_info_list:
405
413
                revs.append(RevisionSpec.from_string(rev))
406
414
 
407
 
        b = Branch.open_containing(u'.')[0]
 
415
        b = Branch.open_containing(directory)[0]
408
416
 
409
417
        if len(revs) == 0:
410
418
            revs.append(RevisionSpec.from_string('-1'))
798
806
                    result.old_revid))
799
807
                old_rh.reverse()
800
808
                new_rh = branch_to.revision_history()
 
809
                log_format = branch_to.get_config().log_format()
801
810
                log.show_changed_revisions(branch_to, old_rh, new_rh,
802
 
                                           to_file=self.outf)
 
811
                                           to_file=self.outf,
 
812
                                           log_format=log_format)
803
813
        finally:
804
814
            branch_to.unlock()
805
815
 
1838
1848
 
1839
1849
        b.lock_read()
1840
1850
        try:
1841
 
            if revision is None:
1842
 
                rev1 = None
1843
 
                rev2 = None
1844
 
            elif len(revision) == 1:
1845
 
                rev1 = rev2 = revision[0].in_history(b)
1846
 
            elif len(revision) == 2:
1847
 
                if revision[1].get_branch() != revision[0].get_branch():
1848
 
                    # b is taken from revision[0].get_branch(), and
1849
 
                    # show_log will use its revision_history. Having
1850
 
                    # different branches will lead to weird behaviors.
1851
 
                    raise errors.BzrCommandError(
1852
 
                        "Log doesn't accept two revisions in different"
1853
 
                        " branches.")
1854
 
                rev1 = revision[0].in_history(b)
1855
 
                rev2 = revision[1].in_history(b)
1856
 
            else:
1857
 
                raise errors.BzrCommandError(
1858
 
                    'bzr log --revision takes one or two values.')
1859
 
 
 
1851
            rev1, rev2 = _get_revision_range(revision, b, self.name())
1860
1852
            if log_format is None:
1861
1853
                log_format = log.log_formatter_registry.get_default(b)
1862
1854
 
1863
1855
            lf = log_format(show_ids=show_ids, to_file=self.outf,
1864
 
                            show_timezone=timezone)
 
1856
                            show_timezone=timezone,
 
1857
                            delta_format=get_verbosity_level())
1865
1858
 
1866
1859
            show_log(b,
1867
1860
                     lf,
1875
1868
        finally:
1876
1869
            b.unlock()
1877
1870
 
 
1871
def _get_revision_range(revisionspec_list, branch, command_name):
 
1872
    """Take the input of a revision option and turn it into a revision range.
 
1873
 
 
1874
    It returns RevisionInfo objects which can be used to obtain the rev_id's
 
1875
    of the desired revisons. It does some user input validations.
 
1876
    """
 
1877
    if revisionspec_list is None:
 
1878
        rev1 = None
 
1879
        rev2 = None
 
1880
    elif len(revisionspec_list) == 1:
 
1881
        rev1 = rev2 = revisionspec_list[0].in_history(branch)
 
1882
    elif len(revisionspec_list) == 2:
 
1883
        if revisionspec_list[1].get_branch() != revisionspec_list[0
 
1884
                ].get_branch():
 
1885
            # b is taken from revision[0].get_branch(), and
 
1886
            # show_log will use its revision_history. Having
 
1887
            # different branches will lead to weird behaviors.
 
1888
            raise errors.BzrCommandError(
 
1889
                "bzr %s doesn't accept two revisions in different"
 
1890
                " branches." % command_name)
 
1891
        rev1 = revisionspec_list[0].in_history(branch)
 
1892
        rev2 = revisionspec_list[1].in_history(branch)
 
1893
    else:
 
1894
        raise errors.BzrCommandError(
 
1895
            'bzr %s --revision takes one or two values.' % command_name)
 
1896
    return rev1, rev2
1878
1897
 
1879
1898
def get_log_format(long=False, short=False, line=False, default='long'):
1880
1899
    log_format = default
1975
1994
                        continue
1976
1995
                    if kind is not None and fkind != kind:
1977
1996
                        continue
 
1997
                    kindch = entry.kind_character()
 
1998
                    outstring = fp + kindch
1978
1999
                    if verbose:
1979
 
                        kindch = entry.kind_character()
1980
 
                        outstring = '%-8s %s%s' % (fc, fp, kindch)
 
2000
                        outstring = '%-8s %s' % (fc, outstring)
1981
2001
                        if show_ids and fid is not None:
1982
2002
                            outstring = "%-50s %s" % (outstring, fid)
1983
2003
                        self.outf.write(outstring + '\n')
1994
2014
                        else:
1995
2015
                            my_id = ''
1996
2016
                        if show_ids:
1997
 
                            self.outf.write('%-50s %s\n' % (fp, my_id))
 
2017
                            self.outf.write('%-50s %s\n' % (outstring, my_id))
1998
2018
                        else:
1999
 
                            self.outf.write(fp + '\n')
 
2019
                            self.outf.write(outstring + '\n')
2000
2020
        finally:
2001
2021
            tree.unlock()
2002
2022
 
4216
4236
 
4217
4237
 
4218
4238
class cmd_send(Command):
4219
 
    """Mail or create a merge-directive for submiting changes.
 
4239
    """Mail or create a merge-directive for submitting changes.
4220
4240
 
4221
4241
    A merge directive provides many things needed for requesting merges:
4222
4242
 
4414
4434
 
4415
4435
class cmd_bundle_revisions(cmd_send):
4416
4436
 
4417
 
    """Create a merge-directive for submiting changes.
 
4437
    """Create a merge-directive for submitting changes.
4418
4438
 
4419
4439
    A merge directive provides many things needed for requesting merges:
4420
4440
 
4564
4584
            time='Sort tags chronologically.',
4565
4585
            ),
4566
4586
        'show-ids',
 
4587
        'revision',
4567
4588
    ]
4568
4589
 
4569
4590
    @display_command
4571
4592
            directory='.',
4572
4593
            sort='alpha',
4573
4594
            show_ids=False,
 
4595
            revision=None,
4574
4596
            ):
4575
4597
        branch, relpath = Branch.open_containing(directory)
 
4598
 
4576
4599
        tags = branch.tags.get_tag_dict().items()
4577
4600
        if not tags:
4578
4601
            return
 
4602
 
 
4603
        if revision:
 
4604
            branch.lock_read()
 
4605
            try:
 
4606
                graph = branch.repository.get_graph()
 
4607
                rev1, rev2 = _get_revision_range(revision, branch, self.name())
 
4608
                revid1, revid2 = rev1.rev_id, rev2.rev_id
 
4609
                # only show revisions between revid1 and revid2 (inclusive)
 
4610
                tags = [(tag, revid) for tag, revid in tags if
 
4611
                     (revid2 is None or
 
4612
                         graph.is_ancestor(revid, revid2)) and
 
4613
                     (revid1 is None or
 
4614
                         graph.is_ancestor(revid1, revid))]
 
4615
            finally:
 
4616
                branch.unlock()
4579
4617
        if sort == 'alpha':
4580
4618
            tags.sort()
4581
4619
        elif sort == 'time':
4738
4776
    ie. out of the way, until a later time when you can bring them back from
4739
4777
    the shelf with the 'unshelve' command.
4740
4778
 
 
4779
    If shelve --list is specified, previously-shelved changes are listed.
 
4780
 
4741
4781
    Shelve is intended to help separate several sets of changes that have
4742
4782
    been inappropriately mingled.  If you just want to get rid of all changes
4743
4783
    and you don't need to restore them later, use revert.  If you want to
4760
4800
        'message',
4761
4801
        RegistryOption('writer', 'Method to use for writing diffs.',
4762
4802
                       bzrlib.option.diff_writer_registry,
4763
 
                       value_switches=True, enum_switch=False)
 
4803
                       value_switches=True, enum_switch=False),
 
4804
 
 
4805
        Option('list', help='List shelved changes.'),
4764
4806
    ]
4765
4807
    _see_also = ['unshelve']
4766
4808
 
4767
4809
    def run(self, revision=None, all=False, file_list=None, message=None,
4768
 
            writer=None):
 
4810
            writer=None, list=False):
 
4811
        if list:
 
4812
            return self.run_for_list()
4769
4813
        from bzrlib.shelf_ui import Shelver
4770
4814
        if writer is None:
4771
4815
            writer = bzrlib.option.diff_writer_registry.get()
4775
4819
        except errors.UserAbort:
4776
4820
            return 0
4777
4821
 
 
4822
    def run_for_list(self):
 
4823
        tree = WorkingTree.open_containing('.')[0]
 
4824
        tree.lock_read()
 
4825
        try:
 
4826
            manager = tree.get_shelf_manager()
 
4827
            shelves = manager.active_shelves()
 
4828
            if len(shelves) == 0:
 
4829
                note('No shelved changes.')
 
4830
                return 0
 
4831
            for shelf_id in reversed(shelves):
 
4832
                message = manager.get_metadata(shelf_id).get('message')
 
4833
                if message is None:
 
4834
                    message = '<no message>'
 
4835
                self.outf.write('%3d: %s\n' % (shelf_id, message))
 
4836
            return 1
 
4837
        finally:
 
4838
            tree.unlock()
 
4839
 
4778
4840
 
4779
4841
class cmd_unshelve(Command):
4780
4842
    """Restore shelved changes.