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

Re: [PATCH 3/4] Add support for matching full refs in hideRefs

From
Lukas Fleischer <lfleischer@lfos.de>
Date
Nov 2, 2015, 05:47 UTC
Message-ID
<20151102054735.24971.50757@typhoon.lan>
In-Reply-To
<CAPig+cST7sATT4W4Kwp5K=DcuvoFkdgsTDA9iOk=8c_8_GE=-Q@mail.gmail.com>
On Sun, 01 Nov 2015 at 21:42:37, Eric Sunshine wrote:
Show 50 quoted lines
> On Sun, Nov 1, 2015 at 2:34 PM, Lukas Fleischer <lfleischer@lfos.de> wrote:
> > In addition to matching stripped refs, one can now add hideRefs patterns
> > that the full (unstripped) ref is matched against. To distinguish
> > between stripped and full matches, those new patterns must be prefixed
> > with a circumflex (^).
> >
> > This commit also removes support for the undocumented and unintended
> > hideRefs settings "have" (suppressing all "have" lines) and
> > "capabilities^{}" (suppressing the capabilities line).
> >
> > Signed-off-by: Lukas Fleischer <lfleischer@lfos.de>
> > ---
> > diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
> > @@ -1198,7 +1200,15 @@ static void reject_updates_to_hidden(struct command *commands)
> >         struct command *cmd;
> >
> >         for (cmd = commands; cmd; cmd = cmd->next) {
> > -               if (cmd->error_string || !ref_is_hidden(cmd->ref_name))
> 
> Would it make sense to retain the cmd->error_string check here in
> order to avoid doing the extra refname_full construction work below?
> 
>     if (cmd->error_string)
>         continue;
> 
> [...]
> This is leaking refname_full each time through the loop since it never
> gets free()d. If you restructure the code like this, it might be
> easier to avoid leaks:
> 
>     for (cmd = ...; ... ; ...) {
>         if (cmd->error_string)
>             continue;
>         strbuf_addf(&refname_full, "%s%s", ...);
>         if (ref_is_hidden(...)) {
>             if (is_null_sha1(...))
>                 cmd->error_string = "...";
>             else
>                 cmd->error_string = "...";
>         }
>         strbuf_release(&refname_full);
>     }
> 
> As a micro-optimization, you could also pre-populate the strbuf with
> get_git_namespace() outside the loop and remember the length. Then,
> each time through the loop, just append cmd->ref_name, do your
> processing, and, at the bottom of the loop, set the strbuf back to the
> remembered length. (And, you still need to free the strbuf after the
> loop.)
> [...]

Sounds good to me. I changed the code to initialize the strbuf only once, save the prefix length and reset using strbuf_setlen() in every loop iteration. Thanks!

Previous: Eric SunshineNext: Lukas Fleischer
Message 6 of 10 in “Improve hideRefs when used with namespaces”
  1. 0/4 Improve hideRefs when used with namespacesLukas Fleischer, Nov 1, 2015
  2. 1/4 Document the semantics of hideRefs with namespacesLukas Fleischer, Nov 1, 2015
  3. 2/4 upload-pack: strip refs before calling ref_is_hidden()Lukas Fleischer, Nov 1, 2015
  4. 3/4 Add support for matching full refs in hideRefsLukas Fleischer, Nov 1, 2015
  5. Eric SunshineNov 1, 2015
  6. Lukas FleischerNov 2, 2015
  7. 4/4 t5509: add basic tests for hideRefsLukas Fleischer, Nov 1, 2015
  8. Eric SunshineNov 1, 2015
  9. Lukas FleischerNov 2, 2015
  10. Eric SunshineNov 2, 2015

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.