From: Junio C Hamano Date: Sun, 18 Jun 2006 00:56:52 +0000 (-0700) Subject: Merge branch 'jc/rw-prefix' X-Git-Tag: v1.4.1-rc1~3^2~24 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=75c3a5ccdf114b5485e4828db1923bf4a35b19e2;p=git.git Merge branch 'jc/rw-prefix' * jc/rw-prefix: read-tree: reorganize bind_merge code. write-tree: --prefix= read-tree: --prefix=/ option. --- 75c3a5ccdf114b5485e4828db1923bf4a35b19e2 diff --cc builtin-read-tree.c index bb50fbd27,fb1d6829d..04506da89 --- a/builtin-read-tree.c +++ b/builtin-read-tree.c @@@ -409,10 -367,11 +410,11 @@@ static int unpack_trees(merge_fn_t fn if (len) { posns = xmalloc(len * sizeof(struct tree_entry_list *)); for (i = 0; i < len; i++) { - posns[i] = ((struct tree *) posn->item)->entries; + posns[i] = create_tree_entry_list((struct tree *) posn->item); posn = posn->next; } - if (unpack_trees_rec(posns, len, "", fn, &indpos)) + if (unpack_trees_rec(posns, len, prefix ? prefix : "", + fn, &indpos)) return -1; } @@@ -851,13 -782,13 +875,13 @@@ static void prime_cache_tree(void } - static const char read_tree_usage[] = "git-read-tree ( | -m [--aggressive] [-u | -i] [ []])"; + static const char read_tree_usage[] = "git-read-tree ( | [[-m [--aggressive] | --reset | --prefix=] [-u | -i]] [ []])"; -static struct cache_file cache_file; +static struct lock_file lock_file; -int main(int argc, char **argv) +int cmd_read_tree(int argc, const char **argv, char **envp) { - int i, newfd, reset, stage = 0; + int i, newfd, stage = 0; unsigned char sha1[20]; merge_fn_t fn = NULL; @@@ -896,12 -827,24 +920,27 @@@ continue; } + /* "--prefix=/" means keep the current index + * entries and put the entries from the tree under the + * given subdirectory. + */ + if (!strncmp(arg, "--prefix=", 9)) { + if (stage || merge || prefix) + usage(read_tree_usage); + prefix = arg + 9; + merge = 1; + stage = 1; + if (read_cache_unmerged()) + die("you need to resolve your current index first"); + continue; + } + - /* This differs from "-m" in that we'll silently ignore unmerged entries */ + /* This differs from "-m" in that we'll silently ignore + * unmerged entries and overwrite working tree files that + * correspond to them. + */ if (!strcmp(arg, "--reset")) { - if (stage || merge) + if (stage || merge || prefix) usage(read_tree_usage); reset = 1; merge = 1; @@@ -975,7 -937,7 +1033,7 @@@ * valid cache-tree because the index must match exactly * what came from the tree. */ - if (trees && trees->item && (!merge || (stage == 2))) { - if (trees->item && !prefix && (!merge || (stage == 2))) { ++ if (trees && trees->item && !prefix && (!merge || (stage == 2))) { cache_tree_free(&active_cache_tree); prime_cache_tree(); } diff --cc write-tree.c index d6a605893,895e7a359..bd07da618 --- a/write-tree.c +++ b/write-tree.c @@@ -8,10 -8,12 +8,12 @@@ #include "cache-tree.h" static int missing_ok = 0; + static char *prefix = NULL; - static const char write_tree_usage[] = "git-write-tree [--missing-ok]"; + static const char write_tree_usage[] = + "git-write-tree [--missing-ok] [--prefix=/]"; -static struct cache_file cache_file; +static struct lock_file lock_file; int main(int argc, char **argv) { @@@ -19,15 -21,20 +21,20 @@@ setup_git_directory(); - newfd = hold_index_file_for_update(&cache_file, get_index_file()); + newfd = hold_lock_file_for_update(&lock_file, get_index_file()); entries = read_cache(); - if (argc == 2) { - if (!strcmp(argv[1], "--missing-ok")) + + while (1 < argc) { + char *arg = argv[1]; + if (!strcmp(arg, "--missing-ok")) missing_ok = 1; + else if (!strncmp(arg, "--prefix=", 9)) + prefix = arg + 9; else die(write_tree_usage); + argc--; argv++; } - + if (argc > 2) die("too many options");