Beispiel #1
0
    def run(self, from_location, to_location, revision=None):
        branch = Branch.open_containing('.')[0]
        root = local_path_from_url(branch.base)

        # select what do it
        if isdir(pathjoin(root, to_location, '.bzr')) or isdir(pathjoin(root, to_location, '.svn')):
            if branch.get_bound_location():
                cmd = ['update', to_location]
            else:
                cmd = ['pull', from_location, '--directory', to_location]
        else:
            if branch.get_bound_location():
                cmd = ['checkout', from_location, to_location]
            else:
                cmd = ['branch', from_location, to_location]

            # command branch don't create recursive directory
            dirs = to_location.rpartition('/')
            if dirs[0] != '' and not isdir(dirs[0]):
                os.makedirs(dirs[0].encode(get_user_encoding()))

        # if use revision options but not for 'update'
        if revision is not None:# and cmd[0] != 'update':
            cmd += ['--revision', revision[0].user_spec]

        note('Add external ' + ' '.join(cmd))
        run_bzr_catch_user_errors(cmd)

        bzrmeta = pathjoin(root, '.bzrmeta')
        if not isdir(bzrmeta):
            os.mkdir(bzrmeta)

        # add new branch to config and snapshot files
        line = from_location + ' ' + self._quoted_if_need(to_location)
        if revision:
            line += ' ' + revision[0].user_spec
        self._add_to_file(root, externals.CONFIG_PATH, line)
        self._add_to_file(root, externals.SNAPSHOT_PATH, line)

        # add ignore mask
        from bzrlib import IGNORE_FILENAME
        self._add_to_file(root, IGNORE_FILENAME, './' + to_location)

        # add config files to repository
        cmd = ['add',
            '.bzrignore',
            '.bzrmeta/externals',
            '.bzrmeta/externals-snapshot']
        run_bzr_catch_user_errors(cmd)
Beispiel #2
0
def _open_crash_file():
    crash_dir = config.crash_dir()
    if not osutils.isdir(crash_dir):
        # on unix this should be /var/crash and should already exist; on
        # Windows or if it's manually configured it might need to be created,
        # and then it should be private
        os.makedirs(crash_dir, mode=0600)
    date_string = time.strftime('%Y-%m-%dT%H:%M', time.gmtime())
    # XXX: getuid doesn't work on win32, but the crash directory is per-user
    if sys.platform == 'win32':
        user_part = ''
    else:
        user_part = '.%d' % os.getuid()
    filename = osutils.pathjoin(
        crash_dir,
        'bzr%s.%s.crash' % (
            user_part,
            date_string))
    # be careful here that people can't play tmp-type symlink mischief in the
    # world-writable directory
    return filename, os.fdopen(
        os.open(filename, 
            os.O_WRONLY|os.O_CREAT|os.O_EXCL,
            0600),
        'wb')
Beispiel #3
0
    def branch_iterator(self, target_root=None):
        if len(self.config) == 0:
            # branch not have externals configuration
            return

        self.bound = True
        if not target_root:
            target_root = self.branch.get_bound_location()
            if not target_root:
                self.bound = False
                target_root = self.branch.get_parent()
                if not target_root:
                    # support new braches with no parent yet
                    target_root = self.branch.base

        for arg in self.config: # url directory [revisionspec]
            location = self._relurljoin(target_root, arg[0])
            if target_root.startswith('file:///'):
                # try to pull externals from the parent for the feature branch
                path = pathjoin(local_path_from_url(target_root), arg[1])
                if isdir(path):
                    location = self._relpath(path)
                else:
                    # parent is local master branch
                    if location.startswith('file:///'):
                        location = self._relpath(local_path_from_url(location))

            check_legal_path(arg[1])
            rel_path = self._relpath(pathjoin(self.root, arg[1]))

            revision = None
            if len(arg) > 2:
                revision = arg[2]
            yield location, rel_path, revision
def delete_items(deletables, dry_run=False):
    """Delete files in the deletables iterable"""
    def onerror(function, path, excinfo):
        """Show warning for errors seen by rmtree.
        """
        # Handle only permission error while removing files.
        # Other errors are re-raised.
        if function is not os.remove or excinfo[1].errno != errno.EACCES:
            raise
        ui.ui_factory.show_warning(gettext('unable to remove %s') % path)
    has_deleted = False
    for path, subp in deletables:
        if not has_deleted:
            note(gettext("deleting paths:"))
            has_deleted = True
        if not dry_run:
            if isdir(path):
                shutil.rmtree(path, onerror=onerror)
            else:
                try:
                    os.unlink(path)
                    note('  ' + subp)
                except OSError, e:
                    # We handle only permission error here
                    if e.errno != errno.EACCES:
                        raise e
                    ui.ui_factory.show_warning(gettext(
                        'unable to remove "{0}": {1}.').format(
                                                    path, e.strerror))
        else:
            note('  ' + subp)
