]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin-add.c
Add script for importing bits-and-pieces to Git.
[thirdparty/git.git] / builtin-add.c
index c1b229a9d8a026ec88cdbf0492856021cacc8097..006fd08769dcf01c20b0c23dd7cf6c4aae931c68 100644 (file)
@@ -97,35 +97,6 @@ static void treat_gitlinks(const char **pathspec)
        }
 }
 
-static void fill_directory(struct dir_struct *dir, const char **pathspec,
-               int ignored_too)
-{
-       const char *path, *base;
-       int baselen;
-
-       /* Set up the default git porcelain excludes */
-       memset(dir, 0, sizeof(*dir));
-       if (!ignored_too) {
-               dir->flags |= DIR_COLLECT_IGNORED;
-               setup_standard_excludes(dir);
-       }
-
-       /*
-        * Calculate common prefix for the pathspec, and
-        * use that to optimize the directory walk
-        */
-       baselen = common_prefix(pathspec);
-       path = ".";
-       base = "";
-       if (baselen)
-               path = base = xmemdupz(*pathspec, baselen);
-
-       /* Read the directory and prune it */
-       read_directory(dir, path, base, baselen, pathspec);
-       if (pathspec)
-               prune_directory(dir, pathspec, baselen);
-}
-
 static void refresh(int verbose, const char **pathspec)
 {
        char *seen;
@@ -134,8 +105,8 @@ static void refresh(int verbose, const char **pathspec)
        for (specs = 0; pathspec[specs];  specs++)
                /* nothing */;
        seen = xcalloc(specs, 1);
-       refresh_index(&the_index, verbose ? REFRESH_SAY_CHANGED : REFRESH_QUIET,
-                     pathspec, seen);
+       refresh_index(&the_index, verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET,
+                     pathspec, seen, "Unstaged changes after refreshing the index:");
        for (i = 0; i < specs; i++) {
                if (!seen[i])
                        die("pathspec '%s' did not match any files", pathspec[i]);
@@ -189,7 +160,7 @@ int interactive_add(int argc, const char **argv, const char *prefix)
        return status;
 }
 
-int edit_patch(int argc, const char **argv, const char *prefix)
+static int edit_patch(int argc, const char **argv, const char *prefix)
 {
        char *file = xstrdup(git_path("ADD_EDIT.patch"));
        const char *apply_argv[] = { "apply", "--recount", "--cached",
@@ -220,7 +191,7 @@ int edit_patch(int argc, const char **argv, const char *prefix)
        launch_editor(file, NULL, NULL);
 
        if (stat(file, &st))
-               die("Could not stat '%s'", file);
+               die_errno("Could not stat '%s'", file);
        if (!st.st_size)
                die("Empty patch. Aborted.");
 
@@ -298,6 +269,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
        int add_new_files;
        int require_pathspec;
 
+       git_config(add_config, NULL);
+
        argc = parse_options(argc, argv, prefix, builtin_add_options,
                          builtin_add_usage, PARSE_OPT_KEEP_ARGV0);
        if (patch_interactive)
@@ -305,8 +278,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
        if (add_interactive)
                exit(interactive_add(argc - 1, argv + 1, prefix));
 
-       git_config(add_config, NULL);
-
        if (edit_interactive)
                return(edit_patch(argc, argv, prefix));
        argc--;
@@ -343,9 +314,21 @@ int cmd_add(int argc, const char **argv, const char *prefix)
                die("index file corrupt");
        treat_gitlinks(pathspec);
 
-       if (add_new_files)
+       if (add_new_files) {
+               int baselen;
+
+               /* Set up the default git porcelain excludes */
+               memset(&dir, 0, sizeof(dir));
+               if (!ignored_too) {
+                       dir.flags |= DIR_COLLECT_IGNORED;
+                       setup_standard_excludes(&dir);
+               }
+
                /* This picks up the paths that are not tracked */
-               fill_directory(&dir, pathspec, ignored_too);
+               baselen = fill_directory(&dir, pathspec);
+               if (pathspec)
+                       prune_directory(&dir, pathspec, baselen);
+       }
 
        if (refresh_only) {
                refresh(verbose, pathspec);