LegacyNamespace inadvertently calls namespace service during renames

legacy_namespace.rb ends up calling add_namespae and mv_namespace for repository storages that only have projects that are hashed storage.

    def move_repositories
      # Move the namespace directory in all storages used by member projects
      repository_storages.each do |repository_storage|
        # Ensure old directory exists before moving it
        gitlab_shell.add_namespace(repository_storage, full_path_before_last_save)

        # Ensure new directory exists before moving it (if there's a parent)
        gitlab_shell.add_namespace(repository_storage, parent.full_path) if parent

        unless gitlab_shell.mv_namespace(repository_storage, full_path_before_last_save, full_path)

          Rails.logger.error "Exception moving path #{repository_storage} from #{full_path_before_last_save} to #{full_path}" # rubocop:disable Gitlab/RailsLogger

          # if we cannot move namespace directory we should rollback
          # db changes in order to prevent out of sync between db and fs
          raise Gitlab::UpdatePathError.new('namespace directory cannot be moved')
        end
      end
    end

    def old_repository_storages
      @old_repository_storage_paths ||= repository_storages
    end

   def repository_storages
      # We need to get the storage paths for all the projects, even the ones that are
      # pending delete. Unscoping also get rids of the default order, which causes
      # problems with SELECT DISTINCT.
      Project.unscoped do
        all_projects.select('distinct(repository_storage)').to_a.map(&:repository_storage)
      end
    end

repository_storages ends up selecting all repository storages, even if they only contain hashed projects. This means that even if there are no hashed projects, the namespace service will still get called to move the whole namespace, which is unnecessary.

It should only have to call move_repositories for repositories that are legacy storage.

Assignee Loading
Time tracking Loading