Mercurial > kallithea
changeset 7409:5eb6805c2a4f
cli: convert 'gearbox update-repoinfo' into 'kallithea-cli repo-update-metadata'
The --update-only option is replaced by listing repository names as separate command line arguments.
The --invalidate-cache option is dropped and we just always invalidate all caches.
author | Thomas De Schampheleire <thomas.de_schampheleire@nokia.com> |
---|---|
date | Sun, 18 Nov 2018 20:02:17 +0100 |
parents | 0080ffd8aea0 |
children | f10d56cb055c |
files | kallithea/bin/kallithea_cli_repo.py kallithea/lib/paster_commands/update_repoinfo.py setup.py |
diffstat | 3 files changed, 37 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/bin/kallithea_cli_repo.py Sun Nov 18 20:02:17 2018 +0100 +++ b/kallithea/bin/kallithea_cli_repo.py Sun Nov 18 20:02:17 2018 +0100 @@ -23,6 +23,9 @@ import kallithea.bin.kallithea_cli_base as cli_base from kallithea.lib.utils import repo2db_mapper +from kallithea.lib.utils2 import safe_unicode +from kallithea.model.db import Repository +from kallithea.model.meta import Session from kallithea.model.scm import ScmModel @cli_base.register_command(config_file_initialize_app=True) @@ -46,3 +49,37 @@ if removed: click.echo('%s: %s' % ('Removed' if remove_missing else 'Missing', ', '.join(removed))) + +@cli_base.register_command(config_file_initialize_app=True) +@click.argument('repositories', nargs=-1) +def repo_update_metadata(repositories): + """ + Update repository metadata in database from repository content. + + In normal operation, Kallithea will keep caches up-to-date + automatically. However, if repositories are externally modified, e.g. by + a direct push via the filesystem rather than via a Kallithea URL, + Kallithea is not aware of it. In this case, you should manually run this + command to update the repository cache. + + If no repositories are specified, the caches of all repositories are + updated. + """ + if not repositories: + repo_list = Repository.query().all() + else: + repo_names = [safe_unicode(n.strip()) for n in repositories] + repo_list = list(Repository.query() + .filter(Repository.repo_name.in_(repo_names))) + + for repo in repo_list: + # update latest revision metadata in database + repo.update_changeset_cache() + # invalidate in-memory VCS object cache... will be repopulated on + # first access + repo.set_invalidate() + + Session().commit() + + click.echo('Updated database with information about latest change in the following %s repositories:' % (len(repo_list))) + click.echo('\n'.join(repo.repo_name for repo in repo_list))
--- a/kallithea/lib/paster_commands/update_repoinfo.py Sun Nov 18 20:02:17 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -# -*- coding: utf-8 -*- -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -""" -kallithea.lib.paster_commands.update_repoinfo -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -update-repoinfo gearbox command for Kallithea - -This file was forked by the Kallithea project in July 2014. -Original author and date, and relevant copyright and licensing information is below: -:created_on: Jul 14, 2012 -:author: marcink -:copyright: (c) 2013 RhodeCode GmbH, and others. -:license: GPLv3, see LICENSE.md for more details. -""" - - - -from kallithea.lib.paster_commands.common import BasePasterCommand -from kallithea.lib.utils2 import safe_unicode -from kallithea.model.db import Repository -from kallithea.model.meta import Session - - -class Command(BasePasterCommand): - "Kallithea: Update database cache of repository data" - - def take_action(self, args): - if args.repo_update_list is None: - repo_list = Repository.query().all() - else: - repo_names = [safe_unicode(n.strip()) - for n in args.repo_update_list.split(',')] - repo_list = list(Repository.query() - .filter(Repository.repo_name.in_(repo_names))) - for repo in repo_list: - repo.update_changeset_cache() - Session().commit() - - if args.invalidate_cache: - for r in repo_list: - r.set_invalidate() - print 'Updated repo info and invalidated cache for %s repositories' % (len(repo_list)) - else: - print 'Updated repo info for %s repositories' % (len(repo_list)) - - def get_parser(self, prog_name): - parser = super(Command, self).get_parser(prog_name) - - parser.add_argument('--update-only', - action='store', - dest='repo_update_list', - help="Specifies a comma separated list of repositories " - "to update last commit info for. OPTIONAL") - parser.add_argument('--invalidate-cache', - action='store_true', - dest='invalidate_cache', - help="Trigger cache invalidation event for repos. " - "OPTIONAL") - - return parser
--- a/setup.py Sun Nov 18 20:02:17 2018 +0100 +++ b/setup.py Sun Nov 18 20:02:17 2018 +0100 @@ -166,7 +166,6 @@ make-index=kallithea.lib.paster_commands.make_index:Command make-rcext=kallithea.lib.paster_commands.make_rcextensions:Command setup-db=kallithea.lib.paster_commands.setup_db:Command - update-repoinfo=kallithea.lib.paster_commands.update_repoinfo:Command upgrade-db=kallithea.lib.dbmigrate:UpgradeDb """, )