Beispiel #5
0
    def pull(self):
        if disable_hooks:
            return

        # need use merged config from repository and working tree
        # because new added external branch from repository or working tree
        # need pull/update for correct snapshot
        self.read_config()
        self.read_config_from_repository()
        if len(self.config) == 0:
            return

        for location, path, revision in self.branch_iterator():
            if location == path:
                # not create feature branch for directory above the root
                continue

            # select what do it
            if isdir(pathjoin(path, '.bzr')) or isdir(pathjoin(path, '.svn')):
                if self.bound:
                    cmd = ['update', path]
                else:
                    cmd = ['pull', location, '--directory', path]
            else:
                if self.bound:
                    cmd = ['checkout', location, path]
                else:
                    cmd = ['branch', location, path]

                # command branch don't create recursive directory
                dirs = path.rpartition('/')
                if dirs[0] != '' and not isdir(dirs[0]):
                    os.makedirs(dirs[0].encode(get_user_encoding()))

            # if use revision options but not for 'update'
            if revision is not None:# and cmd[0] != 'update':
                cmd += ['--revision', revision]
            self.adjust_verbosity(cmd)
            self._report(cmd)
            run_bzr_catch_user_errors(cmd)
    def _probe(self):
        if CaseInsCasePresFilenameFeature.available():
            return False

        from bzrlib import tests

        if tests.TestCaseWithMemoryTransport.TEST_ROOT is None:
            root = osutils.mkdtemp(prefix='testbzr-', suffix='.tmp')
            tests.TestCaseWithMemoryTransport.TEST_ROOT = root
        else:
            root = tests.TestCaseWithMemoryTransport.TEST_ROOT
        tdir = osutils.mkdtemp(prefix='case-sensitive-probe-', suffix='',
            dir=root)
        name_a = osutils.pathjoin(tdir, 'a')
        name_A = osutils.pathjoin(tdir, 'A')
        os.mkdir(name_a)
        result = osutils.isdir(name_A)
        tests._rmtree_temp_dir(tdir)
        return result
Beispiel #7
0
def _open_crash_file():
    crash_dir = config.crash_dir()
    if not osutils.isdir(crash_dir):
        # on unix this should be /var/crash and should already exist; on
        # Windows or if it's manually configured it might need to be created,
        # and then it should be private
        os.makedirs(crash_dir, mode=0600)
    date_string = time.strftime('%Y-%m-%dT%H:%M', time.gmtime())
    # XXX: getuid doesn't work on win32, but the crash directory is per-user
    if sys.platform == 'win32':
        user_part = ''
    else:
        user_part = '.%d' % os.getuid()
    filename = osutils.pathjoin(crash_dir,
                                'bzr%s.%s.crash' % (user_part, date_string))
    # be careful here that people can't play tmp-type symlink mischief in the
    # world-writable directory
    return filename, os.fdopen(
        os.open(filename, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0600), 'wb')
def _filter_out_nested_bzrdirs(deletables):
    result = []
    for path, subp in deletables:
        # bzr won't recurse into unknowns/ignored directories by default
        # so we don't pay a penalty for checking subdirs of path for nested
        # bzrdir.
        # That said we won't detect the branch in the subdir of non-branch
        # directory and therefore delete it. (worth to FIXME?)
        if isdir(path):
            try:
                controldir.ControlDir.open(path)
            except errors.NotBranchError:
                result.append((path,subp))
            else:
                # TODO may be we need to notify user about skipped directories?
                pass
        else:
            result.append((path,subp))
    return result
Beispiel #9
0
def complete_revert(wt, newparents):
    """Simple helper that reverts to specified new parents and makes sure none
    of the extra files are left around.

    :param wt: Working tree to use for rebase
    :param newparents: New parents of the working tree
    """
    newtree = wt.branch.repository.revision_tree(newparents[0])
    delta = wt.changes_from(newtree)
    wt.branch.generate_revision_history(newparents[0])
    wt.set_parent_ids([r for r in newparents[:1] if r != NULL_REVISION])
    for (f, _, _) in delta.added:
        abs_path = wt.abspath(f)
        if osutils.lexists(abs_path):
            if osutils.isdir(abs_path):
                osutils.rmtree(abs_path)
            else:
                os.unlink(abs_path)
    wt.revert(None, old_tree=newtree, backups=False)
    assert not wt.changes_from(wt.basis_tree()).has_changed(), "Rev changed"
    wt.set_parent_ids([r for r in newparents if r != NULL_REVISION])