def get(self, repo): log.debug('get_refs_info') service = self.get_argument('service', default=None) if service is not None: log.debug('looks like smart http') self.set_header('Content-type', 'application/x-%s-advertisement' % ( service)) ret = utils.mk_pkt_line('# service=%s\n%s' % ( service, utils.pkt_flush())) ret = '%s%s' % (ret, subprocess.check_output([git, pack_ops[self.get_argument('service')], '--stateless-rpc', '--advertise-refs', '%s/%s' % (base, repo)])) ret = ret.strip() else: log.debug('looks like dumb http') subprocess.check_call([git, 'update-server-info'], cwd='{}/{}'.format(base, repo)) self.set_header('Content-type', 'text/plain; charset=utf-8') with open('{}/{}/info/refs'.format(base, repo)) as f: ret = ''.join(f.readlines()) utils.hdr_nocache(self) self.write(ret)
def rpc_op(repo, op): log.debug('rpc_op: {0}'.format(op)) git = Git('{0}/{1}'.format(repo_base, repo)) response.set_header('Content-type', 'application/x-{0}-result'.format(op)) hdr_nocache(response) if op == 'git-upload-pack': p = git.upload_pack('--stateless-rpc') elif op == 'git-receive-pack': p = git.receive_pack('--stateless-rpc') log.debug('starting RPC: {0}'.format(request.body)) p.stdin.write(request.body.read()) log.debug('WTF') p.wait() log.debug('Git done') log.debug('getting data') while True: try: l = p.stdout.read(8192) if l == '': break yield l except OSError as e: if e.errno == errno.EBADF: break else: raise
def post(self, repo, op): log.debug('rpc_service') indata = self.request.body utils.hdr_nocache(self) self.set_header('Content-Type', 'application/x-%s-result' % (op)) proc = subprocess.Popen([git, pack_ops[op], '--stateless-rpc', '%s/%s' % (base, repo)], stdin=subprocess.PIPE, stdout=subprocess.PIPE) proc.stdin.write(indata) proc.wait() while True: outdata = proc.stdout.read(8192) if outdata == '': return self.write(outdata) self.flush()
def get_refs(repo): log.debug('service={0}'.format(request.query['service'])) git = Git('{0}/{1}'.format(repo_base, repo)) hdr_nocache(response) response.set_header('X-Powered-By', 'Me') yield mk_pkt_line('# service={0}\n'.format(request.query['service'])) yield '0000' response.set_header('Content-Type', 'application/x-{0}-advertisement'.format(request.query['service'])) if request.query['service'] == 'git-upload-pack': p = git.upload_pack('--stateless-rpc', '--advertise-refs') elif request.query['service'] == 'git-receive-pack': p = git.receive_pack('--stateless-rpc', '--advertise-refs') p.wait() log.debug('reading') while True: try: l = p.stdout.read(8192) if l == '': break yield l.strip() except OSError as e: if e.errno == errno.EBADF: break else: raise