From: IWAMOTO Toshihiro <iwamoto@valinux.co.jp>
To: git@vger.kernel.org
Subject: bug with git-diff --quiet
Date: Thu, 23 Jan 2014 11:45:25 +0900 [thread overview]
Message-ID: <20140123024525.B726248918@mail.valinux.co.jp> (raw)
I found "git-diff --quiet" returns a zero exit status even if there's
a change. The following sequence reproduces the bug:
$ mkdir foo
$ cd foo
$ git init
$ echo a > a.txt
$ echo b >b.txt
$ git add ?.txt
$ git commit
$ echo b >> b.txt
$ touch a.txt
$ git diff --quiet; echo $?
Interestingly, if you issue "git-diff --quiet" again, it returns the
expected exit status 1.
The problem is in the optimization code in run_diff_files(). The
function finds a.txt has different stat(2) data from .git/index and
calls diff_change(), which sets DIFF_OPT_HAS_CHANGES. As the flag
makes diff_can_quit_early() return 1, run_diff_files()'s loop finishes
without calling diff_change() for b.txt.
Then, diffcore_std() examines diff_queued_diff and clears
DIFF_OPT_HAS_CHANGES, because a.txt is unchanged.
This is how a change in b.txt is ignored by git-diff --quiet.
Here's a obvious fix for this bug, but I think you can find a better
fix. Thanks in advance.
diff --git a/diff-lib.c b/diff-lib.c
index 346cac6..0b8c58d 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -105,9 +105,6 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
int changed;
unsigned dirty_submodule = 0;
- if (diff_can_quit_early(&revs->diffopt))
- break;
-
if (!ce_path_match(ce, &revs->prune_data))
continue;
--
IWAMOTO Toshihiro
next reply other threads:[~2014-01-23 2:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-23 2:45 IWAMOTO Toshihiro [this message]
2014-01-25 4:03 ` bug with git-diff --quiet Duy Nguyen
2014-01-25 6:46 ` [PATCH 1/3] Move diffcore_skip_stat_unmatch core logic out for reuse later Nguyễn Thái Ngọc Duy
2014-01-25 6:46 ` [PATCH 2/3] diff: do not quit early on stat-dirty files Nguyễn Thái Ngọc Duy
2014-01-25 6:46 ` [PATCH 3/3] diff: turn off skip_stat_unmatch on "diff --cached" Nguyễn Thái Ngọc Duy
2014-01-27 22:59 ` [PATCH v2 3/3] diff: turn skip_stat_unmatch on selectively Nguyễn Thái Ngọc Duy
2014-01-27 23:45 ` Junio C Hamano
2014-01-28 22:51 ` Junio C Hamano
2014-01-28 23:52 ` Duy Nguyen
2014-01-29 19:25 ` Junio C Hamano
2014-01-30 5:36 ` Duy Nguyen
2014-01-31 16:17 ` Junio C Hamano
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=20140123024525.B726248918@mail.valinux.co.jp \
--to=iwamoto@valinux.co.jp \
--cc=git@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).