Commits

Marcin Kuzminski committed d5527ce

Resolve error occurring during recursive group creation in API create-repo function

  • Participants
  • Parent commits 4d07698

Comments (0)

Files changed (3)

docs/changelog.rst

 - fixed #385 clone by ID url was loosing proxy prefix in URL
 - fixed some unicode problems with waitress
 - fixed issue with escaping < and > in changeset commits
+- fixed error occurring during recursive group creation in API 
+  create_repo function
 
 1.3.3 (**2012-03-02**)
 ----------------------

rhodecode/controllers/api/api.py

 from rhodecode.model.user import UserModel
 from rhodecode.model.users_group import UsersGroupModel
 from rhodecode.model.repos_group import ReposGroupModel
+from rhodecode.lib.utils import map_groups
 
 
 log = logging.getLogger(__name__)
             if Repository.get_by_repo_name(repo_name):
                 raise JSONRPCError("repo %s already exist" % repo_name)
 
-            groups = repo_name.split('/')
+            groups = repo_name.split(Repository.url_sep())
             real_name = groups[-1]
-            groups = groups[:-1]
-            parent_id = None
-            for g in groups:
-                group = RepoGroup.get_by_group_name(g)
-                if not group:
-                    group = ReposGroupModel().create(g, '', parent_id)
-                parent_id = group.group_id
+            # create structure of groups
+            group = map_groups(repo_name)
 
             repo = RepoModel().create(
                 dict(
                     description=description,
                     private=private,
                     repo_type=repo_type,
-                    repo_group=parent_id,
+                    repo_group=group.group_id if group else None,
                     clone_uri=clone_uri
                 ),
                 owner

rhodecode/lib/utils.py

         return 0
 
 
-def map_groups(groups):
+def map_groups(path):
     """
-    Checks for groups existence, and creates groups structures.
-    It returns last group in structure
+    Given a full path to a repository, create all nested groups that this
+    repo is inside. This function creates parent-child relationships between
+    groups and creates default perms for all new groups.
 
-    :param groups: list of groups structure
+    :param paths: full path to repository
     """
     sa = meta.Session
-
+    groups = path.split(Repository.url_sep())
     parent = None
     group = None
 
         group = RepoGroup.get_by_group_name(group_name)
         desc = '%s group' % group_name
 
-#        # WTF that doesn't work !?
-#        if group is None:
-#            group = rgm.create(group_name, desc, parent, just_db=True)
-#            sa.commit()
-
         # skip folders that are now removed repos
         if REMOVED_REPO_PAT.match(group_name):
             break
 
         if group is None:
-            log.debug('creating group level: %s group_name: %s' % (lvl, group_name))
+            log.debug('creating group level: %s group_name: %s' % (lvl,
+                                                                   group_name))
             group = RepoGroup(group_name, parent)
             group.group_description = desc
             sa.add(group)
             rgm._create_default_perms(group)
-            sa.commit()
+            sa.flush()
         parent = group
     return group
 
     added = []
 
     for name, repo in initial_repo_list.items():
-        group = map_groups(name.split(Repository.url_sep()))
+        group = map_groups(name)
         if not rm.get_by_repo_name(name, cache=False):
             log.info('repository %s not found creating default' % name)
             added.append(name)