diff options
| author | Junio C Hamano <gitster@pobox.com> | 2010-01-26 22:53:13 -0800 | 
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2010-01-26 22:53:13 -0800 | 
| commit | d539de9f25920f099e4e56b0acbb4ebf246ff0f4 (patch) | |
| tree | 8453048a2a8f5a8a84d66e5c8dfd4784bdec49b6 | |
| parent | 3fa7c3da379bb47a0e7a52ffc13cb366add880a2 (diff) | |
| parent | 721ceec1ad12625e90b395fd0be0fae9049ebc22 (diff) | |
| download | git-d539de9f25920f099e4e56b0acbb4ebf246ff0f4.tar.gz | |
Merge branch 'jl/diff-submodule-ignore'
* jl/diff-submodule-ignore:
  Teach diff --submodule that modified submodule directory is dirty
  git diff: Don't test submodule dirtiness with --ignore-submodules
  Make ce_uptodate() trustworthy again
| -rw-r--r-- | diff-lib.c | 12 | ||||
| -rw-r--r-- | diff.c | 2 | ||||
| -rw-r--r-- | preload-index.c | 2 | ||||
| -rw-r--r-- | read-cache.c | 6 | ||||
| -rw-r--r-- | submodule.c | 3 | ||||
| -rw-r--r-- | submodule.h | 1 | ||||
| -rwxr-xr-x | t/t4041-diff-submodule.sh | 67 | 
7 files changed, 85 insertions, 8 deletions
diff --git a/diff-lib.c b/diff-lib.c index ec2e2ac005..d7e13cb177 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -161,7 +161,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)  				continue;  		} -		if ((ce_uptodate(ce) && !S_ISGITLINK(ce->ce_mode)) || ce_skip_worktree(ce)) +		if (ce_uptodate(ce) || ce_skip_worktree(ce))  			continue;  		/* If CE_VALID is set, don't look at workdir for file removal */ @@ -179,6 +179,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)  		}  		changed = ce_match_stat(ce, &st, ce_option);  		if (S_ISGITLINK(ce->ce_mode) +		    && !DIFF_OPT_TST(&revs->diffopt, IGNORE_SUBMODULES)  		    && (!changed || (revs->diffopt.output_format & DIFF_FORMAT_PATCH))  		    && is_submodule_modified(ce->name)) {  			changed = 1; @@ -220,7 +221,7 @@ static int get_stat_data(struct cache_entry *ce,  			 const unsigned char **sha1p,  			 unsigned int *modep,  			 int cached, int match_missing, -			 unsigned *dirty_submodule, int output_format) +			 unsigned *dirty_submodule, struct diff_options *diffopt)  {  	const unsigned char *sha1 = ce->sha1;  	unsigned int mode = ce->ce_mode; @@ -241,7 +242,8 @@ static int get_stat_data(struct cache_entry *ce,  		}  		changed = ce_match_stat(ce, &st, 0);  		if (S_ISGITLINK(ce->ce_mode) -		    && (!changed || (output_format & DIFF_FORMAT_PATCH)) +		    && !DIFF_OPT_TST(diffopt, IGNORE_SUBMODULES) +		    && (!changed || (diffopt->output_format & DIFF_FORMAT_PATCH))  		    && is_submodule_modified(ce->name)) {  			changed = 1;  			*dirty_submodule = 1; @@ -270,7 +272,7 @@ static void show_new_file(struct rev_info *revs,  	 * the working copy.  	 */  	if (get_stat_data(new, &sha1, &mode, cached, match_missing, -	    &dirty_submodule, revs->diffopt.output_format) < 0) +	    &dirty_submodule, &revs->diffopt) < 0)  		return;  	diff_index_show_file(revs, "+", new, sha1, mode, dirty_submodule); @@ -287,7 +289,7 @@ static int show_modified(struct rev_info *revs,  	unsigned dirty_submodule = 0;  	if (get_stat_data(new, &sha1, &mode, cached, match_missing, -			  &dirty_submodule, revs->diffopt.output_format) < 0) { +			  &dirty_submodule, &revs->diffopt) < 0) {  		if (report_missing)  			diff_index_show_file(revs, "-", old,  					     old->sha1, old->ce_mode, 0); @@ -1615,7 +1615,7 @@ static void builtin_diff(const char *name_a,  		const char *del = diff_get_color_opt(o, DIFF_FILE_OLD);  		const char *add = diff_get_color_opt(o, DIFF_FILE_NEW);  		show_submodule_summary(o->file, one ? one->path : two->path, -				one->sha1, two->sha1, +				one->sha1, two->sha1, two->dirty_submodule,  				del, add, reset);  		return;  	} diff --git a/preload-index.c b/preload-index.c index 92899333c2..e3d0bda31a 100644 --- a/preload-index.c +++ b/preload-index.c @@ -47,6 +47,8 @@ static void *preload_thread(void *_data)  		if (ce_stage(ce))  			continue; +		if (S_ISGITLINK(ce->ce_mode)) +			continue;  		if (ce_uptodate(ce))  			continue;  		if (!ce_path_match(ce, p->pathspec)) diff --git a/read-cache.c b/read-cache.c index 79938bf09a..309b77a6c9 100644 --- a/read-cache.c +++ b/read-cache.c @@ -612,7 +612,8 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,  	if (alias && !ce_stage(alias) && !ie_match_stat(istate, alias, st, ce_option)) {  		/* Nothing changed, really */  		free(ce); -		ce_mark_uptodate(alias); +		if (!S_ISGITLINK(alias->ce_mode)) +			ce_mark_uptodate(alias);  		alias->ce_flags |= CE_ADDED;  		return 0;  	} @@ -1050,7 +1051,8 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,  			 * because CE_UPTODATE flag is in-core only;  			 * we are not going to write this change out.  			 */ -			ce_mark_uptodate(ce); +			if (!S_ISGITLINK(ce->ce_mode)) +				ce_mark_uptodate(ce);  			return ce;  		}  	} diff --git a/submodule.c b/submodule.c index f657bee379..ca0527fbcb 100644 --- a/submodule.c +++ b/submodule.c @@ -36,6 +36,7 @@ static int add_submodule_odb(const char *path)  void show_submodule_summary(FILE *f, const char *path,  		unsigned char one[20], unsigned char two[20], +		unsigned dirty_submodule,  		const char *del, const char *add, const char *reset)  {  	struct rev_info rev; @@ -85,6 +86,8 @@ void show_submodule_summary(FILE *f, const char *path,  	if (!fast_backward && !fast_forward)  		strbuf_addch(&sb, '.');  	strbuf_addf(&sb, "%s", find_unique_abbrev(two, DEFAULT_ABBREV)); +	if (dirty_submodule) +		strbuf_add(&sb, "-dirty", 6);  	if (message)  		strbuf_addf(&sb, " %s\n", message);  	else diff --git a/submodule.h b/submodule.h index 0773121eb5..233696555e 100644 --- a/submodule.h +++ b/submodule.h @@ -3,6 +3,7 @@  void show_submodule_summary(FILE *f, const char *path,  		unsigned char one[20], unsigned char two[20], +		unsigned dirty_submodule,  		const char *del, const char *add, const char *reset);  int is_submodule_modified(const char *path); diff --git a/t/t4041-diff-submodule.sh b/t/t4041-diff-submodule.sh index 5bb4fed3f5..464305405a 100755 --- a/t/t4041-diff-submodule.sh +++ b/t/t4041-diff-submodule.sh @@ -191,6 +191,73 @@ EOF  "  commit_file sm1 && +test_expect_success 'submodule is up to date' " +	git diff-index -p --submodule=log HEAD >actual && +	diff actual - <<-EOF +EOF +" + +test_expect_success 'submodule contains untracked content' " +	echo new > sm1/new-file && +	git diff-index -p --submodule=log HEAD >actual && +	diff actual - <<-EOF +Submodule sm1 $head6..$head6-dirty: +EOF +" + +test_expect_success 'submodule contains untracked and modifed content' " +	echo new > sm1/foo6 && +	git diff-index -p --submodule=log HEAD >actual && +	diff actual - <<-EOF +Submodule sm1 $head6..$head6-dirty: +EOF +" + +test_expect_success 'submodule contains modifed content' " +	rm -f sm1/new-file && +	git diff-index -p --submodule=log HEAD >actual && +	diff actual - <<-EOF +Submodule sm1 $head6..$head6-dirty: +EOF +" + +(cd sm1; git commit -mchange foo6 >/dev/null) && +head8=$(cd sm1; git rev-parse --verify HEAD | cut -c1-7) && +test_expect_success 'submodule is modified' " +	git diff-index -p --submodule=log HEAD >actual && +	diff actual - <<-EOF +Submodule sm1 $head6..$head8: +  > change +EOF +" + +test_expect_success 'modified submodule contains untracked content' " +	echo new > sm1/new-file && +	git diff-index -p --submodule=log HEAD >actual && +	diff actual - <<-EOF +Submodule sm1 $head6..$head8-dirty: +  > change +EOF +" + +test_expect_success 'modified submodule contains untracked and modifed content' " +	echo modification >> sm1/foo6 && +	git diff-index -p --submodule=log HEAD >actual && +	diff actual - <<-EOF +Submodule sm1 $head6..$head8-dirty: +  > change +EOF +" + +test_expect_success 'modified submodule contains modifed content' " +	rm -f sm1/new-file && +	git diff-index -p --submodule=log HEAD >actual && +	diff actual - <<-EOF +Submodule sm1 $head6..$head8-dirty: +  > change +EOF +" +  rm -rf sm1  test_expect_success 'deleted submodule' "  	git diff-index -p --submodule=log HEAD >actual &&  | 
