]> git.ipfire.org Git - thirdparty/git.git/blob - write-tree.c
Update write-tree to use cache-tree.
[thirdparty/git.git] / write-tree.c
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"
9
10 static unsigned char active_cache_sha1[20];
11 static struct cache_tree *active_cache_tree;
12
13 static int missing_ok = 0;
14
15 static const char write_tree_usage[] = "git-write-tree [--missing-ok]";
16
17 int main(int argc, char **argv)
18 {
19 int entries;
20
21 setup_git_directory();
22
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 }
31
32 if (argc > 2)
33 die("too many options");
34
35 if (entries < 0)
36 die("git-write-tree: error reading cache");
37
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);
42
43 printf("%s\n", sha1_to_hex(active_cache_tree->sha1));
44 return 0;
45 }