builtin/rm.c: consolidate error reporting for removing submodules

We have two (not identical) copies of error reporting when attempting to remove submodules that have their repositories embedded within them. Add a helper function so that we do not have to repeat similar error messages with subtly different wording without a good reason. Noticed by Jiang Xin. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jul 25, 2013 at 23:05 UTC 658ff473cf35217253aa956508ff0e42993711ad
1 file changed +20 -21
builtin/rm.c
+20 -21
@@ -57,6 +57,21 @@ static void print_error_files(struct string_list *files_list,
57 }
58 }
59
60 +static void error_removing_concrete_submodules(struct string_list *files, int *errs)
61 +{
62 + print_error_files(files,
63 + Q_("the following submodule (or one of its nested "
64 + "submodules)\n"
65 + "uses a .git directory:",
66 + "the following submodules (or one of its nested "
67 + "submodules)\n"
68 + "use a .git directory:", files->nr),
69 + _("\n(use 'rm -rf' if you really want to remove "
70 + "it including all of its history)"),
71 + errs);
72 + string_list_clear(files, 0);
73 +}
74 +
75 static int check_submodules_use_gitfiles(void)
76 {
77 int i;
@@ -85,16 +100,8 @@ static int check_submodules_use_gitfiles(void)
100 if (!submodule_uses_gitfile(name))
101 string_list_append(&files, name);
102 }
88 - print_error_files(&files,
89 - Q_("the following submodule (or one of its nested "
90 - "submodules)\n uses a .git directory:",
91 - "the following submodules (or one of its nested "
92 - "submodules)\n use a .git directory:",
93 - files.nr),
94 - _("\n(use 'rm -rf' if you really want to remove "
95 - "it including all of its history)"),
96 - &errs);
97 - string_list_clear(&files, 0);
103 +
104 + error_removing_concrete_submodules(&files, &errs);
105
106 return errs;
107 }
@@ -236,17 +243,9 @@ static int check_local_mod(unsigned char *head, int index_only)
243 " or -f to force removal)"),
244 &errs);
245 string_list_clear(&files_cached, 0);
239 - print_error_files(&files_submodule,
240 - Q_("the following submodule (or one of its nested "
241 - "submodule)\nuses a .git directory:",
242 - "the following submodules (or one of its nested "
243 - "submodule)\nuse a .git directory:",
244 - files_submodule.nr),
245 - _("\n(use 'rm -rf' if you really "
246 - "want to remove it including all "
247 - "of its history)"),
248 - &errs);
249 - string_list_clear(&files_submodule, 0);
246 +
247 + error_removing_concrete_submodules(&files_submodule, &errs);
248 +
249 print_error_files(&files_local,
250 Q_("the following file has local modifications:",
251 "the following files have local modifications:",