Skip to content

Commit

Permalink
fast-import: fix erroneous handling of get-mark with empty orphan com…
Browse files Browse the repository at this point in the history
…mits

When get-mark was introduced in commit 28c7b1f ("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 777f80d ("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>
  • Loading branch information
newren authored and gitster committed Apr 1, 2019
1 parent 7ffde29 commit cf7b857
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
4 changes: 0 additions & 4 deletions Documentation/git-fast-import.txt
Expand Up @@ -971,10 +971,6 @@ might want to refer to in their commit messages.
'get-mark' SP ':' <idnum> LF
....

This command can be used anywhere in the stream that comments are
accepted. In particular, the `get-mark` command can be used in the
middle of a commit but not in the middle of a `data` command.

See ``Responses To Commands'' below for details about how to read
this output safely.

Expand Down
8 changes: 2 additions & 6 deletions fast-import.c
Expand Up @@ -1748,8 +1748,6 @@ static int read_next_command(void)
}

for (;;) {
const char *p;

if (unread_command_buf) {
unread_command_buf = 0;
} else {
Expand Down Expand Up @@ -1782,10 +1780,6 @@ static int read_next_command(void)
rc->prev->next = rc;
cmd_tail = rc;
}
if (skip_prefix(command_buf.buf, "get-mark ", &p)) {
parse_get_mark(p);
continue;
}
if (command_buf.buf[0] == '#')
continue;
return 0;
Expand Down Expand Up @@ -3318,6 +3312,8 @@ int cmd_main(int argc, const char **argv)
parse_ls(v, NULL);
else if (skip_prefix(command_buf.buf, "cat-blob ", &v))
parse_cat_blob(v);
else if (skip_prefix(command_buf.buf, "get-mark ", &v))
parse_get_mark(v);
else if (!strcmp("checkpoint", command_buf.buf))
parse_checkpoint();
else if (!strcmp("done", command_buf.buf))
Expand Down
4 changes: 2 additions & 2 deletions t/t9300-fast-import.sh
Expand Up @@ -3276,11 +3276,11 @@ cat >>W-input <<-W_INPUT_END
LFsget-mark :1
W_INPUT_END

test_expect_failure !MINGW 'W: get-mark & empty orphan commit with no newlines' '
test_expect_success !MINGW 'W: get-mark & empty orphan commit with no newlines' '
sed -e s/LFs// W-input | tr L "\n" | git fast-import
'

test_expect_failure !MINGW 'W: get-mark & empty orphan commit with one newline' '
test_expect_success !MINGW 'W: get-mark & empty orphan commit with one newline' '
sed -e s/LFs/L/ W-input | tr L "\n" | git fast-import
'

Expand Down

0 comments on commit cf7b857

Please sign in to comment.