Skip to content

path: unify git_path_is_* APIs#4662

Merged
ethomson merged 1 commit intolibgit2:masterfrom
pks-t:pks/gitfile-api
Jun 9, 2018
Merged

path: unify git_path_is_* APIs#4662
ethomson merged 1 commit intolibgit2:masterfrom
pks-t:pks/gitfile-api

Conversation

@pks-t
Copy link
Copy Markdown
Member

@pks-t pks-t commented May 30, 2018

Right now, there's quite a lot of different function calls to determine
whether a path component matches a specific name after normalization
from the filesystem. We have a function for each of {gitattributes,
gitmodules, gitignore} multiplicated with {generic, NTFS, HFS} checks.
In the long time, this is unmaintainable in case there are e.g. new
filesystems with specific semantics, blowing up the number of functions
we need to implement.

Replace all functions with a simple git_path_is_gitfile function,
which accepts an enum pointing out the filename that is to be checked
against as well as the filesystem normalizations to check for. This
greatly simplifies implementation at the expense of the caller having to
invoke a somewhat longer function call.


I'm rather indifferent with regards to function and enum names, I'd definitely be open for proposals here. But I think it's undisputed that the explosion of different path verification functions is not something we want, especially if we're going to expose these later on.

/cc @carlosmn

@ethomson
Copy link
Copy Markdown
Member

Yeah, this looks like a nice improvement to me.

I might keep the len argument just to avoid a strlen, since we're often calling this in a loop... but at the same time I hope every compiler would recognize that as a constant strlen and optimize it out. 🤷‍♂️

@pks-t
Copy link
Copy Markdown
Member Author

pks-t commented May 30, 2018

I had the same train of thought with regards to the strlen. I mean I could easily put it into the struct, as well, but I don't know if it's worthwhile. On the other hand it is not complex to do, either

@pks-t
Copy link
Copy Markdown
Member Author

pks-t commented Jun 1, 2018

MSVC 2010 doesn't support explicit indices for array initializers :( To be honest, I didn't even know whether that is allowed in C90

Right now, there's quite a lot of different function calls to determine
whether a path component matches a specific name after normalization
from the filesystem. We have a function for each of {gitattributes,
gitmodules, gitignore} multiplicated with {generic, NTFS, HFS} checks.
In the long time, this is unmaintainable in case there are e.g. new
filesystems with specific semantics, blowing up the number of functions
we need to implement.

Replace all functions with a simple `git_path_is_gitfile` function,
which accepts an enum pointing out the filename that is to be checked
against as well as the filesystem normalizations to check for. This
greatly simplifies implementation at the expense of the caller having to
invoke a somewhat longer function call.
@pks-t pks-t force-pushed the pks/gitfile-api branch from f0dabdb to 92159bd Compare June 1, 2018 10:49
@ethomson ethomson merged commit 44788c9 into libgit2:master Jun 9, 2018
@ethomson
Copy link
Copy Markdown
Member

ethomson commented Jun 9, 2018

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants