def test_04_rm_standard_layout(self):
        """
        Given:
            /trunk/
            /tags/
            /branches/
        Make sure we can't rmdir any of the paths.
        """
        repo = self.create_repo()
        svn = repo.svn

        expected = conf.standard_layout
        raw = svn.ls(repo.uri)
        actual = frozenset(format_dir(l) for l in raw.splitlines())
        self.assertEqual(expected, actual)
        dot()

        error = e.TopLevelRepoDirectoryRemoved
        paths = [p.replace('/', '') for p in conf.standard_layout]
        with chdir(repo.wc):
            for path in paths:
                dot()
                svn.rm(path)
                with ensure_blocked(self, error):
                    svn.ci(path)
    def test_04_rm_standard_layout(self):
        """
        Given:
            /trunk/
            /tags/
            /branches/
        Make sure we can't rmdir any of the paths.
        """
        repo = self.create_repo()
        svn = repo.svn

        expected = conf.standard_layout
        raw = svn.ls(repo.uri)
        actual = frozenset(format_dir(l) for l in raw.splitlines())
        self.assertEqual(expected, actual)
        dot()

        error = e.TopLevelRepoDirectoryRemoved
        paths = [ p.replace('/', '') for p in conf.standard_layout ]
        with chdir(repo.wc):
            for path in paths:
                dot()
                svn.rm(path)
                with ensure_blocked(self, error):
                    svn.ci(path)
示例#3
0
文件: commands.py 项目: tpn/enversion
    def run(self):
        RepositoryCommand.run(self)
        tags_basedir = format_dir(self.tags_basedir)

        rc0 = self.r0_revprop_conf

        if not rc0.get('tags_basedirs'):
            rc0.tags_basedirs = []

        basedirs = rc0.tags_basedirs
        if tags_basedir in basedirs:
            msg = "tags basedir already exists for %s" % tags_basedir
            raise CommandError(msg)

        basedirs.append(tags_basedir)
        repo_name = self.conf.repo_name
        msg = 'Added tags basedir %s to %s.' % (tags_basedir, repo_name)
        self._out(msg)
示例#4
0
文件: commands.py 项目: tpn/enversion
    def run(self):
        RepositoryCommand.run(self)
        branches_basedir = format_dir(self.branches_basedir)

        rc0 = self.r0_revprop_conf

        if not rc0.get('branches_basedirs'):
            rc0.branches_basedirs = []

        basedirs = rc0.branches_basedirs
        if branches_basedir in basedirs:
            msg = "branches basedir already exists for %s" % branches_basedir
            raise CommandError(msg)

        basedirs.append(branches_basedir)
        repo_name = self.conf.repo_name
        msg = 'Added branches basedir %s to %s.' % (
            branches_basedir,
            self.conf.repo_name,
        )
        self._out(msg)
示例#5
0
文件: commands.py 项目: tpn/enversion
    def run(self):
        RepositoryRevisionCommand.run(self)
        root_path = format_dir(self.root_path)

        rev = self.rev

        rc0 = self.r0_revprop_conf

        if not rc0.get('root_hints'):
            raise CommandError("no such root hint: %s" % root_path)

        hints = rc0['root_hints'].get(rev)
        if not hints:
            msg = "no such root hint at r%d: %s" % (rev, root_path)
            raise CommandError(msg)

        if root_path not in hints:
            msg = "no such root hint at r%d: %s" % (rev, root_path)
            raise CommandError(msg)

        del hints[root_path]
        msg = "Removed root hint %r for r%d from %s."
        repo_name = self.conf.repo_name
        self._out(msg % (hint, rev, repo_name))
    def test_01_basic(self):
        """
        Given:
            /trunk/
            /tags/
            /branches/
        Make sure we can't create:
            /bar/
        """
        repo = self.create_repo()
        svn = repo.svn

        expected = conf.standard_layout
        raw = svn.ls(repo.uri)
        actual = frozenset(format_dir(l) for l in raw.splitlines())
        self.assertEqual(expected, actual)
        dot()

        expected = e.InvalidTopLevelRepoDirectoryCreated
        with chdir(repo.wc):
            svn.mkdir('bar')
            with ensure_blocked(self, expected):
                svn.ci()
                dot()
    def test_01_basic(self):
        """
        Given:
            /trunk/
            /tags/
            /branches/
        Make sure we can't create:
            /bar/
        """
        repo = self.create_repo()
        svn = repo.svn

        expected = conf.standard_layout
        raw = svn.ls(repo.uri)
        actual = frozenset(format_dir(l) for l in raw.splitlines())
        self.assertEqual(expected, actual)
        dot()

        expected = e.InvalidTopLevelRepoDirectoryCreated
        with chdir(repo.wc):
            svn.mkdir('bar')
            with ensure_blocked(self, expected):
                svn.ci()
                dot()
