Merge branch 'jc/peace-with-crlf'
authorJunio C Hamano <gitster@pobox.com>
Wed, 3 Feb 2016 22:15:58 +0000 (14:15 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 3 Feb 2016 22:15:58 +0000 (14:15 -0800)
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()

13 files changed:
builtin/cat-file.c
builtin/clone.c
builtin/column.c
builtin/grep.c
builtin/hash-object.c
builtin/rev-parse.c
builtin/send-pack.c
ident.c
remote.c
revision.c
sha1_file.c
test-sha1-array.c
transport-helper.c
index d2ebaf1f5857bbcc5f2a802472824a75ce5d5ccf..54db1184a003897294b6aaa46bc6bf29faa919bc 100644 (file)
@@ -401,7 +401,7 @@ static int batch_objects(struct batch_options *opt)
        save_warning = warn_on_object_refname_ambiguity;
        warn_on_object_refname_ambiguity = 0;
 
-       while (strbuf_getline_lf(&buf, stdin) != EOF) {
+       while (strbuf_getline(&buf, stdin) != EOF) {
                if (data.split_on_whitespace) {
                        /*
                         * Split at first whitespace, tying off the beginning
index 81e238f738bae80b19524fee83f9046be3571cc2..bcba0805e1c9c5691c2e876f9748a2cf492b1c70 100644 (file)
@@ -339,7 +339,7 @@ static void copy_alternates(struct strbuf *src, struct strbuf *dst,
        FILE *in = fopen(src->buf, "r");
        struct strbuf line = STRBUF_INIT;
 
-       while (strbuf_getline_lf(&line, in) != EOF) {
+       while (strbuf_getline(&line, in) != EOF) {
                char *abs_path;
                if (!line.len || line.buf[0] == '#')
                        continue;
index 40eab085946a46b5cbace46ab9dbd8778564cd6f..33314b4d7127cb6e4116c350e113058e07f58474 100644 (file)
@@ -51,7 +51,7 @@ int cmd_column(int argc, const char **argv, const char *prefix)
                        die(_("--command must be the first argument"));
        }
        finalize_colopts(&colopts, -1);
-       while (!strbuf_getline_lf(&sb, stdin))
+       while (!strbuf_getline(&sb, stdin))
                string_list_append(&list, sb.buf);
 
        print_columns(&list, colopts, &copts);
index 6c030dad6b7782478a07a4feb6020e4a30e7f7a0..8c516a95438e5aa997049da24160764ff4ca985c 100644 (file)
@@ -573,7 +573,7 @@ static int file_callback(const struct option *opt, const char *arg, int unset)
        patterns = from_stdin ? stdin : fopen(arg, "r");
        if (!patterns)
                die_errno(_("cannot open '%s'"), arg);
-       while (strbuf_getline_lf(&sb, patterns) == 0) {
+       while (strbuf_getline(&sb, patterns) == 0) {
                /* ignore empty line like grep does */
                if (sb.len == 0)
                        continue;
index 3bc5ec1d2194133fd392ca5bfbaaa5a26b901e5f..ff20395c69780cb5869300af83084d6cac1bbd4d 100644 (file)
@@ -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;
 
-       while (strbuf_getline_lf(&buf, stdin) != EOF) {
+       while (strbuf_getline(&buf, stdin) != EOF) {
                if (buf.buf[0] == '"') {
                        strbuf_reset(&nbuf);
                        if (unquote_c_style(&nbuf, buf.buf, NULL))
index 0324abb74972c48e585070ba19664a4eca45c244..bd16876df5ff7bce4fbf348d84a0ebc4ea53e7d7 100644 (file)
@@ -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 */
        for (;;) {
-               if (strbuf_getline_lf(&sb, stdin) == EOF)
+               if (strbuf_getline(&sb, stdin) == EOF)
                        die("premature end of input");
                ALLOC_GROW(usage, unb + 1, usz);
                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> */
-       while (strbuf_getline_lf(&sb, stdin) != EOF) {
+       while (strbuf_getline(&sb, stdin) != EOF) {
                const char *s;
                const char *help;
                struct option *o;
index 8f9f4f148d7c0d99c0e09e99ddff29798b6c4789..5b9dd6a9d8ebe888c2fc912af3590b92737e7a99 100644 (file)
@@ -212,7 +212,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
                                argv_array_push(&all_refspecs, buf);
                } else {
                        struct strbuf line = STRBUF_INIT;
-                       while (strbuf_getline_lf(&line, stdin) != EOF)
+                       while (strbuf_getline(&line, stdin) != EOF)
                                argv_array_push(&all_refspecs, line.buf);
                        strbuf_release(&line);
                }
diff --git a/ident.c b/ident.c
index 9dd3ae34525563fef5d6c6f0e40b2bc593080063..3da555634290f1812702e2d6da15e5a6806fe635 100644 (file)
--- a/ident.c
+++ b/ident.c
@@ -76,7 +76,7 @@ static int add_mailname_host(struct strbuf *buf)
                                strerror(errno));
                return -1;
        }
-       if (strbuf_getline_lf(&mailnamebuf, mailname) == EOF) {
+       if (strbuf_getline(&mailnamebuf, mailname) == EOF) {
                if (ferror(mailname))
                        warning("cannot read /etc/mailname: %s",
                                strerror(errno));
index f19569385e8d161c75ff45824fd282e1ee6a4c80..7d61dabebb3727e2e70cc282053d3138be5ead9d 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -256,7 +256,7 @@ static void read_remotes_file(struct remote *remote)
        if (!f)
                return;
        remote->origin = REMOTE_REMOTES;
-       while (strbuf_getline_lf(&buf, f) != EOF) {
+       while (strbuf_getline(&buf, f) != EOF) {
                const char *v;
 
                strbuf_rtrim(&buf);
index 0a282f533b3e225a996221d614de8bdc960092a3..8df4e117ff0321d73f521cec49285dba638451e9 100644 (file)
@@ -1635,10 +1635,7 @@ static void append_prune_data(struct cmdline_pathspec *prune, const char **av)
 static void read_pathspec_from_stdin(struct rev_info *revs, struct strbuf *sb,
                                     struct cmdline_pathspec *prune)
 {
-       while (strbuf_getwholeline(sb, stdin, '\n') != EOF) {
-               int len = sb->len;
-               if (len && sb->buf[len - 1] == '\n')
-                       sb->buf[--len] = '\0';
+       while (strbuf_getline(sb, stdin) != EOF) {
                ALLOC_GROW(prune->path, prune->nr + 1, prune->alloc);
                prune->path[prune->nr++] = xstrdup(sb->buf);
        }
@@ -1655,10 +1652,8 @@ static void read_revisions_from_stdin(struct rev_info *revs,
        warn_on_object_refname_ambiguity = 0;
 
        strbuf_init(&sb, 1000);
-       while (strbuf_getwholeline(&sb, stdin, '\n') != EOF) {
+       while (strbuf_getline(&sb, stdin) != EOF) {
                int len = sb.len;
-               if (len && sb.buf[len - 1] == '\n')
-                       sb.buf[--len] = '\0';
                if (!len)
                        break;
                if (sb.buf[0] == '-') {
index 86b5e8cf724a771e1b18630793a3ff488c904bbc..aab1872b4c95416fc7c8ae9c93cd25f341e2d4c1 100644 (file)
@@ -396,7 +396,7 @@ void add_to_alternates_file(const char *reference)
                struct strbuf line = STRBUF_INIT;
                int found = 0;
 
-               while (strbuf_getline_lf(&line, in) != EOF) {
+               while (strbuf_getline(&line, in) != EOF) {
                        if (!strcmp(reference, line.buf)) {
                                found = 1;
                                break;
index 700f3f3422d9014bfc4853e1510e6e7ac8aa9b73..60ea1d5f14e2572df5716da5815143ed26a5be4b 100644 (file)
@@ -11,7 +11,7 @@ int main(int argc, char **argv)
        struct sha1_array array = SHA1_ARRAY_INIT;
        struct strbuf line = STRBUF_INIT;
 
-       while (strbuf_getline_lf(&line, stdin) != EOF) {
+       while (strbuf_getline(&line, stdin) != EOF) {
                const char *arg;
                unsigned char sha1[20];
 
index e45d88f1d7d82b12fe10b886a061477f8d27ad7b..a6bff8b30811c649c82afcdc9e018af1a34ce13c 100644 (file)
@@ -54,7 +54,7 @@ static int recvline_fh(FILE *helper, struct strbuf *buffer, const char *name)
        strbuf_reset(buffer);
        if (debug)
                fprintf(stderr, "Debug: Remote helper: Waiting...\n");
-       if (strbuf_getline_lf(buffer, helper) == EOF) {
+       if (strbuf_getline(buffer, helper) == EOF) {
                if (debug)
                        fprintf(stderr, "Debug: Remote helper quit.\n");
                return 1;