@matheusbsbs / matheus-bagliano / commits / 401d53fa35
Fork 0

Teach fast-import to ignore lines starting with '#'

Several frontend developers have asked that some form of stream comments be permitted within a fast-import data stream. This way they can include information from their own frontend program about where specific data was taken from in the source system, or about a decision that their frontend may have made while creating the fast-import data stream. This change introduces comments in the Bourne-shell/Tcl/Perl style. Lines starting with '#' are ignored, up to and including the LF. Unlike the above mentioned three languages however we do not look for and ignore leading whitespace. This just simplifies the definition of the comment format and the code that parses them. To make comments work we had to stop using read_next_command() within cmd_data() and directly invoke read_line() during the inline variant of the function. This is necessary to retain any lines of the input data that might otherwise look like a comment to fast-import. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Aug 1, 2007 at 00:05 UTC 401d53fa35098266e2a4a904a4598b59f1b74663
3 files changed +69 -2
Documentation/git-fast-import.txt
+14
@@ -176,6 +176,15 @@ results, such as branch names or file names with leading or trailing
176 spaces in their name, or early termination of fast-import when it encounters
177 unexpected input.
178
179 +Stream Comments
180 +~~~~~~~~~~~~~~~
181 +To aid in debugging frontends fast-import ignores any line that
182 +begins with `#` (ASCII pound/hash) up to and including the line
183 +ending `LF`. A comment line may contain any sequence of bytes
184 +that does not contain an LF and therefore may be used to include
185 +any detailed debugging information that might be specific to the
186 +frontend and useful when inspecting a fast-import data stream.
187 +
188 Date Formats
189 ~~~~~~~~~~~~
190 The following date formats are supported. A frontend should select
@@ -689,6 +698,11 @@ intended for production-quality conversions should always use the
698 exact byte count format, as it is more robust and performs better.
699 The delimited format is intended primarily for testing fast-import.
700
701 +Comment lines appearing within the `<raw>` part of `data` commands
702 +are always taken to be part of the body of the data and are therefore
703 +never ignored by fast-import. This makes it safe to import any
704 +file/message content whose lines might start with `#`.
705 +
706 Exact byte count format::
707 The frontend must specify the number of bytes of data.
708 +
fast-import.c
+15 -2
@@ -122,6 +122,17 @@ Format of STDIN stream:
122 email ::= # valid GIT author/committer email;
123 ts ::= # time since the epoch in seconds, ascii base10 notation;
124 tz ::= # GIT style timezone;
125 +
126 + # note: comments may appear anywhere in the input, except
127 + # within a data command. Any form of the data command
128 + # always escapes the related input from comment processing.
129 + #
130 + # In case it is not clear, the '#' that starts the comment
131 + # must be the first character on that the line (an lf have
132 + # preceeded it).
133 + #
134 + comment ::= '#' not_lf* lf;
135 + not_lf ::= # Any byte that is not ASCII newline (LF);
136 */
137
138 #include "builtin.h"
@@ -1454,7 +1465,9 @@ static void dump_marks(void)
1465
1466 static void read_next_command(void)
1467 {
1457 - read_line(&command_buf, stdin, '\n');
1468 + do {
1469 + read_line(&command_buf, stdin, '\n');
1470 + } while (!command_buf.eof && command_buf.buf[0] == '#');
1471 }
1472
1473 static void cmd_mark(void)
@@ -1481,7 +1494,7 @@ static void *cmd_data (size_t *size)
1494 length = 0;
1495 buffer = xmalloc(sz);
1496 for (;;) {
1484 - read_next_command();
1497 + read_line(&command_buf, stdin, '\n');
1498 if (command_buf.eof)
1499 die("EOF in data (terminator '%s' not found)", term);
1500 if (term_len == command_buf.len
t/t9300-fast-import.sh
+40
@@ -778,4 +778,44 @@ test_expect_success \
778 'git-fast-import <input &&
779 test `git-rev-parse N2^{tree}` = `git-rev-parse N3^{tree}`'
780
781 +###
782 +### series O
783 +###
784 +
785 +cat >input <<INPUT_END
786 +#we will
787 +commit refs/heads/O1
788 +# -- ignore all of this text
789 +committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
790 +# $GIT_COMMITTER_NAME has inserted here for his benefit.
791 +data <<COMMIT
792 +dirty directory copy
793 +COMMIT
794 +
795 +# don't forget the import blank line!
796 +#
797 +# yes, we started from our usual base of branch^0.
798 +# i like branch^0.
799 +from refs/heads/branch^0
800 +# and we need to reuse file2/file5 from N3 above.
801 +M 644 inline file2/file5
802 +# otherwise the tree will be different
803 +data <<EOF
804 +$file5_data
805 +EOF
806 +
807 +# don't forget to copy file2 to file3
808 +C file2 file3
809 +#
810 +# or to delete file5 from file2.
811 +D file2/file5
812 +# are we done yet?
813 +
814 +INPUT_END
815 +
816 +test_expect_success \
817 + 'O: comments are all skipped' \
818 + 'git-fast-import <input &&
819 + test `git-rev-parse N3` = `git-rev-parse O1`'
820 +
821 test_done