Code

Add script for importing bits-and-pieces to Git.
[git.git] / builtin-add.c
index 78989dad8cb07dee00054c3ea98d16eb493a05c9..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]);
@@ -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);