~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Robert J. Tanner
  • Date: 2009-04-30 22:40:42 UTC
  • mfrom: (4323 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4324.
  • Revision ID: tanner@real-time.com-20090430224042-53v45axtue5bw45l
Merge 1.14.1 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
 
80
80
 
81
81
def tree_files_for_add(file_list):
82
 
    """Add handles files a bit differently so it a custom implementation."""
 
82
    """
 
83
    Return a tree and list of absolute paths from a file list.
 
84
 
 
85
    Similar to tree_files, but add handles files a bit differently, so it a
 
86
    custom implementation.  In particular, MutableTreeTree.smart_add expects
 
87
    absolute paths, which it immediately converts to relative paths.
 
88
    """
 
89
    # FIXME Would be nice to just return the relative paths like
 
90
    # internal_tree_files does, but there are a large number of unit tests
 
91
    # that assume the current interface to mutabletree.smart_add
83
92
    if file_list:
84
 
        tree = WorkingTree.open_containing(file_list[0])[0]
 
93
        tree, relpath = WorkingTree.open_containing(file_list[0])
85
94
        if tree.supports_views():
86
95
            view_files = tree.views.lookup_view()
87
96
            if view_files:
88
97
                for filename in file_list:
89
98
                    if not osutils.is_inside_any(view_files, filename):
90
99
                        raise errors.FileOutsideView(filename, view_files)
 
100
        file_list = file_list[:]
 
101
        file_list[0] = tree.abspath(relpath)
91
102
    else:
92
103
        tree = WorkingTree.open_containing(u'.')[0]
93
104
        if tree.supports_views():
1017
1028
        if revision is not None:
1018
1029
            revision_id = revision.in_history(br_from).rev_id
1019
1030
        else:
1020
 
            revision_id = br_from.last_revision()
 
1031
            revision_id = None
1021
1032
 
1022
1033
        # Get the stacked_on branch, if any
1023
1034
        if stacked_on is not None:
1575
1586
                    "\nYou may supply --create-prefix to create all"
1576
1587
                    " leading parent directories."
1577
1588
                    % location)
1578
 
            _create_prefix(to_transport)
 
1589
            to_transport.create_prefix()
1579
1590
 
1580
1591
        try:
1581
1592
            a_bzrdir = bzrdir.BzrDir.open_from_transport(to_transport)
3256
3267
 
3257
3268
        if cache_dir is not None:
3258
3269
            tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
3259
 
        if not list_only:
3260
 
            print 'testing: %s' % (osutils.realpath(sys.argv[0]),)
3261
 
            print '   %s (%s python%s)' % (
3262
 
                    bzrlib.__path__[0],
3263
 
                    bzrlib.version_string,
3264
 
                    bzrlib._format_version_tuple(sys.version_info),
3265
 
                    )
3266
 
            print
3267
3270
        if testspecs_list is not None:
3268
3271
            pattern = '|'.join(testspecs_list)
3269
3272
        else:
3309
3312
        finally:
3310
3313
            if benchfile is not None:
3311
3314
                benchfile.close()
3312
 
        if not list_only:
3313
 
            if result:
3314
 
                note('tests passed')
3315
 
            else:
3316
 
                note('tests failed')
3317
3315
        return int(not result)
3318
3316
 
3319
3317
 
5596
5594
                   dry_run=dry_run, no_prompt=force)
5597
5595
 
5598
5596
 
5599
 
def _create_prefix(cur_transport):
5600
 
    needed = [cur_transport]
5601
 
    # Recurse upwards until we can create a directory successfully
5602
 
    while True:
5603
 
        new_transport = cur_transport.clone('..')
5604
 
        if new_transport.base == cur_transport.base:
5605
 
            raise errors.BzrCommandError(
5606
 
                "Failed to create path prefix for %s."
5607
 
                % cur_transport.base)
5608
 
        try:
5609
 
            new_transport.mkdir('.')
5610
 
        except errors.NoSuchFile:
5611
 
            needed.append(new_transport)
5612
 
            cur_transport = new_transport
 
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)
5613
5622
        else:
5614
 
            break
5615
 
    # Now we only need to create child directories
5616
 
    while needed:
5617
 
        cur_transport = needed.pop()
5618
 
        cur_transport.ensure_base()
 
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))
5619
5642
 
5620
5643
 
5621
5644
# these get imported and then picked up by the scan for cmd_*
5628
5651
from bzrlib.bundle.commands import (
5629
5652
    cmd_bundle_info,
5630
5653
    )
 
5654
from bzrlib.foreign import cmd_dpush
5631
5655
from bzrlib.sign_my_commits import cmd_sign_my_commits
5632
5656
from bzrlib.weave_commands import cmd_versionedfile_list, \
5633
5657
        cmd_weave_plan_merge, cmd_weave_merge_text