path: root/utf8.h
diff options
authorJeff King <>2014-12-15 22:56:59 (GMT)
committerJunio C Hamano <>2014-12-17 19:04:39 (GMT)
commit6162a1d323d24fd8cbbb1a6145a91fb849b2568f (patch)
treefe77ce47be17b0db00aeca5ad9ec79d1ca034ebc /utf8.h
parent76e86fc6e3523d28e8db00e7b10c33c553d996b8 (diff)
utf8: add is_hfs_dotgit() helper
We do not allow paths with a ".git" component to be added to the index, as that would mean repository contents could overwrite our repository files. However, asking "is this path the same as .git" is not as simple as strcmp() on some filesystems. HFS+'s case-folding does more than just fold uppercase into lowercase (which we already handle with strcasecmp). It may also skip past certain "ignored" Unicode code points, so that (for example) ".gi\u200ct" is mapped ot ".git". The full list of folds can be found in the tables at: Implementing a full "is this path the same as that path" comparison would require us importing the whole set of tables. However, what we want to do is much simpler: we only care about checking ".git". We know that 'G' is the only thing that folds to 'g', and so on, so we really only need to deal with the set of ignored code points, which is much smaller. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'utf8.h')
1 files changed, 8 insertions, 0 deletions
diff --git a/utf8.h b/utf8.h
index 65d0e42..e4d9183 100644
--- a/utf8.h
+++ b/utf8.h
@@ -42,4 +42,12 @@ static inline char *reencode_string(const char *in,
int mbs_chrlen(const char **text, size_t *remainder_p, const char *encoding);
+ * Returns true if the the path would match ".git" after HFS case-folding.
+ * The path should be NUL-terminated, but we will match variants of both ".git\0"
+ * and ".git/..." (but _not_ ".../.git"). This makes it suitable for both fsck
+ * and verify_path().
+ */
+int is_hfs_dotgit(const char *path);