add: make pathless 'add [-u|-A]' warning a file-global function
authorJonathan Nieder <jrnieder@gmail.com>
Tue, 19 Mar 2013 22:45:26 +0000 (15:45 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 Mar 2013 14:41:42 +0000 (07:41 -0700)
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>
builtin/add.c
index ab1c9e8fb7a0f7c6f60cc78ff0f345838210459a..a4028eea9ee013559c9bbe2fd0b248874af23c8c 100644 (file)
@@ -28,6 +28,41 @@ struct update_callback_data {
        int add_errors;
 };
 
+static const char *option_with_implicit_dot;
+static const char *short_option_with_implicit_dot;
+
+static void warn_pathless_add(void)
+{
+       assert(option_with_implicit_dot && short_option_with_implicit_dot);
+
+       /*
+        * To be consistent with "git add -p" and most Git
+        * commands, we should default to being tree-wide, but
+        * this is not the original behavior and can't be
+        * changed until users trained themselves not to type
+        * "git add -u" or "git add -A". For now, we warn and
+        * keep the old behavior. Later, the behavior can be changed
+        * to tree-wide, keeping the warning for a while, and
+        * eventually we can drop the warning.
+        */
+       warning(_("The behavior of 'git add %s (or %s)' with no path argument from a\n"
+                 "subdirectory of the tree will change in Git 2.0 and should not be used anymore.\n"
+                 "To add content for the whole tree, run:\n"
+                 "\n"
+                 "  git add %s :/\n"
+                 "  (or git add %s :/)\n"
+                 "\n"
+                 "To restrict the command to the current directory, run:\n"
+                 "\n"
+                 "  git add %s .\n"
+                 "  (or git add %s .)\n"
+                 "\n"
+                 "With the current Git version, the command is restricted to the current directory."),
+               option_with_implicit_dot, short_option_with_implicit_dot,
+               option_with_implicit_dot, short_option_with_implicit_dot,
+               option_with_implicit_dot, short_option_with_implicit_dot);
+}
+
 static int fix_unmerged_status(struct diff_filepair *p,
                               struct update_callback_data *data)
 {
@@ -321,35 +356,6 @@ static int add_files(struct dir_struct *dir, int flags)
        return exit_status;
 }
 
-static void warn_pathless_add(const char *option_name, const char *short_name) {
-       /*
-        * To be consistent with "git add -p" and most Git
-        * commands, we should default to being tree-wide, but
-        * this is not the original behavior and can't be
-        * changed until users trained themselves not to type
-        * "git add -u" or "git add -A". For now, we warn and
-        * keep the old behavior. Later, the behavior can be changed
-        * to tree-wide, keeping the warning for a while, and
-        * eventually we can drop the warning.
-        */
-       warning(_("The behavior of 'git add %s (or %s)' with no path argument from a\n"
-                 "subdirectory of the tree will change in Git 2.0 and should not be used anymore.\n"
-                 "To add content for the whole tree, run:\n"
-                 "\n"
-                 "  git add %s :/\n"
-                 "  (or git add %s :/)\n"
-                 "\n"
-                 "To restrict the command to the current directory, run:\n"
-                 "\n"
-                 "  git add %s .\n"
-                 "  (or git add %s .)\n"
-                 "\n"
-                 "With the current Git version, the command is restricted to the current directory."),
-               option_name, short_name,
-               option_name, short_name,
-               option_name, short_name);
-}
-
 int cmd_add(int argc, const char **argv, const char *prefix)
 {
        int exit_status = 0;
@@ -360,8 +366,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
        int add_new_files;
        int require_pathspec;
        char *seen = NULL;
-       const char *option_with_implicit_dot = NULL;
-       const char *short_option_with_implicit_dot = NULL;
 
        git_config(add_config, NULL);
 
@@ -392,8 +396,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
        if (option_with_implicit_dot && !argc) {
                static const char *here[2] = { ".", NULL };
                if (prefix)
-                       warn_pathless_add(option_with_implicit_dot,
-                                         short_option_with_implicit_dot);
+                       warn_pathless_add();
                argc = 1;
                argv = here;
        }