annotate rhodecode/lib/middleware/pygrack.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl

Imported some of the GPLv3'd changes from RhodeCode v2.2.5. This imports changes between changesets 21af6c4eab3d and 6177597791c2 in RhodeCode's original repository, including only changes to Python files and HTML. RhodeCode clearly licensed its changes to these files under GPLv3 in their /LICENSE file, which states the following: The Python code and integrated HTML are licensed under the GPLv3 license. (See: https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE or http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE for an online copy of that LICENSE file) Conservancy reviewed these changes and confirmed that they can be licensed as a whole to the Kallithea project under GPLv3-only. While some of the contents committed herein are clearly licensed GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the statement above from RhodeCode indicates that they intend GPLv3-only as their license, per GPLv3ยง14 and other relevant sections of GPLv3.
author Bradley M. Kuhn <bkuhn@sfconservancy.org>
date Wed, 02 Jul 2014 19:03:13 -0400
parents dc4644865e8b
children 7e5f8c12a3fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 import os
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 import socket
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 import logging
2875
f68522e3df79 more logging in pygrack
Marcin Kuzminski <marcin@python-works.com>
parents: 2870
diff changeset
4 import traceback
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 from webob import Request, Response, exc
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7
3376
e67b2ef07a8e git executable is now configurable via .ini files
Marcin Kuzminski <marcin@python-works.com>
parents: 2875
diff changeset
8 import rhodecode
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3577
diff changeset
9 from rhodecode.lib.vcs import subprocessio
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 log = logging.getLogger(__name__)
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 class FileWrapper(object):
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 def __init__(self, fd, content_length):
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 self.fd = fd
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 self.content_length = content_length
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 self.remain = content_length
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 def read(self, size):
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 if size <= self.remain:
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 try:
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 data = self.fd.read(size)
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 except socket.error:
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 raise IOError(self)
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 self.remain -= size
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 elif self.remain:
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 data = self.fd.read(self.remain)
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 self.remain = 0
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 else:
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32 data = None
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 return data
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 def __repr__(self):
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 return '<FileWrapper %s len: %s, read: %s>' % (
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 self.fd, self.content_length, self.content_length - self.remain
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 )
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 class GitRepository(object):
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 git_folder_signature = set(['config', 'head', 'info', 'objects', 'refs'])
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 commands = ['git-upload-pack', 'git-receive-pack']
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2594
diff changeset
45 def __init__(self, repo_name, content_path, extras):
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 files = set([f.lower() for f in os.listdir(content_path)])
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 if not (self.git_folder_signature.intersection(files)
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 == self.git_folder_signature):
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 raise OSError('%s missing git signature' % content_path)
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 self.content_path = content_path
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 self.valid_accepts = ['application/x-%s-result' %
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 c for c in self.commands]
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 self.repo_name = repo_name
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2594
diff changeset
54 self.extras = extras
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 def _get_fixedpath(self, path):
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 """
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58 Small fix for repo_path
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 :param path:
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 """
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 return path.split(self.repo_name, 1)[-1].strip('/')
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 def inforefs(self, request, environ):
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 """
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 WSGI Response producer for HTTP GET Git Smart
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 HTTP /info/refs request.
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68 """
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2594
diff changeset
70 git_command = request.GET.get('service')
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71 if git_command not in self.commands:
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 log.debug('command %s not allowed' % git_command)
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 return exc.HTTPMethodNotAllowed()
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 # note to self:
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 # please, resist the urge to add '\n' to git capture and increment
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77 # line count by 1.
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 # The code in Git client not only does NOT need '\n', but actually
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 # blows up if you sprinkle "flush" (0000) as "0001\n".
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 # It reads binary, per number of bytes specified.
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81 # if you do add '\n' as part of data, count it.
2579
c344a7fca2a7 reset response charset to fix Egit/JGit issues
Marcin Kuzminski <marcin@python-works.com>
parents: 2502
diff changeset
82 server_advert = '# service=%s' % git_command
c344a7fca2a7 reset response charset to fix Egit/JGit issues
Marcin Kuzminski <marcin@python-works.com>
parents: 2502
diff changeset
83 packet_len = str(hex(len(server_advert) + 4)[2:].rjust(4, '0')).lower()
3376
e67b2ef07a8e git executable is now configurable via .ini files
Marcin Kuzminski <marcin@python-works.com>
parents: 2875
diff changeset
84 _git_path = rhodecode.CONFIG.get('git_path', 'git')
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85 try:
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
86 out = subprocessio.SubprocessIOChunker(
3376
e67b2ef07a8e git executable is now configurable via .ini files
Marcin Kuzminski <marcin@python-works.com>
parents: 2875
diff changeset
87 r'%s %s --stateless-rpc --advertise-refs "%s"' % (
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3840
diff changeset
88 _git_path, git_command[4:], self.content_path),
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 starting_values=[
2579
c344a7fca2a7 reset response charset to fix Egit/JGit issues
Marcin Kuzminski <marcin@python-works.com>
parents: 2502
diff changeset
90 packet_len + server_advert + '0000'
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 ]
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 )
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93 except EnvironmentError, e:
2875
f68522e3df79 more logging in pygrack
Marcin Kuzminski <marcin@python-works.com>
parents: 2870
diff changeset
94 log.error(traceback.format_exc())
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 raise exc.HTTPExpectationFailed()
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 resp = Response()
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97 resp.content_type = 'application/x-%s-advertisement' % str(git_command)
2579
c344a7fca2a7 reset response charset to fix Egit/JGit issues
Marcin Kuzminski <marcin@python-works.com>
parents: 2502
diff changeset
98 resp.charset = None
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99 resp.app_iter = out
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
100 return resp
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 def backend(self, request, environ):
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 """
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104 WSGI Response producer for HTTP POST Git Smart HTTP requests.
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
105 Reads commands and data from HTTP POST's body.
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106 returns an iterator obj with contents of git command's
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
107 response to stdout
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
108 """
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3840
diff changeset
109 _git_path = rhodecode.CONFIG.get('git_path', 'git')
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 git_command = self._get_fixedpath(request.path_info)
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
111 if git_command not in self.commands:
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
112 log.debug('command %s not allowed' % git_command)
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
113 return exc.HTTPMethodNotAllowed()
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
114
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
115 if 'CONTENT_LENGTH' in environ:
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
116 inputstream = FileWrapper(environ['wsgi.input'],
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117 request.content_length)
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
118 else:
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
119 inputstream = environ['wsgi.input']
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
120
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
121 try:
2402
2eeb2ed72e55 Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents: 2398
diff changeset
122 gitenv = os.environ
2eeb2ed72e55 Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents: 2398
diff changeset
123 # forget all configs
2eeb2ed72e55 Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents: 2398
diff changeset
124 gitenv['GIT_CONFIG_NOGLOBAL'] = '1'
2eeb2ed72e55 Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents: 2398
diff changeset
125 opts = dict(
2406
7be31af5bc78 changed scope of calling EXTENSIONS from rhodecode for githooks to be able to execute them
Marcin Kuzminski <marcin@python-works.com>
parents: 2402
diff changeset
126 env=gitenv,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3840
diff changeset
127 cwd=self.content_path,
2402
2eeb2ed72e55 Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents: 2398
diff changeset
128 )
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3840
diff changeset
129 cmd = r'%s %s --stateless-rpc "%s"' % (_git_path, git_command[4:],
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3840
diff changeset
130 self.content_path),
2875
f68522e3df79 more logging in pygrack
Marcin Kuzminski <marcin@python-works.com>
parents: 2870
diff changeset
131 log.debug('handling cmd %s' % cmd)
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
132 out = subprocessio.SubprocessIOChunker(
2875
f68522e3df79 more logging in pygrack
Marcin Kuzminski <marcin@python-works.com>
parents: 2870
diff changeset
133 cmd,
2402
2eeb2ed72e55 Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents: 2398
diff changeset
134 inputstream=inputstream,
2eeb2ed72e55 Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents: 2398
diff changeset
135 **opts
2eeb2ed72e55 Added handling of git hooks, extract pushed revisions and store them inside
Marcin Kuzminski <marcin@python-works.com>
parents: 2398
diff changeset
136 )
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
137 except EnvironmentError, e:
2875
f68522e3df79 more logging in pygrack
Marcin Kuzminski <marcin@python-works.com>
parents: 2870
diff changeset
138 log.error(traceback.format_exc())
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
139 raise exc.HTTPExpectationFailed()
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
140
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
141 if git_command in [u'git-receive-pack']:
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
142 # updating refs manually after each push.
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
143 # Needed for pre-1.7.0.4 git clients using regular HTTP mode.
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3840
diff changeset
144 from rhodecode.lib.vcs import get_repo
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3840
diff changeset
145 from dulwich.server import update_server_info
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3840
diff changeset
146 repo = get_repo(self.content_path)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3840
diff changeset
147 if repo:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3840
diff changeset
148 update_server_info(repo._repo)
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
149
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
150 resp = Response()
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
151 resp.content_type = 'application/x-%s-result' % git_command.encode('utf8')
2581
ee980eadc4b1 reset charset for git rpc cals also
Marcin Kuzminski <marcin@python-works.com>
parents: 2579
diff changeset
152 resp.charset = None
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
153 resp.app_iter = out
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
154 return resp
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
155
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
156 def __call__(self, environ, start_response):
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
157 request = Request(environ)
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
158 _path = self._get_fixedpath(request.path_info)
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
159 if _path.startswith('info/refs'):
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
160 app = self.inforefs
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
161 elif [a for a in self.valid_accepts if a in request.accept]:
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
162 app = self.backend
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
163 try:
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
164 resp = app(request, environ)
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
165 except exc.HTTPException, e:
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
166 resp = e
2875
f68522e3df79 more logging in pygrack
Marcin Kuzminski <marcin@python-works.com>
parents: 2870
diff changeset
167 log.error(traceback.format_exc())
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
168 except Exception, e:
2875
f68522e3df79 more logging in pygrack
Marcin Kuzminski <marcin@python-works.com>
parents: 2870
diff changeset
169 log.error(traceback.format_exc())
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
170 resp = exc.HTTPInternalServerError()
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
171 return resp(environ, start_response)
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
172
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
173
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
174 class GitDirectory(object):
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
175
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2594
diff changeset
176 def __init__(self, repo_root, repo_name, extras):
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
177 repo_location = os.path.join(repo_root, repo_name)
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
178 if not os.path.isdir(repo_location):
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
179 raise OSError(repo_location)
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
180
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
181 self.content_path = repo_location
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
182 self.repo_name = repo_name
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
183 self.repo_location = repo_location
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2594
diff changeset
184 self.extras = extras
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
185
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
186 def __call__(self, environ, start_response):
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
187 content_path = self.content_path
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
188 try:
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2594
diff changeset
189 app = GitRepository(self.repo_name, content_path, self.extras)
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
190 except (AssertionError, OSError):
2764
c7a27b04ce58 fixed #545, exception during cloning of non-bare repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
191 content_path = os.path.join(content_path, '.git')
c7a27b04ce58 fixed #545, exception during cloning of non-bare repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
192 if os.path.isdir(content_path):
c7a27b04ce58 fixed #545, exception during cloning of non-bare repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
193 app = GitRepository(self.repo_name, content_path, self.extras)
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
194 else:
2594
3a54e1e121d5 fix http NotFound call in pygrack
Marcin Kuzminski <marcin@python-works.com>
parents: 2581
diff changeset
195 return exc.HTTPNotFound()(environ, start_response)
2382
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
196 return app(environ, start_response)
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
197
034e4fe1ebb2 changed dulwich git interface to gitweb + subprocessio
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
198
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2594
diff changeset
199 def make_wsgi_app(repo_name, repo_root, extras):
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3840
diff changeset
200 from dulwich.web import LimitedInputFilter, GunzipFilter
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3840
diff changeset
201 app = GitDirectory(repo_root, repo_name, extras)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3840
diff changeset
202 return GunzipFilter(LimitedInputFilter(app))