示例#8
0
文件: root.py 项目: tpn/enversion
    def add_root_path(self, path):
        """
        >>> rm = SimpleRootMatcher(set(['/trunk/']))

        >>> rm.add_root_path('/trunk/')
        Traceback (most recent call last):
            ...
        AssertionError

        >>> rm.add_root_path('/trunk/foo/')
        Traceback (most recent call last):
            ...
        AssertionError

        >>> rm.add_root_path('//foo/')
        Traceback (most recent call last):
            ...
        AssertionError

        >>> rm.add_root_path('//')
        Traceback (most recent call last):
            ...
        AssertionError

        >>> rm.add_root_path('/trunk/foo/trunk/')
        Traceback (most recent call last):
            ...
        AssertionError
        """

        p = path
        assert (p == format_dir(p) and p not in self.__roots
                and p.count('/') >= 2 and p != '//')

        # Lop off the first and last empty elements via the [1:-1] splice.
        dirs = p.split('/')[1:-1]
        length = len(dirs)
        assert length >= 1

        # Make sure there are no overlapping roots.  For example, if we're
        # adding the root '/src/foo/bar/trunk/', we make sure that none of
        # the following roots exist: '/src/foo/bar/', '/src/foo/', '/src/'.
        for i in range(length, 0, -1):
            roots = self.__root_dirs_by_length.get(i)
            if roots:
                s = '/%s/' % '/'.join(dirs[:i])
                #if s in self.__root_dirs_by_length[i]:
                #    import ipdb
                #    ipdb.set_trace()
                assert s not in self.__root_dirs_by_length[i]

        roots = self.__root_dirs_by_length.get(length)
        if roots is None:
            # Force reversed lengths to be recalculated when the property is
            # next accessed by get_root_details().
            self.__reversed_root_dir_lengths = None
            self.__root_dirs_by_length[length] = set()
        else:
            # Force a __nonzero__ test to catch if we're an empty set().
            assert roots
            assert p not in roots
            assert p not in self.__root_details

        self.__root_dirs_by_length[length].add(p)
        self.__roots.add(p)
        self.__version += 1
示例#9
0
 def standard_layout(self):
     layout = self.get("main", "standard-layout")
     if not layout:
         return
     dirs = layout.split(",")
     return frozenset(format_dir(d) for d in dirs)
示例#10
0
    def run(self):
        RepositoryRevisionCommand.run(self)

        assert self.root_path and isinstance(self.root_path, str)
        p = format_dir(self.root_path)

        k = dict(fs=self.fs, rev=self.rev, conf=self.conf)
        rc = RepositoryRevisionConfig(**k)
        roots = rc.roots
        if not roots:
            m = "Repository '%s' has no roots defined at r%d"
            self._out(m % (self.name, self.rev))
            return

        root = roots.get(p)
        if not root:
            m = "No root named '%s' is present in repository '%s' at r%d."
            self._out(m % (p, self.name, self.rev))
            return

        created = root['created']
        m = "Found root '%s' in repository '%s' at r%d (created at r%d)."
        self._verbose(m % (p, self.name, self.rev, created))

        k = dict(fs=self.fs, rev=created, conf=self.conf)
        rc = RepositoryRevisionConfig(**k)
        roots = rc.roots
        assert roots
        root = roots[p]
        assert root
        m = "Displaying root info for '%s' from r%d:"
        self._verbose(m % (p, created))
        d = { p : root }

        if self.options.json:
            import json
            json.dump(d, self.ostream, sort_keys=True, indent=4)
            return

        buf = StringIO.StringIO()
        w = buf.write
        w("'%s': {\n" % p)
        if root['copies']:
            w("    'copies': {\n")

            copies = pprint.pformat(root['copies'])
            indent = ' ' * 8
            w(indent)
            w(copies[1:-1].replace('\n', '\n' + indent))
            w("\n    },\n")
        else:
            w("    'copies': { },\n")

        for (k, v) in root.items():
            if k == 'copies':
                continue
            w("    '%s': %s,\n" % (k, pprint.pformat(v)))
        w("}\n")

        buf.seek(0)
        self.ostream.write(buf.read())
