fast-import: fix erroneous handling of get-mark with empty orphan commits

When get-mark was introduced in commit 28c7b1f7b7b7 ("fast-import: add a get-mark command", 2015-07-01), it followed the precedent of the cat-blob command to be allowed on any line other than in the middle of a data directive; see commit 777f80d7429b ("fast-import: Allow cat-blob requests at arbitrary points in stream", 2010-11-28). It was useful to allow cat-blob directives in the middle of a commit to get more data that would be used in writing the current commit object. get-mark is not similarly useful since fast-import can already use either object id or mark. Further, trying to allow this command anywhere caused parsing bugs. Fix the parsing problems by only allowing get-mark commands to appear when other commands have completed. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Feb 20, 2019 at 14:58 UTC cf7b857a77bda6a9a93e2cde2f6ae1764e7a2517
3 files changed +4 -12
Documentation/git-fast-import.txt
-4
@@ -971,10 +971,6 @@ might want to refer to in their commit messages.
971 'get-mark' SP ':' <idnum> LF
972 ....
973
974 -This command can be used anywhere in the stream that comments are
975 -accepted. In particular, the `get-mark` command can be used in the
976 -middle of a commit but not in the middle of a `data` command.
977 -
974 See ``Responses To Commands'' below for details about how to read
975 this output safely.
976
fast-import.c
+2 -6
@@ -1748,8 +1748,6 @@ static int read_next_command(void)
1748 }
1749
1750 for (;;) {
1751 - const char *p;
1752 -
1751 if (unread_command_buf) {
1752 unread_command_buf = 0;
1753 } else {
@@ -1782,10 +1780,6 @@ static int read_next_command(void)
1780 rc->prev->next = rc;
1781 cmd_tail = rc;
1782 }
1785 - if (skip_prefix(command_buf.buf, "get-mark ", &p)) {
1786 - parse_get_mark(p);
1787 - continue;
1788 - }
1783 if (command_buf.buf[0] == '#')
1784 continue;
1785 return 0;
@@ -3318,6 +3312,8 @@ int cmd_main(int argc, const char **argv)
3312 parse_ls(v, NULL);
3313 else if (skip_prefix(command_buf.buf, "cat-blob ", &v))
3314 parse_cat_blob(v);
3315 + else if (skip_prefix(command_buf.buf, "get-mark ", &v))
3316 + parse_get_mark(v);
3317 else if (!strcmp("checkpoint", command_buf.buf))
3318 parse_checkpoint();
3319 else if (!strcmp("done", command_buf.buf))
t/t9300-fast-import.sh
+2 -2
@@ -3276,11 +3276,11 @@ cat >>W-input <<-W_INPUT_END
3276 LFsget-mark :1
3277 W_INPUT_END
3278
3279 -test_expect_failure !MINGW 'W: get-mark & empty orphan commit with no newlines' '
3279 +test_expect_success !MINGW 'W: get-mark & empty orphan commit with no newlines' '
3280 sed -e s/LFs// W-input | tr L "\n" | git fast-import
3281 '
3282
3283 -test_expect_failure !MINGW 'W: get-mark & empty orphan commit with one newline' '
3283 +test_expect_success !MINGW 'W: get-mark & empty orphan commit with one newline' '
3284 sed -e s/LFs/L/ W-input | tr L "\n" | git fast-import
3285 '
3286