diff --git a/Documentation/git-fast-import.txt b/Documentation/git-fast-import.txt index 30ee98d17f..a92ae6d1a3 100644 --- a/Documentation/git-fast-import.txt +++ b/Documentation/git-fast-import.txt @@ -176,6 +176,15 @@ results, such as branch names or file names with leading or trailing spaces in their name, or early termination of fast-import when it encounters unexpected input. +Stream Comments +~~~~~~~~~~~~~~~ +To aid in debugging frontends fast-import ignores any line that +begins with `#` (ASCII pound/hash) up to and including the line +ending `LF`. A comment line may contain any sequence of bytes +that does not contain an LF and therefore may be used to include +any detailed debugging information that might be specific to the +frontend and useful when inspecting a fast-import data stream. + Date Formats ~~~~~~~~~~~~ The following date formats are supported. A frontend should select @@ -689,6 +698,11 @@ intended for production-quality conversions should always use the exact byte count format, as it is more robust and performs better. The delimited format is intended primarily for testing fast-import. +Comment lines appearing within the `` part of `data` commands +are always taken to be part of the body of the data and are therefore +never ignored by fast-import. This makes it safe to import any +file/message content whose lines might start with `#`. + Exact byte count format:: The frontend must specify the number of bytes of data. + diff --git a/fast-import.c b/fast-import.c index d7fa2b7baa..98ebe4770d 100644 --- a/fast-import.c +++ b/fast-import.c @@ -122,6 +122,17 @@ Format of STDIN stream: email ::= # valid GIT author/committer email; ts ::= # time since the epoch in seconds, ascii base10 notation; tz ::= # GIT style timezone; + + # note: comments may appear anywhere in the input, except + # within a data command. Any form of the data command + # always escapes the related input from comment processing. + # + # In case it is not clear, the '#' that starts the comment + # must be the first character on that the line (an lf have + # preceeded it). + # + comment ::= '#' not_lf* lf; + not_lf ::= # Any byte that is not ASCII newline (LF); */ #include "builtin.h" @@ -1454,7 +1465,9 @@ static void dump_marks(void) static void read_next_command(void) { - read_line(&command_buf, stdin, '\n'); + do { + read_line(&command_buf, stdin, '\n'); + } while (!command_buf.eof && command_buf.buf[0] == '#'); } static void cmd_mark(void) @@ -1481,7 +1494,7 @@ static void *cmd_data (size_t *size) length = 0; buffer = xmalloc(sz); for (;;) { - read_next_command(); + read_line(&command_buf, stdin, '\n'); if (command_buf.eof) die("EOF in data (terminator '%s' not found)", term); if (term_len == command_buf.len diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index dac6135b22..1f6426a49e 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -778,4 +778,44 @@ test_expect_success \ 'git-fast-import input < $GIT_COMMITTER_DATE +# $GIT_COMMITTER_NAME has inserted here for his benefit. +data <