fast-import: allow unquoted empty path for root
commitb5062f752ef039b6fa8b3a7491072c2f1dfe3cf2
authorThalia Archibald <thalia@archibald.dev>
Sun, 14 Apr 2024 01:11:52 +0000 (14 01:11 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 15 Apr 2024 17:06:17 +0000 (15 10:06 -0700)
tree6a68dae1bf1abe1d2949fe9d76c6eea309cbdc2a
parent5733f894d7e66d0f0fbd29675d8420825ce0c29f
fast-import: allow unquoted empty path for root

Ever since filerename was added in f39a946a1f (Support wholesale
directory renames in fast-import, 2007-07-09) and filecopy in b6f3481bb4
(Teach fast-import to recursively copy files/directories, 2007-07-15),
both have produced an error when the destination path is empty. Later,
when support for targeting the root directory with an empty string was
added in 2794ad5244 (fast-import: Allow filemodify to set the root,
2010-10-10), this had the effect of allowing the quoted empty string
(`""`), but forbidding its unquoted variant (``). This seems to have
been intended as simple data validation for parsing two paths, rather
than a syntax restriction, because it was not extended to the other
operations.

All other occurrences of paths (in filemodify, filedelete, the source of
filecopy and filerename, and ls) allow both.

For most of this feature's lifetime, the documentation has not
prescribed the use of quoted empty strings. In e5959106d6
(Documentation/fast-import: put explanation of M 040000 <dataref> "" in
context, 2011-01-15), its documentation was changed from “`<path>` may
also be an empty string (`""`) to specify the root of the tree” to “The
root of the tree can be represented by an empty string as `<path>`”.

Thus, we should assume that some front-ends have depended on this
behavior.

Remove this restriction for the destination paths of filecopy and
filerename and change tests targeting the root to test `""` and ``.

Signed-off-by: Thalia Archibald <thalia@archibald.dev>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fast-import.c
t/t9300-fast-import.sh