@ -40,6 +40,7 @@ static int read_patches(const char *range, struct string_list *list,
char *line, *current_filename = NULL;
char *line, *current_filename = NULL;
ssize_t len;
ssize_t len;
size_t size;
size_t size;
int ret = -1;
strvec_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",
strvec_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",
"--reverse", "--date-order", "--decorate=no",
"--reverse", "--date-order", "--decorate=no",
@ -68,10 +69,10 @@ static int read_patches(const char *range, struct string_list *list,
if (strbuf_read(&contents, cp.out, 0) < 0) {
if (strbuf_read(&contents, cp.out, 0) < 0) {
error_errno(_("could not read `log` output"));
error_errno(_("could not read `log` output"));
finish_command(&cp);
finish_command(&cp);
return -1;
goto cleanup;
}
}
if (finish_command(&cp))
if (finish_command(&cp))
return -1;
goto cleanup;
line = contents.buf;
line = contents.buf;
size = contents.len;
size = contents.len;
@ -95,12 +96,9 @@ static int read_patches(const char *range, struct string_list *list,
CALLOC_ARRAY(util, 1);
CALLOC_ARRAY(util, 1);
if (get_oid(p, &util->oid)) {
if (get_oid(p, &util->oid)) {
error(_("could not parse commit '%s'"), p);
error(_("could not parse commit '%s'"), p);
free(util);
FREE_AND_NULL(util);
free(current_filename);
string_list_clear(list, 1);
string_list_clear(list, 1);
strbuf_release(&buf);
goto cleanup;
strbuf_release(&contents);
return -1;
}
}
util->matching = -1;
util->matching = -1;
in_header = 1;
in_header = 1;
@ -111,11 +109,8 @@ static int read_patches(const char *range, struct string_list *list,
error(_("could not parse first line of `log` output: "
error(_("could not parse first line of `log` output: "
"did not start with 'commit ': '%s'"),
"did not start with 'commit ': '%s'"),
line);
line);
free(current_filename);
string_list_clear(list, 1);
string_list_clear(list, 1);
strbuf_release(&buf);
goto cleanup;
strbuf_release(&contents);
return -1;
}
}
if (starts_with(line, "diff --git")) {
if (starts_with(line, "diff --git")) {
@ -136,12 +131,9 @@ static int read_patches(const char *range, struct string_list *list,
if (len < 0) {
if (len < 0) {
error(_("could not parse git header '%.*s'"),
error(_("could not parse git header '%.*s'"),
orig_len, line);
orig_len, line);
free(util);
FREE_AND_NULL(util);
free(current_filename);
string_list_clear(list, 1);
string_list_clear(list, 1);
strbuf_release(&buf);
goto cleanup;
strbuf_release(&contents);
return -1;
}
}
strbuf_addstr(&buf, " ## ");
strbuf_addstr(&buf, " ## ");
if (patch.is_new > 0)
if (patch.is_new > 0)
@ -165,6 +157,7 @@ static int read_patches(const char *range, struct string_list *list,
patch.old_mode, patch.new_mode);
patch.old_mode, patch.new_mode);
strbuf_addstr(&buf, " ##");
strbuf_addstr(&buf, " ##");
release_patch(&patch);
} else if (in_header) {
} else if (in_header) {
if (starts_with(line, "Author: ")) {
if (starts_with(line, "Author: ")) {
strbuf_addstr(&buf, " ## Metadata ##\n");
strbuf_addstr(&buf, " ## Metadata ##\n");
@ -218,6 +211,9 @@ static int read_patches(const char *range, struct string_list *list,
strbuf_addch(&buf, '\n');
strbuf_addch(&buf, '\n');
util->diffsize++;
util->diffsize++;
}
}
ret = 0;
cleanup:
strbuf_release(&contents);
strbuf_release(&contents);
if (util)
if (util)
@ -225,7 +221,7 @@ static int read_patches(const char *range, struct string_list *list,
strbuf_release(&buf);
strbuf_release(&buf);
free(current_filename);
free(current_filename);
return 0;
return ret;
}
}
static int patch_util_cmp(const void *dummy, const struct patch_util *a,
static int patch_util_cmp(const void *dummy, const struct patch_util *a,