зеркало из https://github.com/microsoft/git.git
Merge branch 'jc/strbuf-getline'
The preliminary clean-up for jc/peace-with-crlf topic. * jc/strbuf-getline: strbuf: give strbuf_getline() to the "most text friendly" variant checkout-index: there are only two possible line terminations update-index: there are only two possible line terminations check-ignore: there are only two possible line terminations check-attr: there are only two possible line terminations mktree: there are only two possible line terminations strbuf: introduce strbuf_getline_{lf,nul}() strbuf: make strbuf_getline_crlf() global strbuf: miniscule style fix
This commit is contained in:
Коммит
b62624b51a
8
bisect.c
8
bisect.c
|
@ -440,7 +440,7 @@ static void read_bisect_paths(struct argv_array *array)
|
||||||
if (!fp)
|
if (!fp)
|
||||||
die_errno("Could not open file '%s'", filename);
|
die_errno("Could not open file '%s'", filename);
|
||||||
|
|
||||||
while (strbuf_getline(&str, fp, '\n') != EOF) {
|
while (strbuf_getline_lf(&str, fp) != EOF) {
|
||||||
strbuf_trim(&str);
|
strbuf_trim(&str);
|
||||||
if (sq_dequote_to_argv_array(str.buf, array))
|
if (sq_dequote_to_argv_array(str.buf, array))
|
||||||
die("Badly quoted content in file '%s': %s",
|
die("Badly quoted content in file '%s': %s",
|
||||||
|
@ -668,7 +668,7 @@ static int is_expected_rev(const struct object_id *oid)
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (strbuf_getline(&str, fp, '\n') != EOF)
|
if (strbuf_getline_lf(&str, fp) != EOF)
|
||||||
res = !strcmp(str.buf, oid_to_hex(oid));
|
res = !strcmp(str.buf, oid_to_hex(oid));
|
||||||
|
|
||||||
strbuf_release(&str);
|
strbuf_release(&str);
|
||||||
|
@ -914,9 +914,9 @@ void read_bisect_terms(const char **read_bad, const char **read_good)
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
strbuf_getline(&str, fp, '\n');
|
strbuf_getline_lf(&str, fp);
|
||||||
*read_bad = strbuf_detach(&str, NULL);
|
*read_bad = strbuf_detach(&str, NULL);
|
||||||
strbuf_getline(&str, fp, '\n');
|
strbuf_getline_lf(&str, fp);
|
||||||
*read_good = strbuf_detach(&str, NULL);
|
*read_good = strbuf_detach(&str, NULL);
|
||||||
}
|
}
|
||||||
strbuf_release(&str);
|
strbuf_release(&str);
|
||||||
|
|
37
builtin/am.c
37
builtin/am.c
|
@ -45,21 +45,6 @@ static int is_empty_file(const char *filename)
|
||||||
return !st.st_size;
|
return !st.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Like strbuf_getline(), but treats both '\n' and "\r\n" as line terminators.
|
|
||||||
*/
|
|
||||||
static int strbuf_getline_crlf(struct strbuf *sb, FILE *fp)
|
|
||||||
{
|
|
||||||
if (strbuf_getwholeline(sb, fp, '\n'))
|
|
||||||
return EOF;
|
|
||||||
if (sb->buf[sb->len - 1] == '\n') {
|
|
||||||
strbuf_setlen(sb, sb->len - 1);
|
|
||||||
if (sb->len > 0 && sb->buf[sb->len - 1] == '\r')
|
|
||||||
strbuf_setlen(sb, sb->len - 1);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the length of the first line of msg.
|
* Returns the length of the first line of msg.
|
||||||
*/
|
*/
|
||||||
|
@ -284,7 +269,7 @@ static char *read_shell_var(FILE *fp, const char *key)
|
||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
const char *str;
|
const char *str;
|
||||||
|
|
||||||
if (strbuf_getline(&sb, fp, '\n'))
|
if (strbuf_getline_lf(&sb, fp))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (!skip_prefix(sb.buf, key, &str))
|
if (!skip_prefix(sb.buf, key, &str))
|
||||||
|
@ -573,7 +558,7 @@ static int copy_notes_for_rebase(const struct am_state *state)
|
||||||
|
|
||||||
fp = xfopen(am_path(state, "rewritten"), "r");
|
fp = xfopen(am_path(state, "rewritten"), "r");
|
||||||
|
|
||||||
while (!strbuf_getline(&sb, fp, '\n')) {
|
while (!strbuf_getline_lf(&sb, fp)) {
|
||||||
unsigned char from_obj[GIT_SHA1_RAWSZ], to_obj[GIT_SHA1_RAWSZ];
|
unsigned char from_obj[GIT_SHA1_RAWSZ], to_obj[GIT_SHA1_RAWSZ];
|
||||||
|
|
||||||
if (sb.len != GIT_SHA1_HEXSZ * 2 + 1) {
|
if (sb.len != GIT_SHA1_HEXSZ * 2 + 1) {
|
||||||
|
@ -628,7 +613,7 @@ static int is_mail(FILE *fp)
|
||||||
if (regcomp(®ex, header_regex, REG_NOSUB | REG_EXTENDED))
|
if (regcomp(®ex, header_regex, REG_NOSUB | REG_EXTENDED))
|
||||||
die("invalid pattern: %s", header_regex);
|
die("invalid pattern: %s", header_regex);
|
||||||
|
|
||||||
while (!strbuf_getline_crlf(&sb, fp)) {
|
while (!strbuf_getline(&sb, fp)) {
|
||||||
if (!sb.len)
|
if (!sb.len)
|
||||||
break; /* End of header */
|
break; /* End of header */
|
||||||
|
|
||||||
|
@ -675,7 +660,7 @@ static int detect_patch_format(const char **paths)
|
||||||
|
|
||||||
fp = xfopen(*paths, "r");
|
fp = xfopen(*paths, "r");
|
||||||
|
|
||||||
while (!strbuf_getline_crlf(&l1, fp)) {
|
while (!strbuf_getline(&l1, fp)) {
|
||||||
if (l1.len)
|
if (l1.len)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -696,9 +681,9 @@ static int detect_patch_format(const char **paths)
|
||||||
}
|
}
|
||||||
|
|
||||||
strbuf_reset(&l2);
|
strbuf_reset(&l2);
|
||||||
strbuf_getline_crlf(&l2, fp);
|
strbuf_getline(&l2, fp);
|
||||||
strbuf_reset(&l3);
|
strbuf_reset(&l3);
|
||||||
strbuf_getline_crlf(&l3, fp);
|
strbuf_getline(&l3, fp);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the second line is empty and the third is a From, Author or Date
|
* If the second line is empty and the third is a From, Author or Date
|
||||||
|
@ -817,7 +802,7 @@ static int stgit_patch_to_mail(FILE *out, FILE *in, int keep_cr)
|
||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
int subject_printed = 0;
|
int subject_printed = 0;
|
||||||
|
|
||||||
while (!strbuf_getline(&sb, in, '\n')) {
|
while (!strbuf_getline_lf(&sb, in)) {
|
||||||
const char *str;
|
const char *str;
|
||||||
|
|
||||||
if (str_isspace(sb.buf))
|
if (str_isspace(sb.buf))
|
||||||
|
@ -875,7 +860,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths,
|
||||||
return error(_("could not open '%s' for reading: %s"), *paths,
|
return error(_("could not open '%s' for reading: %s"), *paths,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
|
||||||
while (!strbuf_getline(&sb, fp, '\n')) {
|
while (!strbuf_getline_lf(&sb, fp)) {
|
||||||
if (*sb.buf == '#')
|
if (*sb.buf == '#')
|
||||||
continue; /* skip comment lines */
|
continue; /* skip comment lines */
|
||||||
|
|
||||||
|
@ -900,7 +885,7 @@ static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr)
|
||||||
{
|
{
|
||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
|
|
||||||
while (!strbuf_getline(&sb, in, '\n')) {
|
while (!strbuf_getline_lf(&sb, in)) {
|
||||||
const char *str;
|
const char *str;
|
||||||
|
|
||||||
if (skip_prefix(sb.buf, "# User ", &str))
|
if (skip_prefix(sb.buf, "# User ", &str))
|
||||||
|
@ -1317,7 +1302,7 @@ static int parse_mail(struct am_state *state, const char *mail)
|
||||||
|
|
||||||
/* Extract message and author information */
|
/* Extract message and author information */
|
||||||
fp = xfopen(am_path(state, "info"), "r");
|
fp = xfopen(am_path(state, "info"), "r");
|
||||||
while (!strbuf_getline(&sb, fp, '\n')) {
|
while (!strbuf_getline_lf(&sb, fp)) {
|
||||||
const char *x;
|
const char *x;
|
||||||
|
|
||||||
if (skip_prefix(sb.buf, "Subject: ", &x)) {
|
if (skip_prefix(sb.buf, "Subject: ", &x)) {
|
||||||
|
@ -1383,7 +1368,7 @@ static int get_mail_commit_sha1(unsigned char *commit_id, const char *mail)
|
||||||
FILE *fp = xfopen(mail, "r");
|
FILE *fp = xfopen(mail, "r");
|
||||||
const char *x;
|
const char *x;
|
||||||
|
|
||||||
if (strbuf_getline(&sb, fp, '\n'))
|
if (strbuf_getline_lf(&sb, fp))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!skip_prefix(sb.buf, "From ", &x))
|
if (!skip_prefix(sb.buf, "From ", &x))
|
||||||
|
|
|
@ -401,7 +401,7 @@ static int batch_objects(struct batch_options *opt)
|
||||||
save_warning = warn_on_object_refname_ambiguity;
|
save_warning = warn_on_object_refname_ambiguity;
|
||||||
warn_on_object_refname_ambiguity = 0;
|
warn_on_object_refname_ambiguity = 0;
|
||||||
|
|
||||||
while (strbuf_getline(&buf, stdin, '\n') != EOF) {
|
while (strbuf_getline_lf(&buf, stdin) != EOF) {
|
||||||
if (data.split_on_whitespace) {
|
if (data.split_on_whitespace) {
|
||||||
/*
|
/*
|
||||||
* Split at first whitespace, tying off the beginning
|
* Split at first whitespace, tying off the beginning
|
||||||
|
|
|
@ -73,12 +73,13 @@ static void check_attr_stdin_paths(const char *prefix, int cnt,
|
||||||
struct git_attr_check *check)
|
struct git_attr_check *check)
|
||||||
{
|
{
|
||||||
struct strbuf buf, nbuf;
|
struct strbuf buf, nbuf;
|
||||||
int line_termination = nul_term_line ? 0 : '\n';
|
strbuf_getline_fn getline_fn;
|
||||||
|
|
||||||
|
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
|
||||||
strbuf_init(&buf, 0);
|
strbuf_init(&buf, 0);
|
||||||
strbuf_init(&nbuf, 0);
|
strbuf_init(&nbuf, 0);
|
||||||
while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
|
while (getline_fn(&buf, stdin) != EOF) {
|
||||||
if (line_termination && buf.buf[0] == '"') {
|
if (!nul_term_line && buf.buf[0] == '"') {
|
||||||
strbuf_reset(&nbuf);
|
strbuf_reset(&nbuf);
|
||||||
if (unquote_c_style(&nbuf, buf.buf, NULL))
|
if (unquote_c_style(&nbuf, buf.buf, NULL))
|
||||||
die("line is badly quoted");
|
die("line is badly quoted");
|
||||||
|
|
|
@ -117,13 +117,14 @@ static int check_ignore_stdin_paths(struct dir_struct *dir, const char *prefix)
|
||||||
{
|
{
|
||||||
struct strbuf buf, nbuf;
|
struct strbuf buf, nbuf;
|
||||||
char *pathspec[2] = { NULL, NULL };
|
char *pathspec[2] = { NULL, NULL };
|
||||||
int line_termination = nul_term_line ? 0 : '\n';
|
strbuf_getline_fn getline_fn;
|
||||||
int num_ignored = 0;
|
int num_ignored = 0;
|
||||||
|
|
||||||
|
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
|
||||||
strbuf_init(&buf, 0);
|
strbuf_init(&buf, 0);
|
||||||
strbuf_init(&nbuf, 0);
|
strbuf_init(&nbuf, 0);
|
||||||
while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
|
while (getline_fn(&buf, stdin) != EOF) {
|
||||||
if (line_termination && buf.buf[0] == '"') {
|
if (!nul_term_line && buf.buf[0] == '"') {
|
||||||
strbuf_reset(&nbuf);
|
strbuf_reset(&nbuf);
|
||||||
if (unquote_c_style(&nbuf, buf.buf, NULL))
|
if (unquote_c_style(&nbuf, buf.buf, NULL))
|
||||||
die("line is badly quoted");
|
die("line is badly quoted");
|
||||||
|
|
|
@ -54,7 +54,7 @@ int cmd_check_mailmap(int argc, const char **argv, const char *prefix)
|
||||||
|
|
||||||
if (use_stdin) {
|
if (use_stdin) {
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
while (strbuf_getline(&buf, stdin, '\n') != EOF) {
|
while (strbuf_getline_lf(&buf, stdin) != EOF) {
|
||||||
check_mailmap(&mailmap, buf.buf);
|
check_mailmap(&mailmap, buf.buf);
|
||||||
maybe_flush_or_die(stdout, "stdout");
|
maybe_flush_or_die(stdout, "stdout");
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include "parse-options.h"
|
#include "parse-options.h"
|
||||||
|
|
||||||
#define CHECKOUT_ALL 4
|
#define CHECKOUT_ALL 4
|
||||||
static int line_termination = '\n';
|
static int nul_term_line;
|
||||||
static int checkout_stage; /* default to checkout stage0 */
|
static int checkout_stage; /* default to checkout stage0 */
|
||||||
static int to_tempfile;
|
static int to_tempfile;
|
||||||
static char topath[4][TEMPORARY_FILENAME_LENGTH + 1];
|
static char topath[4][TEMPORARY_FILENAME_LENGTH + 1];
|
||||||
|
@ -35,7 +35,8 @@ static void write_tempfile_record(const char *name, const char *prefix)
|
||||||
fputs(topath[checkout_stage], stdout);
|
fputs(topath[checkout_stage], stdout);
|
||||||
|
|
||||||
putchar('\t');
|
putchar('\t');
|
||||||
write_name_quoted_relative(name, prefix, stdout, line_termination);
|
write_name_quoted_relative(name, prefix, stdout,
|
||||||
|
nul_term_line ? '\0' : '\n');
|
||||||
|
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
topath[i][0] = 0;
|
topath[i][0] = 0;
|
||||||
|
@ -144,10 +145,7 @@ static int option_parse_u(const struct option *opt,
|
||||||
static int option_parse_z(const struct option *opt,
|
static int option_parse_z(const struct option *opt,
|
||||||
const char *arg, int unset)
|
const char *arg, int unset)
|
||||||
{
|
{
|
||||||
if (unset)
|
nul_term_line = !unset;
|
||||||
line_termination = '\n';
|
|
||||||
else
|
|
||||||
line_termination = 0;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,13 +252,15 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
|
||||||
|
|
||||||
if (read_from_stdin) {
|
if (read_from_stdin) {
|
||||||
struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
|
||||||
|
strbuf_getline_fn getline_fn;
|
||||||
|
|
||||||
if (all)
|
if (all)
|
||||||
die("git checkout-index: don't mix '--all' and '--stdin'");
|
die("git checkout-index: don't mix '--all' and '--stdin'");
|
||||||
|
|
||||||
while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
|
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
|
||||||
|
while (getline_fn(&buf, stdin) != EOF) {
|
||||||
char *p;
|
char *p;
|
||||||
if (line_termination && buf.buf[0] == '"') {
|
if (!nul_term_line && buf.buf[0] == '"') {
|
||||||
strbuf_reset(&nbuf);
|
strbuf_reset(&nbuf);
|
||||||
if (unquote_c_style(&nbuf, buf.buf, NULL))
|
if (unquote_c_style(&nbuf, buf.buf, NULL))
|
||||||
die("line is badly quoted");
|
die("line is badly quoted");
|
||||||
|
|
|
@ -594,7 +594,7 @@ static int *list_and_choose(struct menu_opts *opts, struct menu_stuff *stuff)
|
||||||
clean_get_color(CLEAN_COLOR_RESET));
|
clean_get_color(CLEAN_COLOR_RESET));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strbuf_getline(&choice, stdin, '\n') != EOF) {
|
if (strbuf_getline_lf(&choice, stdin) != EOF) {
|
||||||
strbuf_trim(&choice);
|
strbuf_trim(&choice);
|
||||||
} else {
|
} else {
|
||||||
eof = 1;
|
eof = 1;
|
||||||
|
@ -676,7 +676,7 @@ static int filter_by_patterns_cmd(void)
|
||||||
clean_print_color(CLEAN_COLOR_PROMPT);
|
clean_print_color(CLEAN_COLOR_PROMPT);
|
||||||
printf(_("Input ignore patterns>> "));
|
printf(_("Input ignore patterns>> "));
|
||||||
clean_print_color(CLEAN_COLOR_RESET);
|
clean_print_color(CLEAN_COLOR_RESET);
|
||||||
if (strbuf_getline(&confirm, stdin, '\n') != EOF)
|
if (strbuf_getline_lf(&confirm, stdin) != EOF)
|
||||||
strbuf_trim(&confirm);
|
strbuf_trim(&confirm);
|
||||||
else
|
else
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
@ -774,7 +774,7 @@ static int ask_each_cmd(void)
|
||||||
qname = quote_path_relative(item->string, NULL, &buf);
|
qname = quote_path_relative(item->string, NULL, &buf);
|
||||||
/* TRANSLATORS: Make sure to keep [y/N] as is */
|
/* TRANSLATORS: Make sure to keep [y/N] as is */
|
||||||
printf(_("Remove %s [y/N]? "), qname);
|
printf(_("Remove %s [y/N]? "), qname);
|
||||||
if (strbuf_getline(&confirm, stdin, '\n') != EOF) {
|
if (strbuf_getline_lf(&confirm, stdin) != EOF) {
|
||||||
strbuf_trim(&confirm);
|
strbuf_trim(&confirm);
|
||||||
} else {
|
} else {
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
|
|
@ -339,7 +339,7 @@ static void copy_alternates(struct strbuf *src, struct strbuf *dst,
|
||||||
FILE *in = fopen(src->buf, "r");
|
FILE *in = fopen(src->buf, "r");
|
||||||
struct strbuf line = STRBUF_INIT;
|
struct strbuf line = STRBUF_INIT;
|
||||||
|
|
||||||
while (strbuf_getline(&line, in, '\n') != EOF) {
|
while (strbuf_getline_lf(&line, in) != EOF) {
|
||||||
char *abs_path;
|
char *abs_path;
|
||||||
if (!line.len || line.buf[0] == '#')
|
if (!line.len || line.buf[0] == '#')
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -51,7 +51,7 @@ int cmd_column(int argc, const char **argv, const char *prefix)
|
||||||
die(_("--command must be the first argument"));
|
die(_("--command must be the first argument"));
|
||||||
}
|
}
|
||||||
finalize_colopts(&colopts, -1);
|
finalize_colopts(&colopts, -1);
|
||||||
while (!strbuf_getline(&sb, stdin, '\n'))
|
while (!strbuf_getline_lf(&sb, stdin))
|
||||||
string_list_append(&list, sb.buf);
|
string_list_append(&list, sb.buf);
|
||||||
|
|
||||||
print_columns(&list, colopts, &copts);
|
print_columns(&list, colopts, &copts);
|
||||||
|
|
|
@ -1690,7 +1690,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
die_errno(_("could not open '%s' for reading"),
|
die_errno(_("could not open '%s' for reading"),
|
||||||
git_path_merge_head());
|
git_path_merge_head());
|
||||||
while (strbuf_getline(&m, fp, '\n') != EOF) {
|
while (strbuf_getline_lf(&m, fp) != EOF) {
|
||||||
struct commit *parent;
|
struct commit *parent;
|
||||||
|
|
||||||
parent = get_merge_parent(m.buf);
|
parent = get_merge_parent(m.buf);
|
||||||
|
|
|
@ -158,7 +158,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
|
||||||
else {
|
else {
|
||||||
/* read from stdin one ref per line, until EOF */
|
/* read from stdin one ref per line, until EOF */
|
||||||
struct strbuf line = STRBUF_INIT;
|
struct strbuf line = STRBUF_INIT;
|
||||||
while (strbuf_getline(&line, stdin, '\n') != EOF)
|
while (strbuf_getline_lf(&line, stdin) != EOF)
|
||||||
add_sought_entry(&sought, &nr_sought, &alloc_sought, line.buf);
|
add_sought_entry(&sought, &nr_sought, &alloc_sought, line.buf);
|
||||||
strbuf_release(&line);
|
strbuf_release(&line);
|
||||||
}
|
}
|
||||||
|
|
|
@ -573,7 +573,7 @@ static int file_callback(const struct option *opt, const char *arg, int unset)
|
||||||
patterns = from_stdin ? stdin : fopen(arg, "r");
|
patterns = from_stdin ? stdin : fopen(arg, "r");
|
||||||
if (!patterns)
|
if (!patterns)
|
||||||
die_errno(_("cannot open '%s'"), arg);
|
die_errno(_("cannot open '%s'"), arg);
|
||||||
while (strbuf_getline(&sb, patterns, '\n') == 0) {
|
while (strbuf_getline_lf(&sb, patterns) == 0) {
|
||||||
/* ignore empty line like grep does */
|
/* ignore empty line like grep does */
|
||||||
if (sb.len == 0)
|
if (sb.len == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -60,7 +60,7 @@ static void hash_stdin_paths(const char *type, int no_filters, unsigned flags,
|
||||||
{
|
{
|
||||||
struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
|
||||||
|
|
||||||
while (strbuf_getline(&buf, stdin, '\n') != EOF) {
|
while (strbuf_getline_lf(&buf, stdin) != EOF) {
|
||||||
if (buf.buf[0] == '"') {
|
if (buf.buf[0] == '"') {
|
||||||
strbuf_reset(&nbuf);
|
strbuf_reset(&nbuf);
|
||||||
if (unquote_c_style(&nbuf, buf.buf, NULL))
|
if (unquote_c_style(&nbuf, buf.buf, NULL))
|
||||||
|
|
|
@ -65,7 +65,7 @@ static const char *mktree_usage[] = {
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
static void mktree_line(char *buf, size_t len, int line_termination, int allow_missing)
|
static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_missing)
|
||||||
{
|
{
|
||||||
char *ptr, *ntr;
|
char *ptr, *ntr;
|
||||||
unsigned mode;
|
unsigned mode;
|
||||||
|
@ -97,7 +97,7 @@ static void mktree_line(char *buf, size_t len, int line_termination, int allow_m
|
||||||
*ntr++ = 0; /* now at the beginning of SHA1 */
|
*ntr++ = 0; /* now at the beginning of SHA1 */
|
||||||
|
|
||||||
path = ntr + 41; /* at the beginning of name */
|
path = ntr + 41; /* at the beginning of name */
|
||||||
if (line_termination && path[0] == '"') {
|
if (!nul_term_line && path[0] == '"') {
|
||||||
struct strbuf p_uq = STRBUF_INIT;
|
struct strbuf p_uq = STRBUF_INIT;
|
||||||
if (unquote_c_style(&p_uq, path, NULL))
|
if (unquote_c_style(&p_uq, path, NULL))
|
||||||
die("invalid quoting");
|
die("invalid quoting");
|
||||||
|
@ -141,23 +141,25 @@ int cmd_mktree(int ac, const char **av, const char *prefix)
|
||||||
{
|
{
|
||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
int line_termination = '\n';
|
int nul_term_line = 0;
|
||||||
int allow_missing = 0;
|
int allow_missing = 0;
|
||||||
int is_batch_mode = 0;
|
int is_batch_mode = 0;
|
||||||
int got_eof = 0;
|
int got_eof = 0;
|
||||||
|
strbuf_getline_fn getline_fn;
|
||||||
|
|
||||||
const struct option option[] = {
|
const struct option option[] = {
|
||||||
OPT_SET_INT('z', NULL, &line_termination, N_("input is NUL terminated"), '\0'),
|
OPT_BOOL('z', NULL, &nul_term_line, N_("input is NUL terminated")),
|
||||||
OPT_SET_INT( 0 , "missing", &allow_missing, N_("allow missing objects"), 1),
|
OPT_SET_INT( 0 , "missing", &allow_missing, N_("allow missing objects"), 1),
|
||||||
OPT_SET_INT( 0 , "batch", &is_batch_mode, N_("allow creation of more than one tree"), 1),
|
OPT_SET_INT( 0 , "batch", &is_batch_mode, N_("allow creation of more than one tree"), 1),
|
||||||
OPT_END()
|
OPT_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
ac = parse_options(ac, av, prefix, option, mktree_usage, 0);
|
ac = parse_options(ac, av, prefix, option, mktree_usage, 0);
|
||||||
|
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
|
||||||
|
|
||||||
while (!got_eof) {
|
while (!got_eof) {
|
||||||
while (1) {
|
while (1) {
|
||||||
if (strbuf_getline(&sb, stdin, line_termination) == EOF) {
|
if (getline_fn(&sb, stdin) == EOF) {
|
||||||
got_eof = 1;
|
got_eof = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -167,7 +169,7 @@ int cmd_mktree(int ac, const char **av, const char *prefix)
|
||||||
break;
|
break;
|
||||||
die("input format error: (blank line only valid in batch mode)");
|
die("input format error: (blank line only valid in batch mode)");
|
||||||
}
|
}
|
||||||
mktree_line(sb.buf, sb.len, line_termination, allow_missing);
|
mktree_line(sb.buf, sb.len, nul_term_line, allow_missing);
|
||||||
}
|
}
|
||||||
if (is_batch_mode && got_eof && used < 1) {
|
if (is_batch_mode && got_eof && used < 1) {
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -290,7 +290,7 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
|
||||||
t = &default_notes_tree;
|
t = &default_notes_tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (strbuf_getline(&buf, stdin, '\n') != EOF) {
|
while (strbuf_getline_lf(&buf, stdin) != EOF) {
|
||||||
unsigned char from_obj[20], to_obj[20];
|
unsigned char from_obj[20], to_obj[20];
|
||||||
struct strbuf **split;
|
struct strbuf **split;
|
||||||
int err;
|
int err;
|
||||||
|
|
|
@ -385,7 +385,7 @@ static void get_merge_heads(struct sha1_array *merge_heads)
|
||||||
|
|
||||||
if (!(fp = fopen(filename, "r")))
|
if (!(fp = fopen(filename, "r")))
|
||||||
die_errno(_("could not open '%s' for reading"), filename);
|
die_errno(_("could not open '%s' for reading"), filename);
|
||||||
while (strbuf_getline(&sb, fp, '\n') != EOF) {
|
while (strbuf_getline_lf(&sb, fp) != EOF) {
|
||||||
if (get_sha1_hex(sb.buf, sha1))
|
if (get_sha1_hex(sb.buf, sha1))
|
||||||
continue; /* invalid line: does not start with SHA1 */
|
continue; /* invalid line: does not start with SHA1 */
|
||||||
if (starts_with(sb.buf + GIT_SHA1_HEXSZ, "\tnot-for-merge\t"))
|
if (starts_with(sb.buf + GIT_SHA1_HEXSZ, "\tnot-for-merge\t"))
|
||||||
|
|
|
@ -266,7 +266,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
out = xfdopen(cmd.out, "r");
|
out = xfdopen(cmd.out, "r");
|
||||||
while (strbuf_getline(&line, out, '\n') != EOF) {
|
while (strbuf_getline_lf(&line, out) != EOF) {
|
||||||
if (line.len != 40)
|
if (line.len != 40)
|
||||||
die("repack: Expecting 40 character sha1 lines only from pack-objects.");
|
die("repack: Expecting 40 character sha1 lines only from pack-objects.");
|
||||||
string_list_append(&names, line.buf);
|
string_list_append(&names, line.buf);
|
||||||
|
|
|
@ -383,7 +383,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
|
||||||
|
|
||||||
/* get the usage up to the first line with a -- on it */
|
/* get the usage up to the first line with a -- on it */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (strbuf_getline(&sb, stdin, '\n') == EOF)
|
if (strbuf_getline_lf(&sb, stdin) == EOF)
|
||||||
die("premature end of input");
|
die("premature end of input");
|
||||||
ALLOC_GROW(usage, unb + 1, usz);
|
ALLOC_GROW(usage, unb + 1, usz);
|
||||||
if (!strcmp("--", sb.buf)) {
|
if (!strcmp("--", sb.buf)) {
|
||||||
|
@ -396,7 +396,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parse: (<short>|<short>,<long>|<long>)[*=?!]*<arghint>? SP+ <help> */
|
/* parse: (<short>|<short>,<long>|<long>)[*=?!]*<arghint>? SP+ <help> */
|
||||||
while (strbuf_getline(&sb, stdin, '\n') != EOF) {
|
while (strbuf_getline_lf(&sb, stdin) != EOF) {
|
||||||
const char *s;
|
const char *s;
|
||||||
const char *help;
|
const char *help;
|
||||||
struct option *o;
|
struct option *o;
|
||||||
|
|
|
@ -212,7 +212,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
|
||||||
argv_array_push(&all_refspecs, buf);
|
argv_array_push(&all_refspecs, buf);
|
||||||
} else {
|
} else {
|
||||||
struct strbuf line = STRBUF_INIT;
|
struct strbuf line = STRBUF_INIT;
|
||||||
while (strbuf_getline(&line, stdin, '\n') != EOF)
|
while (strbuf_getline_lf(&line, stdin) != EOF)
|
||||||
argv_array_push(&all_refspecs, line.buf);
|
argv_array_push(&all_refspecs, line.buf);
|
||||||
strbuf_release(&line);
|
strbuf_release(&line);
|
||||||
}
|
}
|
||||||
|
|
|
@ -468,12 +468,14 @@ static void update_one(const char *path)
|
||||||
report("add '%s'", path);
|
report("add '%s'", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void read_index_info(int line_termination)
|
static void read_index_info(int nul_term_line)
|
||||||
{
|
{
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
struct strbuf uq = STRBUF_INIT;
|
struct strbuf uq = STRBUF_INIT;
|
||||||
|
strbuf_getline_fn getline_fn;
|
||||||
|
|
||||||
while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
|
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
|
||||||
|
while (getline_fn(&buf, stdin) != EOF) {
|
||||||
char *ptr, *tab;
|
char *ptr, *tab;
|
||||||
char *path_name;
|
char *path_name;
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
|
@ -522,7 +524,7 @@ static void read_index_info(int line_termination)
|
||||||
goto bad_line;
|
goto bad_line;
|
||||||
|
|
||||||
path_name = ptr;
|
path_name = ptr;
|
||||||
if (line_termination && path_name[0] == '"') {
|
if (!nul_term_line && path_name[0] == '"') {
|
||||||
strbuf_reset(&uq);
|
strbuf_reset(&uq);
|
||||||
if (unquote_c_style(&uq, path_name, NULL)) {
|
if (unquote_c_style(&uq, path_name, NULL)) {
|
||||||
die("git update-index: bad quoting of path name");
|
die("git update-index: bad quoting of path name");
|
||||||
|
@ -844,12 +846,12 @@ static int cacheinfo_callback(struct parse_opt_ctx_t *ctx,
|
||||||
static int stdin_cacheinfo_callback(struct parse_opt_ctx_t *ctx,
|
static int stdin_cacheinfo_callback(struct parse_opt_ctx_t *ctx,
|
||||||
const struct option *opt, int unset)
|
const struct option *opt, int unset)
|
||||||
{
|
{
|
||||||
int *line_termination = opt->value;
|
int *nul_term_line = opt->value;
|
||||||
|
|
||||||
if (ctx->argc != 1)
|
if (ctx->argc != 1)
|
||||||
return error("option '%s' must be the last argument", opt->long_name);
|
return error("option '%s' must be the last argument", opt->long_name);
|
||||||
allow_add = allow_replace = allow_remove = 1;
|
allow_add = allow_replace = allow_remove = 1;
|
||||||
read_index_info(*line_termination);
|
read_index_info(*nul_term_line);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -901,7 +903,7 @@ static int reupdate_callback(struct parse_opt_ctx_t *ctx,
|
||||||
|
|
||||||
int cmd_update_index(int argc, const char **argv, const char *prefix)
|
int cmd_update_index(int argc, const char **argv, const char *prefix)
|
||||||
{
|
{
|
||||||
int newfd, entries, has_errors = 0, line_termination = '\n';
|
int newfd, entries, has_errors = 0, nul_term_line = 0;
|
||||||
int untracked_cache = -1;
|
int untracked_cache = -1;
|
||||||
int read_from_stdin = 0;
|
int read_from_stdin = 0;
|
||||||
int prefix_length = prefix ? strlen(prefix) : 0;
|
int prefix_length = prefix ? strlen(prefix) : 0;
|
||||||
|
@ -912,6 +914,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
|
||||||
int split_index = -1;
|
int split_index = -1;
|
||||||
struct lock_file *lock_file;
|
struct lock_file *lock_file;
|
||||||
struct parse_opt_ctx_t ctx;
|
struct parse_opt_ctx_t ctx;
|
||||||
|
strbuf_getline_fn getline_fn;
|
||||||
int parseopt_state = PARSE_OPT_UNKNOWN;
|
int parseopt_state = PARSE_OPT_UNKNOWN;
|
||||||
struct option options[] = {
|
struct option options[] = {
|
||||||
OPT_BIT('q', NULL, &refresh_args.flags,
|
OPT_BIT('q', NULL, &refresh_args.flags,
|
||||||
|
@ -963,13 +966,13 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
|
||||||
N_("add to index only; do not add content to object database"), 1),
|
N_("add to index only; do not add content to object database"), 1),
|
||||||
OPT_SET_INT(0, "force-remove", &force_remove,
|
OPT_SET_INT(0, "force-remove", &force_remove,
|
||||||
N_("remove named paths even if present in worktree"), 1),
|
N_("remove named paths even if present in worktree"), 1),
|
||||||
OPT_SET_INT('z', NULL, &line_termination,
|
OPT_BOOL('z', NULL, &nul_term_line,
|
||||||
N_("with --stdin: input lines are terminated by null bytes"), '\0'),
|
N_("with --stdin: input lines are terminated by null bytes")),
|
||||||
{OPTION_LOWLEVEL_CALLBACK, 0, "stdin", &read_from_stdin, NULL,
|
{OPTION_LOWLEVEL_CALLBACK, 0, "stdin", &read_from_stdin, NULL,
|
||||||
N_("read list of paths to be updated from standard input"),
|
N_("read list of paths to be updated from standard input"),
|
||||||
PARSE_OPT_NONEG | PARSE_OPT_NOARG,
|
PARSE_OPT_NONEG | PARSE_OPT_NOARG,
|
||||||
(parse_opt_cb *) stdin_callback},
|
(parse_opt_cb *) stdin_callback},
|
||||||
{OPTION_LOWLEVEL_CALLBACK, 0, "index-info", &line_termination, NULL,
|
{OPTION_LOWLEVEL_CALLBACK, 0, "index-info", &nul_term_line, NULL,
|
||||||
N_("add entries from standard input to the index"),
|
N_("add entries from standard input to the index"),
|
||||||
PARSE_OPT_NONEG | PARSE_OPT_NOARG,
|
PARSE_OPT_NONEG | PARSE_OPT_NOARG,
|
||||||
(parse_opt_cb *) stdin_cacheinfo_callback},
|
(parse_opt_cb *) stdin_cacheinfo_callback},
|
||||||
|
@ -1057,6 +1060,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
argc = parse_options_end(&ctx);
|
argc = parse_options_end(&ctx);
|
||||||
|
|
||||||
|
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
|
||||||
if (preferred_index_format) {
|
if (preferred_index_format) {
|
||||||
if (preferred_index_format < INDEX_FORMAT_LB ||
|
if (preferred_index_format < INDEX_FORMAT_LB ||
|
||||||
INDEX_FORMAT_UB < preferred_index_format)
|
INDEX_FORMAT_UB < preferred_index_format)
|
||||||
|
@ -1073,9 +1078,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
|
||||||
struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
|
||||||
|
|
||||||
setup_work_tree();
|
setup_work_tree();
|
||||||
while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
|
while (getline_fn(&buf, stdin) != EOF) {
|
||||||
char *p;
|
char *p;
|
||||||
if (line_termination && buf.buf[0] == '"') {
|
if (!nul_term_line && buf.buf[0] == '"') {
|
||||||
strbuf_reset(&nbuf);
|
strbuf_reset(&nbuf);
|
||||||
if (unquote_c_style(&nbuf, buf.buf, NULL))
|
if (unquote_c_style(&nbuf, buf.buf, NULL))
|
||||||
die("line is badly quoted");
|
die("line is badly quoted");
|
||||||
|
|
|
@ -122,7 +122,7 @@ char *git_terminal_prompt(const char *prompt, int echo)
|
||||||
fputs(prompt, output_fh);
|
fputs(prompt, output_fh);
|
||||||
fflush(output_fh);
|
fflush(output_fh);
|
||||||
|
|
||||||
r = strbuf_getline(&buf, input_fh, '\n');
|
r = strbuf_getline_lf(&buf, input_fh);
|
||||||
if (!echo) {
|
if (!echo) {
|
||||||
putc('\n', output_fh);
|
putc('\n', output_fh);
|
||||||
fflush(output_fh);
|
fflush(output_fh);
|
||||||
|
|
|
@ -96,12 +96,12 @@ static int read_request(FILE *fh, struct credential *c,
|
||||||
static struct strbuf item = STRBUF_INIT;
|
static struct strbuf item = STRBUF_INIT;
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
strbuf_getline(&item, fh, '\n');
|
strbuf_getline_lf(&item, fh);
|
||||||
if (!skip_prefix(item.buf, "action=", &p))
|
if (!skip_prefix(item.buf, "action=", &p))
|
||||||
return error("client sent bogus action line: %s", item.buf);
|
return error("client sent bogus action line: %s", item.buf);
|
||||||
strbuf_addstr(action, p);
|
strbuf_addstr(action, p);
|
||||||
|
|
||||||
strbuf_getline(&item, fh, '\n');
|
strbuf_getline_lf(&item, fh);
|
||||||
if (!skip_prefix(item.buf, "timeout=", &p))
|
if (!skip_prefix(item.buf, "timeout=", &p))
|
||||||
return error("client sent bogus timeout line: %s", item.buf);
|
return error("client sent bogus timeout line: %s", item.buf);
|
||||||
*timeout = atoi(p);
|
*timeout = atoi(p);
|
||||||
|
|
|
@ -23,7 +23,7 @@ static int parse_credential_file(const char *fn,
|
||||||
return found_credential;
|
return found_credential;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (strbuf_getline(&line, fh, '\n') != EOF) {
|
while (strbuf_getline_lf(&line, fh) != EOF) {
|
||||||
credential_from_url(&entry, line.buf);
|
credential_from_url(&entry, line.buf);
|
||||||
if (entry.username && entry.password &&
|
if (entry.username && entry.password &&
|
||||||
credential_match(c, &entry)) {
|
credential_match(c, &entry)) {
|
||||||
|
|
|
@ -142,7 +142,7 @@ int credential_read(struct credential *c, FILE *fp)
|
||||||
{
|
{
|
||||||
struct strbuf line = STRBUF_INIT;
|
struct strbuf line = STRBUF_INIT;
|
||||||
|
|
||||||
while (strbuf_getline(&line, fp, '\n') != EOF) {
|
while (strbuf_getline_lf(&line, fp) != EOF) {
|
||||||
char *key = line.buf;
|
char *key = line.buf;
|
||||||
char *value = strchr(key, '=');
|
char *value = strchr(key, '=');
|
||||||
|
|
||||||
|
|
2
daemon.c
2
daemon.c
|
@ -424,7 +424,7 @@ static void copy_to_log(int fd)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (strbuf_getline(&line, fp, '\n') != EOF) {
|
while (strbuf_getline_lf(&line, fp) != EOF) {
|
||||||
logerror("%s", line.buf);
|
logerror("%s", line.buf);
|
||||||
strbuf_setlen(&line, 0);
|
strbuf_setlen(&line, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1888,7 +1888,7 @@ static int read_next_command(void)
|
||||||
struct recent_command *rc;
|
struct recent_command *rc;
|
||||||
|
|
||||||
strbuf_detach(&command_buf, NULL);
|
strbuf_detach(&command_buf, NULL);
|
||||||
stdin_eof = strbuf_getline(&command_buf, stdin, '\n');
|
stdin_eof = strbuf_getline_lf(&command_buf, stdin);
|
||||||
if (stdin_eof)
|
if (stdin_eof)
|
||||||
return EOF;
|
return EOF;
|
||||||
|
|
||||||
|
@ -1960,7 +1960,7 @@ static int parse_data(struct strbuf *sb, uintmax_t limit, uintmax_t *len_res)
|
||||||
|
|
||||||
strbuf_detach(&command_buf, NULL);
|
strbuf_detach(&command_buf, NULL);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (strbuf_getline(&command_buf, stdin, '\n') == EOF)
|
if (strbuf_getline_lf(&command_buf, stdin) == EOF)
|
||||||
die("EOF in data (terminator '%s' not found)", term);
|
die("EOF in data (terminator '%s' not found)", term);
|
||||||
if (term_len == command_buf.len
|
if (term_len == command_buf.len
|
||||||
&& !strcmp(term, command_buf.buf))
|
&& !strcmp(term, command_buf.buf))
|
||||||
|
|
2
ident.c
2
ident.c
|
@ -76,7 +76,7 @@ static int add_mailname_host(struct strbuf *buf)
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (strbuf_getline(&mailnamebuf, mailname, '\n') == EOF) {
|
if (strbuf_getline_lf(&mailnamebuf, mailname) == EOF) {
|
||||||
if (ferror(mailname))
|
if (ferror(mailname))
|
||||||
warning("cannot read /etc/mailname: %s",
|
warning("cannot read /etc/mailname: %s",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
|
|
@ -732,7 +732,7 @@ static int read_one_header_line(struct strbuf *line, FILE *in)
|
||||||
struct strbuf continuation = STRBUF_INIT;
|
struct strbuf continuation = STRBUF_INIT;
|
||||||
|
|
||||||
/* Get the first part of the line. */
|
/* Get the first part of the line. */
|
||||||
if (strbuf_getline(line, in, '\n'))
|
if (strbuf_getline_lf(line, in))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -756,7 +756,7 @@ static int read_one_header_line(struct strbuf *line, FILE *in)
|
||||||
peek = fgetc(in); ungetc(peek, in);
|
peek = fgetc(in); ungetc(peek, in);
|
||||||
if (peek != ' ' && peek != '\t')
|
if (peek != ' ' && peek != '\t')
|
||||||
break;
|
break;
|
||||||
if (strbuf_getline(&continuation, in, '\n'))
|
if (strbuf_getline_lf(&continuation, in))
|
||||||
break;
|
break;
|
||||||
continuation.buf[0] = ' ';
|
continuation.buf[0] = ' ';
|
||||||
strbuf_rtrim(&continuation);
|
strbuf_rtrim(&continuation);
|
||||||
|
@ -769,7 +769,7 @@ static int read_one_header_line(struct strbuf *line, FILE *in)
|
||||||
|
|
||||||
static int find_boundary(struct mailinfo *mi, struct strbuf *line)
|
static int find_boundary(struct mailinfo *mi, struct strbuf *line)
|
||||||
{
|
{
|
||||||
while (!strbuf_getline(line, mi->input, '\n')) {
|
while (!strbuf_getline_lf(line, mi->input)) {
|
||||||
if (*(mi->content_top) && is_multipart_boundary(mi, line))
|
if (*(mi->content_top) && is_multipart_boundary(mi, line))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -820,7 +820,7 @@ again:
|
||||||
|
|
||||||
strbuf_release(&newline);
|
strbuf_release(&newline);
|
||||||
/* replenish line */
|
/* replenish line */
|
||||||
if (strbuf_getline(line, mi->input, '\n'))
|
if (strbuf_getline_lf(line, mi->input))
|
||||||
return 0;
|
return 0;
|
||||||
strbuf_addch(line, '\n');
|
strbuf_addch(line, '\n');
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -827,7 +827,7 @@ static void parse_fetch(struct strbuf *buf)
|
||||||
die("http transport does not support %s", buf->buf);
|
die("http transport does not support %s", buf->buf);
|
||||||
|
|
||||||
strbuf_reset(buf);
|
strbuf_reset(buf);
|
||||||
if (strbuf_getline(buf, stdin, '\n') == EOF)
|
if (strbuf_getline_lf(buf, stdin) == EOF)
|
||||||
return;
|
return;
|
||||||
if (!*buf->buf)
|
if (!*buf->buf)
|
||||||
break;
|
break;
|
||||||
|
@ -940,7 +940,7 @@ static void parse_push(struct strbuf *buf)
|
||||||
die("http transport does not support %s", buf->buf);
|
die("http transport does not support %s", buf->buf);
|
||||||
|
|
||||||
strbuf_reset(buf);
|
strbuf_reset(buf);
|
||||||
if (strbuf_getline(buf, stdin, '\n') == EOF)
|
if (strbuf_getline_lf(buf, stdin) == EOF)
|
||||||
goto free_specs;
|
goto free_specs;
|
||||||
if (!*buf->buf)
|
if (!*buf->buf)
|
||||||
break;
|
break;
|
||||||
|
@ -990,7 +990,7 @@ int main(int argc, const char **argv)
|
||||||
do {
|
do {
|
||||||
const char *arg;
|
const char *arg;
|
||||||
|
|
||||||
if (strbuf_getline(&buf, stdin, '\n') == EOF) {
|
if (strbuf_getline_lf(&buf, stdin) == EOF) {
|
||||||
if (ferror(stdin))
|
if (ferror(stdin))
|
||||||
error("remote-curl: error reading command stream from git");
|
error("remote-curl: error reading command stream from git");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -154,7 +154,7 @@ static void check_or_regenerate_marks(int latestrev)
|
||||||
fclose(marksfile);
|
fclose(marksfile);
|
||||||
} else {
|
} else {
|
||||||
strbuf_addf(&sb, ":%d ", latestrev);
|
strbuf_addf(&sb, ":%d ", latestrev);
|
||||||
while (strbuf_getline(&line, marksfile, '\n') != EOF) {
|
while (strbuf_getline_lf(&line, marksfile) != EOF) {
|
||||||
if (starts_with(line.buf, sb.buf)) {
|
if (starts_with(line.buf, sb.buf)) {
|
||||||
found++;
|
found++;
|
||||||
break;
|
break;
|
||||||
|
@ -322,7 +322,7 @@ int main(int argc, char **argv)
|
||||||
marksfilename = marksfilename_sb.buf;
|
marksfilename = marksfilename_sb.buf;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (strbuf_getline(&buf, stdin, '\n') == EOF) {
|
if (strbuf_getline_lf(&buf, stdin) == EOF) {
|
||||||
if (ferror(stdin))
|
if (ferror(stdin))
|
||||||
die("Error reading command stream");
|
die("Error reading command stream");
|
||||||
else
|
else
|
||||||
|
|
4
remote.c
4
remote.c
|
@ -256,7 +256,7 @@ static void read_remotes_file(struct remote *remote)
|
||||||
if (!f)
|
if (!f)
|
||||||
return;
|
return;
|
||||||
remote->origin = REMOTE_REMOTES;
|
remote->origin = REMOTE_REMOTES;
|
||||||
while (strbuf_getline(&buf, f, '\n') != EOF) {
|
while (strbuf_getline_lf(&buf, f) != EOF) {
|
||||||
const char *v;
|
const char *v;
|
||||||
|
|
||||||
strbuf_rtrim(&buf);
|
strbuf_rtrim(&buf);
|
||||||
|
@ -281,7 +281,7 @@ static void read_branches_file(struct remote *remote)
|
||||||
if (!f)
|
if (!f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
strbuf_getline(&buf, f, '\n');
|
strbuf_getline_lf(&buf, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
strbuf_trim(&buf);
|
strbuf_trim(&buf);
|
||||||
if (!buf.len) {
|
if (!buf.len) {
|
||||||
|
|
|
@ -886,7 +886,7 @@ static int sequencer_rollback(struct replay_opts *opts)
|
||||||
if (!f)
|
if (!f)
|
||||||
return error(_("cannot open %s: %s"), git_path_head_file(),
|
return error(_("cannot open %s: %s"), git_path_head_file(),
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
if (strbuf_getline(&buf, f, '\n')) {
|
if (strbuf_getline_lf(&buf, f)) {
|
||||||
error(_("cannot read %s: %s"), git_path_head_file(),
|
error(_("cannot read %s: %s"), git_path_head_file(),
|
||||||
ferror(f) ? strerror(errno) : _("unexpected end of file"));
|
ferror(f) ? strerror(errno) : _("unexpected end of file"));
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
|
@ -396,7 +396,7 @@ void add_to_alternates_file(const char *reference)
|
||||||
struct strbuf line = STRBUF_INIT;
|
struct strbuf line = STRBUF_INIT;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
|
||||||
while (strbuf_getline(&line, in, '\n') != EOF) {
|
while (strbuf_getline_lf(&line, in) != EOF) {
|
||||||
if (!strcmp(reference, line.buf)) {
|
if (!strcmp(reference, line.buf)) {
|
||||||
found = 1;
|
found = 1;
|
||||||
break;
|
break;
|
||||||
|
|
2
shell.c
2
shell.c
|
@ -88,7 +88,7 @@ static void run_shell(void)
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
fprintf(stderr, "git> ");
|
fprintf(stderr, "git> ");
|
||||||
if (strbuf_getline(&line, stdin, '\n') == EOF) {
|
if (strbuf_getline_lf(&line, stdin) == EOF) {
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
strbuf_release(&line);
|
strbuf_release(&line);
|
||||||
break;
|
break;
|
||||||
|
|
28
strbuf.c
28
strbuf.c
|
@ -512,15 +512,37 @@ int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int strbuf_getline(struct strbuf *sb, FILE *fp, int term)
|
static int strbuf_getdelim(struct strbuf *sb, FILE *fp, int term)
|
||||||
{
|
{
|
||||||
if (strbuf_getwholeline(sb, fp, term))
|
if (strbuf_getwholeline(sb, fp, term))
|
||||||
return EOF;
|
return EOF;
|
||||||
if (sb->buf[sb->len-1] == term)
|
if (sb->buf[sb->len - 1] == term)
|
||||||
strbuf_setlen(sb, sb->len-1);
|
strbuf_setlen(sb, sb->len - 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int strbuf_getline(struct strbuf *sb, FILE *fp)
|
||||||
|
{
|
||||||
|
if (strbuf_getwholeline(sb, fp, '\n'))
|
||||||
|
return EOF;
|
||||||
|
if (sb->buf[sb->len - 1] == '\n') {
|
||||||
|
strbuf_setlen(sb, sb->len - 1);
|
||||||
|
if (sb->len && sb->buf[sb->len - 1] == '\r')
|
||||||
|
strbuf_setlen(sb, sb->len - 1);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int strbuf_getline_lf(struct strbuf *sb, FILE *fp)
|
||||||
|
{
|
||||||
|
return strbuf_getdelim(sb, fp, '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
int strbuf_getline_nul(struct strbuf *sb, FILE *fp)
|
||||||
|
{
|
||||||
|
return strbuf_getdelim(sb, fp, '\0');
|
||||||
|
}
|
||||||
|
|
||||||
int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term)
|
int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term)
|
||||||
{
|
{
|
||||||
strbuf_reset(sb);
|
strbuf_reset(sb);
|
||||||
|
|
29
strbuf.h
29
strbuf.h
|
@ -354,8 +354,8 @@ extern void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm
|
||||||
*
|
*
|
||||||
* NOTE: The buffer is rewound if the read fails. If -1 is returned,
|
* NOTE: The buffer is rewound if the read fails. If -1 is returned,
|
||||||
* `errno` must be consulted, like you would do for `read(3)`.
|
* `errno` must be consulted, like you would do for `read(3)`.
|
||||||
* `strbuf_read()`, `strbuf_read_file()` and `strbuf_getline()` has the
|
* `strbuf_read()`, `strbuf_read_file()` and `strbuf_getline_*()`
|
||||||
* same behaviour as well.
|
* family of functions have the same behaviour as well.
|
||||||
*/
|
*/
|
||||||
extern size_t strbuf_fread(struct strbuf *, size_t, FILE *);
|
extern size_t strbuf_fread(struct strbuf *, size_t, FILE *);
|
||||||
|
|
||||||
|
@ -387,14 +387,31 @@ extern ssize_t strbuf_read_file(struct strbuf *sb, const char *path, size_t hint
|
||||||
extern int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint);
|
extern int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a line from a FILE *, overwriting the existing contents
|
* Read a line from a FILE *, overwriting the existing contents of
|
||||||
* of the strbuf. The second argument specifies the line
|
* the strbuf. The strbuf_getline*() family of functions share
|
||||||
* terminator character, typically `'\n'`.
|
* this signature, but have different line termination conventions.
|
||||||
|
*
|
||||||
* Reading stops after the terminator or at EOF. The terminator
|
* Reading stops after the terminator or at EOF. The terminator
|
||||||
* is removed from the buffer before returning. Returns 0 unless
|
* is removed from the buffer before returning. Returns 0 unless
|
||||||
* there was nothing left before EOF, in which case it returns `EOF`.
|
* there was nothing left before EOF, in which case it returns `EOF`.
|
||||||
*/
|
*/
|
||||||
extern int strbuf_getline(struct strbuf *, FILE *, int);
|
typedef int (*strbuf_getline_fn)(struct strbuf *, FILE *);
|
||||||
|
|
||||||
|
/* Uses LF as the line terminator */
|
||||||
|
extern int strbuf_getline_lf(struct strbuf *sb, FILE *fp);
|
||||||
|
|
||||||
|
/* Uses NUL as the line terminator */
|
||||||
|
extern int strbuf_getline_nul(struct strbuf *sb, FILE *fp);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Similar to strbuf_getline_lf(), but additionally treats a CR that
|
||||||
|
* comes immediately before the LF as part of the terminator.
|
||||||
|
* This is the most friendly version to be used to read "text" files
|
||||||
|
* that can come from platforms whose native text format is CRLF
|
||||||
|
* terminated.
|
||||||
|
*/
|
||||||
|
extern int strbuf_getline(struct strbuf *, FILE *);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like `strbuf_getline`, but keeps the trailing terminator (if
|
* Like `strbuf_getline`, but keeps the trailing terminator (if
|
||||||
|
|
|
@ -11,7 +11,7 @@ int main(int argc, char **argv)
|
||||||
struct sha1_array array = SHA1_ARRAY_INIT;
|
struct sha1_array array = SHA1_ARRAY_INIT;
|
||||||
struct strbuf line = STRBUF_INIT;
|
struct strbuf line = STRBUF_INIT;
|
||||||
|
|
||||||
while (strbuf_getline(&line, stdin, '\n') != EOF) {
|
while (strbuf_getline_lf(&line, stdin) != EOF) {
|
||||||
const char *arg;
|
const char *arg;
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ static int recvline_fh(FILE *helper, struct strbuf *buffer, const char *name)
|
||||||
strbuf_reset(buffer);
|
strbuf_reset(buffer);
|
||||||
if (debug)
|
if (debug)
|
||||||
fprintf(stderr, "Debug: Remote helper: Waiting...\n");
|
fprintf(stderr, "Debug: Remote helper: Waiting...\n");
|
||||||
if (strbuf_getline(buffer, helper, '\n') == EOF) {
|
if (strbuf_getline_lf(buffer, helper) == EOF) {
|
||||||
if (debug)
|
if (debug)
|
||||||
fprintf(stderr, "Debug: Remote helper quit.\n");
|
fprintf(stderr, "Debug: Remote helper quit.\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -137,7 +137,8 @@ static struct child_process *get_helper(struct transport *transport)
|
||||||
data->no_disconnect_req = 0;
|
data->no_disconnect_req = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Open the output as FILE* so strbuf_getline() can be used.
|
* Open the output as FILE* so strbuf_getline_*() family of
|
||||||
|
* functions can be used.
|
||||||
* Do this with duped fd because fclose() will close the fd,
|
* Do this with duped fd because fclose() will close the fd,
|
||||||
* and stuff like taking over will require the fd to remain.
|
* and stuff like taking over will require the fd to remain.
|
||||||
*/
|
*/
|
||||||
|
|
2
walker.c
2
walker.c
|
@ -220,7 +220,7 @@ int walker_targets_stdin(char ***target, const char ***write_ref)
|
||||||
char *rf_one = NULL;
|
char *rf_one = NULL;
|
||||||
char *tg_one;
|
char *tg_one;
|
||||||
|
|
||||||
if (strbuf_getline(&buf, stdin, '\n') == EOF)
|
if (strbuf_getline_lf(&buf, stdin) == EOF)
|
||||||
break;
|
break;
|
||||||
tg_one = buf.buf;
|
tg_one = buf.buf;
|
||||||
rf_one = strchr(tg_one, '\t');
|
rf_one = strchr(tg_one, '\t');
|
||||||
|
|
|
@ -988,7 +988,7 @@ static char *read_line_from_git_path(const char *filename)
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
strbuf_getline(&buf, fp, '\n');
|
strbuf_getline_lf(&buf, fp);
|
||||||
if (!fclose(fp)) {
|
if (!fclose(fp)) {
|
||||||
return strbuf_detach(&buf, NULL);
|
return strbuf_detach(&buf, NULL);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1076,7 +1076,7 @@ static void read_rebase_todolist(const char *fname, struct string_list *lines)
|
||||||
if (!f)
|
if (!f)
|
||||||
die_errno("Could not open file %s for reading",
|
die_errno("Could not open file %s for reading",
|
||||||
git_path("%s", fname));
|
git_path("%s", fname));
|
||||||
while (!strbuf_getline(&line, f, '\n')) {
|
while (!strbuf_getline_lf(&line, f)) {
|
||||||
if (line.len && line.buf[0] == comment_line_char)
|
if (line.len && line.buf[0] == comment_line_char)
|
||||||
continue;
|
continue;
|
||||||
strbuf_trim(&line);
|
strbuf_trim(&line);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче