Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/helper/test-delta.c # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / helper / test-delta.c` 58 lines ยท 1527 bytes Raw Blame History 1 /* 2 * test-delta.c: test code to exercise diff-delta.c and patch-delta.c 3 * 4 * (C) 2005 Nicolas Pitre 5 * 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. 9 */ 10 11 #include "test-tool.h" 12 #include "git-compat-util.h" 13 #include "delta.h" 14 #include "strbuf.h" 15 16 static const char usage_str[] = 17 "test-tool delta (-d|-p) "; 18 19 int cmd__delta(int argc, const char **argv) 20 { 21 int fd; 22 struct strbuf from = STRBUF_INIT, data = STRBUF_INIT; 23 char *out_buf; 24 size_t out_size; 25 26 if (argc != 5 || (strcmp(argv[1], "-d") && strcmp(argv[1], "-p"))) 27 usage(usage_str); 28 29 if (strbuf_read_file(&from, argv[2], 0) < 0) 30 die_errno("unable to read '%s'", argv[2]); 31 if (strbuf_read_file(&data, argv[3], 0) < 0) 32 die_errno("unable to read '%s'", argv[3]); 33 34 if (argv[1][1] == 'd') { 35 size_t delta_size; 36 out_buf = diff_delta(from.buf, from.len, 37 data.buf, data.len, 38 &delta_size, 0); 39 out_size = delta_size; 40 } else 41 out_buf = patch_delta(from.buf, from.len, 42 data.buf, data.len, 43 &out_size); 44 if (!out_buf) 45 die("delta operation failed (returned NULL)"); 46 47 fd = xopen(argv[4], O_WRONLY|O_CREAT|O_TRUNC, 0666); 48 if (write_in_full(fd, out_buf, out_size) < 0) 49 die_errno("write(%s)", argv[4]); 50 if (close(fd) < 0) 51 die_errno("close(%s)", argv[4]); 52 53 strbuf_release(&from); 54 strbuf_release(&data); 55 free(out_buf); 56 57 return 0; 58 }