OSDN Git Service

revision: read --stdin with strbuf_getline()
authorJunio C Hamano <gitster@pobox.com>
Wed, 28 Oct 2015 21:05:53 +0000 (14:05 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 15 Jan 2016 18:33:28 +0000 (10:33 -0800)
Reading with getwholeline() and manually stripping the terminating
'\n' would leave CR at the end of the line if the input comes from
a DOS editor.

Constrasting this with the other changes around "--stdin" in this
series, one may realize that the way "log" family of commands read
the paths with "--stdin" looks inconsistent and sloppy.  It does not
allow us to C-quote a textual input, neither does it accept records
that are NUL-terminated.  These are unfortunately way too late to
fix X-<.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
revision.c

index 0a282f5..8df4e11 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] == '-') {