Mercurial > kallithea
changeset 8973:5c7b4229503e stable
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.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Thu, 22 Dec 2022 01:02:36 +0100 |
parents | 4b5ab0426388 |
children | c6c30609df33 |
files | kallithea/model/repo_group.py |
diffstat | 1 files changed, 10 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/model/repo_group.py Wed Dec 21 23:15:38 2022 +0100 +++ b/kallithea/model/repo_group.py Thu Dec 22 01:02:36 2022 +0100 @@ -286,13 +286,18 @@ 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 @@ # 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)