vcs-svn: allow input from file descriptor
[gitweb.git] / test-line-buffer.c
index ec19b13ee23d0de5a2423941655452627d3d00cc..25b20b93fd4a1113629c99bd5a53dfee965119c1 100644 (file)
@@ -3,6 +3,7 @@
  */
 
 #include "git-compat-util.h"
+#include "strbuf.h"
 #include "vcs-svn/line_buffer.h"
 
 static uint32_t strtouint32(const char *s)
@@ -17,6 +18,15 @@ static uint32_t strtouint32(const char *s)
 static void handle_command(const char *command, const char *arg, struct line_buffer *buf)
 {
        switch (*command) {
+       case 'b':
+               if (!prefixcmp(command, "binary ")) {
+                       struct strbuf sb = STRBUF_INIT;
+                       strbuf_addch(&sb, '>');
+                       buffer_read_binary(buf, &sb, strtouint32(arg));
+                       fwrite(sb.buf, 1, sb.len, stdout);
+                       strbuf_release(&sb);
+                       return;
+               }
        case 'c':
                if (!prefixcmp(command, "copy ")) {
                        buffer_copy_bytes(buf, strtouint32(arg));
@@ -59,13 +69,18 @@ int main(int argc, char *argv[])
        else if (argc == 2)
                filename = argv[1];
        else
-               usage("test-line-buffer [file] < script");
+               usage("test-line-buffer [file | &fd] < script");
 
        if (buffer_init(&stdin_buf, NULL))
                die_errno("open error");
        if (filename) {
-               if (buffer_init(&file_buf, filename))
-                       die_errno("error opening %s", filename);
+               if (*filename == '&') {
+                       if (buffer_fdinit(&file_buf, strtouint32(filename + 1)))
+                               die_errno("error opening fd %s", filename + 1);
+               } else {
+                       if (buffer_init(&file_buf, filename))
+                               die_errno("error opening %s", filename);
+               }
                input = &file_buf;
        }