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 10static int missing_ok =0; 11 12static const char write_tree_usage[] ="git-write-tree [--missing-ok]"; 13 14static struct cache_file cache_file; 15 16intmain(int argc,char**argv) 17{ 18int entries, was_valid, newfd; 19 20setup_git_directory(); 21 22 newfd =hold_index_file_for_update(&cache_file,get_index_file()); 23 entries =read_cache(); 24if(argc ==2) { 25if(!strcmp(argv[1],"--missing-ok")) 26 missing_ok =1; 27else 28die(write_tree_usage); 29} 30 31if(argc >2) 32die("too many options"); 33 34if(entries <0) 35die("git-write-tree: error reading cache"); 36 37if(!active_cache_tree) 38 active_cache_tree =cache_tree(); 39 40 was_valid =cache_tree_fully_valid(active_cache_tree); 41if(!was_valid) { 42if(cache_tree_update(active_cache_tree, 43 active_cache, active_nr, 44 missing_ok) <0) 45die("git-write-tree: error building trees"); 46if(0<= newfd) { 47if(!write_cache(newfd, active_cache, active_nr)) 48commit_index_file(&cache_file); 49} 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. 55 */ 56} 57printf("%s\n",sha1_to_hex(active_cache_tree->sha1)); 58return0; 59}