from __future__ import absolute_import
import os, sys, struct, subprocess
-from bup import options, git
+from bup import options, git, vfs, vint
+from bup.compat import hexstr
from bup.git import MissingObject
from bup.helpers import (Conn, debug1, debug2, linereader, lines_until_sentinel,
log)
debug1("bup server: suggesting index %s\n"
% git.shorten_hash(name))
debug1("bup server: because of object %s\n"
- % shar.encode('hex'))
+ % hexstr(shar))
conn.write('index %s\n' % name)
suggested.add(name)
continue
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),
+ env=git._gitenv(git.repodir),
stdout=subprocess.PIPE)
while True:
out = p.stdout.read(64 * 1024)
if not out:
break
conn.write(out)
+ conn.write('\n')
rv = p.wait() # not fatal
if rv:
msg = 'git rev-list returned error %d' % rv
raise GitError(msg)
conn.ok()
+def resolve(conn, args):
+ _init_session()
+ (flags,) = args.split()
+ flags = int(flags)
+ want_meta = bool(flags & 1)
+ follow = bool(flags & 2)
+ have_parent = bool(flags & 4)
+ parent = vfs.read_resolution(conn) if have_parent else None
+ path = vint.read_bvec(conn)
+ if not len(path):
+ raise Exception('Empty resolve path')
+ try:
+ res = list(vfs.resolve(repo, path, parent=parent, want_meta=want_meta,
+ follow=follow))
+ except vfs.IOError as ex:
+ res = ex
+ if isinstance(res, vfs.IOError):
+ conn.write(b'\0') # error
+ vfs.write_ioerror(conn, res)
+ else:
+ conn.write(b'\1') # success
+ vfs.write_resolution(conn, res)
+ conn.ok()
optspec = """
bup server
'cat': join, # apocryphal alias
'cat-batch' : cat_batch,
'refs': refs,
- 'rev-list': rev_list
+ 'rev-list': rev_list,
+ 'resolve': resolve
}
# FIXME: this protocol is totally lame and not at all future-proof.