def rev_list(conn, _): _init_session() count = conn.readline() if not count: raise Exception('Unexpected EOF while reading rev-list count') count = None if count == '\n' else int(count) fmt = conn.readline() if not fmt: raise Exception('Unexpected EOF while reading rev-list format') fmt = None if fmt == '\n' else fmt[:-1] refs = tuple(x[:-1] for x in lines_until_sentinel(conn, '\n', Exception)) args = git.rev_list_invocation(refs, count=count, format=fmt) p = subprocess.Popen(git.rev_list_invocation(refs, count=count, format=fmt), preexec_fn=git._gitenv(git.repodir), stdout=subprocess.PIPE) while True: out = p.stdout.read(64 * 1024) if not out: break conn.write(out) rv = p.wait() # not fatal if rv: msg = 'git rev-list returned error %d' % rv conn.error(msg) raise GitError(msg) conn.ok()
def refs(self, patterns=None, limit_to_heads=False, limit_to_tags=False): patterns = patterns or tuple() self._require_command(b'refs') self.check_busy() self._busy = b'refs' conn = self.conn conn.write(b'refs %d %d\n' % (1 if limit_to_heads else 0, 1 if limit_to_tags else 0)) for pattern in patterns: assert b'\n' not in pattern conn.write(pattern) conn.write(b'\n') conn.write(b'\n') for line in lines_until_sentinel(conn, b'\n', ClientError): line = line[:-1] oidx, name = line.split(b' ') if len(oidx) != 40: raise ClientError('Invalid object fingerprint in %r' % line) if not name: raise ClientError('Invalid reference name in %r' % line) yield name, unhexlify(oidx) # FIXME: confusing not_ok = self.check_ok() if not_ok: raise not_ok self._not_busy()
def refs(self, patterns=None, limit_to_heads=False, limit_to_tags=False): patterns = patterns or tuple() self._require_command('refs') self.check_busy() self._busy = 'refs' conn = self.conn conn.write('refs %s %s\n' % (1 if limit_to_heads else 0, 1 if limit_to_tags else 0)) for pattern in patterns: assert '\n' not in pattern conn.write(pattern) conn.write('\n') conn.write('\n') for line in lines_until_sentinel(conn, '\n', ClientError): line = line[:-1] oidx, name = line.split(' ') if len(oidx) != 40: raise ClientError('Invalid object fingerprint in %r' % line) if not name: raise ClientError('Invalid reference name in %r' % line) yield name, oidx.decode('hex') # FIXME: confusing not_ok = self.check_ok() if not_ok: raise not_ok self._not_busy()
def rev_list(self, refs, count=None, parse=None, format=None): """See git.rev_list for the general semantics, but note that with the current interface, the parse function must be able to handle (consume) any blank lines produced by the format because the first one received that it doesn't consume will be interpreted as a terminator for the entire rev-list result. """ self._require_command(b'rev-list') assert (count is None) or (isinstance(count, Integral)) if format: assert b'\n' not in format assert parse for ref in refs: assert ref assert b'\n' not in ref self.check_busy() self._busy = b'rev-list' conn = self.conn conn.write(b'rev-list\n') if count is not None: conn.write(b'%d' % count) conn.write(b'\n') if format: conn.write(format) conn.write(b'\n') for ref in refs: conn.write(ref) conn.write(b'\n') conn.write(b'\n') if not format: for line in lines_until_sentinel(conn, b'\n', ClientError): line = line.strip() assert len(line) == 40 yield line else: for line in lines_until_sentinel(conn, b'\n', ClientError): if not line.startswith(b'commit '): raise ClientError('unexpected line ' + repr(line)) cmt_oidx = line[7:].strip() assert len(cmt_oidx) == 40 yield cmt_oidx, parse(conn) # FIXME: confusing not_ok = self.check_ok() if not_ok: raise not_ok self._not_busy()
def rev_list(self, refs, count=None, parse=None, format=None): """See git.rev_list for the general semantics, but note that with the current interface, the parse function must be able to handle (consume) any blank lines produced by the format because the first one received that it doesn't consume will be interpreted as a terminator for the entire rev-list result. """ self._require_command('rev-list') assert (count is None) or (isinstance(count, Integral)) if format: assert '\n' not in format assert parse for ref in refs: assert ref assert '\n' not in ref self.check_busy() self._busy = 'rev-list' conn = self.conn conn.write('rev-list\n') if count is not None: conn.write(str(count)) conn.write('\n') if format: conn.write(format) conn.write('\n') for ref in refs: conn.write(ref) conn.write('\n') conn.write('\n') if not format: for line in lines_until_sentinel(conn, '\n', ClientError): line = line.strip() assert len(line) == 40 yield line else: for line in lines_until_sentinel(conn, '\n', ClientError): if not line.startswith('commit '): raise ClientError('unexpected line ' + repr(line)) cmt_oidx = line[7:].strip() assert len(cmt_oidx) == 40 yield cmt_oidx, parse(conn) # FIXME: confusing not_ok = self.check_ok() if not_ok: raise not_ok self._not_busy()
def cat_batch(self, dummy): self.init_session() # For now, avoid potential deadlock by just reading them all for ref in tuple(lines_until_sentinel(self.conn, b'\n', Exception)): ref = ref[:-1] it = self.repo.cat(ref) info = next(it) if not info[0]: self.conn.write(b'missing\n') continue self.conn.write(b'%s %s %d\n' % info) for buf in it: self.conn.write(buf) self.conn.ok()
def refs(conn, args): limit_to_heads, limit_to_tags = args.split() assert limit_to_heads in ('0', '1') assert limit_to_tags in ('0', '1') limit_to_heads = int(limit_to_heads) limit_to_tags = int(limit_to_tags) _init_session() patterns = tuple(x[:-1] for x in lines_until_sentinel(conn, '\n', Exception)) for name, oid in git.list_refs(patterns=patterns, limit_to_heads=limit_to_heads, limit_to_tags=limit_to_tags): assert '\n' not in name conn.write('%s %s\n' % (oid.encode('hex'), name)) conn.write('\n') conn.ok()
def cat_batch(conn, dummy): _init_session() cat_pipe = git.cp() # For now, avoid potential deadlock by just reading them all for ref in tuple(lines_until_sentinel(conn, '\n', Exception)): ref = ref[:-1] it = cat_pipe.get(ref) info = next(it) if not info[0]: conn.write('missing\n') continue conn.write('%s %s %d\n' % info) for buf in it: conn.write(buf) conn.ok()
def refs(self, args): limit_to_heads, limit_to_tags = args.split() assert limit_to_heads in (b'0', b'1') assert limit_to_tags in (b'0', b'1') limit_to_heads = int(limit_to_heads) limit_to_tags = int(limit_to_tags) self.init_session() patterns = tuple( x[:-1] for x in lines_until_sentinel(self.conn, b'\n', Exception)) for name, oid in self.repo.refs(patterns, limit_to_heads, limit_to_tags): assert b'\n' not in name self.conn.write(b'%s %s\n' % (hexlify(oid), name)) self.conn.write(b'\n') self.conn.ok()
def rev_list(self, _): self.init_session() count = self.conn.readline() if not count: raise Exception('Unexpected EOF while reading rev-list count') assert count == b'\n' count = None fmt = self.conn.readline() if not fmt: raise Exception('Unexpected EOF while reading rev-list format') fmt = None if fmt == b'\n' else fmt[:-1] refs = tuple( x[:-1] for x in lines_until_sentinel(self.conn, b'\n', Exception)) try: for buf in self.repo.rev_list_raw(refs, fmt): self.conn.write(buf) self.conn.write(b'\n') self.conn.ok() except git.GitError as e: self.conn.write(b'\n') self.conn.error(str(e).encode('ascii')) raise