Show More
@@ -33,6 +33,7 b' from mercurial.node import nullrev' | |||||
33 | from rhodecode.lib import helpers as h |
|
33 | from rhodecode.lib import helpers as h | |
34 | from rhodecode.lib.utils import action_logger |
|
34 | from rhodecode.lib.utils import action_logger | |
35 | from rhodecode.lib.vcs.backends.base import EmptyChangeset |
|
35 | from rhodecode.lib.vcs.backends.base import EmptyChangeset | |
|
36 | from rhodecode.lib.compat import json | |||
36 |
|
37 | |||
37 |
|
38 | |||
38 | def _get_scm_size(alias, root_path): |
|
39 | def _get_scm_size(alias, root_path): | |
@@ -90,12 +91,23 b' def log_pull_action(ui, repo, **kwargs):' | |||||
90 | :param ui: |
|
91 | :param ui: | |
91 | :param repo: |
|
92 | :param repo: | |
92 | """ |
|
93 | """ | |
|
94 | try: | |||
|
95 | rc_extras = json.loads(os.environ.get('RC_SCM_DATA', "{}")) | |||
|
96 | except: | |||
|
97 | rc_extras = {} | |||
93 | extras = dict(repo.ui.configitems('rhodecode_extras')) |
|
98 | extras = dict(repo.ui.configitems('rhodecode_extras')) | |
|
99 | if 'username' in extras: | |||
94 | username = extras['username'] |
|
100 | username = extras['username'] | |
95 | repository = extras['repository'] |
|
101 | repository = extras['repository'] | |
96 | scm = extras['scm'] |
|
102 | scm = extras['scm'] | |
|
103 | elif 'username' in rc_extras: | |||
|
104 | username = rc_extras['username'] | |||
|
105 | repository = rc_extras['repository'] | |||
|
106 | scm = rc_extras['scm'] | |||
|
107 | else: | |||
|
108 | raise Exception('Missing data in repo.ui and os.environ') | |||
|
109 | ||||
97 | action = 'pull' |
|
110 | action = 'pull' | |
98 |
|
||||
99 | action_logger(username, action, repository, extras['ip'], commit=True) |
|
111 | action_logger(username, action, repository, extras['ip'], commit=True) | |
100 | # extension hook call |
|
112 | # extension hook call | |
101 | from rhodecode import EXTENSIONS |
|
113 | from rhodecode import EXTENSIONS | |
@@ -116,11 +128,24 b' def log_push_action(ui, repo, **kwargs):' | |||||
116 | :param repo: repo object containing the `ui` object |
|
128 | :param repo: repo object containing the `ui` object | |
117 | """ |
|
129 | """ | |
118 |
|
130 | |||
|
131 | try: | |||
|
132 | rc_extras = json.loads(os.environ.get('RC_SCM_DATA', "{}")) | |||
|
133 | except: | |||
|
134 | rc_extras = {} | |||
|
135 | ||||
119 | extras = dict(repo.ui.configitems('rhodecode_extras')) |
|
136 | extras = dict(repo.ui.configitems('rhodecode_extras')) | |
|
137 | if 'username' in extras: | |||
120 | username = extras['username'] |
|
138 | username = extras['username'] | |
121 | repository = extras['repository'] |
|
139 | repository = extras['repository'] | |
122 | action = extras['action'] + ':%s' |
|
|||
123 | scm = extras['scm'] |
|
140 | scm = extras['scm'] | |
|
141 | elif 'username' in rc_extras: | |||
|
142 | username = rc_extras['username'] | |||
|
143 | repository = rc_extras['repository'] | |||
|
144 | scm = rc_extras['scm'] | |||
|
145 | else: | |||
|
146 | raise Exception('Missing data in repo.ui and os.environ') | |||
|
147 | ||||
|
148 | action = 'push' + ':%s' | |||
124 |
|
149 | |||
125 | if scm == 'hg': |
|
150 | if scm == 'hg': | |
126 | node = kwargs['node'] |
|
151 | node = kwargs['node'] |
@@ -81,6 +81,7 b' from rhodecode.lib.utils2 import safe_st' | |||||
81 | from rhodecode.lib.base import BaseVCSController |
|
81 | from rhodecode.lib.base import BaseVCSController | |
82 | from rhodecode.lib.auth import get_container_username |
|
82 | from rhodecode.lib.auth import get_container_username | |
83 | from rhodecode.lib.utils import is_valid_repo, make_ui |
|
83 | from rhodecode.lib.utils import is_valid_repo, make_ui | |
|
84 | from rhodecode.lib.compat import json | |||
84 | from rhodecode.model.db import User, RhodeCodeUi |
|
85 | from rhodecode.model.db import User, RhodeCodeUi | |
85 |
|
86 | |||
86 | log = logging.getLogger(__name__) |
|
87 | log = logging.getLogger(__name__) | |
@@ -122,7 +123,7 b' class SimpleGit(BaseVCSController):' | |||||
122 | return HTTPInternalServerError()(environ, start_response) |
|
123 | return HTTPInternalServerError()(environ, start_response) | |
123 |
|
124 | |||
124 | # quick check if that dir exists... |
|
125 | # quick check if that dir exists... | |
125 | if is_valid_repo(repo_name, self.basepath) is False: |
|
126 | if is_valid_repo(repo_name, self.basepath, 'git') is False: | |
126 | return HTTPNotFound()(environ, start_response) |
|
127 | return HTTPNotFound()(environ, start_response) | |
127 |
|
128 | |||
128 | #====================================================================== |
|
129 | #====================================================================== | |
@@ -190,7 +191,8 b' class SimpleGit(BaseVCSController):' | |||||
190 | 'repository': repo_name, |
|
191 | 'repository': repo_name, | |
191 | 'scm': 'git', |
|
192 | 'scm': 'git', | |
192 | } |
|
193 | } | |
193 |
|
194 | # set the environ variables for this request | ||
|
195 | os.environ['RC_SCM_DATA'] = json.dumps(extras) | |||
194 | #=================================================================== |
|
196 | #=================================================================== | |
195 | # GIT REQUEST HANDLING |
|
197 | # GIT REQUEST HANDLING | |
196 | #=================================================================== |
|
198 | #=================================================================== |
@@ -40,6 +40,7 b' from rhodecode.lib.utils2 import safe_st' | |||||
40 | from rhodecode.lib.base import BaseVCSController |
|
40 | from rhodecode.lib.base import BaseVCSController | |
41 | from rhodecode.lib.auth import get_container_username |
|
41 | from rhodecode.lib.auth import get_container_username | |
42 | from rhodecode.lib.utils import make_ui, is_valid_repo, ui_sections |
|
42 | from rhodecode.lib.utils import make_ui, is_valid_repo, ui_sections | |
|
43 | from rhodecode.lib.compat import json | |||
43 | from rhodecode.model.db import User |
|
44 | from rhodecode.model.db import User | |
44 |
|
45 | |||
45 |
|
46 | |||
@@ -87,7 +88,7 b' class SimpleHg(BaseVCSController):' | |||||
87 | return HTTPInternalServerError()(environ, start_response) |
|
88 | return HTTPInternalServerError()(environ, start_response) | |
88 |
|
89 | |||
89 | # quick check if that dir exists... |
|
90 | # quick check if that dir exists... | |
90 | if is_valid_repo(repo_name, self.basepath) is False: |
|
91 | if is_valid_repo(repo_name, self.basepath, 'hg') is False: | |
91 | return HTTPNotFound()(environ, start_response) |
|
92 | return HTTPNotFound()(environ, start_response) | |
92 |
|
93 | |||
93 | #====================================================================== |
|
94 | #====================================================================== | |
@@ -157,7 +158,8 b' class SimpleHg(BaseVCSController):' | |||||
157 | 'repository': repo_name, |
|
158 | 'repository': repo_name, | |
158 | 'scm': 'hg', |
|
159 | 'scm': 'hg', | |
159 | } |
|
160 | } | |
160 |
|
161 | # set the environ variables for this request | ||
|
162 | os.environ['RC_SCM_DATA'] = json.dumps(extras) | |||
161 | #====================================================================== |
|
163 | #====================================================================== | |
162 | # MERCURIAL REQUEST HANDLING |
|
164 | # MERCURIAL REQUEST HANDLING | |
163 | #====================================================================== |
|
165 | #====================================================================== |
@@ -203,19 +203,24 b' def get_repos(path, recursive=False):' | |||||
203 | return _get_repos(path) |
|
203 | return _get_repos(path) | |
204 |
|
204 | |||
205 |
|
205 | |||
206 | def is_valid_repo(repo_name, base_path): |
|
206 | def is_valid_repo(repo_name, base_path, scm=None): | |
207 | """ |
|
207 | """ | |
208 | Returns True if given path is a valid repository False otherwise |
|
208 | Returns True if given path is a valid repository False otherwise. | |
|
209 | If scm param is given also compare if given scm is the same as expected | |||
|
210 | from scm parameter | |||
209 |
|
211 | |||
210 | :param repo_name: |
|
212 | :param repo_name: | |
211 | :param base_path: |
|
213 | :param base_path: | |
|
214 | :param scm: | |||
212 |
|
215 | |||
213 | :return True: if given path is a valid repository |
|
216 | :return True: if given path is a valid repository | |
214 | """ |
|
217 | """ | |
215 | full_path = os.path.join(safe_str(base_path), safe_str(repo_name)) |
|
218 | full_path = os.path.join(safe_str(base_path), safe_str(repo_name)) | |
216 |
|
219 | |||
217 | try: |
|
220 | try: | |
218 | get_scm(full_path) |
|
221 | scm_ = get_scm(full_path) | |
|
222 | if scm: | |||
|
223 | return scm_[0] == scm | |||
219 | return True |
|
224 | return True | |
220 | except VCSError: |
|
225 | except VCSError: | |
221 | return False |
|
226 | return False |
General Comments 0
You need to be logged in to leave comments.
Login now