Skip to content

Commit 9e5da3d

Browse files
peffgitster
authored andcommitted
add: use separate ADD_CACHE_RENORMALIZE flag
Commit 9472935 (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 <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 98cdfbb commit 9e5da3d

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

builtin/add.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
137137
continue; /* do not touch non blobs */
138138
if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
139139
continue;
140-
retval |= add_file_to_cache(ce->name, flags | HASH_RENORMALIZE);
140+
retval |= add_file_to_cache(ce->name, flags | ADD_CACHE_RENORMALIZE);
141141
}
142142

143143
return retval;

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ extern int index_name_pos(const struct index_state *, const char *name, int name
738738
#define ADD_CACHE_JUST_APPEND 8 /* Append only; tree.c::read_tree() */
739739
#define ADD_CACHE_NEW_ONLY 16 /* Do not replace existing ones */
740740
#define ADD_CACHE_KEEP_CACHE_TREE 32 /* Do not invalidate cache-tree */
741+
#define ADD_CACHE_RENORMALIZE 64 /* Pass along HASH_RENORMALIZE */
741742
extern int add_index_entry(struct index_state *, struct cache_entry *ce, int option);
742743
extern void rename_index_entry_at(struct index_state *, int pos, const char *new_name);
743744

read-cache.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,10 +694,10 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
694694
int intent_only = flags & ADD_CACHE_INTENT;
695695
int add_option = (ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE|
696696
(intent_only ? ADD_CACHE_NEW_ONLY : 0));
697-
int newflags = HASH_WRITE_OBJECT;
697+
int hash_flags = HASH_WRITE_OBJECT;
698698

699-
if (flags & HASH_RENORMALIZE)
700-
newflags |= HASH_RENORMALIZE;
699+
if (flags & ADD_CACHE_RENORMALIZE)
700+
hash_flags |= HASH_RENORMALIZE;
701701

702702
if (!S_ISREG(st_mode) && !S_ISLNK(st_mode) && !S_ISDIR(st_mode))
703703
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,
753753
}
754754
}
755755
if (!intent_only) {
756-
if (index_path(&ce->oid, path, st, newflags)) {
756+
if (index_path(&ce->oid, path, st, hash_flags)) {
757757
discard_cache_entry(ce);
758758
return error("unable to index file %s", path);
759759
}

t/t0025-crlf-renormalize.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,13 @@ test_expect_success 'renormalize CRLF in repo' '
2727
test_cmp expect actual
2828
'
2929

30+
test_expect_success 'ignore-errors not mistaken for renormalize' '
31+
git reset --hard &&
32+
echo "*.txt text=auto" >.gitattributes &&
33+
git ls-files --eol >expect &&
34+
git add --ignore-errors "*.txt" &&
35+
git ls-files --eol >actual &&
36+
test_cmp expect actual
37+
'
38+
3039
test_done

0 commit comments

Comments
 (0)