Skip to content

Commit 0175655

Browse files
committed
Merge branch 'jc/peace-with-crlf'
Many commands that read files that are expected to contain text that is generated (or can be edited) by the end user to control their behaviour (e.g. "git grep -f <filename>") have been updated to be more tolerant to lines that are terminated with CRLF (they used to treat such a line to contain payload that ends with CR, which is usually not what the users expect). * jc/peace-with-crlf: test-sha1-array: read command stream with strbuf_getline() grep: read -f file with strbuf_getline() send-pack: read list of refs with strbuf_getline() column: read lines with strbuf_getline() cat-file: read batch stream with strbuf_getline() transport-helper: read helper response with strbuf_getline() clone/sha1_file: read info/alternates with strbuf_getline() remote.c: read $GIT_DIR/remotes/* with strbuf_getline() ident.c: read /etc/mailname with strbuf_getline() rev-parse: read parseopt spec with strbuf_getline() revision: read --stdin with strbuf_getline() hash-object: read --stdin-paths with strbuf_getline()
2 parents 07c314d + f06068c commit 0175655

File tree

13 files changed

+15
-20
lines changed

13 files changed

+15
-20
lines changed

builtin/cat-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ static int batch_objects(struct batch_options *opt)
401401
save_warning = warn_on_object_refname_ambiguity;
402402
warn_on_object_refname_ambiguity = 0;
403403

404-
while (strbuf_getline_lf(&buf, stdin) != EOF) {
404+
while (strbuf_getline(&buf, stdin) != EOF) {
405405
if (data.split_on_whitespace) {
406406
/*
407407
* Split at first whitespace, tying off the beginning

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ static void copy_alternates(struct strbuf *src, struct strbuf *dst,
339339
FILE *in = fopen(src->buf, "r");
340340
struct strbuf line = STRBUF_INIT;
341341

342-
while (strbuf_getline_lf(&line, in) != EOF) {
342+
while (strbuf_getline(&line, in) != EOF) {
343343
char *abs_path;
344344
if (!line.len || line.buf[0] == '#')
345345
continue;

builtin/column.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int cmd_column(int argc, const char **argv, const char *prefix)
5151
die(_("--command must be the first argument"));
5252
}
5353
finalize_colopts(&colopts, -1);
54-
while (!strbuf_getline_lf(&sb, stdin))
54+
while (!strbuf_getline(&sb, stdin))
5555
string_list_append(&list, sb.buf);
5656

5757
print_columns(&list, colopts, &copts);

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ static int file_callback(const struct option *opt, const char *arg, int unset)
573573
patterns = from_stdin ? stdin : fopen(arg, "r");
574574
if (!patterns)
575575
die_errno(_("cannot open '%s'"), arg);
576-
while (strbuf_getline_lf(&sb, patterns) == 0) {
576+
while (strbuf_getline(&sb, patterns) == 0) {
577577
/* ignore empty line like grep does */
578578
if (sb.len == 0)
579579
continue;

builtin/hash-object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static void hash_stdin_paths(const char *type, int no_filters, unsigned flags,
6060
{
6161
struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
6262

63-
while (strbuf_getline_lf(&buf, stdin) != EOF) {
63+
while (strbuf_getline(&buf, stdin) != EOF) {
6464
if (buf.buf[0] == '"') {
6565
strbuf_reset(&nbuf);
6666
if (unquote_c_style(&nbuf, buf.buf, NULL))

builtin/rev-parse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
383383

384384
/* get the usage up to the first line with a -- on it */
385385
for (;;) {
386-
if (strbuf_getline_lf(&sb, stdin) == EOF)
386+
if (strbuf_getline(&sb, stdin) == EOF)
387387
die("premature end of input");
388388
ALLOC_GROW(usage, unb + 1, usz);
389389
if (!strcmp("--", sb.buf)) {
@@ -396,7 +396,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
396396
}
397397

398398
/* parse: (<short>|<short>,<long>|<long>)[*=?!]*<arghint>? SP+ <help> */
399-
while (strbuf_getline_lf(&sb, stdin) != EOF) {
399+
while (strbuf_getline(&sb, stdin) != EOF) {
400400
const char *s;
401401
const char *help;
402402
struct option *o;

builtin/send-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
212212
argv_array_push(&all_refspecs, buf);
213213
} else {
214214
struct strbuf line = STRBUF_INIT;
215-
while (strbuf_getline_lf(&line, stdin) != EOF)
215+
while (strbuf_getline(&line, stdin) != EOF)
216216
argv_array_push(&all_refspecs, line.buf);
217217
strbuf_release(&line);
218218
}

ident.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static int add_mailname_host(struct strbuf *buf)
7676
strerror(errno));
7777
return -1;
7878
}
79-
if (strbuf_getline_lf(&mailnamebuf, mailname) == EOF) {
79+
if (strbuf_getline(&mailnamebuf, mailname) == EOF) {
8080
if (ferror(mailname))
8181
warning("cannot read /etc/mailname: %s",
8282
strerror(errno));

remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static void read_remotes_file(struct remote *remote)
256256
if (!f)
257257
return;
258258
remote->origin = REMOTE_REMOTES;
259-
while (strbuf_getline_lf(&buf, f) != EOF) {
259+
while (strbuf_getline(&buf, f) != EOF) {
260260
const char *v;
261261

262262
strbuf_rtrim(&buf);

revision.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,10 +1635,7 @@ static void append_prune_data(struct cmdline_pathspec *prune, const char **av)
16351635
static void read_pathspec_from_stdin(struct rev_info *revs, struct strbuf *sb,
16361636
struct cmdline_pathspec *prune)
16371637
{
1638-
while (strbuf_getwholeline(sb, stdin, '\n') != EOF) {
1639-
int len = sb->len;
1640-
if (len && sb->buf[len - 1] == '\n')
1641-
sb->buf[--len] = '\0';
1638+
while (strbuf_getline(sb, stdin) != EOF) {
16421639
ALLOC_GROW(prune->path, prune->nr + 1, prune->alloc);
16431640
prune->path[prune->nr++] = xstrdup(sb->buf);
16441641
}
@@ -1655,10 +1652,8 @@ static void read_revisions_from_stdin(struct rev_info *revs,
16551652
warn_on_object_refname_ambiguity = 0;
16561653

16571654
strbuf_init(&sb, 1000);
1658-
while (strbuf_getwholeline(&sb, stdin, '\n') != EOF) {
1655+
while (strbuf_getline(&sb, stdin) != EOF) {
16591656
int len = sb.len;
1660-
if (len && sb.buf[len - 1] == '\n')
1661-
sb.buf[--len] = '\0';
16621657
if (!len)
16631658
break;
16641659
if (sb.buf[0] == '-') {

0 commit comments

Comments
 (0)