[PATCH 08 of 17 v3] cli: convert 'gearbox update-repoinfo' into 'kallithea-cli repo-update-cache'

Thomas De Schampheleire patrickdepinguin at gmail.com
Thu Oct 18 20:49:31 UTC 2018


# HG changeset patch
# User Thomas De Schampheleire <thomas.de_schampheleire at nokia.com>
# Date 1539371855 -7200
#      Fri Oct 12 21:17:35 2018 +0200
# Node ID 41448a482e0d03d701e8acd0fa03a15cfe3ba2aa
# Parent  14d028cae3da185a91fa9025df498632913ff056
cli: convert 'gearbox update-repoinfo' into 'kallithea-cli repo-update-cache'

diff --git a/kallithea/bin/kallithea_cli_repo.py b/kallithea/bin/kallithea_cli_repo.py
--- a/kallithea/bin/kallithea_cli_repo.py
+++ b/kallithea/bin/kallithea_cli_repo.py
@@ -24,6 +24,9 @@ from kallithea.bin.kallithea_cli_base im
 import kallithea.bin.kallithea_cli_util as cli_util
 
 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.command()
@@ -48,3 +51,38 @@ def repo_scan(config_file, remove_missin
     if removed:
         click.echo('%s: %s' % ('Removed' if remove_missing else 'Missing',
                           ', '.join(removed)))
+
+ at cli.command()
+ at cli_util.auto_setup_app()
+ at click.argument('repositories', nargs=-1)
+def repo_update_cache(config_file, repositories):
+    """
+    Update repo cache after external modification.
+
+    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 repository cache for following %s repositories' % (len(repo_list)))
+    click.echo('\n'.join(repo.repo_name for repo in repo_list))
diff --git a/kallithea/lib/paster_commands/update_repoinfo.py b/kallithea/lib/paster_commands/update_repoinfo.py
deleted file mode 100644
--- a/kallithea/lib/paster_commands/update_repoinfo.py
+++ /dev/null
@@ -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
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -163,7 +163,6 @@ setuptools.setup(
     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
     """,
 )


More information about the kallithea-general mailing list