2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
8 #include "cache-tree.h"
10 static int missing_ok
= 0;
11 static char *prefix
= NULL
;
13 static const char write_tree_usage
[] =
14 "git-write-tree [--missing-ok] [--prefix=<prefix>/]";
16 static struct cache_file cache_file
;
18 int main(int argc
, char **argv
)
20 int entries
, was_valid
, newfd
;
22 setup_git_directory();
24 newfd
= hold_index_file_for_update(&cache_file
, get_index_file());
25 entries
= read_cache();
29 if (!strcmp(arg
, "--missing-ok"))
31 else if (!strncmp(arg
, "--prefix=", 9))
34 die(write_tree_usage
);
39 die("too many options");
42 die("git-write-tree: error reading cache");
44 if (!active_cache_tree
)
45 active_cache_tree
= cache_tree();
47 was_valid
= cache_tree_fully_valid(active_cache_tree
);
49 if (cache_tree_update(active_cache_tree
,
50 active_cache
, active_nr
,
52 die("git-write-tree: error building trees");
54 if (!write_cache(newfd
, active_cache
, active_nr
))
55 commit_index_file(&cache_file
);
57 /* Not being able to write is fine -- we are only interested
58 * in updating the cache-tree part, and if the next caller
59 * ends up using the old index with unupdated cache-tree part
60 * it misses the work we did here, but that is just a
61 * performance penalty and not a big deal.
65 struct cache_tree
*subtree
=
66 cache_tree_find(active_cache_tree
, prefix
);
67 printf("%s\n", sha1_to_hex(subtree
->sha1
));
70 printf("%s\n", sha1_to_hex(active_cache_tree
->sha1
));