Changeset - 5c7b4229503e
[Not reviewed]
stable
0 1 0
Mads Kiilerich - 3 years ago 2022-12-22 01:02:36
mads@kiilerich.com
repo group: fix logging of rename/move

After renaming a group, it would iterate over all the contained groups and
repos and update their full path while logging the update from the/old/path to
the the/new/path. Doing that, it would also visit the already renamed top level
group, but since the full path of that one already had been updated, it would
log it as renaming from the/new/path to the/new/path.

Fixed by logging when renaming in the first place, and skipping the top level
repo group while iterating.

To avoid redundant logging, only log (and rename) if the name or parent
actually change.

Based on a patch by toras9000.
1 file changed with 10 insertions and 3 deletions:
0 comments (0 inline, 0 general)
kallithea/model/repo_group.py
Show inline comments
 
@@ -286,13 +286,18 @@ class RepoGroupModel(object):
 
                repo_group.group_description = repo_group_args['group_description']
 
            if 'parent_group_id' in repo_group_args:
 
                assert repo_group_args['parent_group_id'] != '-1', repo_group_args  # RepoGroupForm should have converted to None
 
                repo_group.parent_group = db.RepoGroup.get(repo_group_args['parent_group_id'])
 
                repo_group.group_name = repo_group.get_new_name(repo_group.name)
 
                new_parent_group = db.RepoGroup.get(repo_group_args['parent_group_id'])
 
                if new_parent_group is not repo_group.parent_group:
 
                    repo_group.parent_group = new_parent_group
 
                    repo_group.group_name = repo_group.get_new_name(repo_group.name)
 
                    log.debug('Moving repo group %s to %s', old_path, repo_group.group_name)
 
            if 'group_name' in repo_group_args:
 
                group_name = repo_group_args['group_name']
 
                if kallithea.lib.utils2.repo_name_slug(group_name) != group_name:
 
                    raise Exception('invalid repo group name %s' % group_name)
 
                repo_group.group_name = repo_group.get_new_name(group_name)
 
                if repo_group.name != group_name:
 
                    repo_group.group_name = repo_group.get_new_name(group_name)
 
                    log.debug('Renaming repo group %s to %s', old_path, repo_group.group_name)
 
            new_path = repo_group.full_path
 
            meta.Session().add(repo_group)
 

	
 
@@ -301,6 +306,8 @@ class RepoGroupModel(object):
 
            # full path of the parent.
 
            # This can potentially be a heavy operation.
 
            for obj in repo_group.recursive_groups_and_repos():
 
                if obj is repo_group:
 
                    continue  # already updated and logged
 
                if isinstance(obj, db.RepoGroup):
 
                    new_name = obj.get_new_name(obj.name)
 
                    log.debug('Fixing repo group %s to new name %s', obj.group_name, new_name)
0 comments (0 inline, 0 general)