@matheusbsbs / matheus-bagliano / commits / ae6d5c1b6f
Fork 0

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>

Jens Lehmann committed Mar 11, 2010 at 22:50 UTC ae6d5c1b6f78ef48f606e5a267915fa31b37a679
2 files changed +33 -18
diff-lib.c
+27 -18
@@ -55,6 +55,29 @@ static int check_removed(const struct cache_entry *ce, struct stat *st)
55 return 0;
56 }
57
58 +/*
59 + * Has a file changed or has a submodule new commits or a dirty work tree?
60 + *
61 + * Return 1 when changes are detected, 0 otherwise. If the DIRTY_SUBMODULES
62 + * option is set, the caller does not only want to know if a submodule is
63 + * modified at all but wants to know all the conditions that are met (new
64 + * commits, untracked content and/or modified content).
65 + */
66 +static int match_stat_with_submodule(struct diff_options *diffopt,
67 + struct cache_entry *ce, struct stat *st,
68 + unsigned ce_option, unsigned *dirty_submodule)
69 +{
70 + int changed = ce_match_stat(ce, st, ce_option);
71 + if (S_ISGITLINK(ce->ce_mode)
72 + && !DIFF_OPT_TST(diffopt, IGNORE_SUBMODULES)
73 + && (!changed || DIFF_OPT_TST(diffopt, DIRTY_SUBMODULES))) {
74 + *dirty_submodule = is_submodule_modified(ce->name);
75 + if (*dirty_submodule)
76 + changed = 1;
77 + }
78 + return changed;
79 +}
80 +
81 int run_diff_files(struct rev_info *revs, unsigned int option)
82 {
83 int entries, i;
@@ -177,15 +200,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
200 ce->sha1, ce->name, 0);
201 continue;
202 }
180 - changed = ce_match_stat(ce, &st, ce_option);
181 - if (S_ISGITLINK(ce->ce_mode)
182 - && !DIFF_OPT_TST(&revs->diffopt, IGNORE_SUBMODULES)
183 - && (!changed || (revs->diffopt.output_format & DIFF_FORMAT_PATCH)
184 - || DIFF_OPT_TST(&revs->diffopt, DIRTY_SUBMODULES))) {
185 - dirty_submodule = is_submodule_modified(ce->name);
186 - if (dirty_submodule)
187 - changed = 1;
188 - }
203 + changed = match_stat_with_submodule(&revs->diffopt, ce, &st,
204 + ce_option, &dirty_submodule);
205 if (!changed) {
206 ce_mark_uptodate(ce);
207 if (!DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER))
@@ -241,15 +257,8 @@ static int get_stat_data(struct cache_entry *ce,
257 }
258 return -1;
259 }
244 - changed = ce_match_stat(ce, &st, 0);
245 - if (S_ISGITLINK(ce->ce_mode)
246 - && !DIFF_OPT_TST(diffopt, IGNORE_SUBMODULES)
247 - && (!changed || (diffopt->output_format & DIFF_FORMAT_PATCH)
248 - || DIFF_OPT_TST(diffopt, DIRTY_SUBMODULES))) {
249 - *dirty_submodule = is_submodule_modified(ce->name);
250 - if (*dirty_submodule)
251 - changed = 1;
252 - }
260 + changed = match_stat_with_submodule(diffopt, ce, &st,
261 + 0, dirty_submodule);
262 if (changed) {
263 mode = ce_mode_from_stat(ce, st.st_mode);
264 sha1 = null_sha1;
diff.c
+6
@@ -2628,6 +2628,12 @@ int diff_setup_done(struct diff_options *options)
2628 */
2629 if (options->pickaxe)
2630 DIFF_OPT_SET(options, RECURSIVE);
2631 + /*
2632 + * When patches are generated, submodules diffed against the work tree
2633 + * must be checked for dirtiness too so it can be shown in the output
2634 + */
2635 + if (options->output_format & DIFF_FORMAT_PATCH)
2636 + DIFF_OPT_SET(options, DIRTY_SUBMODULES);
2637
2638 if (options->detect_rename && options->rename_limit < 0)
2639 options->rename_limit = diff_rename_limit_default;