* Reads the patches into a string list, with the `util` field being populated * as struct object_id (will need to be free()d). */
| 39 | * as struct object_id (will need to be free()d). |
| 40 | */ |
| 41 | static int read_patches(const char *range, struct string_list *list, |
| 42 | const struct strvec *log_arg, |
| 43 | unsigned int include_merges) |
| 44 | { |
| 45 | struct child_process cp = CHILD_PROCESS_INIT; |
| 46 | struct strbuf buf = STRBUF_INIT, contents = STRBUF_INIT; |
| 47 | struct patch_util *util = NULL; |
| 48 | int in_header = 1; |
| 49 | char *line, *current_filename = NULL; |
| 50 | ssize_t len; |
| 51 | size_t size; |
| 52 | int ret = -1; |
| 53 | |
| 54 | strvec_pushl(&cp.args, "log", "--no-color", "-p", |
| 55 | "--reverse", "--date-order", "--decorate=no", |
| 56 | "--no-prefix", "--submodule=short", |
| 57 | /* |
| 58 | * Choose indicators that are not used anywhere |
| 59 | * else in diffs, but still look reasonable |
| 60 | * (e.g. will not be confusing when debugging) |
| 61 | */ |
| 62 | "--output-indicator-new=>", |
| 63 | "--output-indicator-old=<", |
| 64 | "--output-indicator-context=#", |
| 65 | "--no-abbrev-commit", |
| 66 | "--pretty=medium", |
| 67 | "--show-notes-by-default", |
| 68 | NULL); |
| 69 | if (!include_merges) |
| 70 | strvec_push(&cp.args, "--no-merges"); |
| 71 | strvec_push(&cp.args, range); |
| 72 | if (log_arg) |
| 73 | strvec_pushv(&cp.args, log_arg->v); |
| 74 | cp.out = -1; |
| 75 | cp.no_stdin = 1; |
| 76 | cp.git_cmd = 1; |
| 77 | |
| 78 | if (start_command(&cp)) |
| 79 | return error_errno(_("could not start `log`")); |
| 80 | if (strbuf_read(&contents, cp.out, 0) < 0) { |
| 81 | error_errno(_("could not read `log` output")); |
| 82 | finish_command(&cp); |
| 83 | goto cleanup; |
| 84 | } |
| 85 | if (finish_command(&cp)) |
| 86 | goto cleanup; |
| 87 | |
| 88 | line = contents.buf; |
| 89 | size = contents.len; |
| 90 | for (; size > 0; size -= len, line += len) { |
| 91 | char *p; |
| 92 | char *eol; |
| 93 | |
| 94 | eol = memchr(line, '\n', size); |
| 95 | if (eol) { |
| 96 | *eol = '\0'; |
| 97 | len = eol + 1 - line; |
| 98 | } else { |
no test coverage detected