-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Index API updates for consistency #4807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
include/git2/index.h
Outdated
@@ -86,7 +86,7 @@ typedef struct git_index_entry { | |||
typedef enum { | |||
GIT_IDXENTRY_EXTENDED = (0x4000), | |||
GIT_IDXENTRY_VALID = (0x8000), | |||
} git_indxentry_flag_t; | |||
} git_idxentry_flag_t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh. This very much does look breaking to me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, a bit more constructive: what about also providing a second typedef? typedef git_indxentry_flag_t git_idxentry_flag_t
so that nobody needs to change his code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, but wouldn't that introduce warnings in user code anyway because of the mismatch ? Thinking about it, I don't think it will, because the usage seems to be limited to bitwise operations. I'm just concerned that a -Werror
downstream will have to change the code anyways.
Personally, I'd go for git_index_entry_flag_t
for consistency, as that's the name of the struct, and it's part of the index
system. I'm fine with just dropping the "n" though, since that's worst 😉.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, yes, this was very much a WIP that is not at all ready for review. Changing the title to reflect that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as the naming goes, I too would prefer git_index_entry_...
except that the rest of the things in this file are named git_idxentry
. Possible that we can get away without breakage here, possibly not.
Appreciate the thoughts about -Werror
. I'm not sure that we've ever said that we guarantee that people can avoid warnings using libgit2 (and, indeed, you can see that the 32 bit platforms have loads of them that we should deal with but haven't yet). But as that's something to strive for it's something interesting to keep in mind.
055c067
to
f48f38d
Compare
fa78fd0
to
6f1a2f0
Compare
Okay, I've updated this to update the names for this prefixed with Background: I'm playing around with some automated tools to extract our APIs for a binding and having improved consistency in our naming would be 👍 . I've added
so that compilers will see users sending values in the While we're here, we can also clean up some unused values that users should not be relying on and in fact represent internal structures that we likely do not want to publish, even if we do start using them internally. For example, |
These first commits change the API definition only. All our own callers are using the old names; I wanted to open this with only those changes to ensure a CI pass with no warnings to address @tiennou's (very reasonable) concerns. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely welcome those changes. I've had my own grief with "git_otype" several times already, because I instinctively searched for "git_object_type" instead. And as you said in another PR, I'm always in favor of having distinctive names instead of saving a few small characters
GIT_OBJECT__EXT2 = 5, /**< Reserved. */ | ||
GIT_OBJECT_OFS_DELTA = 6, /**< A delta, base is given by an offset. */ | ||
GIT_OBJECT_REF_DELTA = 7, /**< A delta, base is given by object id. */ | ||
} git_object_t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I like git_object_t
. For me, _t
usually just says "This is a typedef" instead of "This is a type". So I'd rather vote for either git_object_type
or git_object_type_t
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I struggled with this one a bit. I agree with you but we're reasonably consistent with _t
meaning "this is a type`". A few examples:
(It's not perfect, eg git_credtype_t
, which does have values of GIT_CREDTYPE_...
so that's nice, but they might have been more consistent as GIT_CREDENTIAL_USERNAME
...) But anyway, this feels consistent even if it wasn't my preference to begin with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough 👍
6f1a2f0
to
3d6e1e3
Compare
Thanks - agree with |
3d6e1e3
to
d3f45a7
Compare
OK, this seems like a change that isn't contentious. I'll update internal callers to use the new names, possible tomorrow (Thanksgiving) but more likely over the weekend. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. In the ideal case, we'd add deprecation notices to all those old typedefs. But I'm not sure I'd want to do this immediately, as downstream users are likely to rage in that case as their code will be full of warnings. And I don't even know if it's possible to deprecate macros 🤔
d3f45a7
to
ebd55cd
Compare
I'm in agreement with you. Let's hold off and do it when we remember which will probably be far enough from now that it seems like a reasonable time to do it. :P |
/rebuild |
Okay, @ethomson, I started to rebuild this pull request as build #1082. |
We have various macro, enumeration and structure names that were introduced (very) early in the project and do not match our current naming conventions. For instance: `GIT_IDXENTRY...` flags that correspond to a structure named `git_index_entry`. Update these to match the current guidance. The old macros and enumeration names are reflected as new macros in order to support backward compatibility (and do so without warnings for consumers).
Update the `git_otype` names to reflect our current naming conventions. `git_otype` is now `git_object_t` and the `GIT_OBJ_*` values are now `GIT_OBJECT_*` values. The old macro, enumeration and structure names are retained and simply set to the new names.
The two "reserved" bits in `git_object_t` are unused. They were included for completeness, but downstream users should never use them and they should not have been made public. These values are never set. With the refactoring of `git_otype` into `git_object_t`, we can remove these from the new API. They will remain in the old (deprecated) API in the unlikely event that someone was using them.
git_object_t is the future; update the public API to use it. This will also ensure that we can build our tests which make use of the old API without modification (and without compiler warnings).
Use the new-style index names throughout our own codebase.
ebd55cd
to
2e8bf25
Compare
Use the new object_type enumeration names within the codebase.
2e8bf25
to
168fe39
Compare
OK, I rebased this. Going to |
I've been angry at
index.h
for a little while now and would like to make some (non-breaking) fixes for better consistency with the project. I'll pile them in here.