Show More
@@ -22,6 +22,7 b'' | |||||
22 | SimpleGit middleware for handling git protocol request (push/clone etc.) |
|
22 | SimpleGit middleware for handling git protocol request (push/clone etc.) | |
23 | It's implemented with basic auth function |
|
23 | It's implemented with basic auth function | |
24 | """ |
|
24 | """ | |
|
25 | import os | |||
25 | import re |
|
26 | import re | |
26 | import logging |
|
27 | import logging | |
27 | import urlparse |
|
28 | import urlparse | |
@@ -34,7 +35,18 b' log = logging.getLogger(__name__)' | |||||
34 |
|
35 | |||
35 |
|
36 | |||
36 | GIT_PROTO_PAT = re.compile( |
|
37 | GIT_PROTO_PAT = re.compile( | |
37 | r'^/(.+)/(info/refs|git-upload-pack|git-receive-pack)') |
|
38 | r'^/(.+)/(info/refs|info/lfs/(.+)|git-upload-pack|git-receive-pack)') | |
|
39 | GIT_LFS_PROTO_PAT = re.compile(r'^/(.+)/(info/lfs/(.+))') | |||
|
40 | ||||
|
41 | ||||
|
42 | def default_lfs_store(): | |||
|
43 | """ | |||
|
44 | Default lfs store location, it's consistent with Mercurials large file | |||
|
45 | store which is in .cache/largefiles | |||
|
46 | """ | |||
|
47 | from rhodecode.lib.vcs.backends.git import lfs_store | |||
|
48 | user_home = os.path.expanduser("~") | |||
|
49 | return lfs_store(user_home) | |||
38 |
|
50 | |||
39 |
|
51 | |||
40 | class SimpleGit(simplevcs.SimpleVCS): |
|
52 | class SimpleGit(simplevcs.SimpleVCS): | |
@@ -48,8 +60,53 b' class SimpleGit(simplevcs.SimpleVCS):' | |||||
48 | :param environ: environ where PATH_INFO is stored |
|
60 | :param environ: environ where PATH_INFO is stored | |
49 | """ |
|
61 | """ | |
50 | repo_name = GIT_PROTO_PAT.match(environ['PATH_INFO']).group(1) |
|
62 | repo_name = GIT_PROTO_PAT.match(environ['PATH_INFO']).group(1) | |
|
63 | # for GIT LFS, and bare format strip .git suffix from names | |||
|
64 | if repo_name.endswith('.git'): | |||
|
65 | repo_name = repo_name[:-4] | |||
51 | return repo_name |
|
66 | return repo_name | |
52 |
|
67 | |||
|
68 | def _get_lfs_action(self, path, request_method): | |||
|
69 | """ | |||
|
70 | return an action based on LFS requests type. | |||
|
71 | Those routes are handled inside vcsserver app. | |||
|
72 | ||||
|
73 | batch -> POST to /info/lfs/objects/batch => PUSH/PULL | |||
|
74 | batch is based on the `operation. | |||
|
75 | that could be download or upload, but those are only | |||
|
76 | instructions to fetch so we return pull always | |||
|
77 | ||||
|
78 | download -> GET to /info/lfs/{oid} => PULL | |||
|
79 | upload -> PUT to /info/lfs/{oid} => PUSH | |||
|
80 | ||||
|
81 | verification -> POST to /info/lfs/verify => PULL | |||
|
82 | ||||
|
83 | """ | |||
|
84 | ||||
|
85 | match_obj = GIT_LFS_PROTO_PAT.match(path) | |||
|
86 | _parts = match_obj.groups() | |||
|
87 | repo_name, path, operation = _parts | |||
|
88 | log.debug( | |||
|
89 | 'LFS: detecting operation based on following ' | |||
|
90 | 'data: %s, req_method:%s', _parts, request_method) | |||
|
91 | ||||
|
92 | if operation == 'verify': | |||
|
93 | return 'pull' | |||
|
94 | elif operation == 'objects/batch': | |||
|
95 | # batch sends back instructions for API to dl/upl we report it | |||
|
96 | # as pull | |||
|
97 | if request_method == 'POST': | |||
|
98 | return 'pull' | |||
|
99 | ||||
|
100 | elif operation: | |||
|
101 | # probably a OID, upload is PUT, download a GET | |||
|
102 | if request_method == 'GET': | |||
|
103 | return 'pull' | |||
|
104 | else: | |||
|
105 | return 'push' | |||
|
106 | ||||
|
107 | # if default not found require push, as action | |||
|
108 | return 'push' | |||
|
109 | ||||
53 | _ACTION_MAPPING = { |
|
110 | _ACTION_MAPPING = { | |
54 | 'git-receive-pack': 'push', |
|
111 | 'git-receive-pack': 'push', | |
55 | 'git-upload-pack': 'pull', |
|
112 | 'git-upload-pack': 'pull', | |
@@ -68,6 +125,11 b' class SimpleGit(simplevcs.SimpleVCS):' | |||||
68 | query = urlparse.parse_qs(environ['QUERY_STRING']) |
|
125 | query = urlparse.parse_qs(environ['QUERY_STRING']) | |
69 | service_cmd = query.get('service', [''])[0] |
|
126 | service_cmd = query.get('service', [''])[0] | |
70 | return self._ACTION_MAPPING.get(service_cmd, 'pull') |
|
127 | return self._ACTION_MAPPING.get(service_cmd, 'pull') | |
|
128 | ||||
|
129 | elif GIT_LFS_PROTO_PAT.match(environ['PATH_INFO']): | |||
|
130 | return self._get_lfs_action( | |||
|
131 | environ['PATH_INFO'], environ['REQUEST_METHOD']) | |||
|
132 | ||||
71 | elif path.endswith('/git-receive-pack'): |
|
133 | elif path.endswith('/git-receive-pack'): | |
72 | return 'push' |
|
134 | return 'push' | |
73 | elif path.endswith('/git-upload-pack'): |
|
135 | elif path.endswith('/git-upload-pack'): | |
@@ -82,4 +144,10 b' class SimpleGit(simplevcs.SimpleVCS):' | |||||
82 | def _create_config(self, extras, repo_name): |
|
144 | def _create_config(self, extras, repo_name): | |
83 | extras['git_update_server_info'] = utils2.str2bool( |
|
145 | extras['git_update_server_info'] = utils2.str2bool( | |
84 | rhodecode.CONFIG.get('git_update_server_info')) |
|
146 | rhodecode.CONFIG.get('git_update_server_info')) | |
|
147 | ||||
|
148 | # TODO(marcink): controll this via DB settings, store and enabled-per | |||
|
149 | # repo settings | |||
|
150 | ||||
|
151 | extras['git_lfs_enabled'] = True | |||
|
152 | extras['git_lfs_store_path'] = default_lfs_store() | |||
85 | return extras |
|
153 | return extras |
General Comments 0
You need to be logged in to leave comments.
Login now