diff --git a/Documentation/git-fast-import.txt b/Documentation/git-fast-import.txt index a92ae6d1a36f800256a477f23c8280e2717b13c9..eb0c8c48ee257b87e4ae28351e91645d9221079e 100644 --- a/Documentation/git-fast-import.txt +++ b/Documentation/git-fast-import.txt @@ -708,13 +708,18 @@ Exact byte count format:: + .... 'data' SP LF - LF + LF? .... + where `` is the exact number of bytes appearing within ``. The value of `` is expressed as an ASCII decimal integer. The `LF` on either side of `` is not included in `` and will not be included in the imported data. ++ +The `LF` after `` is optional (it used to be required) but +recommended. Always including it makes debugging a fast-import +stream easier as the next command always starts in column 0 +of the next line, even if `` did not end with an `LF`. Delimited format:: A delimiter string is used to mark the end of the data. @@ -726,6 +731,7 @@ Delimited format:: 'data' SP '<<' LF LF LF + LF? .... + where `` is the chosen delimiter string. The string `` @@ -734,6 +740,8 @@ fast-import will think the data ends earlier than it really does. The `LF` immediately trailing `` is part of ``. This is one of the limitations of the delimited format, it is impossible to supply a data chunk which does not have an LF as its last byte. ++ +The `LF` after ` LF` is optional (it used to be required). `checkpoint` ~~~~~~~~~~~~ diff --git a/fast-import.c b/fast-import.c index 98ebe4770d239eeee26aca339166bd271adc5d8d..f950cff5efb5d2f1a26eedf269626a52690e5178 100644 --- a/fast-import.c +++ b/fast-import.c @@ -61,7 +61,7 @@ Format of STDIN stream: # mark ::= 'mark' sp idnum lf; data ::= (delimited_data | exact_data) - lf; + lf?; # note: delim may be any string but must not contain lf. # data_line may contain any data but must not be exactly @@ -1470,6 +1470,13 @@ static void read_next_command(void) } while (!command_buf.eof && command_buf.buf[0] == '#'); } +static void skip_optional_lf() +{ + int term_char = fgetc(stdin); + if (term_char != '\n' && term_char != EOF) + ungetc(term_char, stdin); +} + static void cmd_mark(void) { if (!prefixcmp(command_buf.buf, "mark :")) { @@ -1522,9 +1529,7 @@ static void *cmd_data (size_t *size) } } - if (fgetc(stdin) != '\n') - die("An lf did not trail the binary data as expected."); - + skip_optional_lf(); *size = length; return buffer; } diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 1f6426a49e5c42a865ca7fa2c736223b04105f46..5be6f196bdf8778f8a278107f29df8426d7cb02c 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -818,4 +818,25 @@ test_expect_success \ 'git-fast-import input < $GIT_COMMITTER_DATE +data <