git-remote: support remotes with a dot in the name
[gitweb.git] / builtin-read-tree.c
index 8869cedea1f9b07d78520858876cca614283d01b..8ba436dbace7ec25ec5768a5c6c84f3202f92159 100644 (file)
 #include "tree-walk.h"
 #include "cache-tree.h"
 #include "unpack-trees.h"
+#include "dir.h"
 #include "builtin.h"
 
-static struct object_list *trees = NULL;
+static struct object_list *trees;
 
 static int list_tree(unsigned char *sha1)
 {
@@ -53,7 +54,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
        struct name_entry entry;
        int cnt;
 
-       memcpy(it->sha1, tree->object.sha1, 20);
+       hashcpy(it->sha1, tree->object.sha1);
        desc.buf = tree->buffer;
        desc.size = tree->size;
        cnt = 0;
@@ -84,11 +85,11 @@ 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>] <sha1> [<sha2> [<sha3>]])";
 
 static struct lock_file lock_file;
 
-int cmd_read_tree(int argc, const char **argv, const char *prefix)
+int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
 {
        int i, newfd, stage = 0;
        unsigned char sha1[20];
@@ -100,9 +101,7 @@ int cmd_read_tree(int argc, const char **argv, const char *prefix)
        setup_git_directory();
        git_config(git_default_config);
 
-       newfd = hold_lock_file_for_update(&lock_file, get_index_file());
-       if (newfd < 0)
-               die("unable to create new index file");
+       newfd = hold_lock_file_for_update(&lock_file, get_index_file(), 1);
 
        git_config(git_default_config);
 
@@ -180,6 +179,23 @@ int cmd_read_tree(int argc, const char **argv, const char *prefix)
                        continue;
                }
 
+               if (!strncmp(arg, "--exclude-per-directory=", 24)) {
+                       struct dir_struct *dir;
+
+                       if (opts.dir)
+                               die("more than one --exclude-per-directory are given.");
+
+                       dir = calloc(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);
@@ -192,6 +208,8 @@ int cmd_read_tree(int argc, const char **argv, const char *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);