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

Re: [PATCH 0/6] Improved infrastructure for refname normalization

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 9, 2011, 17:57 UTC
Message-ID
<7vzkidtx81.fsf@alter.siamese.dyndns.org>
In-Reply-To
<4E6A31D1.5020404@alum.mit.edu>
Michael Haggerty <mhagger@alum.mit.edu> writes:
Show 17 quoted lines
> The library could do the normalization, but
>
> 1. It would probably cost a lot of redundant checks as reference names
> pass in and out of the library and back in again
>
> 2. Normalization requires copying or overwriting the incoming string, so
> each time a refname crosses the library perimeter there might have to be
> an extra memory allocation with the associated headaches of dealing with
> the ownership of the memory.
>
> 3. The library doesn't encapsulate all uses of reference names; for
> example, for_each_ref() invokes a callback function with the refname as
> an argument.  The callback function is free to do a strcmp() of the
> refname (normalized by the library) with some arbitrary string that it
> got from the command line.  Either the caller has to do the
> normalization itself (i.e., outside of the library) or the library has
> to learn how to do every possible filtering operation with refnames.
4. The caller needs to be corrected to pay attention to the normalization
the library did for it. Your code may use a string as a ref and then
create something based on the refname; illustrating with a fictitious
example:
	ref = make_branch_ref("refs/heads/%s", branch_name);
        update_ref(ref, sha1);
        write_log("created branch '%s'", branch_name);

Even though make_branch_ref() may have removed duplicated slashes from the name in "branch_name" when it computed "ref", the log still will record unnormalized name.

I think the callers need to be aware of the normalization in practice anyway for this reason, and a good way forward is to give the callers a library interface to do so. It might even make sense to make the other parts of the API _reject_ unnormalized input to catch offending callers.

By the way, does this series introduce new infrastructure features that can be reused in different areas, such as Hui's "alt_odb path normalization" patch?

Previous: Michael HaggertyNext: Michael Haggerty
Message 12 of 13 in “Improved infrastructure for refname normalization”
  1. 0/6 Improved infrastructure for refname normalizationMichael Haggerty, Sep 9, 2011
  2. 1/6 Change bad_ref_char() to return a boolean valueMichael Haggerty, Sep 9, 2011
  3. 2/6 git check-ref-format: add options --onelevel-ok and --refname-patternMichael Haggerty, Sep 9, 2011
  4. 3/6 Change check_ref_format() to take a flags argumentMichael Haggerty, Sep 9, 2011
  5. 4/6 Add a library function normalize_refname()Michael Haggerty, Sep 9, 2011
  6. 5/6 Do not allow ".lock" at the end of any refname componentMichael Haggerty, Sep 9, 2011
  7. 6/6 Add a REFNAME_ALLOW_UNNORMALIZED flag to check_ref_format()Michael Haggerty, Sep 9, 2011
  8. Junio C HamanoSep 9, 2011
  9. Michael HaggertySep 10, 2011
  10. A Large Angry SCMSep 9, 2011
  11. Michael HaggertySep 9, 2011
  12. Junio C HamanoSep 9, 2011
  13. Michael HaggertySep 10, 2011

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.