~abentley/bzr/status

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Aaron Bentley
  • Date: 2009-05-05 18:16:33 UTC
  • mfrom: (1731.1744.1078 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1931.
  • Revision ID: aaron@aaronbentley.com-20090505181633-3qtq1skwjzed0kug
Merge bzr.dev into composite-tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5594
5594
                   dry_run=dry_run, no_prompt=force)
5595
5595
 
5596
5596
 
 
5597
class cmd_reference(Command):
 
5598
    """list, view and set branch locations for nested trees.
 
5599
 
 
5600
    If no arguments are provided, lists the branch locations for nested trees.
 
5601
    If one argument is provided, display the branch location for that tree.
 
5602
    If two arguments are provided, set the branch location for that tree.
 
5603
    """
 
5604
 
 
5605
    hidden = True
 
5606
 
 
5607
    takes_args = ['path?', 'location?']
 
5608
 
 
5609
    def run(self, path=None, location=None):
 
5610
        branchdir = '.'
 
5611
        if path is not None:
 
5612
            branchdir = path
 
5613
        tree, branch, relpath =(
 
5614
            bzrdir.BzrDir.open_containing_tree_or_branch(branchdir))
 
5615
        if path is not None:
 
5616
            path = relpath
 
5617
        if tree is None:
 
5618
            tree = branch.basis_tree()
 
5619
        if path is None:
 
5620
            info = branch._get_all_reference_info().iteritems()
 
5621
            self._display_reference_info(tree, branch, info)
 
5622
        else:
 
5623
            file_id = tree.path2id(path)
 
5624
            if file_id is None:
 
5625
                raise errors.NotVersionedError(path)
 
5626
            if location is None:
 
5627
                info = [(file_id, branch.get_reference_info(file_id))]
 
5628
                self._display_reference_info(tree, branch, info)
 
5629
            else:
 
5630
                branch.set_reference_info(file_id, path, location)
 
5631
 
 
5632
    def _display_reference_info(self, tree, branch, info):
 
5633
        ref_list = []
 
5634
        for file_id, (path, location) in info:
 
5635
            try:
 
5636
                path = tree.id2path(file_id)
 
5637
            except errors.NoSuchId:
 
5638
                pass
 
5639
            ref_list.append((path, location))
 
5640
        for path, location in sorted(ref_list):
 
5641
            self.outf.write('%s %s\n' % (path, location))
 
5642
 
 
5643
 
5597
5644
# these get imported and then picked up by the scan for cmd_*
5598
5645
# TODO: Some more consistent way to split command definitions across files;
5599
5646
# we do need to load at least some information about them to know of