From: Junio C Hamano <gitster@pobox.com>
To: Joanna Wang <jojwang@google.com>
Cc: git@vger.kernel.org, sunshine@sunshineco.com, tboegi@web.de
Subject: Re: [PATCH 1/1] attr: add builtin objectmode values support
Date: Tue, 12 Dec 2023 15:17:40 -0800 [thread overview]
Message-ID: <xmqqedfrovsb.fsf@gitster.g> (raw)
In-Reply-To: <CAMmZTi-U_ufzoBLCDWKbrf=3GZzGszxnM1_Pu6ufBeoYjj7Gdw@mail.gmail.com> (Joanna Wang's message of "Fri, 1 Dec 2023 12:01:54 +0800")
Joanna Wang <jojwang@google.com> writes:
>> Cumulatively, aside from the removal of the t/#t* file, here is what
>> I ended up with so far.
>
> I want to double check if I should followup here.
> I assumed that you had already applied these final fixes on my behalf,
> similar to my patch for enabling attr for `git-add`. But if I was wrong,
> I'm happy to send another update with all the fixes.
I've squashed the fix in, so no need to resend only to patch up what
I pointed out earlier.
The end result fails t0003 under GIT_TEST_PASSING_SANITIZE_LEAK
though. As the synthetic attribute values are allocated without
being in the hashmap based on the value read from .gitattributes
files, somebody needs to hold pointers to them *and* we need to
avoid allocating unbounded number of them.
The attached is one possible way to plug the leak; I am not sure if
it is the best one, though. One thing I like about the solution is
that the approach makes sure that the mode attributes we would ever
return are very tightly controlled and does not allow a buggy code
to come up with "mode" to be passed to this new helper function to
pass random and unsupported mode bits without triggering the BUG().
attr.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git c/attr.c w/attr.c
index b03c20f768..679e42258c 100644
--- c/attr.c
+++ w/attr.c
@@ -1250,10 +1250,34 @@ static struct object_id *default_attr_source(void)
return &attr_source;
}
+static const char *interned_mode_string(unsigned int mode)
+{
+ static struct {
+ unsigned int val;
+ char str[7];
+ } mode_string[] = {
+ { .val = 0040000 },
+ { .val = 0100644 },
+ { .val = 0100755 },
+ { .val = 0120000 },
+ { .val = 0160000 },
+ };
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(mode_string); i++) {
+ if (mode_string[i].val != mode)
+ continue;
+ if (!*mode_string[i].str)
+ snprintf(mode_string[i].str, sizeof(mode_string[i].str),
+ "%06o", mode);
+ return mode_string[i].str;
+ }
+ BUG("Unsupported mode 0%o", mode);
+}
+
static const char *builtin_object_mode_attr(struct index_state *istate, const char *path)
{
unsigned int mode;
- struct strbuf sb = STRBUF_INIT;
if (direction == GIT_ATTR_CHECKIN) {
struct object_id oid;
@@ -1287,8 +1311,8 @@ static const char *builtin_object_mode_attr(struct index_state *istate, const ch
else
return ATTR__UNSET;
}
- strbuf_addf(&sb, "%06o", mode);
- return strbuf_detach(&sb, NULL);
+
+ return interned_mode_string(mode);
}
next prev parent reply other threads:[~2023-12-12 23:17 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-14 2:28 [PATCH 1/1] attr: add native file mode values support Joanna Wang
2023-11-14 2:52 ` Junio C Hamano
2023-11-14 21:49 ` [PATCH 1/1] attr: add builtin objectmode " Joanna Wang
2023-11-16 1:26 ` Junio C Hamano
2023-11-16 1:37 ` Eric Sunshine
2023-11-16 2:53 ` Junio C Hamano
2023-11-16 5:44 ` Joanna Wang
2023-11-16 6:17 ` Junio C Hamano
2023-11-16 8:08 ` Junio C Hamano
2023-11-16 17:54 ` Joanna Wang
2023-12-01 4:01 ` Joanna Wang
2023-12-12 23:17 ` Junio C Hamano [this message]
2023-12-20 20:07 ` Junio C Hamano
2024-01-12 6:12 ` Joanna Wang
2023-11-16 7:57 ` Junio C Hamano
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=xmqqedfrovsb.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jojwang@google.com \
--cc=sunshine@sunshineco.com \
--cc=tboegi@web.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.