##// END OF EJS Templates
strip: cleanup code.
marcink -
r1698:ca5ed56e default
parent child Browse files
Show More
@@ -1,6 +1,6 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2011-2017 RhodeCode GmbH
3 # Copyright (C) 2017-2017 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
@@ -24,7 +24,7 b' from pyramid.view import view_config'
24 from rhodecode.apps._base import RepoAppView
24 from rhodecode.apps._base import RepoAppView
25 from rhodecode.lib.auth import (LoginRequired, HasRepoPermissionAnyDecorator,
25 from rhodecode.lib.auth import (LoginRequired, HasRepoPermissionAnyDecorator,
26 NotAnonymous)
26 NotAnonymous)
27
27 from rhodecode.lib.ext_json import json
28
28
29 log = logging.getLogger(__name__)
29 log = logging.getLogger(__name__)
30
30
@@ -57,21 +57,21 b' class StripView(RepoAppView):'
57 @HasRepoPermissionAnyDecorator('repository.admin')
57 @HasRepoPermissionAnyDecorator('repository.admin')
58 @view_config(
58 @view_config(
59 route_name='strip_check', request_method='POST',
59 route_name='strip_check', request_method='POST',
60 renderer='json', xhr=True
60 renderer='json', xhr=True)
61 )
62 def strip_check(self):
61 def strip_check(self):
63 from rhodecode.lib.vcs.backends.base import EmptyCommit
62 from rhodecode.lib.vcs.backends.base import EmptyCommit
64 data = {}
63 data = {}
65 rp = self.request.POST
64 rp = self.request.POST
66 for i in range(1, 11):
65 for i in range(1, 11):
67 chset = 'changeset_id-%d'%(i,)
66 chset = 'changeset_id-%d' % (i,)
68 check = rp.get(chset)
67 check = rp.get(chset)
69 if check:
68 if check:
70 data[i] = self.db_repo.get_changeset(rp[chset])
69 data[i] = self.db_repo.get_changeset(rp[chset])
71 if isinstance(data[i], EmptyCommit):
70 if isinstance(data[i], EmptyCommit):
72 data[i] = {'rev': None, 'commit': rp[chset]}
71 data[i] = {'rev': None, 'commit': rp[chset]}
73 else:
72 else:
74 data[i] = {'rev': data[i].raw_id, 'branch': data[i].branch, 'author': data[i].author,
73 data[i] = {'rev': data[i].raw_id, 'branch': data[i].branch,
74 'author': data[i].author,
75 'comment': data[i].message}
75 'comment': data[i].message}
76 else:
76 else:
77 break
77 break
@@ -82,12 +82,9 b' class StripView(RepoAppView):'
82 @HasRepoPermissionAnyDecorator('repository.admin')
82 @HasRepoPermissionAnyDecorator('repository.admin')
83 @view_config(
83 @view_config(
84 route_name='strip_execute', request_method='POST',
84 route_name='strip_execute', request_method='POST',
85 renderer='json', xhr=True
85 renderer='json', xhr=True)
86 )
87 def strip_execute(self):
86 def strip_execute(self):
88
89 from rhodecode.model.scm import ScmModel
87 from rhodecode.model.scm import ScmModel
90 from rhodecode.lib.ext_json import json
91
88
92 c = self.load_default_context()
89 c = self.load_default_context()
93 user = self._rhodecode_user
90 user = self._rhodecode_user
@@ -95,16 +92,18 b' class StripView(RepoAppView):'
95 data = {}
92 data = {}
96 for idx in rp:
93 for idx in rp:
97 commit = json.loads(rp[idx])
94 commit = json.loads(rp[idx])
98 #If someone put two times the same branch
95 # If someone put two times the same branch
99 if commit['branch'] in data.keys():
96 if commit['branch'] in data.keys():
100 continue
97 continue
101 try:
98 try:
102 ScmModel().strip(repo=c.repo_info,
99 ScmModel().strip(
103 commit_id=commit['rev'], branch=commit['branch'])
100 repo=c.repo_info,
104 log.info('Stripped commit %s from repo `%s` by %s' % (commit['rev'], c.repo_info.repo_name, user))
101 commit_id=commit['rev'], branch=commit['branch'])
102 log.info('Stripped commit %s from repo `%s` by %s' % (
103 commit['rev'], c.repo_info.repo_name, user))
105 data[commit['rev']] = True
104 data[commit['rev']] = True
106 except Exception, e:
105 except Exception as e:
107 data[commit['rev']] = False
106 data[commit['rev']] = False
108 log.debug('Stripped commit %s from repo `%s` failed by %s, exeption %s' % (commit['rev'],
107 log.debug('Stripped commit %s from repo `%s` failed by %s, exeption %s' % (
109 c.repo_info.repo_name, user, e.message))
108 commit['rev'], self.db_repo_name, user, e.message))
110 return data
109 return data
General Comments 0
You need to be logged in to leave comments. Login now