提交 d539de9f 编写于 作者: J Junio C Hamano

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
......@@ -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;
}
......
......@@ -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))
......
......@@ -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;
}
}
......
......@@ -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
......
......@@ -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);
......
......@@ -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 &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册