git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] Make ident dynamic, not just a hardcoded value of "$Id".

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 2, 2021, 19:04 UTC
Message-ID
<xmqqmtoukdec.fsf@gitster.g>
In-Reply-To
<xmqqr1e77q01.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
> If we are not restricting the characters that can be used in the
> custom ID placeholder, we probably should have tests that use
> allowed but unusual characters.

There is a test in t/t0021-conversion.sh that ensures that we recognise expanded and unexpanded keyword strings using various lines that has placeholder-lookalike on it, which starts like this:

    # If an expanded ident ever gets into the repository, we want to make sure that
    # it is collapsed before being expanded again on checkout
    test_expect_success expanded_in_repo '
            {
                    echo "File with expanded keywords"
                    echo "\$Id\$"
                    echo "\$Id:\$"
                    echo "\$Id: 0000000000000000000000000000000000000000 \$"
                    echo "\$Id: NoSpaceAtEnd\$"
                    echo "\$Id:NoSpaceAtFront \$"
                    echo "\$Id:NoSpaceAtEitherEnd\$"
                    echo "\$Id: NoTerminatingSymbol"
                    echo "\$Id: Foreign Commit With Spaces \$"
            } >expanded-keywords.0 &&
	    ...

It would be good to have a copy of this test with the placeholder customized to something unusual like " Id:", "Id: $ $", ":", "$ $" etc. to make sure we can parse out the keyword correctly without imposing the letters that can be used in the placeholder.

    Side note.  I of course do not literally mean to "copy" and make
    the number of tests explode.  I think it can be done with a loop
    to test various custom strings, which may begin like ...
	for kwd in "Id" " Id:" "Id $" "Id: $ $" ":" "$ $"
	do
		cat >expanded-keywords.0 <<-EOF &&
		\$$kwd\$
		\$$kwd:\$
		\$$kwd: 0000000000000000000000000000000000000000 \$
		\$$kwd: NoSpaceAtEnd\$
		\$$kwd:NoSpaceAtFront \$
		\$$kwd:NoSpaceAtEitherEnd\$
		\$$kwd: NoTerminatingSymbol
		\$$kwd: Foreign Commit With Spaces \$
		EOF
		...

If we can do without restriction, that would be even better, but I do not think it is the end of the world if we found some corner case that a certain customized placeholder can make the syntax ambiguous and we cannot recognise expanded keywords in the working tree files, as it is reasonable to limit the letters we allow in placeholders.

One thing we should not do is to tell users that they can use anything as their customized Id string, and then later find such a corner case and tell them now we forbid certain letters. To avoid such a mistake, it is better to start reasonably tight, allowing what we know will never cause problems (like alphanumerics) and forbidding what we know will not be missed in real-world usecases (like whitespaces and punctuations). After we discover that certain things that we initially forbid have real uses in the future, we can loosen the restriction. "Start loose and then tighten" will lead to a regression when viewed from the end-user's workflow. "Start tight and then loosen" will not have that problem.

Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 11 in “Make ident dynamic, not just a hardcoded value of "$Id".”
  1. Make ident dynamic, not just a hardcoded value of "$Id".Maksym Sobolyev via GitGitGadget, Aug 23, 2021
  2. Junio C HamanoAug 23, 2021
  3. Philip OakleyAug 23, 2021
  4. Make ident dynamic, not just a hardcoded value of "$Id".Maksym Sobolyev via GitGitGadget, Aug 26, 2021
  5. Matheus TavaresAug 26, 2021
  6. Junio C HamanoSep 2, 2021
  7. Junio C HamanoSep 2, 2021
  8. Junio C HamanoAug 27, 2021
  9. Make ident dynamic, not just a hardcoded value of "$Id".Maksym Sobolyev via GitGitGadget, Sep 1, 2021
  10. Đoàn Trần Công DanhSep 2, 2021
  11. Junio C HamanoSep 1, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.