git-commit-vandalism/write-tree.c
Junio C Hamano a52139b47e Update write-tree to use cache-tree.
The updated write-tree reads from $GIT_DIR/index.aux to pick up
subtree objects information, updates the cache-tree with the
index, and updates index.aux file after writing a tree out of
the index file.

Until update-index and other programs that modify the index are
updated to maintain index.aux file, the index.aux file written
by the last write-tree will become stale immediately after they
update the index, which will result in the whole tree
recomputation just like the original write-tree.

The idea is to convert those commands to invalidate cache-tree
whenever they touch the index entries, and write updated
index.aux out.  After the index is updated with them, write-tree
will be able to reuse the parts of the cache-tree that have not
been touched.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-04-23 20:18:57 -07:00

46 lines
1004 B
C

/*
* GIT - The information manager from hell
*
* Copyright (C) Linus Torvalds, 2005
*/
#include "cache.h"
#include "tree.h"
#include "cache-tree.h"
static unsigned char active_cache_sha1[20];
static struct cache_tree *active_cache_tree;
static int missing_ok = 0;
static const char write_tree_usage[] = "git-write-tree [--missing-ok]";
int main(int argc, char **argv)
{
int entries;
setup_git_directory();
entries = read_cache_1(active_cache_sha1);
active_cache_tree = read_cache_tree(active_cache_sha1);
if (argc == 2) {
if (!strcmp(argv[1], "--missing-ok"))
missing_ok = 1;
else
die(write_tree_usage);
}
if (argc > 2)
die("too many options");
if (entries < 0)
die("git-write-tree: error reading cache");
if (cache_tree_update(active_cache_tree, active_cache, active_nr,
missing_ok))
die("git-write-tree: error building trees");
write_cache_tree(active_cache_sha1, active_cache_tree);
printf("%s\n", sha1_to_hex(active_cache_tree->sha1));
return 0;
}