From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 2/3] diff-lib.c: enable --shift-ita in index_differs_from()
Date: Wed, 28 Sep 2016 18:43:47 +0700 [thread overview]
Message-ID: <20160928114348.1470-3-pclouds@gmail.com> (raw)
In-Reply-To: <20160928114348.1470-1-pclouds@gmail.com>
This function is basically "git diff --cached HEAD", It has three
callers:
- One in builtin/commit.c, which uses it to determine if the index is
different from HEAD and go ahead making a new commit.
- Two in sequencer.c, which use it to see if the index is dirty.
In the first case, if ita entries are present, index_differs_from() may
report "dirty". However at tree creation phase, ita entries are dropped
and the result tree may look exactly the same as HEAD (assuming that
nothing else is changed in index). This is what we need index_differs_from()
for, to catch new empty commits. Enabling shift_ita in index_differs_from()
fixes this.
In the second case, the presence of ita entries are enough to say the
index is dirty and not continue on. Make an explicit check for that
before comparing index against HEAD (whether --shift-ita is present is
irrelevant)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
cache.h | 1 +
diff-lib.c | 1 +
read-cache.c | 10 ++++++++++
sequencer.c | 5 +++--
t/t2203-add-intent.sh | 11 +++++++++++
5 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/cache.h b/cache.h
index d0494c8..1ddd515 100644
--- a/cache.h
+++ b/cache.h
@@ -561,6 +561,7 @@ extern int do_read_index(struct index_state *istate, const char *path,
extern int read_index_from(struct index_state *, const char *path);
extern int is_index_unborn(struct index_state *);
extern int read_index_unmerged(struct index_state *);
+extern int has_ita_entries(struct index_state *);
#define COMMIT_LOCK (1 << 0)
#define CLOSE_LOCK (1 << 1)
extern int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
diff --git a/diff-lib.c b/diff-lib.c
index 62d67c8..ea55ee2 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -545,6 +545,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.shift_ita = 1;
run_diff_index(&rev, 1);
if (rev.pending.alloc)
free(rev.pending.objects);
diff --git a/read-cache.c b/read-cache.c
index 31eddec..f6a5f61 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1674,6 +1674,16 @@ int is_index_unborn(struct index_state *istate)
return (!istate->cache_nr && !istate->timestamp.sec);
}
+int has_ita_entries(struct index_state *istate)
+{
+ int i;
+
+ for (i = 0; i < istate->cache_nr; i++)
+ if (ce_intent_to_add(istate->cache[i]))
+ return 1;
+ return 0;
+}
+
int discard_index(struct index_state *istate)
{
int i;
diff --git a/sequencer.c b/sequencer.c
index eec8a60..10cded0 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -469,7 +469,8 @@ 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 (has_ita_entries(&the_index) ||
+ index_differs_from(unborn ? EMPTY_TREE_SHA1_HEX : "HEAD", 0))
return error_dirty_index(opts);
}
discard_cache();
@@ -1064,7 +1065,7 @@ static int sequencer_continue(struct replay_opts *opts)
if (ret)
return ret;
}
- if (index_differs_from("HEAD", 0))
+ if (has_ita_entries(&the_index) || index_differs_from("HEAD", 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 c6a4648..aa06415 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
--
2.8.2.524.g6ff3d78
next prev parent reply other threads:[~2016-09-28 11:44 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-28 11:43 [PATCH 0/3] i-t-a entries in git-status, and git-commit Nguyễn Thái Ngọc Duy
2016-09-28 11:43 ` [PATCH 1/3] Resurrect "diff-lib.c: adjust position of i-t-a entries in diff" Nguyễn Thái Ngọc Duy
2016-09-28 19:28 ` Junio C Hamano
2016-09-28 20:33 ` Junio C Hamano
2016-10-03 10:36 ` Duy Nguyen
2016-10-04 16:15 ` Junio C Hamano
2016-10-05 9:43 ` Duy Nguyen
2016-10-06 19:15 ` Junio C Hamano
2016-10-07 12:56 ` Duy Nguyen
2016-10-10 23:08 ` Junio C Hamano
2016-09-28 11:43 ` Nguyễn Thái Ngọc Duy [this message]
2016-09-28 18:49 ` [PATCH 2/3] diff-lib.c: enable --shift-ita in index_differs_from() Junio C Hamano
2016-09-28 11:43 ` [PATCH 3/3] commit: don't be fooled by ita entries when creating initial commit Nguyễn Thái Ngọc Duy
2016-09-28 11:51 ` [PATCH 0/3] i-t-a entries in git-status, and git-commit Duy Nguyen
2016-10-24 10:42 ` [PATCH 0/4] nd/ita-empty-commit update Nguyễn Thái Ngọc Duy
2016-10-24 10:42 ` [PATCH 1/4] diff-lib: allow ita entries treated as "not yet exist in index" Nguyễn Thái Ngọc Duy
2016-10-24 10:42 ` [PATCH 2/4] diff: add --ita-[in]visible-in-index Nguyễn Thái Ngọc Duy
2016-10-24 10:42 ` [PATCH 3/4] commit: fix empty commit creation when there's no changes but ita entries Nguyễn Thái Ngọc Duy
2016-10-24 10:42 ` [PATCH 4/4] commit: don't be fooled by ita entries when creating initial commit Nguyễn Thái Ngọc Duy
2016-10-24 17:58 ` [PATCH 0/4] nd/ita-empty-commit update Junio C Hamano
2016-10-25 9:34 ` Duy Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160928114348.1470-3-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.