From 425a28e0a4edfc39585cec6b0b6368c0ad9dbf7e Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Mon, 24 Oct 2016 17:42:19 +0700 Subject: diff-lib: allow ita entries treated as "not yet exist in index" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When comparing the index and the working tree to show which paths are new, and comparing the tree recorded in the HEAD and the index to see if committing the contents recorded in the index would result in an empty commit, we would want the former comparison to say "these are new paths" and the latter to say "there is no change" for paths that are marked as intent-to-add. We made a similar attempt at d95d728a ("diff-lib.c: adjust position of i-t-a entries in diff", 2015-03-16), which redefined the semantics of these two comparison modes globally, which was a disaster and had to be reverted at 78cc1a54 ("Revert "diff-lib.c: adjust position of i-t-a entries in diff"", 2015-06-23). To make sure we do not repeat the same mistake, introduce a new internal diffopt option so that this different semantics can be asked for only by callers that ask it, while making sure other unaudited callers will get the same comparison result. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- diff.h | 1 + 1 file changed, 1 insertion(+) (limited to 'diff.h') diff --git a/diff.h b/diff.h index 25ae60d5ff..ce3535e9ad 100644 --- a/diff.h +++ b/diff.h @@ -146,6 +146,7 @@ struct diff_options { int dirstat_permille; int setup; int abbrev; + int ita_invisible_in_index; /* white-space error highlighting */ #define WSEH_NEW 1 #define WSEH_CONTEXT 2 -- cgit v1.2.3 From 018ec3c8203ad1aee683840a580cfba7914419b6 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Mon, 24 Oct 2016 17:42:21 +0700 Subject: commit: fix empty commit creation when there's no changes but ita entries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If i-t-a entries are present and there is no change between the index and HEAD i-t-a entries, index_differs_from() still returns "dirty, new entries" (aka, the resulting commit is not empty), but cache-tree will skip i-t-a entries and produce the exact same tree of current commit. index_differs_from() is supposed to catch this so we can abort git-commit (unless --no-empty is specified). Update it to optionally ignore i-t-a entries when doing a diff between the index and HEAD so that it would return "no change" in this case and abort commit. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/commit.c | 2 +- diff-lib.c | 4 +++- diff.h | 2 +- sequencer.c | 4 ++-- t/t2203-add-intent.sh | 11 +++++++++++ 5 files changed, 18 insertions(+), 5 deletions(-) (limited to 'diff.h') diff --git a/builtin/commit.c b/builtin/commit.c index 1cba3b75c8..400d2a54e6 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -910,7 +910,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, if (ignore_submodule_arg && !strcmp(ignore_submodule_arg, "all")) diff_flags |= DIFF_OPT_IGNORE_SUBMODULES; - commitable = index_differs_from(parent, diff_flags); + commitable = index_differs_from(parent, diff_flags, 1); } } strbuf_release(&committer_ident); diff --git a/diff-lib.c b/diff-lib.c index 27f12282b3..52447466b5 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -535,7 +535,8 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt) return 0; } -int index_differs_from(const char *def, int diff_flags) +int index_differs_from(const char *def, int diff_flags, + int ita_invisible_in_index) { struct rev_info rev; struct setup_revision_opt opt; @@ -547,6 +548,7 @@ int index_differs_from(const char *def, int diff_flags) DIFF_OPT_SET(&rev.diffopt, QUICK); DIFF_OPT_SET(&rev.diffopt, EXIT_WITH_STATUS); rev.diffopt.flags |= diff_flags; + rev.diffopt.ita_invisible_in_index = ita_invisible_in_index; run_diff_index(&rev, 1); if (rev.pending.alloc) free(rev.pending.objects); diff --git a/diff.h b/diff.h index ce3535e9ad..94422e1e93 100644 --- a/diff.h +++ b/diff.h @@ -357,7 +357,7 @@ extern int diff_result_code(struct diff_options *, int); extern void diff_no_index(struct rev_info *, int, const char **); -extern int index_differs_from(const char *def, int diff_flags); +extern int index_differs_from(const char *def, int diff_flags, int ita_invisible_in_index); /* * Fill the contents of the filespec "df", respecting any textconv defined by diff --git a/sequencer.c b/sequencer.c index eec8a60d6b..b0826353e3 100644 --- a/sequencer.c +++ b/sequencer.c @@ -469,7 +469,7 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts) unborn = get_sha1("HEAD", head); if (unborn) hashcpy(head, EMPTY_TREE_SHA1_BIN); - if (index_differs_from(unborn ? EMPTY_TREE_SHA1_HEX : "HEAD", 0)) + if (index_differs_from(unborn ? EMPTY_TREE_SHA1_HEX : "HEAD", 0, 0)) return error_dirty_index(opts); } discard_cache(); @@ -1064,7 +1064,7 @@ static int sequencer_continue(struct replay_opts *opts) if (ret) return ret; } - if (index_differs_from("HEAD", 0)) + if (index_differs_from("HEAD", 0, 0)) return error_dirty_index(opts); todo_list = todo_list->next; return pick_commits(todo_list, opts); diff --git a/t/t2203-add-intent.sh b/t/t2203-add-intent.sh index 0e54f63cf7..8652a96d86 100755 --- a/t/t2203-add-intent.sh +++ b/t/t2203-add-intent.sh @@ -129,5 +129,16 @@ test_expect_success 'cache-tree does skip dir that becomes empty' ' ) ' +test_expect_success 'commit: ita entries ignored in empty commit check' ' + git init empty-subsequent-commit && + ( + cd empty-subsequent-commit && + test_commit one && + : >two && + git add -N two && + test_must_fail git commit -m nothing-new-here + ) +' + test_done -- cgit v1.2.3