]> arthur.barton.de Git - bup.git/blobdiff - cmd/server-cmd.py
vint: remove unnecessary condition
[bup.git] / cmd / server-cmd.py
index 853ab7f13d386e5b6cf5edda8311924c313bf6df..b1b77297e4977ca21b7c1e2e36adf7c31af621be 100755 (executable)
@@ -8,7 +8,8 @@ exec "$bup_python" "$0" ${1+"$@"}
 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)
@@ -131,7 +132,7 @@ def receive_objects_v2(conn, junk):
                     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
@@ -219,13 +220,14 @@ def rev_list(conn, _):
     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
@@ -233,6 +235,29 @@ def rev_list(conn, _):
         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
@@ -259,7 +284,8 @@ commands = {
     '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.