git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Ping Yin <pkufranky@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 3/4] Fix diff regression for submodules not checked out
Date: Sat, 03 May 2008 23:45:23 -0700	[thread overview]
Message-ID: <7vej8ir2ik.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 7vfxt0wdkq.fsf@gitster.siamese.dyndns.org

Junio C Hamano <gitster@pobox.com> writes:

> The second case is "not checked out -- treat me as unmodified", and the
> third case is "the user does not want the submodule there", and the latter
> is still reported as "removed".  That is exactly what your patch does.

Having looked at the code a bit more, I do not think we need the
three-kind distinction for this part.

The attached patch would be both sufficient and cleaner.  The real change
is a single-liner, and everything else is additional comment ;-)  I'd
follow it up with s/check_work_tree_entity/check_removed/ for
clarification.

A cleaned up series is queued near the tip of 'pu' for tonight, but 'pu'
itself has some uncompiable crap in it (not your series) and needs to be
rebuilt soon.

---
[PATCH] diff: a submodule not checked out is not modified

948dd34 (diff-index: careful when inspecting work tree items, 2008-03-30)
made the work tree check careful not to be fooled by a new directory that
exists at a place the index expects a blob.  For such a change to be a
typechange from blob to submodule, the new directory has to be a
repository.

However, if the index expects a submodule there, we should not insist the
work tree entity to be a repository --- a simple directory that is not a
full fledged repository (even an empty directory would do) should be
considered an unmodified subproject, because that is how a superproject
with a submodule is checked out sparsely by default.

This makes the function check_work_tree_entity() even more careful not to
report a submodule that is not checked out as removed.  It fixes the
recently added test in t4027.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 diff-lib.c                |   25 ++++++++++++++++++++++---
 t/t4027-diff-submodule.sh |    2 +-
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/diff-lib.c b/diff-lib.c
index cfd629d..e0ebcdc 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -337,9 +337,15 @@ int run_diff_files_cmd(struct rev_info *revs, int argc, const char **argv)
 	}
 	return run_diff_files(revs, options);
 }
+
 /*
- * See if work tree has an entity that can be staged.  Return 0 if so,
- * return 1 if not and return -1 if error.
+ * Has the work tree entity been removed?
+ *
+ * Return 1 if it was removed from the work tree, 0 if an entity to be
+ * compared with the cache entry ce still exists (the latter includes
+ * the case where a directory that is not a submodule repository
+ * exists for ce that is a submodule -- it is a submodule that is not
+ * checked out).  Return negative for an error.
  */
 static int check_work_tree_entity(const struct cache_entry *ce, struct stat *st, char *symcache)
 {
@@ -352,7 +358,20 @@ static int check_work_tree_entity(const struct cache_entry *ce, struct stat *st,
 		return 1;
 	if (S_ISDIR(st->st_mode)) {
 		unsigned char sub[20];
-		if (resolve_gitlink_ref(ce->name, "HEAD", sub))
+
+		/*
+		 * If ce is already a gitlink, we can have a plain
+		 * directory (i.e. the submodule is not checked out),
+		 * or a checked out submodule.  Either case this is not
+		 * a case where something was removed from the work tree,
+		 * so we will return 0.
+		 *
+		 * Otherwise, if the directory is not a submodule
+		 * repository, that means ce which was a blob turned into
+		 * a directory --- the blob was removed!
+		 */
+		if (!S_ISGITLINK(ce->ce_mode) &&
+		    resolve_gitlink_ref(ce->name, "HEAD", sub))
 			return 1;
 	}
 	return 0;
diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh
index 61caad0..ba6679c 100755
--- a/t/t4027-diff-submodule.sh
+++ b/t/t4027-diff-submodule.sh
@@ -50,7 +50,7 @@ test_expect_success 'git diff-files --raw' '
 	test_cmp expect actual.files
 '
 
-test_expect_failure 'git diff (empty submodule dir)' '
+test_expect_success 'git diff (empty submodule dir)' '
 	: >empty &&
 	rm -rf sub/* sub/.git &&
 	git diff > actual.empty &&
-- 
1.5.5.1.219.gb8f92

  parent reply	other threads:[~2008-05-04  6:46 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-22 11:01 [regression?] "git status -a" reports modified for empty submodule directory Ping Yin
2008-04-22 11:04 ` Ping Yin
2008-04-22 12:15 ` Johannes Sixt
2008-04-22 12:39   ` Ping Yin
2008-04-22 12:46     ` Johannes Sixt
2008-04-22 18:00     ` Roman Shaposhnik
2008-04-29 15:31 ` Ping Yin
2008-04-29 16:07   ` [PATCH 0/2] Add tests for submodule with empty directory Ping Yin
2008-04-29 16:07     ` [PATCH 1/2] t4027: test diff " Ping Yin
2008-04-29 16:07       ` [PATCH 2/2] Add t7506 to test submodule related functions for git-status Ping Yin
2008-04-29 21:40   ` [regression?] "git status -a" reports modified for empty submodule directory Junio C Hamano
2008-04-30  6:39     ` Johannes Sixt
2008-04-30  7:29       ` Junio C Hamano
2008-04-30 15:56         ` Ping Yin
2008-05-02 13:35           ` [PATCH 0/4] Fix regression for unchecked out submodules Ping Yin
2008-05-02 13:35             ` [PATCH 1/4] t4027: test diff for submodule with empty directory Ping Yin
2008-05-02 13:35               ` [PATCH 2/4] Add t7506 to test submodule related functions for git-status Ping Yin
2008-05-02 13:35                 ` [PATCH 3/4] Fix diff regression for submodules not checked out Ping Yin
2008-05-02 13:35                   ` [PATCH 4/4] Fix ie_match_stat for non-checked-out submodule Ping Yin
2008-05-02 21:57                     ` Junio C Hamano
2008-05-02 23:34                       ` Ping Yin
2008-05-02 22:23                   ` [PATCH 3/4] Fix diff regression for submodules not checked out Junio C Hamano
2008-05-02 23:55                     ` Ping Yin
2008-05-03  0:07                     ` [PATCH] Rename ENT_INEXISTENT to ENT_NONEXISTENT Ping Yin
2008-05-03 12:36                     ` [PATCH 3/4] Fix diff regression for submodules not checked out Johannes Schindelin
2008-05-03 16:59                       ` Junio C Hamano
2008-05-04  6:45                     ` Junio C Hamano [this message]
2008-05-04  7:10                       ` Ping Yin

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=7vej8ir2ik.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=pkufranky@gmail.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 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).