示例#11
0
文件: root.py 项目: smapjb/enversion
    def add_root_path(self, path):
        """
        >>> rm = SimpleRootMatcher(set(['/trunk/']))

        >>> rm.add_root_path('/trunk/')
        Traceback (most recent call last):
            ...
        AssertionError

        >>> rm.add_root_path('/trunk/foo/')
        Traceback (most recent call last):
            ...
        AssertionError

        >>> rm.add_root_path('//foo/')
        Traceback (most recent call last):
            ...
        AssertionError

        >>> rm.add_root_path('//')
        Traceback (most recent call last):
            ...
        AssertionError

        >>> rm.add_root_path('/trunk/foo/trunk/')
        Traceback (most recent call last):
            ...
        AssertionError
        """

        p = path
        assert (
            p == format_dir(p) and
            p not in self.__roots and
            p.count('/') >= 2 and p != '//'
        )

        # Lop off the first and last empty elements via the [1:-1] splice.
        dirs = p.split('/')[1:-1]
        length = len(dirs)
        assert length >= 1

        # Make sure there are no overlapping roots.  For example, if we're
        # adding the root '/src/foo/bar/trunk/', we make sure that none of
        # the following roots exist: '/src/foo/bar/', '/src/foo/', '/src/'.
        for i in range(length, 0, -1):
            roots = self.__root_dirs_by_length.get(i)
            if roots:
                s = '/%s/' % '/'.join(dirs[:i])
                #if s in self.__root_dirs_by_length[i]:
                #    import ipdb
                #    ipdb.set_trace()
                assert s not in self.__root_dirs_by_length[i]

        roots = self.__root_dirs_by_length.get(length)
        if roots is None:
            # Force reversed lengths to be recalculated when the property is
            # next accessed by get_root_details().
            self.__reversed_root_dir_lengths = None
            self.__root_dirs_by_length[length] = set()
        else:
            # Force a __nonzero__ test to catch if we're an empty set().
            assert roots
            assert p not in roots
            assert p not in self.__root_details

        self.__root_dirs_by_length[length].add(p)
        self.__roots.add(p)
        self.__version += 1
示例#12
0
文件: commands.py 项目: tpn/enversion
    def run(self):
        RepositoryRevisionCommand.run(self)

        assert self.root_path and isinstance(self.root_path, str)
        p = format_dir(self.root_path)

        k = dict(fs=self.fs, rev=self.rev, conf=self.conf)
        rc = RepositoryRevisionConfig(**k)
        roots = rc.roots
        if not roots:
            m = "Repository '%s' has no roots defined at r%d"
            self._out(m % (self.name, self.rev))
            return

        root = roots.get(p)
        if not root:
            m = "No root named '%s' is present in repository '%s' at r%d."
            self._out(m % (p, self.name, self.rev))
            return

        created = root['created']
        m = "Found root '%s' in repository '%s' at r%d (created at r%d)."
        self._verbose(m % (p, self.name, self.rev, created))

        k = dict(fs=self.fs, rev=created, conf=self.conf)
        rc = RepositoryRevisionConfig(**k)
        roots = rc.roots
        assert roots
        root = roots[p]
        assert root
        m = "Displaying root info for '%s' from r%d:"
        self._verbose(m % (p, created))
        d = { p : root }

        if self.options.json:
            import json
            json.dump(d, self.ostream, sort_keys=True, indent=4)
            return

        buf = StringIO.StringIO()
        w = buf.write
        w("'%s': {\n" % p)
        if root['copies']:
            w("    'copies': {\n")

            copies = pprint.pformat(root['copies'])
            indent = ' ' * 8
            w(indent)
            w(copies[1:-1].replace('\n', '\n' + indent))
            w("\n    },\n")
        else:
            w("    'copies': { },\n")

        for (k, v) in root.items():
            if k == 'copies':
                continue
            w("    '%s': %s,\n" % (k, pprint.pformat(v)))
        w("}\n")

        buf.seek(0)
        self.ostream.write(buf.read())
