diff --git a/rhodecode/apps/repository/__init__.py b/rhodecode/apps/repository/__init__.py --- a/rhodecode/apps/repository/__init__.py +++ b/rhodecode/apps/repository/__init__.py @@ -29,5 +29,18 @@ def includeme(config): name='repo_maintenance_execute', pattern='/{repo_name:.*?[^/]}/maintenance/execute', repo_route=True) + + # Strip + config.add_route( + name='strip', + pattern='/{repo_name:.*?[^/]}/strip', repo_route=True) + + config.add_route( + name='strip_check', + pattern='/{repo_name:.*?[^/]}/strip_check', repo_route=True) + + config.add_route( + name='strip_execute', + pattern='/{repo_name:.*?[^/]}/strip_execute', repo_route=True) # Scan module for configuration decorators. config.scan() diff --git a/rhodecode/apps/repository/views/repo_maintainance.py b/rhodecode/apps/repository/views/strip.py copy from rhodecode/apps/repository/views/repo_maintainance.py copy to rhodecode/apps/repository/views/strip.py --- a/rhodecode/apps/repository/views/repo_maintainance.py +++ b/rhodecode/apps/repository/views/strip.py @@ -19,18 +19,17 @@ # and proprietary license terms, please see https://rhodecode.com/licenses/ import logging - from pyramid.view import view_config from rhodecode.apps._base import RepoAppView from rhodecode.lib.auth import (LoginRequired, HasRepoPermissionAnyDecorator, NotAnonymous) -from rhodecode.lib import repo_maintenance + log = logging.getLogger(__name__) -class RepoMaintenanceView(RepoAppView): +class StripView(RepoAppView): def load_default_context(self): c = self._get_local_tmpl_context() @@ -44,27 +43,68 @@ class RepoMaintenanceView(RepoAppView): @NotAnonymous() @HasRepoPermissionAnyDecorator('repository.admin') @view_config( - route_name='repo_maintenance', request_method='GET', + route_name='strip', request_method='GET', renderer='rhodecode:templates/admin/repos/repo_edit.mako') - def repo_maintenance(self): + def strip(self): c = self.load_default_context() - c.active = 'maintenance' - maintenance = repo_maintenance.RepoMaintenance() - c.executable_tasks = maintenance.get_tasks_for_repo(self.db_repo) + c.active = 'strip' + c.strip_limit = 10 + return self._get_template_context(c) @LoginRequired() @NotAnonymous() @HasRepoPermissionAnyDecorator('repository.admin') @view_config( - route_name='repo_maintenance_execute', request_method='GET', - renderer='json', xhr=True) - def repo_maintenance_execute(self): + route_name='strip_check', request_method='POST', + renderer='json', xhr=True + ) + def strip_check(self): + from rhodecode.lib.vcs.backends.base import EmptyCommit + data = {} + rp = self.request.POST + for i in range(1, 11): + chset = 'changeset_id-%d'%(i,) + check = rp.get(chset) + if check: + data[i] = self.db_repo.get_changeset(rp[chset]) + if isinstance(data[i], EmptyCommit): + data[i] = {'rev': None, 'commit': rp[chset]} + else: + data[i] = {'rev': data[i].raw_id, 'branch': data[i].branch, 'author': data[i].author, + 'comment': data[i].message} + else: + break + return data + + @LoginRequired() + @NotAnonymous() + @HasRepoPermissionAnyDecorator('repository.admin') + @view_config( + route_name='strip_execute', request_method='POST', + renderer='json', xhr=True + ) + def strip_execute(self): + + from rhodecode.model.scm import ScmModel + from rhodecode.lib.ext_json import json + c = self.load_default_context() - c.active = 'maintenance' - _ = self.request.translate - - maintenance = repo_maintenance.RepoMaintenance() - executed_types = maintenance.execute(self.db_repo) - - return executed_types + user = self._rhodecode_user + rp = self.request.POST + data = {} + for idx in rp: + commit = json.loads(rp[idx]) + #If someone put two times the same branch + if commit['branch'] in data.keys(): + continue + try: + ScmModel().strip(repo=c.repo_info, + commit_id=commit['rev'], branch=commit['branch']) + log.info('Stripped commit %s from repo `%s` by %s' % (commit['rev'], c.repo_info.repo_name, user)) + data[commit['rev']] = True + except Exception, e: + data[commit['rev']] = False + log.debug('Stripped commit %s from repo `%s` failed by %s, exeption %s' % (commit['rev'], + c.repo_info.repo_name, user, e.message)) + return data diff --git a/rhodecode/templates/admin/repos/repo_edit.mako b/rhodecode/templates/admin/repos/repo_edit.mako --- a/rhodecode/templates/admin/repos/repo_edit.mako +++ b/rhodecode/templates/admin/repos/repo_edit.mako @@ -74,6 +74,9 @@
  • ${_('Maintenance')}
  • +
  • + ${_('Strip')} +
  • ## TODO: dan: replace repo navigation with navlist registry like with ## admin menu. First must find way to allow runtime configuration ## it to account for the c.repo_info.repo_type != 'svn' call above diff --git a/rhodecode/templates/admin/repos/repo_edit_maintenance.mako b/rhodecode/templates/admin/repos/repo_edit_strip.mako copy from rhodecode/templates/admin/repos/repo_edit_maintenance.mako copy to rhodecode/templates/admin/repos/repo_edit_strip.mako --- a/rhodecode/templates/admin/repos/repo_edit_maintenance.mako +++ b/rhodecode/templates/admin/repos/repo_edit_strip.mako @@ -1,58 +1,169 @@
    -

    ${_('Maintenance')}

    +

    ${_('Strip')}

    + %if c.repo_info.repo_type != 'svn': +

    +

    ${_('Please provide up to %s commits commits to strip')%c.strip_limit}

    +

    +

    + ${_('In the first step commits will be verified for existance in the repository')}.
    + ${_('In the second step, correct commits will be available for stripping')}. +

    + ${h.secure_form(h.route_path('strip_check', repo_name=c.repo_info.repo_name), method='post')} +
    +
    + +
    + ${_('Add another commit')} +
    +
    +
    + +
    + +
    + -

    - % if c.executable_tasks: - ${_('Perform maintenance tasks for this repo, following tasks will be performed')}: -

      - % for task in c.executable_tasks: -
    1. ${task}
    2. - % endfor -
    - % else: - ${_('No maintenance tasks for this repo available')} - % endif -

    + ${h.end_form()} + %else: +

    +

    ${_('Sorry this functionality is not available for SVN repository')}

    +

    - - % if c.executable_tasks: -
    -
    - -
    -
    - % endif + %endif