Code

Teach "fsck" not to follow subproject links
[git.git] / builtin-read-tree.c
index c1867d2a0052ad797481f3d5f9aa544952ff251b..316fb0f8dae022b35a89b71c94a22331a77a500a 100644 (file)
@@ -10,6 +10,7 @@
 #include "tree-walk.h"
 #include "cache-tree.h"
 #include "unpack-trees.h"
+#include "dir.h"
 #include "builtin.h"
 
 static struct object_list *trees;
@@ -54,8 +55,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
        int cnt;
 
        hashcpy(it->sha1, tree->object.sha1);
-       desc.buf = tree->buffer;
-       desc.size = tree->size;
+       init_tree_desc(&desc, tree->buffer, tree->size);
        cnt = 0;
        while (tree_entry(&desc, &entry)) {
                if (!S_ISDIR(entry.mode))
@@ -84,7 +84,7 @@ static void prime_cache_tree(void)
 
 }
 
-static const char read_tree_usage[] = "git-read-tree (<sha> | [[-m [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] <sha1> [<sha2> [<sha3>]])";
+static const char read_tree_usage[] = "git-read-tree (<sha> | [[-m [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] [--index-output=<file>] <sha1> [<sha2> [<sha3>]])";
 
 static struct lock_file lock_file;
 
@@ -100,7 +100,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
        setup_git_directory();
        git_config(git_default_config);
 
-       newfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1);
+       newfd = hold_locked_index(&lock_file, 1);
 
        git_config(git_default_config);
 
@@ -128,11 +128,16 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
                        continue;
                }
 
+               if (!prefixcmp(arg, "--index-output=")) {
+                       set_alternate_index_output(arg + 15);
+                       continue;
+               }
+
                /* "--prefix=<subdirectory>/" means keep the current index
                 *  entries and put the entries from the tree under the
                 * given subdirectory.
                 */
-               if (!strncmp(arg, "--prefix=", 9)) {
+               if (!prefixcmp(arg, "--prefix=")) {
                        if (stage || opts.merge || opts.prefix)
                                usage(read_tree_usage);
                        opts.prefix = arg + 9;
@@ -178,6 +183,23 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
                        continue;
                }
 
+               if (!prefixcmp(arg, "--exclude-per-directory=")) {
+                       struct dir_struct *dir;
+
+                       if (opts.dir)
+                               die("more than one --exclude-per-directory are given.");
+
+                       dir = xcalloc(1, sizeof(*opts.dir));
+                       dir->show_ignored = 1;
+                       dir->exclude_per_dir = arg + 24;
+                       opts.dir = dir;
+                       /* We do not need to nor want to do read-directory
+                        * here; we are merely interested in reusing the
+                        * per directory ignore stack mechanism.
+                        */
+                       continue;
+               }
+
                /* using -u and -i at the same time makes no sense */
                if (1 < opts.index_only + opts.update)
                        usage(read_tree_usage);
@@ -190,6 +212,8 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
        }
        if ((opts.update||opts.index_only) && !opts.merge)
                usage(read_tree_usage);
+       if ((opts.dir && !opts.update))
+               die("--exclude-per-directory is meaningless unless -u");
 
        if (opts.prefix) {
                int pfxlen = strlen(opts.prefix);
@@ -209,6 +233,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
                if (0 <= pos)
                        die("file '%.*s' already exists.",
                                        pfxlen-1, opts.prefix);
+               opts.pos = -1 - pos;
        }
 
        if (opts.merge) {
@@ -248,7 +273,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
        }
 
        if (write_cache(newfd, active_cache, active_nr) ||
-           close(newfd) || commit_lock_file(&lock_file))
+           close(newfd) || commit_locked_index(&lock_file))
                die("unable to write new index file");
        return 0;
 }