示例#13
0
文件: commands.py 项目: tpn/enversion
    def run(self):
        RepositoryRevisionCommand.run(self)
        rev = self.rev
        root_path = format_dir(self.root_path)
        root_type = self.root_type
        assert root_type in ('tag', 'trunk', 'branch')

        rc0 = self.r0_revprop_conf
        self.ensure_readonly()

        if not rc0.get('root_hints'):
            rc0.root_hints = {}

        if not rc0['root_hints'].get(rev):
            rc0['root_hints'][rev] = {}

        hints = rc0['root_hints'][rev]
        if root_path in hints:
            msg = "hint already exists for %s@%d" % (root_path, rev)
            raise CommandError(msg)

        from evn.change import ChangeSet
        opts = Options()
        cs = ChangeSet(self.path, self.rev, opts)
        cs.load()

        import svn.fs
        from svn.core import (
            svn_node_dir,
            svn_node_file,
            svn_node_none,
            svn_node_unknown,
        )

        svn_root = cs._get_root(rev)
        node_kind = svn.fs.check_path(svn_root, root_path, self.pool)
        if node_kind == svn_node_none:
            msg = "no such path %s in revision %d"
            raise CommandError(msg % (root_path, rev))
        elif node_kind == svn_node_unknown:
            msg = "unexpected node type 'unknown' for path %s in revision %d"
            raise CommandError(msg % (root_path, rev))
        elif node_kind == svn_node_file:
            msg = "path %s was a file in revision %d, not a directory"
            raise CommandError(msg % (root_path, rev))
        else:
            assert node_kind == svn_node_dir, node_kind

        change = cs.get_change_for_path(root_path)
        if not change:
            msg = (
                "path %s already existed in revision %d; specify the revision "
                "it was created in when adding a root hint (tip: try running "
                "`svn log --stop-on-copy --limit 1 %s%s@%d` to get the "
                "correct revision to use)" % (
                    root_path,
                    rev,
                    self.uri,
                    root_path,
                    rev,
                )
            )
            raise CommandError(msg)

        if change.is_remove or change.is_modify:
            msg = (
                "path %s wasn't created in revision %d; you need to specify "
                "the revision it was created in when adding a root hint "
                "(tip: try running `svn log --stop-on-copy --limit 1 %s%s@%d`"
                " to get the correct revision to use)" % (
                    root_path,
                    rev,
                    self.uri,
                    root_path,
                    rev,
                )
            )
            raise CommandError(msg)

        hints[root_path] = root_type

        repo_name = self.conf.repo_name
        msg = 'Added root hint for %s@%d to %s.' % (root_path, rev, repo_name)
        self._out(msg)

        last_rev = rev-1
        if rc0.last_rev <= last_rev:
            msg = (
                'evn:last_rev (%d) is already set less than or equal to the '
                'new would-be evn:last_rev (%d) based on the revision used '
                'for this root hint (%d); run `evnadmin analyze %s` when '
                'ready to restart analysis from revision %d.' % (
                    rc0.last_rev,
                    last_rev,
                    rev,
                    repo_name,
                    rc0.last_rev,
                )
            )
        else:
            rc0.last_rev = last_rev
            msg = (
                'evn:last_rev has been reset from %d to %d; '
                'run `evnadmin analyze %s` when ready to '
                'restart analysis from revision %d.' % (
                    rev,
                    last_rev,
                    repo_name,
                    last_rev,
                )
            )
        self._out(msg)
