git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: Lukas Fleischer <lfleischer@lfos.de>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [PATCH 3/4] Add support for matching full refs in hideRefs
Date: Sun, 1 Nov 2015 15:42:37 -0500	[thread overview]
Message-ID: <CAPig+cST7sATT4W4Kwp5K=DcuvoFkdgsTDA9iOk=8c_8_GE=-Q@mail.gmail.com> (raw)
In-Reply-To: <1446406463-22527-4-git-send-email-lfleischer@lfos.de>

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;

> +               const char *refname = cmd->ref_name;
> +               struct strbuf refname_full_buf = STRBUF_INIT;
> +               const char *refname_full;
> +
> +               strbuf_addf(&refname_full_buf, "%s%s", get_git_namespace(),
> +                               refname);
> +               refname_full = strbuf_detach(&refname_full_buf, NULL);
> +
> +               if (cmd->error_string || !ref_is_hidden(refname, refname_full))
>                         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.)

>                 if (is_null_sha1(cmd->new_sha1))
>                         cmd->error_string = "deny deleting a hidden ref";

  reply	other threads:[~2015-11-01 20:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-01 19:34 [PATCH 0/4] Improve hideRefs when used with namespaces Lukas Fleischer
2015-11-01 19:34 ` [PATCH 1/4] Document the semantics of hideRefs " Lukas Fleischer
2015-11-01 19:34 ` [PATCH 2/4] upload-pack: strip refs before calling ref_is_hidden() Lukas Fleischer
2015-11-01 19:34 ` [PATCH 3/4] Add support for matching full refs in hideRefs Lukas Fleischer
2015-11-01 20:42   ` Eric Sunshine [this message]
2015-11-02  5:47     ` Lukas Fleischer
2015-11-01 19:34 ` [PATCH 4/4] t5509: add basic tests for hideRefs Lukas Fleischer
2015-11-01 21:13   ` Eric Sunshine
2015-11-02  6:25     ` Lukas Fleischer
2015-11-02  7:30       ` Eric Sunshine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPig+cST7sATT4W4Kwp5K=DcuvoFkdgsTDA9iOk=8c_8_GE=-Q@mail.gmail.com' \
    --to=sunshine@sunshineco.com \
    --cc=git@vger.kernel.org \
    --cc=lfleischer@lfos.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).