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

Re: [GSoC] Use unsigned integral type for collection of bits

From
eugenio gigante <giganteeugenio2@gmail.com>
Date
Feb 19, 2024, 23:43 UTC
Message-ID
<CAFJh0PQPB3DBfxhLhzYgY212yzXOtRt_TtU=7B=SsBOH_iScVQ@mail.gmail.com>
In-Reply-To
<CAFJh0PRJkVBr-A=UtmEcAh4cPgC3w_vdTPg6kkjgHVQXHTYRmA@mail.gmail.com>

On Sun, Feb 18, 2024 at 20:09 AM eric sunshine <sunshine@sunshineco.com> wrote:

Show 7 quoted lines
> The code in question is not being used as a "bag of bits". Rather,
> it's a tristate binary with values "not-set", "true", and "false".
> Whereas a typical binary could be represented by a single bit, this
> one needs the extra bit to handle the "not-set" case. Moreover, it is
> idiomatic in the Git codebase for -1 to represent "not-set", so I
> think this code is fine as-is since its meaning is clear to those
> familiar with the codebase, thus does not need any changes made to it.
Thank you for the clarification and sorry for the misunderstanding.
> So, refresh_index() is correctly expecting an unsigned value for
> `flags` but refresh() in `builtin/add.c` has undesirably declared
> `flags` as signed.

So, an unsigned type is preferable since we are dealing with 'bags of bits', and probably only bitwise operators operate on them. Also the mixing is not ideal. Yes, I'm interested in fixing the one in `builtin/add.c`.

Il giorno mar 20 feb 2024 alle ore 00:39 eugenio gigante <giganteeugenio2@gmail.com> ha scritto:

Show 21 quoted lines
>
> On Sun, Feb 18, 2024 at 20:09 AM eric sunshine
> <sunshine@sunshineco.com> wrote:
> > The code in question is not being used as a "bag of bits". Rather,
> > it's a tristate binary with values "not-set", "true", and "false".
> > Whereas a typical binary could be represented by a single bit, this
> > one needs the extra bit to handle the "not-set" case. Moreover, it is
> > idiomatic in the Git codebase for -1 to represent "not-set", so I
> > think this code is fine as-is since its meaning is clear to those
> > familiar with the codebase, thus does not need any changes made to it.
>
> Thank you for the clarification and sorry for the misunderstanding.
>
> > So, refresh_index() is correctly expecting an unsigned value for
> > `flags` but refresh() in `builtin/add.c` has undesirably declared
> > `flags` as signed.
>
> So, an unsigned type is preferable since we are dealing
> with 'bags of bits', and probably only bitwise operators operate
> on them. Also the mixing is not ideal.
> Yes, I'm interested in fixing the one in `builtin/add.c`.
Previous: Junio C Hamano
Message 4 of 4 in “[GSoC] Use unsigned integral type for collection of bits”
  1. eugenio giganteFeb 18, 2024
  2. Eric SunshineFeb 18, 2024
  3. Junio C HamanoFeb 20, 2024
  4. eugenio giganteFeb 19, 2024

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.