示例#14
0
    def test_01(self):
        """
        Create a single-component repo, then convert to multi-component.
        """
        repo = self.create_repo()

        svn = repo.svn
        name = repo.name
        evnadmin = repo.evnadmin

        expected = conf.standard_layout
        raw = svn.ls(repo.uri)
        actual = frozenset(format_dir(l) for l in raw.splitlines())
        self.assertEqual(expected, actual)

        dot()
        self.assertEqual(0, repo.component_depth)

        dot()
        roots = {
            '/trunk/': {
                'copies': {},
                'created': 1,
                'creation_method': 'created',
            }
        }
        self.assertEqual(roots, repo.roots)

        dot()
        with chdir(repo.wc):
            svn.cp('trunk', 'branches/1.x')
            svn.ci(m='Branching 1.x.')

        dot()
        with chdir(repo.wc):
            svn.cp('branches/1.x', 'tags/1.1')
            svn.ci(m='Tagging 1.1.')

        dot()
        error = 'root ancestor path renamed to unknown path'
        with chdir(repo.wc):
            svn.up()
            svn.mkdir('foo')
            svn.mv('tags', 'foo')
            svn.mv('trunk', 'foo')
            svn.mv('branches', 'foo')
            with ensure_blocked(self, error):
                svn.ci()

        dot()
        evnadmin.disable(name)
        with chdir(repo.wc):
            svn.ci()
        evnadmin.set_repo_component_depth(repo.name, multi=True)
        evnadmin.enable(name)

        roots = {
            '/foo/branches/1.x/': {
                'copies': {},
                'created': 4,
                'creation_method': 'renamed_indirectly',
                'errors': ['root ancestor path renamed to unknown path'],
                'renamed_from': ('/branches/1.x/', 3),
                'renamed_indirectly_from': (
                    '/branches/',
                    '/foo/branches/',
                ),
            },
            '/foo/tags/1.1/': {
                'copies': {},
                'created': 4,
                'creation_method': 'renamed_indirectly',
                'errors': ['root ancestor path renamed to unknown path'],
                'renamed_from': ('/tags/1.1/', 3),
                'renamed_indirectly_from': (
                    '/tags/',
                    '/foo/tags/',
                ),
            },
            '/foo/trunk/': {
                'copies': {},
                'created': 4,
                'creation_method': 'renamed',
                'errors': [],
                'renamed_from': ('/trunk/', 3)
            }
        }

        self.assertEqual(roots, repo.roots)
示例#15
0
文件: config.py 项目: tpn/enversion
 def standard_layout(self):
     layout = self.get('main', 'standard-layout')
     if not layout:
         return
     dirs = layout.split(',')
     return frozenset(format_dir(d) for d in dirs)
    def test_01(self):
        """
        Create a single-component repo, then convert to multi-component.
        """
        repo = self.create_repo()

        svn = repo.svn
        name = repo.name
        evnadmin = repo.evnadmin

        expected = conf.standard_layout
        raw = svn.ls(repo.uri)
        actual = frozenset(format_dir(l) for l in raw.splitlines())
        self.assertEqual(expected, actual)

        dot()
        self.assertEqual(0, repo.component_depth)

        dot()
        roots = {
            '/trunk/': {
                'copies': {},
                'created': 1,
                'creation_method': 'created',
            }
        }
        self.assertEqual(roots, repo.roots)

        dot()
        with chdir(repo.wc):
            svn.cp('trunk', 'branches/1.x')
            svn.ci(m='Branching 1.x.')

        dot()
        with chdir(repo.wc):
            svn.cp('branches/1.x', 'tags/1.1')
            svn.ci(m='Tagging 1.1.')

        dot()
        error = 'root ancestor path renamed to unknown path'
        with chdir(repo.wc):
            svn.up()
            svn.mkdir('foo')
            svn.mv('tags', 'foo')
            svn.mv('trunk', 'foo')
            svn.mv('branches', 'foo')
            with ensure_blocked(self, error):
                svn.ci()

        dot()
        evnadmin.disable(name)
        with chdir(repo.wc):
            svn.ci()
        evnadmin.set_repo_component_depth(repo.name, multi=True)
        evnadmin.enable(name)

        roots = {
            '/foo/branches/1.x/': {
                'copies': {},
                'created': 4,
                'creation_method': 'renamed_indirectly',
                'errors': ['root ancestor path renamed to unknown path'],
                'renamed_from': ('/branches/1.x/', 3),
                'renamed_indirectly_from': (
                    '/branches/',
                    '/foo/branches/',
                ),
            },
            '/foo/tags/1.1/': {
                'copies': {},
                'created': 4,
                'creation_method': 'renamed_indirectly',
                'errors': ['root ancestor path renamed to unknown path'],
                'renamed_from': ('/tags/1.1/', 3),
                'renamed_indirectly_from': (
                    '/tags/',
                    '/foo/tags/',
                ),
            },
            '/foo/trunk/': {
                'copies': {},
                 'created': 4,
                 'creation_method': 'renamed',
                 'errors': [],
                 'renamed_from': ('/trunk/', 3)
            }
        }

        self.assertEqual(roots, repo.roots)