From: Junio C Hamano Date: Mon, 13 Feb 2012 06:42:42 +0000 (-0800) Subject: Merge branch 'nd/cache-tree-api-refactor' X-Git-Tag: v1.7.10-rc0~97 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/a7844827da8273dcf030b9313bc381da3eac011d?ds=inline;hp=-c Merge branch 'nd/cache-tree-api-refactor' * nd/cache-tree-api-refactor: cache-tree: update API to take abitrary flags --- a7844827da8273dcf030b9313bc381da3eac011d diff --combined builtin/commit.c index eae5a29aeb,bf42bb384d..3714582e19 --- a/builtin/commit.c +++ b/builtin/commit.c @@@ -196,16 -196,16 +196,16 @@@ static void determine_whence(struct wt_ static const char *whence_s(void) { - char *s = ""; + const char *s = ""; switch (whence) { case FROM_COMMIT: break; case FROM_MERGE: - s = "merge"; + s = _("merge"); break; case FROM_CHERRY_PICK: - s = "cherry-pick"; + s = _("cherry-pick"); break; } @@@ -400,7 -400,7 +400,7 @@@ static char *prepare_index(int argc, co fd = hold_locked_index(&index_lock, 1); add_files_to_cache(also ? prefix : NULL, pathspec, 0); refresh_cache_or_die(refresh_flags); - update_main_cache_tree(1); + update_main_cache_tree(WRITE_TREE_SILENT); if (write_cache(fd, active_cache, active_nr) || close_lock_file(&index_lock)) die(_("unable to write new_index file")); @@@ -421,7 -421,7 +421,7 @@@ fd = hold_locked_index(&index_lock, 1); refresh_cache_or_die(refresh_flags); if (active_cache_changed) { - update_main_cache_tree(1); + update_main_cache_tree(WRITE_TREE_SILENT); if (write_cache(fd, active_cache, active_nr) || commit_locked_index(&index_lock)) die(_("unable to write new_index file")); @@@ -543,7 -543,6 +543,7 @@@ static void determine_author_info(struc if (author_message) { const char *a, *lb, *rb, *eol; + size_t len; a = strstr(author_message_buffer, "\nauthor "); if (!a) @@@ -564,11 -563,6 +564,11 @@@ (a + strlen("\nauthor ")))); email = xmemdupz(lb + strlen("<"), rb - (lb + strlen("<"))); date = xmemdupz(rb + strlen("> "), eol - (rb + strlen("> "))); + len = eol - (rb + strlen("> ")); + date = xmalloc(len + 2); + *date = '@'; + memcpy(date + 1, rb + strlen("> "), len); + date[len + 1] = '\0'; } if (force_author) { diff --combined cache-tree.c index bf03cb7fce,c1eacafd19..28ed6574a2 --- a/cache-tree.c +++ b/cache-tree.c @@@ -150,15 -150,16 +150,16 @@@ void cache_tree_invalidate_path(struct } static int verify_cache(struct cache_entry **cache, - int entries, int silent) + int entries, int flags) { int i, funny; + int silent = flags & WRITE_TREE_SILENT; /* Verify that the tree is merged */ funny = 0; for (i = 0; i < entries; i++) { struct cache_entry *ce = cache[i]; - if (ce_stage(ce) || (ce->ce_flags & CE_INTENT_TO_ADD)) { + if (ce_stage(ce)) { if (silent) return -1; if (10 < ++funny) { @@@ -241,10 -242,11 +242,11 @@@ static int update_one(struct cache_tre int entries, const char *base, int baselen, - int missing_ok, - int dryrun) + int flags) { struct strbuf buffer; + int missing_ok = flags & WRITE_TREE_MISSING_OK; + int dryrun = flags & WRITE_TREE_DRY_RUN; int i; if (0 <= it->entry_count && has_sha1_file(it->sha1)) @@@ -288,8 -290,7 +290,7 @@@ cache + i, entries - i, path, baselen + sublen + 1, - missing_ok, - dryrun); + flags); if (subcnt < 0) return subcnt; i += subcnt - 1; @@@ -338,8 -339,8 +339,8 @@@ mode, sha1_to_hex(sha1), entlen+baselen, path); } - if (ce->ce_flags & CE_REMOVE) - continue; /* entry being removed */ + if (ce->ce_flags & (CE_REMOVE | CE_INTENT_TO_ADD)) + continue; /* entry being removed or placeholder */ strbuf_grow(&buffer, entlen + 100); strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0'); @@@ -371,15 -372,13 +372,13 @@@ int cache_tree_update(struct cache_tree *it, struct cache_entry **cache, int entries, - int missing_ok, - int dryrun, - int silent) + int flags) { int i; - i = verify_cache(cache, entries, silent); + i = verify_cache(cache, entries, flags); if (i) return i; - i = update_one(it, cache, entries, "", 0, missing_ok, dryrun); + i = update_one(it, cache, entries, "", 0, flags); if (i < 0) return i; return 0; @@@ -572,11 -571,9 +571,9 @@@ int write_cache_as_tree(unsigned char * was_valid = cache_tree_fully_valid(active_cache_tree); if (!was_valid) { - int missing_ok = flags & WRITE_TREE_MISSING_OK; - if (cache_tree_update(active_cache_tree, active_cache, active_nr, - missing_ok, 0, 0) < 0) + flags) < 0) return WRITE_TREE_UNMERGED_INDEX; if (0 <= newfd) { if (!write_cache(newfd, active_cache, active_nr) && @@@ -672,10 -669,10 +669,10 @@@ int cache_tree_matches_traversal(struc return 0; } - int update_main_cache_tree (int silent) + int update_main_cache_tree(int flags) { if (!the_index.cache_tree) the_index.cache_tree = cache_tree(); return cache_tree_update(the_index.cache_tree, - the_index.cache, the_index.cache_nr, 0, 0, silent); + the_index.cache, the_index.cache_nr, flags); }