Sync with 2.30.9
* maint-2.30: (23 commits) Git 2.30.9 gettext: avoid using gettext if the locale dir is not present apply --reject: overwrite existing `.rej` symlink if it exists http.c: clear the 'finished' member once we are done with it clone.c: avoid "exceeds maximum object size" error with GCC v12.x 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() t5604: GETTEXT_POISON fix, conclusion t5604: GETTEXT_POISON fix, part 1 t5619: GETTEXT_POISON fix t0003: GETTEXT_POISON fix, conclusion t0003: GETTEXT_POISON fix, part 1 t0033: GETTEXT_POISON fix http: support CURLOPT_PROTOCOLS_STR http: prefer CURLOPT_SEEKFUNCTION to CURLOPT_IOCTLFUNCTION http-push: prefer CURLOPT_UPLOAD to CURLOPT_PUT ci: install python on ubuntu ci: use the same version of p4 on both Linux and macOS ci: remove the pipe after "p4 -V" to catch errors github-actions: run gcc-8 on ubuntu-20.04 image ...
This commit is contained in:
36
config.c
36
config.c
@ -3195,9 +3195,10 @@ void git_config_set_multivar(const char *key, const char *value,
|
||||
flags);
|
||||
}
|
||||
|
||||
static int section_name_match (const char *buf, const char *name)
|
||||
static size_t section_name_match (const char *buf, const char *name)
|
||||
{
|
||||
int i = 0, j = 0, dot = 0;
|
||||
size_t i = 0, j = 0;
|
||||
int dot = 0;
|
||||
if (buf[i] != '[')
|
||||
return 0;
|
||||
for (i = 1; buf[i] && buf[i] != ']'; i++) {
|
||||
@ -3250,6 +3251,8 @@ static int section_name_is_ok(const char *name)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define GIT_CONFIG_MAX_LINE_LEN (512 * 1024)
|
||||
|
||||
/* if new_name == NULL, the section is removed instead */
|
||||
static int git_config_copy_or_rename_section_in_file(const char *config_filename,
|
||||
const char *old_name,
|
||||
@ -3259,11 +3262,12 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
|
||||
char *filename_buf = NULL;
|
||||
struct lock_file lock = LOCK_INIT;
|
||||
int out_fd;
|
||||
char buf[1024];
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
FILE *config_file = NULL;
|
||||
struct stat st;
|
||||
struct strbuf copystr = STRBUF_INIT;
|
||||
struct config_store_data store;
|
||||
uint32_t line_nr = 0;
|
||||
|
||||
memset(&store, 0, sizeof(store));
|
||||
|
||||
@ -3300,16 +3304,25 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
|
||||
goto out;
|
||||
}
|
||||
|
||||
while (fgets(buf, sizeof(buf), config_file)) {
|
||||
unsigned i;
|
||||
int length;
|
||||
while (!strbuf_getwholeline(&buf, config_file, '\n')) {
|
||||
size_t i, length;
|
||||
int is_section = 0;
|
||||
char *output = buf;
|
||||
for (i = 0; buf[i] && isspace(buf[i]); i++)
|
||||
char *output = buf.buf;
|
||||
|
||||
line_nr++;
|
||||
|
||||
if (buf.len >= GIT_CONFIG_MAX_LINE_LEN) {
|
||||
ret = error(_("refusing to work with overly long line "
|
||||
"in '%s' on line %"PRIuMAX),
|
||||
config_filename, (uintmax_t)line_nr);
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (i = 0; buf.buf[i] && isspace(buf.buf[i]); i++)
|
||||
; /* do nothing */
|
||||
if (buf[i] == '[') {
|
||||
if (buf.buf[i] == '[') {
|
||||
/* it's a section */
|
||||
int offset;
|
||||
size_t offset;
|
||||
is_section = 1;
|
||||
|
||||
/*
|
||||
@ -3326,7 +3339,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename
|
||||
strbuf_reset(©str);
|
||||
}
|
||||
|
||||
offset = section_name_match(&buf[i], old_name);
|
||||
offset = section_name_match(&buf.buf[i], old_name);
|
||||
if (offset > 0) {
|
||||
ret++;
|
||||
if (new_name == NULL) {
|
||||
@ -3401,6 +3414,7 @@ out:
|
||||
out_no_rollback:
|
||||
free(filename_buf);
|
||||
config_store_data_clear(&store);
|
||||
strbuf_release(&buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user