From: Junio C Hamano Date: Tue, 6 Jun 2006 21:31:29 +0000 (-0700) Subject: Merge branch 'jc/lockfile' into next X-Git-Tag: v1.4.1-rc1~33 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/68a40e5096add9a4d8f2dc0fecce19e9438eaba1?hp=-c Merge branch 'jc/lockfile' into next * jc/lockfile: ref-log: style fixes. refs.c: convert it to use lockfile interface. Make index file locking code reusable to others. HTTP cleanup HTTP cleanup git-format-patch: add --output-directory long option again --- 68a40e5096add9a4d8f2dc0fecce19e9438eaba1 diff --combined builtin-read-tree.c index 57bc4516a0,bb50fbd274..04506da892 --- a/builtin-read-tree.c +++ b/builtin-read-tree.c @@@ -24,7 -24,6 +24,7 @@@ static int trivial_merges_only = 0 static int aggressive = 0; static int verbose_update = 0; static volatile int progress_update = 0; +static const char *prefix = NULL; static int head_idx = -1; static int merge_size = 0; @@@ -413,8 -412,7 +413,8 @@@ static int unpack_trees(merge_fn_t fn 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; } @@@ -763,28 -761,6 +763,28 @@@ static int twoway_merge(struct cache_en return deleted_entry(oldtree, current); } +/* + * Bind merge. + * + * Keep the index entries at stage0, collapse stage1 but make sure + * stage0 does not have anything there. + */ +static int bind_merge(struct cache_entry **src) +{ + struct cache_entry *old = src[0]; + struct cache_entry *a = src[1]; + + if (merge_size != 1) + return error("Cannot do a bind merge of %d trees\n", + merge_size); + if (a && old) + die("Entry '%s' overlaps. Cannot bind.", a->name); + if (!a) + return keep_entry(old); + else + return merged_entry(a, NULL); +} + /* * One-way merge. * @@@ -875,9 -851,9 +875,9 @@@ 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 cmd_read_tree(int argc, const char **argv, char **envp) { @@@ -888,9 -864,9 +888,9 @@@ setup_git_directory(); git_config(git_default_config); - newfd = hold_index_file_for_update(&cache_file, get_index_file()); + newfd = hold_lock_file_for_update(&lock_file, get_index_file()); if (newfd < 0) - die("unable to create new cachefile"); + die("unable to create new index file"); git_config(git_default_config); @@@ -920,27 -896,12 +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 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; @@@ -961,7 -922,7 +961,7 @@@ /* "-m" stands for "merge", meaning we start in stage 1 */ if (!strcmp(arg, "-m")) { - if (stage || merge) + if (stage || merge || prefix) usage(read_tree_usage); if (read_cache_unmerged()) die("you need to resolve your current index first"); @@@ -983,31 -944,12 +983,31 @@@ if ((update||index_only) && !merge) usage(read_tree_usage); + if (prefix) { + int pfxlen = strlen(prefix); + int pos; + if (prefix[pfxlen-1] != '/') + die("prefix must end with /"); + if (stage != 2) + die("binding merge takes only one tree"); + pos = cache_name_pos(prefix, pfxlen); + if (0 <= pos) + die("corrupt index file"); + pos = -pos-1; + if (pos < active_nr && + !strncmp(active_cache[pos]->name, prefix, pfxlen)) + die("subdirectory '%s' already exists.", prefix); + pos = cache_name_pos(prefix, pfxlen-1); + if (0 <= pos) + die("file '%.*s' already exists.", pfxlen-1, prefix); + } + if (merge) { if (stage < 2) die("just how do you expect me to merge %d trees?", stage-1); switch (stage - 1) { case 1: - fn = oneway_merge; + fn = prefix ? bind_merge : oneway_merge; break; case 2: fn = twoway_merge; @@@ -1033,13 -975,13 +1033,13 @@@ * valid cache-tree because the index must match exactly * what came from the tree. */ - if (trees && trees->item && (!merge || (stage == 2))) { + if (trees && trees->item && !prefix && (!merge || (stage == 2))) { cache_tree_free(&active_cache_tree); prime_cache_tree(); } if (write_cache(newfd, active_cache, active_nr) || - commit_index_file(&cache_file)) + commit_lock_file(&lock_file)) die("unable to write new index file"); return 0; } diff --combined write-tree.c index 895e7a359d,d6a605893d..bd07da6183 --- a/write-tree.c +++ b/write-tree.c @@@ -8,12 -8,10 +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) { @@@ -21,20 -19,15 +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"); @@@ -52,7 -45,7 +52,7 @@@ die("git-write-tree: error building trees"); if (0 <= newfd) { if (!write_cache(newfd, active_cache, active_nr)) - commit_index_file(&cache_file); + commit_lock_file(&lock_file); } /* Not being able to write is fine -- we are only interested * in updating the cache-tree part, and if the next caller @@@ -61,12 -54,6 +61,12 @@@ * performance penalty and not a big deal. */ } - printf("%s\n", sha1_to_hex(active_cache_tree->sha1)); + if (prefix) { + struct cache_tree *subtree = + cache_tree_find(active_cache_tree, prefix); + printf("%s\n", sha1_to_hex(subtree->sha1)); + } + else + printf("%s\n", sha1_to_hex(active_cache_tree->sha1)); return 0; }