Merge branch 'cr/tag-options'
[gitweb.git] / builtin-add.c
index f61681c3ae186e1a6f96c5f7d4d6b978d0de5ddb..cf815a0b8ef0e588cfaf25f71747ba7248d19d70 100644 (file)
@@ -21,7 +21,6 @@ static const char * const builtin_add_usage[] = {
 };
 
 static int take_worktree_changes;
-static const char *excludes_file;
 
 static void prune_directory(struct dir_struct *dir, const char **pathspec, int prefix)
 {
@@ -61,12 +60,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec,
        memset(dir, 0, sizeof(*dir));
        if (!ignored_too) {
                dir->collect_ignored = 1;
-               dir->exclude_per_dir = ".gitignore";
-               path = git_path("info/exclude");
-               if (!access(path, R_OK))
-                       add_excludes_from_file(dir, path);
-               if (excludes_file != NULL && !access(excludes_file, R_OK))
-                       add_excludes_from_file(dir, excludes_file);
+               setup_standard_excludes(dir);
        }
 
        /*
@@ -111,7 +105,7 @@ static void update_callback(struct diff_queue_struct *q,
        }
 }
 
-static void update(int verbose, const char *prefix, const char **files)
+void add_files_to_cache(int verbose, const char *prefix, const char **files)
 {
        struct rev_info rev;
        init_revisions(&rev, prefix);
@@ -120,9 +114,7 @@ static void update(int verbose, const char *prefix, const char **files)
        rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
        rev.diffopt.format_callback = update_callback;
        rev.diffopt.format_callback_data = &verbose;
-       if (read_cache() < 0)
-               die("index file corrupt");
-       run_diff_files(&rev, 0);
+       run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
 }
 
 static void refresh(int verbose, const char **pathspec)
@@ -143,16 +135,11 @@ static void refresh(int verbose, const char **pathspec)
         free(seen);
 }
 
-static int git_add_config(const char *var, const char *value)
+int interactive_add(void)
 {
-       if (!strcmp(var, "core.excludesfile")) {
-               if (!value)
-                       die("core.excludesfile without value");
-               excludes_file = xstrdup(value);
-               return 0;
-       }
+       const char *argv[2] = { "add--interactive", NULL };
 
-       return git_default_config(var, value);
+       return run_command_v_opt(argv, RUN_GIT_CMD);
 }
 
 static struct lock_file lock_file;
@@ -183,20 +170,19 @@ int cmd_add(int argc, const char **argv, const char *prefix)
        argc = parse_options(argc, argv, builtin_add_options,
                          builtin_add_usage, 0);
        if (add_interactive) {
-               const char *args[] = { "add--interactive", NULL };
-
                if (add_interactive != 1 || orig_argc != 2)
                        die("add --interactive does not take any parameters");
-               execv_git_cmd(args);
-               exit(1);
+               exit(interactive_add());
        }
 
-       git_config(git_add_config);
+       git_config(git_default_config);
 
        newfd = hold_locked_index(&lock_file, 1);
 
        if (take_worktree_changes) {
-               update(verbose, prefix, argv);
+               if (read_cache() < 0)
+                       die("index file corrupt");
+               add_files_to_cache(verbose, prefix, argv);
                goto finish;
        }