1 /*
2 * GIT - The information manager from hell
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
6 #include "cache.h"
7 #include "tree.h"
8 #include "cache-tree.h"
10 static unsigned char active_cache_sha1[20];
11 static struct cache_tree *active_cache_tree;
13 static int missing_ok = 0;
15 static const char write_tree_usage[] = "git-write-tree [--missing-ok]";
17 int main(int argc, char **argv)
18 {
19 int entries;
21 setup_git_directory();
23 entries = read_cache_1(active_cache_sha1);
24 active_cache_tree = read_cache_tree(active_cache_sha1);
25 if (argc == 2) {
26 if (!strcmp(argv[1], "--missing-ok"))
27 missing_ok = 1;
28 else
29 die(write_tree_usage);
30 }
32 if (argc > 2)
33 die("too many options");
35 if (entries < 0)
36 die("git-write-tree: error reading cache");
38 if (cache_tree_update(active_cache_tree, active_cache, active_nr,
39 missing_ok))
40 die("git-write-tree: error building trees");
41 write_cache_tree(active_cache_sha1, active_cache_tree);
43 printf("%s\n", sha1_to_hex(active_cache_tree->sha1));
44 return 0;
45 }