Skip to content
  • Jeff King's avatar
    alternates: accept double-quoted paths · cf3c6352
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    We read lists of alternates from objects/info/alternates
    files (delimited by newline), as well as from the
    GIT_ALTERNATE_OBJECT_DIRECTORIES environment variable
    (delimited by colon or semi-colon, depending on the
    platform).
    
    There's no mechanism for quoting the delimiters, so it's
    impossible to specify an alternate path that contains a
    colon in the environment, or one that contains a newline in
    a file. We've lived with that restriction for ages because
    both alternates and filenames with colons are relatively
    rare, and it's only a problem when the two meet. But since
    722ff7f8
    
     (receive-pack: quarantine objects until
    pre-receive accepts, 2016-10-03), which builds on the
    alternates system, every push causes the receiver to set
    GIT_ALTERNATE_OBJECT_DIRECTORIES internally.
    
    It would be convenient to have some way to quote the
    delimiter so that we can represent arbitrary paths.
    
    The simplest thing would be an escape character before a
    quoted delimiter (e.g., "\:" as a literal colon). But that
    creates a backwards compatibility problem: any path which
    uses that escape character is now broken, and we've just
    shifted the problem. We could choose an unlikely escape
    character (e.g., something from the non-printable ASCII
    range), but that's awkward to use.
    
    Instead, let's treat names as unquoted unless they begin
    with a double-quote, in which case they are interpreted via
    our usual C-stylke quoting rules. This also breaks
    backwards-compatibility, but in a smaller way: it only
    matters if your file has a double-quote as the very _first_
    character in the path (whereas an escape character is a
    problem anywhere in the path).  It's also consistent with
    many other parts of git, which accept either a bare pathname
    or a double-quoted one, and the sender can choose to quote
    or not as required.
    
    Signed-off-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    cf3c6352