add: make pathless 'add [-u|-A]' warning a file-global function

Currently warn_pathless_add() is only called directly by cmd_add(), but that is about to change. Move its definition higher in the file and pass the "--update" or "--all" option name used in its message through globals instead of function arguments to make it easier to call without passing values that will not change through the call chain. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Mar 19, 2013 at 15:45 UTC e24afab09137d785f07e62aee8936b548436d21f
1 file changed +36 -33
builtin/add.c
+36 -33
@@ -28,6 +28,41 @@ struct update_callback_data {
28 int add_errors;
29 };
30
31 +static const char *option_with_implicit_dot;
32 +static const char *short_option_with_implicit_dot;
33 +
34 +static void warn_pathless_add(void)
35 +{
36 + assert(option_with_implicit_dot && short_option_with_implicit_dot);
37 +
38 + /*
39 + * To be consistent with "git add -p" and most Git
40 + * commands, we should default to being tree-wide, but
41 + * this is not the original behavior and can't be
42 + * changed until users trained themselves not to type
43 + * "git add -u" or "git add -A". For now, we warn and
44 + * keep the old behavior. Later, the behavior can be changed
45 + * to tree-wide, keeping the warning for a while, and
46 + * eventually we can drop the warning.
47 + */
48 + warning(_("The behavior of 'git add %s (or %s)' with no path argument from a\n"
49 + "subdirectory of the tree will change in Git 2.0 and should not be used anymore.\n"
50 + "To add content for the whole tree, run:\n"
51 + "\n"
52 + " git add %s :/\n"
53 + " (or git add %s :/)\n"
54 + "\n"
55 + "To restrict the command to the current directory, run:\n"
56 + "\n"
57 + " git add %s .\n"
58 + " (or git add %s .)\n"
59 + "\n"
60 + "With the current Git version, the command is restricted to the current directory."),
61 + option_with_implicit_dot, short_option_with_implicit_dot,
62 + option_with_implicit_dot, short_option_with_implicit_dot,
63 + option_with_implicit_dot, short_option_with_implicit_dot);
64 +}
65 +
66 static int fix_unmerged_status(struct diff_filepair *p,
67 struct update_callback_data *data)
68 {
@@ -321,35 +356,6 @@ static int add_files(struct dir_struct *dir, int flags)
356 return exit_status;
357 }
358
324 -static void warn_pathless_add(const char *option_name, const char *short_name) {
325 - /*
326 - * To be consistent with "git add -p" and most Git
327 - * commands, we should default to being tree-wide, but
328 - * this is not the original behavior and can't be
329 - * changed until users trained themselves not to type
330 - * "git add -u" or "git add -A". For now, we warn and
331 - * keep the old behavior. Later, the behavior can be changed
332 - * to tree-wide, keeping the warning for a while, and
333 - * eventually we can drop the warning.
334 - */
335 - warning(_("The behavior of 'git add %s (or %s)' with no path argument from a\n"
336 - "subdirectory of the tree will change in Git 2.0 and should not be used anymore.\n"
337 - "To add content for the whole tree, run:\n"
338 - "\n"
339 - " git add %s :/\n"
340 - " (or git add %s :/)\n"
341 - "\n"
342 - "To restrict the command to the current directory, run:\n"
343 - "\n"
344 - " git add %s .\n"
345 - " (or git add %s .)\n"
346 - "\n"
347 - "With the current Git version, the command is restricted to the current directory."),
348 - option_name, short_name,
349 - option_name, short_name,
350 - option_name, short_name);
351 -}
352 -
359 int cmd_add(int argc, const char **argv, const char *prefix)
360 {
361 int exit_status = 0;
@@ -360,8 +366,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
366 int add_new_files;
367 int require_pathspec;
368 char *seen = NULL;
363 - const char *option_with_implicit_dot = NULL;
364 - const char *short_option_with_implicit_dot = NULL;
369
370 git_config(add_config, NULL);
371
@@ -392,8 +396,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
396 if (option_with_implicit_dot && !argc) {
397 static const char *here[2] = { ".", NULL };
398 if (prefix)
395 - warn_pathless_add(option_with_implicit_dot,
396 - short_option_with_implicit_dot);
399 + warn_pathless_add();
400 argc = 1;
401 argv = here;
402 }