# HG changeset patch # User Marcin Kuzminski # Date 2018-09-06 15:43:54 # Node ID ae9279cbd48903e6d9b90dd72dbeb268e07320ab # Parent ab171c02a5d590d08885320a69c73121ed47ea5d maintainance: add repack and fsck for git maintainance execution list. diff --git a/rhodecode/apps/repository/views/repo_maintainance.py b/rhodecode/apps/repository/views/repo_maintainance.py --- a/rhodecode/apps/repository/views/repo_maintainance.py +++ b/rhodecode/apps/repository/views/repo_maintainance.py @@ -32,8 +32,6 @@ log = logging.getLogger(__name__) class RepoMaintenanceView(RepoAppView): def load_default_context(self): c = self._get_local_tmpl_context() - - return c @LoginRequired() diff --git a/rhodecode/lib/repo_maintenance.py b/rhodecode/lib/repo_maintenance.py --- a/rhodecode/lib/repo_maintenance.py +++ b/rhodecode/lib/repo_maintenance.py @@ -51,25 +51,81 @@ class GitGC(MaintenanceTask): output = [] instance = self.db_repo.scm_instance() - objects = self._count_objects(instance) - output.append(objects) - log.debug('GIT objects:%s', objects) - - stdout, stderr = instance.run_git_command( - ['gc', '--aggressive'], fail_on_stderr=False) + objects_before = self._count_objects(instance) - out = 'executed git gc --aggressive' - if stderr: - out = ''.join(stderr.splitlines()) + log.debug('GIT objects:%s', objects_before) + cmd = ['gc', '--aggressive'] + stdout, stderr = instance.run_git_command(cmd, fail_on_stderr=False) - elif stdout: - out = ''.join(stdout.splitlines()) - + out = 'executed {}'.format(' '.join(cmd)) output.append(out) - objects = self._count_objects(instance) - log.debug('GIT objects:%s', objects) - output.append(objects) + out = '' + if stderr: + out += ''.join(stderr.splitlines()) + + if stdout: + out += ''.join(stdout.splitlines()) + + if out: + output.append(out) + + objects_after = self._count_objects(instance) + log.debug('GIT objects:%s', objects_after) + output.append('objects before :' + objects_before) + output.append('objects after :' + objects_after) + + return '\n'.join(output) + + +class GitFSCK(MaintenanceTask): + human_name = 'GIT FSCK' + + def run(self): + output = [] + instance = self.db_repo.scm_instance() + + cmd = ['fsck', '--full'] + stdout, stderr = instance.run_git_command(cmd, fail_on_stderr=False) + + out = 'executed {}'.format(' '.join(cmd)) + output.append(out) + + out = '' + if stderr: + out += ''.join(stderr.splitlines()) + + if stdout: + out += ''.join(stdout.splitlines()) + + if out: + output.append(out) + + return '\n'.join(output) + + +class GitRepack(MaintenanceTask): + human_name = 'GIT Repack' + + def run(self): + output = [] + instance = self.db_repo.scm_instance() + cmd = ['repack', '-a', '-d', + '--window-memory', '10m', '--max-pack-size', '100m'] + stdout, stderr = instance.run_git_command(cmd, fail_on_stderr=False) + + out = 'executed {}'.format(' '.join(cmd)) + output.append(out) + out = '' + + if stderr: + out += ''.join(stderr.splitlines()) + + if stdout: + out += ''.join(stdout.splitlines()) + + if out: + output.append(out) return '\n'.join(output) @@ -98,7 +154,7 @@ class RepoMaintenance(object): """ tasks = { 'hg': [HGVerify], - 'git': [GitGC], + 'git': [GitFSCK, GitGC, GitRepack], 'svn': [SVNVerify], } @@ -114,5 +170,6 @@ class RepoMaintenance(object): def execute(self, db_repo): executed_tasks = [] for task in self.tasks[db_repo.repo_type]: - executed_tasks.append(task(db_repo).run()) + output = task.human_name + ':\n' + task(db_repo).run() + '\n--\n' + executed_tasks.append(output) return executed_tasks