2 * test-delta.c: test code to exercise diff-delta.c and patch-delta.c
4 * (C) 2005 Nicolas Pitre <nico@fluxnic.net>
6 * This code is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include "test-tool.h"
12 #include "git-compat-util.h"
16 static const char usage_str[] =
17 "test-tool delta (-d|-p) <from_file> <data_file> <out_file>";
19 int cmd__delta(int argc, const char **argv)
23 void *from_buf, *data_buf, *out_buf;
24 unsigned long from_size, data_size, out_size;
26 if (argc != 5 || (strcmp(argv[1], "-d") && strcmp(argv[1], "-p"))) {
27 fprintf(stderr, "usage: %s\n", usage_str);
31 fd = open(argv[2], O_RDONLY);
32 if (fd < 0 || fstat(fd, &st)) {
36 from_size = st.st_size;
37 from_buf = xmalloc(from_size);
38 if (read_in_full(fd, from_buf, from_size) < 0) {
45 fd = open(argv[3], O_RDONLY);
46 if (fd < 0 || fstat(fd, &st)) {
50 data_size = st.st_size;
51 data_buf = xmalloc(data_size);
52 if (read_in_full(fd, data_buf, data_size) < 0) {
59 if (argv[1][1] == 'd')
60 out_buf = diff_delta(from_buf, from_size,
64 out_buf = patch_delta(from_buf, from_size,
68 fprintf(stderr, "delta operation failed (returned NULL)\n");
72 fd = open (argv[4], O_WRONLY|O_CREAT|O_TRUNC, 0666);
73 if (fd < 0 || write_in_full(fd, out_buf, out_size) < 0) {