MCPcopy Create free account
hub / github.com/git/git / read_patches

Function read_patches

range-diff.c:41–239  ·  view source on GitHub ↗

* Reads the patches into a string list, with the `util` field being populated * as struct object_id (will need to be free()d). */

Source from the content-addressed store, hash-verified

39 * as struct object_id (will need to be free()d).
40 */
41static 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 {

Callers 1

show_range_diffFunction · 0.85

Calls 15

strvec_pushlFunction · 0.85
strvec_pushFunction · 0.85
strvec_pushvFunction · 0.85
start_commandFunction · 0.85
error_errnoFunction · 0.85
strbuf_readFunction · 0.85
finish_commandFunction · 0.85
repo_get_oidFunction · 0.85
errorFunction · 0.85
string_list_clearFunction · 0.85
starts_withFunction · 0.85
strbuf_addchFunction · 0.85

Tested by

no test coverage detected