Refactor dirty submodule detection in diff-lib.c
Moving duplicated code into the new function match_stat_with_submodule(). Replacing the implicit activation of detailed checks for the dirtiness of submodules when DIFF_FORMAT_PATCH was selected with explicitly setting the recently added DIFF_OPT_DIRTY_SUBMODULES option in diff_setup_done(). Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
9297f77e6d
commit
ae6d5c1b6f
45
diff-lib.c
45
diff-lib.c
@ -55,6 +55,29 @@ static int check_removed(const struct cache_entry *ce, struct stat *st)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Has a file changed or has a submodule new commits or a dirty work tree?
|
||||||
|
*
|
||||||
|
* Return 1 when changes are detected, 0 otherwise. If the DIRTY_SUBMODULES
|
||||||
|
* option is set, the caller does not only want to know if a submodule is
|
||||||
|
* modified at all but wants to know all the conditions that are met (new
|
||||||
|
* commits, untracked content and/or modified content).
|
||||||
|
*/
|
||||||
|
static int match_stat_with_submodule(struct diff_options *diffopt,
|
||||||
|
struct cache_entry *ce, struct stat *st,
|
||||||
|
unsigned ce_option, unsigned *dirty_submodule)
|
||||||
|
{
|
||||||
|
int changed = ce_match_stat(ce, st, ce_option);
|
||||||
|
if (S_ISGITLINK(ce->ce_mode)
|
||||||
|
&& !DIFF_OPT_TST(diffopt, IGNORE_SUBMODULES)
|
||||||
|
&& (!changed || DIFF_OPT_TST(diffopt, DIRTY_SUBMODULES))) {
|
||||||
|
*dirty_submodule = is_submodule_modified(ce->name);
|
||||||
|
if (*dirty_submodule)
|
||||||
|
changed = 1;
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
int run_diff_files(struct rev_info *revs, unsigned int option)
|
int run_diff_files(struct rev_info *revs, unsigned int option)
|
||||||
{
|
{
|
||||||
int entries, i;
|
int entries, i;
|
||||||
@ -177,15 +200,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
|
|||||||
ce->sha1, ce->name, 0);
|
ce->sha1, ce->name, 0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
changed = ce_match_stat(ce, &st, ce_option);
|
changed = match_stat_with_submodule(&revs->diffopt, ce, &st,
|
||||||
if (S_ISGITLINK(ce->ce_mode)
|
ce_option, &dirty_submodule);
|
||||||
&& !DIFF_OPT_TST(&revs->diffopt, IGNORE_SUBMODULES)
|
|
||||||
&& (!changed || (revs->diffopt.output_format & DIFF_FORMAT_PATCH)
|
|
||||||
|| DIFF_OPT_TST(&revs->diffopt, DIRTY_SUBMODULES))) {
|
|
||||||
dirty_submodule = is_submodule_modified(ce->name);
|
|
||||||
if (dirty_submodule)
|
|
||||||
changed = 1;
|
|
||||||
}
|
|
||||||
if (!changed) {
|
if (!changed) {
|
||||||
ce_mark_uptodate(ce);
|
ce_mark_uptodate(ce);
|
||||||
if (!DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER))
|
if (!DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER))
|
||||||
@ -241,15 +257,8 @@ static int get_stat_data(struct cache_entry *ce,
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
changed = ce_match_stat(ce, &st, 0);
|
changed = match_stat_with_submodule(diffopt, ce, &st,
|
||||||
if (S_ISGITLINK(ce->ce_mode)
|
0, dirty_submodule);
|
||||||
&& !DIFF_OPT_TST(diffopt, IGNORE_SUBMODULES)
|
|
||||||
&& (!changed || (diffopt->output_format & DIFF_FORMAT_PATCH)
|
|
||||||
|| DIFF_OPT_TST(diffopt, DIRTY_SUBMODULES))) {
|
|
||||||
*dirty_submodule = is_submodule_modified(ce->name);
|
|
||||||
if (*dirty_submodule)
|
|
||||||
changed = 1;
|
|
||||||
}
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
mode = ce_mode_from_stat(ce, st.st_mode);
|
mode = ce_mode_from_stat(ce, st.st_mode);
|
||||||
sha1 = null_sha1;
|
sha1 = null_sha1;
|
||||||
|
|||||||
6
diff.c
6
diff.c
@ -2628,6 +2628,12 @@ int diff_setup_done(struct diff_options *options)
|
|||||||
*/
|
*/
|
||||||
if (options->pickaxe)
|
if (options->pickaxe)
|
||||||
DIFF_OPT_SET(options, RECURSIVE);
|
DIFF_OPT_SET(options, RECURSIVE);
|
||||||
|
/*
|
||||||
|
* When patches are generated, submodules diffed against the work tree
|
||||||
|
* must be checked for dirtiness too so it can be shown in the output
|
||||||
|
*/
|
||||||
|
if (options->output_format & DIFF_FORMAT_PATCH)
|
||||||
|
DIFF_OPT_SET(options, DIRTY_SUBMODULES);
|
||||||
|
|
||||||
if (options->detect_rename && options->rename_limit < 0)
|
if (options->detect_rename && options->rename_limit < 0)
|
||||||
options->rename_limit = diff_rename_limit_default;
|
options->rename_limit = diff_rename_limit_default;
|
||||||
|
|||||||
Reference in New Issue
Block a user