strbuf: introduce strbuf_getline_{lf,nul}()

The strbuf_getline() interface allows a byte other than LF or NUL as the line terminator, but this is only because I wrote these codepaths anticipating that there might be a value other than NUL and LF that could be useful when I introduced line_termination long time ago. No useful caller that uses other value has emerged. By now, it is clear that the interface is overly broad without a good reason. Many codepaths have hardcoded preference to read either LF terminated or NUL terminated records from their input, and then call strbuf_getline() with LF or NUL as the third parameter. This step introduces two thin wrappers around strbuf_getline(), namely, strbuf_getline_lf() and strbuf_getline_nul(), and mechanically rewrites these call sites to call either one of them. The changes contained in this patch are: * introduction of these two functions in strbuf.[ch] * mechanical conversion of all callers to strbuf_getline() with either '\n' or '\0' as the third parameter to instead call the respective thin wrapper. After this step, output from "git grep 'strbuf_getline('" would become a lot smaller. An interim goal of this series is to make this an empty set, so that we can have strbuf_getline_crlf() take over the shorter name strbuf_getline(). Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jan 13, 2016 at 15:31 UTC 8f309aeb8225a9c26f20c0dbc031f1ea8df75d49
36 files changed +81 -59
bisect.c
+4 -4
@@ -440,7 +440,7 @@ static void read_bisect_paths(struct argv_array *array)
440 if (!fp)
441 die_errno("Could not open file '%s'", filename);
442
443 - while (strbuf_getline(&str, fp, '\n') != EOF) {
443 + while (strbuf_getline_lf(&str, fp) != EOF) {
444 strbuf_trim(&str);
445 if (sq_dequote_to_argv_array(str.buf, array))
446 die("Badly quoted content in file '%s': %s",
@@ -668,7 +668,7 @@ static int is_expected_rev(const struct object_id *oid)
668 if (!fp)
669 return 0;
670
671 - if (strbuf_getline(&str, fp, '\n') != EOF)
671 + if (strbuf_getline_lf(&str, fp) != EOF)
672 res = !strcmp(str.buf, oid_to_hex(oid));
673
674 strbuf_release(&str);
@@ -914,9 +914,9 @@ void read_bisect_terms(const char **read_bad, const char **read_good)
914 strerror(errno));
915 }
916 } else {
917 - strbuf_getline(&str, fp, '\n');
917 + strbuf_getline_lf(&str, fp);
918 *read_bad = strbuf_detach(&str, NULL);
919 - strbuf_getline(&str, fp, '\n');
919 + strbuf_getline_lf(&str, fp);
920 *read_good = strbuf_detach(&str, NULL);
921 }
922 strbuf_release(&str);
builtin/am.c
+7 -7
@@ -269,7 +269,7 @@ static char *read_shell_var(FILE *fp, const char *key)
269 struct strbuf sb = STRBUF_INIT;
270 const char *str;
271
272 - if (strbuf_getline(&sb, fp, '\n'))
272 + if (strbuf_getline_lf(&sb, fp))
273 goto fail;
274
275 if (!skip_prefix(sb.buf, key, &str))
@@ -558,7 +558,7 @@ static int copy_notes_for_rebase(const struct am_state *state)
558
559 fp = xfopen(am_path(state, "rewritten"), "r");
560
561 - while (!strbuf_getline(&sb, fp, '\n')) {
561 + while (!strbuf_getline_lf(&sb, fp)) {
562 unsigned char from_obj[GIT_SHA1_RAWSZ], to_obj[GIT_SHA1_RAWSZ];
563
564 if (sb.len != GIT_SHA1_HEXSZ * 2 + 1) {
@@ -802,7 +802,7 @@ static int stgit_patch_to_mail(FILE *out, FILE *in, int keep_cr)
802 struct strbuf sb = STRBUF_INIT;
803 int subject_printed = 0;
804
805 - while (!strbuf_getline(&sb, in, '\n')) {
805 + while (!strbuf_getline_lf(&sb, in)) {
806 const char *str;
807
808 if (str_isspace(sb.buf))
@@ -860,7 +860,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths,
860 return error(_("could not open '%s' for reading: %s"), *paths,
861 strerror(errno));
862
863 - while (!strbuf_getline(&sb, fp, '\n')) {
863 + while (!strbuf_getline_lf(&sb, fp)) {
864 if (*sb.buf == '#')
865 continue; /* skip comment lines */
866
@@ -885,7 +885,7 @@ static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr)
885 {
886 struct strbuf sb = STRBUF_INIT;
887
888 - while (!strbuf_getline(&sb, in, '\n')) {
888 + while (!strbuf_getline_lf(&sb, in)) {
889 const char *str;
890
891 if (skip_prefix(sb.buf, "# User ", &str))
@@ -1302,7 +1302,7 @@ static int parse_mail(struct am_state *state, const char *mail)
1302
1303 /* Extract message and author information */
1304 fp = xfopen(am_path(state, "info"), "r");
1305 - while (!strbuf_getline(&sb, fp, '\n')) {
1305 + while (!strbuf_getline_lf(&sb, fp)) {
1306 const char *x;
1307
1308 if (skip_prefix(sb.buf, "Subject: ", &x)) {
@@ -1368,7 +1368,7 @@ static int get_mail_commit_sha1(unsigned char *commit_id, const char *mail)
1368 FILE *fp = xfopen(mail, "r");
1369 const char *x;
1370
1371 - if (strbuf_getline(&sb, fp, '\n'))
1371 + if (strbuf_getline_lf(&sb, fp))
1372 return -1;
1373
1374 if (!skip_prefix(sb.buf, "From ", &x))
builtin/cat-file.c
+1 -1
@@ -401,7 +401,7 @@ static int batch_objects(struct batch_options *opt)
401 save_warning = warn_on_object_refname_ambiguity;
402 warn_on_object_refname_ambiguity = 0;
403
404 - while (strbuf_getline(&buf, stdin, '\n') != EOF) {
404 + while (strbuf_getline_lf(&buf, stdin) != EOF) {
405 if (data.split_on_whitespace) {
406 /*
407 * Split at first whitespace, tying off the beginning
builtin/check-mailmap.c
+1 -1
@@ -54,7 +54,7 @@ int cmd_check_mailmap(int argc, const char **argv, const char *prefix)
54
55 if (use_stdin) {
56 struct strbuf buf = STRBUF_INIT;
57 - while (strbuf_getline(&buf, stdin, '\n') != EOF) {
57 + while (strbuf_getline_lf(&buf, stdin) != EOF) {
58 check_mailmap(&mailmap, buf.buf);
59 maybe_flush_or_die(stdout, "stdout");
60 }
builtin/clean.c
+3 -3
@@ -594,7 +594,7 @@ static int *list_and_choose(struct menu_opts *opts, struct menu_stuff *stuff)
594 clean_get_color(CLEAN_COLOR_RESET));
595 }
596
597 - if (strbuf_getline(&choice, stdin, '\n') != EOF) {
597 + if (strbuf_getline_lf(&choice, stdin) != EOF) {
598 strbuf_trim(&choice);
599 } else {
600 eof = 1;
@@ -676,7 +676,7 @@ static int filter_by_patterns_cmd(void)
676 clean_print_color(CLEAN_COLOR_PROMPT);
677 printf(_("Input ignore patterns>> "));
678 clean_print_color(CLEAN_COLOR_RESET);
679 - if (strbuf_getline(&confirm, stdin, '\n') != EOF)
679 + if (strbuf_getline_lf(&confirm, stdin) != EOF)
680 strbuf_trim(&confirm);
681 else
682 putchar('\n');
@@ -774,7 +774,7 @@ static int ask_each_cmd(void)
774 qname = quote_path_relative(item->string, NULL, &buf);
775 /* TRANSLATORS: Make sure to keep [y/N] as is */
776 printf(_("Remove %s [y/N]? "), qname);
777 - if (strbuf_getline(&confirm, stdin, '\n') != EOF) {
777 + if (strbuf_getline_lf(&confirm, stdin) != EOF) {
778 strbuf_trim(&confirm);
779 } else {
780 putchar('\n');
builtin/clone.c
+1 -1
@@ -339,7 +339,7 @@ static void copy_alternates(struct strbuf *src, struct strbuf *dst,
339 FILE *in = fopen(src->buf, "r");
340 struct strbuf line = STRBUF_INIT;
341
342 - while (strbuf_getline(&line, in, '\n') != EOF) {
342 + while (strbuf_getline_lf(&line, in) != EOF) {
343 char *abs_path;
344 if (!line.len || line.buf[0] == '#')
345 continue;
builtin/column.c
+1 -1
@@ -51,7 +51,7 @@ int cmd_column(int argc, const char **argv, const char *prefix)
51 die(_("--command must be the first argument"));
52 }
53 finalize_colopts(&colopts, -1);
54 - while (!strbuf_getline(&sb, stdin, '\n'))
54 + while (!strbuf_getline_lf(&sb, stdin))
55 string_list_append(&list, sb.buf);
56
57 print_columns(&list, colopts, &copts);
builtin/commit.c
+1 -1
@@ -1690,7 +1690,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1690 if (fp == NULL)
1691 die_errno(_("could not open '%s' for reading"),
1692 git_path_merge_head());
1693 - while (strbuf_getline(&m, fp, '\n') != EOF) {
1693 + while (strbuf_getline_lf(&m, fp) != EOF) {
1694 struct commit *parent;
1695
1696 parent = get_merge_parent(m.buf);
builtin/fetch-pack.c
+1 -1
@@ -158,7 +158,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
158 else {
159 /* read from stdin one ref per line, until EOF */
160 struct strbuf line = STRBUF_INIT;
161 - while (strbuf_getline(&line, stdin, '\n') != EOF)
161 + while (strbuf_getline_lf(&line, stdin) != EOF)
162 add_sought_entry(&sought, &nr_sought, &alloc_sought, line.buf);
163 strbuf_release(&line);
164 }
builtin/grep.c
+1 -1
@@ -562,7 +562,7 @@ static int file_callback(const struct option *opt, const char *arg, int unset)
562 patterns = from_stdin ? stdin : fopen(arg, "r");
563 if (!patterns)
564 die_errno(_("cannot open '%s'"), arg);
565 - while (strbuf_getline(&sb, patterns, '\n') == 0) {
565 + while (strbuf_getline_lf(&sb, patterns) == 0) {
566 /* ignore empty line like grep does */
567 if (sb.len == 0)
568 continue;
builtin/hash-object.c
+1 -1
@@ -60,7 +60,7 @@ static void hash_stdin_paths(const char *type, int no_filters, unsigned flags,
60 {
61 struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
62
63 - while (strbuf_getline(&buf, stdin, '\n') != EOF) {
63 + while (strbuf_getline_lf(&buf, stdin) != EOF) {
64 if (buf.buf[0] == '"') {
65 strbuf_reset(&nbuf);
66 if (unquote_c_style(&nbuf, buf.buf, NULL))
builtin/notes.c
+1 -1
@@ -290,7 +290,7 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
290 t = &default_notes_tree;
291 }
292
293 - while (strbuf_getline(&buf, stdin, '\n') != EOF) {
293 + while (strbuf_getline_lf(&buf, stdin) != EOF) {
294 unsigned char from_obj[20], to_obj[20];
295 struct strbuf **split;
296 int err;
builtin/pull.c
+1 -1
@@ -378,7 +378,7 @@ static void get_merge_heads(struct sha1_array *merge_heads)
378
379 if (!(fp = fopen(filename, "r")))
380 die_errno(_("could not open '%s' for reading"), filename);
381 - while (strbuf_getline(&sb, fp, '\n') != EOF) {
381 + while (strbuf_getline_lf(&sb, fp) != EOF) {
382 if (get_sha1_hex(sb.buf, sha1))
383 continue; /* invalid line: does not start with SHA1 */
384 if (starts_with(sb.buf + GIT_SHA1_HEXSZ, "\tnot-for-merge\t"))
builtin/repack.c
+1 -1
@@ -266,7 +266,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
266 return ret;
267
268 out = xfdopen(cmd.out, "r");
269 - while (strbuf_getline(&line, out, '\n') != EOF) {
269 + while (strbuf_getline_lf(&line, out) != EOF) {
270 if (line.len != 40)
271 die("repack: Expecting 40 character sha1 lines only from pack-objects.");
272 string_list_append(&names, line.buf);
builtin/rev-parse.c
+2 -2
@@ -383,7 +383,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
383
384 /* get the usage up to the first line with a -- on it */
385 for (;;) {
386 - if (strbuf_getline(&sb, stdin, '\n') == EOF)
386 + if (strbuf_getline_lf(&sb, stdin) == EOF)
387 die("premature end of input");
388 ALLOC_GROW(usage, unb + 1, usz);
389 if (!strcmp("--", sb.buf)) {
@@ -396,7 +396,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
396 }
397
398 /* parse: (<short>|<short>,<long>|<long>)[*=?!]*<arghint>? SP+ <help> */
399 - while (strbuf_getline(&sb, stdin, '\n') != EOF) {
399 + while (strbuf_getline_lf(&sb, stdin) != EOF) {
400 const char *s;
401 const char *help;
402 struct option *o;
builtin/send-pack.c
+1 -1
@@ -212,7 +212,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
212 argv_array_push(&all_refspecs, buf);
213 } else {
214 struct strbuf line = STRBUF_INIT;
215 - while (strbuf_getline(&line, stdin, '\n') != EOF)
215 + while (strbuf_getline_lf(&line, stdin) != EOF)
216 argv_array_push(&all_refspecs, line.buf);
217 strbuf_release(&line);
218 }
compat/terminal.c
+1 -1
@@ -122,7 +122,7 @@ char *git_terminal_prompt(const char *prompt, int echo)
122 fputs(prompt, output_fh);
123 fflush(output_fh);
124
125 - r = strbuf_getline(&buf, input_fh, '\n');
125 + r = strbuf_getline_lf(&buf, input_fh);
126 if (!echo) {
127 putc('\n', output_fh);
128 fflush(output_fh);
credential-cache--daemon.c
+2 -2
@@ -96,12 +96,12 @@ static int read_request(FILE *fh, struct credential *c,
96 static struct strbuf item = STRBUF_INIT;
97 const char *p;
98
99 - strbuf_getline(&item, fh, '\n');
99 + strbuf_getline_lf(&item, fh);
100 if (!skip_prefix(item.buf, "action=", &p))
101 return error("client sent bogus action line: %s", item.buf);
102 strbuf_addstr(action, p);
103
104 - strbuf_getline(&item, fh, '\n');
104 + strbuf_getline_lf(&item, fh);
105 if (!skip_prefix(item.buf, "timeout=", &p))
106 return error("client sent bogus timeout line: %s", item.buf);
107 *timeout = atoi(p);
credential-store.c
+1 -1
@@ -23,7 +23,7 @@ static int parse_credential_file(const char *fn,
23 return found_credential;
24 }
25
26 - while (strbuf_getline(&line, fh, '\n') != EOF) {
26 + while (strbuf_getline_lf(&line, fh) != EOF) {
27 credential_from_url(&entry, line.buf);
28 if (entry.username && entry.password &&
29 credential_match(c, &entry)) {
credential.c
+1 -1
@@ -142,7 +142,7 @@ int credential_read(struct credential *c, FILE *fp)
142 {
143 struct strbuf line = STRBUF_INIT;
144
145 - while (strbuf_getline(&line, fp, '\n') != EOF) {
145 + while (strbuf_getline_lf(&line, fp) != EOF) {
146 char *key = line.buf;
147 char *value = strchr(key, '=');
148
daemon.c
+1 -1
@@ -424,7 +424,7 @@ static void copy_to_log(int fd)
424 return;
425 }
426
427 - while (strbuf_getline(&line, fp, '\n') != EOF) {
427 + while (strbuf_getline_lf(&line, fp) != EOF) {
428 logerror("%s", line.buf);
429 strbuf_setlen(&line, 0);
430 }
fast-import.c
+2 -2
@@ -1888,7 +1888,7 @@ static int read_next_command(void)
1888 struct recent_command *rc;
1889
1890 strbuf_detach(&command_buf, NULL);
1891 - stdin_eof = strbuf_getline(&command_buf, stdin, '\n');
1891 + stdin_eof = strbuf_getline_lf(&command_buf, stdin);
1892 if (stdin_eof)
1893 return EOF;
1894
@@ -1960,7 +1960,7 @@ static int parse_data(struct strbuf *sb, uintmax_t limit, uintmax_t *len_res)
1960
1961 strbuf_detach(&command_buf, NULL);
1962 for (;;) {
1963 - if (strbuf_getline(&command_buf, stdin, '\n') == EOF)
1963 + if (strbuf_getline_lf(&command_buf, stdin) == EOF)
1964 die("EOF in data (terminator '%s' not found)", term);
1965 if (term_len == command_buf.len
1966 && !strcmp(term, command_buf.buf))
ident.c
+1 -1
@@ -76,7 +76,7 @@ static int add_mailname_host(struct strbuf *buf)
76 strerror(errno));
77 return -1;
78 }
79 - if (strbuf_getline(&mailnamebuf, mailname, '\n') == EOF) {
79 + if (strbuf_getline_lf(&mailnamebuf, mailname) == EOF) {
80 if (ferror(mailname))
81 warning("cannot read /etc/mailname: %s",
82 strerror(errno));
mailinfo.c
+4 -4
@@ -732,7 +732,7 @@ static int read_one_header_line(struct strbuf *line, FILE *in)
732 struct strbuf continuation = STRBUF_INIT;
733
734 /* Get the first part of the line. */
735 - if (strbuf_getline(line, in, '\n'))
735 + if (strbuf_getline_lf(line, in))
736 return 0;
737
738 /*
@@ -756,7 +756,7 @@ static int read_one_header_line(struct strbuf *line, FILE *in)
756 peek = fgetc(in); ungetc(peek, in);
757 if (peek != ' ' && peek != '\t')
758 break;
759 - if (strbuf_getline(&continuation, in, '\n'))
759 + if (strbuf_getline_lf(&continuation, in))
760 break;
761 continuation.buf[0] = ' ';
762 strbuf_rtrim(&continuation);
@@ -769,7 +769,7 @@ static int read_one_header_line(struct strbuf *line, FILE *in)
769
770 static int find_boundary(struct mailinfo *mi, struct strbuf *line)
771 {
772 - while (!strbuf_getline(line, mi->input, '\n')) {
772 + while (!strbuf_getline_lf(line, mi->input)) {
773 if (*(mi->content_top) && is_multipart_boundary(mi, line))
774 return 1;
775 }
@@ -820,7 +820,7 @@ again:
820
821 strbuf_release(&newline);
822 /* replenish line */
823 - if (strbuf_getline(line, mi->input, '\n'))
823 + if (strbuf_getline_lf(line, mi->input))
824 return 0;
825 strbuf_addch(line, '\n');
826 return 1;
remote-curl.c
+3 -3
@@ -827,7 +827,7 @@ static void parse_fetch(struct strbuf *buf)
827 die("http transport does not support %s", buf->buf);
828
829 strbuf_reset(buf);
830 - if (strbuf_getline(buf, stdin, '\n') == EOF)
830 + if (strbuf_getline_lf(buf, stdin) == EOF)
831 return;
832 if (!*buf->buf)
833 break;
@@ -940,7 +940,7 @@ static void parse_push(struct strbuf *buf)
940 die("http transport does not support %s", buf->buf);
941
942 strbuf_reset(buf);
943 - if (strbuf_getline(buf, stdin, '\n') == EOF)
943 + if (strbuf_getline_lf(buf, stdin) == EOF)
944 goto free_specs;
945 if (!*buf->buf)
946 break;
@@ -990,7 +990,7 @@ int main(int argc, const char **argv)
990 do {
991 const char *arg;
992
993 - if (strbuf_getline(&buf, stdin, '\n') == EOF) {
993 + if (strbuf_getline_lf(&buf, stdin) == EOF) {
994 if (ferror(stdin))
995 error("remote-curl: error reading command stream from git");
996 return 1;
remote-testsvn.c
+2 -2
@@ -154,7 +154,7 @@ static void check_or_regenerate_marks(int latestrev)
154 fclose(marksfile);
155 } else {
156 strbuf_addf(&sb, ":%d ", latestrev);
157 - while (strbuf_getline(&line, marksfile, '\n') != EOF) {
157 + while (strbuf_getline_lf(&line, marksfile) != EOF) {
158 if (starts_with(line.buf, sb.buf)) {
159 found++;
160 break;
@@ -322,7 +322,7 @@ int main(int argc, char **argv)
322 marksfilename = marksfilename_sb.buf;
323
324 while (1) {
325 - if (strbuf_getline(&buf, stdin, '\n') == EOF) {
325 + if (strbuf_getline_lf(&buf, stdin) == EOF) {
326 if (ferror(stdin))
327 die("Error reading command stream");
328 else
remote.c
+2 -2
@@ -256,7 +256,7 @@ static void read_remotes_file(struct remote *remote)
256 if (!f)
257 return;
258 remote->origin = REMOTE_REMOTES;
259 - while (strbuf_getline(&buf, f, '\n') != EOF) {
259 + while (strbuf_getline_lf(&buf, f) != EOF) {
260 const char *v;
261
262 strbuf_rtrim(&buf);
@@ -281,7 +281,7 @@ static void read_branches_file(struct remote *remote)
281 if (!f)
282 return;
283
284 - strbuf_getline(&buf, f, '\n');
284 + strbuf_getline_lf(&buf, f);
285 fclose(f);
286 strbuf_trim(&buf);
287 if (!buf.len) {
sequencer.c
+1 -1
@@ -886,7 +886,7 @@ static int sequencer_rollback(struct replay_opts *opts)
886 if (!f)
887 return error(_("cannot open %s: %s"), git_path_head_file(),
888 strerror(errno));
889 - if (strbuf_getline(&buf, f, '\n')) {
889 + if (strbuf_getline_lf(&buf, f)) {
890 error(_("cannot read %s: %s"), git_path_head_file(),
891 ferror(f) ? strerror(errno) : _("unexpected end of file"));
892 fclose(f);
sha1_file.c
+1 -1
@@ -396,7 +396,7 @@ void add_to_alternates_file(const char *reference)
396 struct strbuf line = STRBUF_INIT;
397 int found = 0;
398
399 - while (strbuf_getline(&line, in, '\n') != EOF) {
399 + while (strbuf_getline_lf(&line, in) != EOF) {
400 if (!strcmp(reference, line.buf)) {
401 found = 1;
402 break;
shell.c
+1 -1
@@ -88,7 +88,7 @@ static void run_shell(void)
88 int count;
89
90 fprintf(stderr, "git> ");
91 - if (strbuf_getline(&line, stdin, '\n') == EOF) {
91 + if (strbuf_getline_lf(&line, stdin) == EOF) {
92 fprintf(stderr, "\n");
93 strbuf_release(&line);
94 break;
strbuf.c
+10
@@ -522,6 +522,16 @@ int strbuf_getline_crlf(struct strbuf *sb, FILE *fp)
522 return 0;
523 }
524
525 +int strbuf_getline_lf(struct strbuf *sb, FILE *fp)
526 +{
527 + return strbuf_getline(sb, fp, '\n');
528 +}
529 +
530 +int strbuf_getline_nul(struct strbuf *sb, FILE *fp)
531 +{
532 + return strbuf_getline(sb, fp, '\0');
533 +}
534 +
535 int strbuf_getwholeline_fd(struct strbuf *sb, int fd, int term)
536 {
537 strbuf_reset(sb);
strbuf.h
+15 -3
@@ -388,13 +388,25 @@ extern int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint);
388 */
389 extern int strbuf_getline(struct strbuf *, FILE *, int);
390
391 +/**
392 + * The strbuf_getline*() family of functions share this signature, but
393 + * have different line termination conventions.
394 + */
395 +typedef int (*strbuf_getline_fn)(struct strbuf *, FILE *);
396 +
397 +/* Uses LF as the line terminator */
398 +extern int strbuf_getline_lf(struct strbuf *sb, FILE *fp);
399 +
400 +/* Uses NUL as the line terminator */
401 +extern int strbuf_getline_nul(struct strbuf *sb, FILE *fp);
402 +
403 /*
392 - * Similar to strbuf_getline(), but uses '\n' as the terminator,
393 - * and additionally treats a '\r' that comes immediately before '\n'
394 - * as part of the terminator.
404 + * Similar to strbuf_getline_lf(), but additionally treats a CR that
405 + * comes immediately before the LF as part of the terminator.
406 */
407 extern int strbuf_getline_crlf(struct strbuf *, FILE *);
408
409 +
410 /**
411 * Like `strbuf_getline`, but keeps the trailing terminator (if
412 * any) in the buffer.
test-sha1-array.c
+1 -1
@@ -11,7 +11,7 @@ int main(int argc, char **argv)
11 struct sha1_array array = SHA1_ARRAY_INIT;
12 struct strbuf line = STRBUF_INIT;
13
14 - while (strbuf_getline(&line, stdin, '\n') != EOF) {
14 + while (strbuf_getline_lf(&line, stdin) != EOF) {
15 const char *arg;
16 unsigned char sha1[20];
17
transport-helper.c
+1 -1
@@ -54,7 +54,7 @@ static int recvline_fh(FILE *helper, struct strbuf *buffer, const char *name)
54 strbuf_reset(buffer);
55 if (debug)
56 fprintf(stderr, "Debug: Remote helper: Waiting...\n");
57 - if (strbuf_getline(buffer, helper, '\n') == EOF) {
57 + if (strbuf_getline_lf(buffer, helper) == EOF) {
58 if (debug)
59 fprintf(stderr, "Debug: Remote helper quit.\n");
60 return 1;
walker.c
+1 -1
@@ -220,7 +220,7 @@ int walker_targets_stdin(char ***target, const char ***write_ref)
220 char *rf_one = NULL;
221 char *tg_one;
222
223 - if (strbuf_getline(&buf, stdin, '\n') == EOF)
223 + if (strbuf_getline_lf(&buf, stdin) == EOF)
224 break;
225 tg_one = buf.buf;
226 rf_one = strchr(tg_one, '\t');
wt-status.c
+2 -2
@@ -988,7 +988,7 @@ static char *read_line_from_git_path(const char *filename)
988 strbuf_release(&buf);
989 return NULL;
990 }
991 - strbuf_getline(&buf, fp, '\n');
991 + strbuf_getline_lf(&buf, fp);
992 if (!fclose(fp)) {
993 return strbuf_detach(&buf, NULL);
994 } else {
@@ -1076,7 +1076,7 @@ static void read_rebase_todolist(const char *fname, struct string_list *lines)
1076 if (!f)
1077 die_errno("Could not open file %s for reading",
1078 git_path("%s", fname));
1079 - while (!strbuf_getline(&line, f, '\n')) {
1079 + while (!strbuf_getline_lf(&line, f)) {
1080 if (line.len && line.buf[0] == comment_line_char)
1081 continue;
1082 strbuf_trim(&line);