From 9e5da3d055c558fc6492d3b996736ff7e8d115c3 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 17 Jan 2019 11:27:11 -0500 Subject: 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". Reported-by: Dmitriy Smirnov Signed-off-by: Jeff King Signed-off-by: Junio C Hamano diff --git a/builtin/add.c b/builtin/add.c index 0b64bcd..95a7ec1 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -137,7 +137,7 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags) continue; /* do not touch non blobs */ if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL)) continue; - retval |= add_file_to_cache(ce->name, flags | HASH_RENORMALIZE); + retval |= add_file_to_cache(ce->name, flags | ADD_CACHE_RENORMALIZE); } return retval; diff --git a/cache.h b/cache.h index 3f419b6..18ecbe7 100644 --- a/cache.h +++ b/cache.h @@ -738,6 +738,7 @@ extern int index_name_pos(const struct index_state *, const char *name, int name #define ADD_CACHE_JUST_APPEND 8 /* Append only; tree.c::read_tree() */ #define ADD_CACHE_NEW_ONLY 16 /* Do not replace existing ones */ #define ADD_CACHE_KEEP_CACHE_TREE 32 /* Do not invalidate cache-tree */ +#define ADD_CACHE_RENORMALIZE 64 /* Pass along HASH_RENORMALIZE */ extern int add_index_entry(struct index_state *, struct cache_entry *ce, int option); extern void rename_index_entry_at(struct index_state *, int pos, const char *new_name); diff --git a/read-cache.c b/read-cache.c index 8f644f6..ce679c1 100644 --- a/read-cache.c +++ b/read-cache.c @@ -694,10 +694,10 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, int intent_only = flags & ADD_CACHE_INTENT; int add_option = (ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE| (intent_only ? ADD_CACHE_NEW_ONLY : 0)); - int newflags = HASH_WRITE_OBJECT; + int hash_flags = HASH_WRITE_OBJECT; - if (flags & HASH_RENORMALIZE) - newflags |= HASH_RENORMALIZE; + if (flags & ADD_CACHE_RENORMALIZE) + hash_flags |= HASH_RENORMALIZE; if (!S_ISREG(st_mode) && !S_ISLNK(st_mode) && !S_ISDIR(st_mode)) return error("%s: can only add regular files, symbolic links or git-directories", path); @@ -753,7 +753,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, } } if (!intent_only) { - if (index_path(&ce->oid, path, st, newflags)) { + if (index_path(&ce->oid, path, st, hash_flags)) { discard_cache_entry(ce); return error("unable to index file %s", path); } diff --git a/t/t0025-crlf-renormalize.sh b/t/t0025-crlf-renormalize.sh index 9d9e02a..e13363a 100755 --- a/t/t0025-crlf-renormalize.sh +++ b/t/t0025-crlf-renormalize.sh @@ -27,4 +27,13 @@ test_expect_success 'renormalize CRLF in repo' ' test_cmp expect actual ' +test_expect_success 'ignore-errors not mistaken for renormalize' ' + git reset --hard && + echo "*.txt text=auto" >.gitattributes && + git ls-files --eol >expect && + git add --ignore-errors "*.txt" && + git ls-files --eol >actual && + test_cmp expect actual +' + test_done -- cgit v0.10.2-6-g49f6