mirror of
https://github.com/git/git.git
synced 2024-10-19 02:28:13 +02:00
Merge branch 'jk/range-diff-fixes'
"git range-diff" code clean-up. * jk/range-diff-fixes: range-diff: use ssize_t for parsed "len" in read_patches() range-diff: handle unterminated lines in read_patches() range-diff: drop useless "offset" variable from read_patches()
This commit is contained in:
commit
fb0b14df65
29
range-diff.c
29
range-diff.c
@ -26,17 +26,6 @@ struct patch_util {
|
|||||||
struct object_id oid;
|
struct object_id oid;
|
||||||
};
|
};
|
||||||
|
|
||||||
static size_t find_end_of_line(char *buffer, unsigned long size)
|
|
||||||
{
|
|
||||||
char *eol = memchr(buffer, '\n', size);
|
|
||||||
|
|
||||||
if (!eol)
|
|
||||||
return size;
|
|
||||||
|
|
||||||
*eol = '\0';
|
|
||||||
return eol + 1 - buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reads the patches into a string list, with the `util` field being populated
|
* Reads the patches into a string list, with the `util` field being populated
|
||||||
* as struct object_id (will need to be free()d).
|
* as struct object_id (will need to be free()d).
|
||||||
@ -49,7 +38,7 @@ static int read_patches(const char *range, struct string_list *list,
|
|||||||
struct patch_util *util = NULL;
|
struct patch_util *util = NULL;
|
||||||
int in_header = 1;
|
int in_header = 1;
|
||||||
char *line, *current_filename = NULL;
|
char *line, *current_filename = NULL;
|
||||||
int offset, len;
|
ssize_t len;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
strvec_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",
|
strvec_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",
|
||||||
@ -86,11 +75,18 @@ static int read_patches(const char *range, struct string_list *list,
|
|||||||
|
|
||||||
line = contents.buf;
|
line = contents.buf;
|
||||||
size = contents.len;
|
size = contents.len;
|
||||||
for (offset = 0; size > 0; offset += len, size -= len, line += len) {
|
for (; size > 0; size -= len, line += len) {
|
||||||
const char *p;
|
const char *p;
|
||||||
|
char *eol;
|
||||||
|
|
||||||
|
eol = memchr(line, '\n', size);
|
||||||
|
if (eol) {
|
||||||
|
*eol = '\0';
|
||||||
|
len = eol + 1 - line;
|
||||||
|
} else {
|
||||||
|
len = size;
|
||||||
|
}
|
||||||
|
|
||||||
len = find_end_of_line(line, size);
|
|
||||||
line[len - 1] = '\0';
|
|
||||||
if (skip_prefix(line, "commit ", &p)) {
|
if (skip_prefix(line, "commit ", &p)) {
|
||||||
if (util) {
|
if (util) {
|
||||||
string_list_append(list, buf.buf)->util = util;
|
string_list_append(list, buf.buf)->util = util;
|
||||||
@ -132,7 +128,8 @@ static int read_patches(const char *range, struct string_list *list,
|
|||||||
strbuf_addch(&buf, '\n');
|
strbuf_addch(&buf, '\n');
|
||||||
if (!util->diff_offset)
|
if (!util->diff_offset)
|
||||||
util->diff_offset = buf.len;
|
util->diff_offset = buf.len;
|
||||||
line[len - 1] = '\n';
|
if (eol)
|
||||||
|
*eol = '\n';
|
||||||
orig_len = len;
|
orig_len = len;
|
||||||
len = parse_git_diff_header(&root, &linenr, 0, line,
|
len = parse_git_diff_header(&root, &linenr, 0, line,
|
||||||
len, size, &patch);
|
len, size, &patch);
|
||||||
|
Loading…
Reference in New Issue
Block a user