From: Jeff King <peff@peff.net>
To: Dmitriy Smirnov <dmitriy.smirnov@jetbrains.com>
Cc: "Torsten Bögershausen" <tboegi@web.de>,
git@vger.kernel.org,
"Kirill Likhodedov" <kirill.likhodedov@jetbrains.com>,
"Aleksey Pivovarov" <aleksey.pivovarov@jetbrains.com>
Subject: Re: git add —ignore-errors causes --renormalize
Date: Thu, 17 Jan 2019 11:45:07 -0500 [thread overview]
Message-ID: <20190117164507.GA27819@sigill.intra.peff.net> (raw)
In-Reply-To: <20190117162711.GA7935@sigill.intra.peff.net>
On Thu, Jan 17, 2019 at 11:27:11AM -0500, Jeff King wrote:
> -- >8 --
> Subject: [PATCH] add: use separate ADD_CACHE_RENORMALIZE flag
>
> Commit 9472935d81 (add: introduce "--renormalize", 2017-11-16) taught
> git-add to pass HASH_RENORMALIZE to add_to_index(), which then passes
> the flag along to index_path(). However, the flags taken by
> add_to_index() and the ones taken by index_path() are distinct
> namespaces. We cannot take HASH_* flags in add_to_index(), because they
> overlap with the ADD_CACHE_* flags we already take (in this case,
> HASH_RENORMALIZE conflicts with ADD_CACHE_IGNORE_ERRORS).
>
> We can solve this by adding a new ADD_CACHE_RENORMALIZE flag, and using
> it to set HASH_RENORMALIZE within add_to_index(). In order to make it
> clear that these two flags come from distinct sets, let's also change
> the name "newflags" in the function to "hash_flags".
By the way, I wondered if there was a good way for the compiler to help
us find an error like this. There's no type-checking here, since all of
the flags are "int", with the values #define macros. Could enums give us
better safety?
My experiments suggest no, since the compiler is pretty loose about what
it will allow, even with -Wenum-compare. In particular, I think it's
happy to allow bitwise-AND even against tags from other enums. But if
somebody can figure out a way to make it work, I'm all ears. :)
A more drastic option is to replace the flag int with a struct
containing a bitfield. I.e., something like:
struct add_cache_flags {
unsigned ignore_errors : 1;
unsigned renormalize : 1;
... etc ...
};
That gives us real type safety and eliminates the need to manually
assign numbers to each flag. But there are downsides:
- it's syntactically more awkward to modify the flags. I.e.:
foo(flags | BAR);
becomes:
struct flags new_flags = old_flags;
new_flags.bar = 1;
foo(&new_flags);
There might be some C99-isms that can help us out (though I suspect
not completely -- even if we can use anonymous structs, I don't
think there's such a thing as "initialize this anonymous struct and
then modify these fields").
- there's no grouping, so you can't mask off certain values
So I dunno. Maybe that road is too painful, and we're stuck with what C
gives us.
-Peff
next prev parent reply other threads:[~2019-01-17 16:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-17 15:22 git add —ignore-errors causes --renormalize Dmitriy Smirnov
2019-01-17 16:27 ` Jeff King
2019-01-17 16:45 ` Jeff King [this message]
2019-01-19 17:08 ` Torsten Bögershausen
2019-01-29 21:35 ` SZEDER Gábor
2019-01-29 22:51 ` Jeff King
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=20190117164507.GA27819@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=aleksey.pivovarov@jetbrains.com \
--cc=dmitriy.smirnov@jetbrains.com \
--cc=git@vger.kernel.org \
--cc=kirill.likhodedov@jetbrains.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 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).