2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
8 #include "cache-tree.h"
10 static int missing_ok = 0;
12 static const char write_tree_usage[] = "git-write-tree [--missing-ok]";
14 static struct cache_file cache_file;
16 int main(int argc, char **argv)
18 int entries, was_valid, newfd;
20 setup_git_directory();
22 newfd = hold_index_file_for_update(&cache_file, get_index_file());
23 entries = read_cache();
25 if (!strcmp(argv[1], "--missing-ok"))
28 die(write_tree_usage);
32 die("too many options");
35 die("git-write-tree: error reading cache");
37 if (!active_cache_tree)
38 active_cache_tree = cache_tree();
40 was_valid = cache_tree_fully_valid(active_cache_tree);
42 if (cache_tree_update(active_cache_tree,
43 active_cache, active_nr,
45 die("git-write-tree: error building trees");
47 if (!write_cache(newfd, active_cache, active_nr))
48 commit_index_file(&cache_file);
50 /* Not being able to write is fine -- we are only interested
51 * in updating the cache-tree part, and if the next caller
52 * ends up using the old index with unupdated cache-tree part
53 * it misses the work we did here, but that is just a
54 * performance penalty and not a big deal.
57 printf("%s\n", sha1_to_hex(active_cache_tree->sha1));