Merge branch 'jc/maint-read-tree-multi'
* jc/maint-read-tree-multi: checkout branch: prime cache-tree fully read-tree -m A B: prime cache-tree from the switched-to tree Move prime_cache_tree() to cache-tree.c read-tree A B: do not corrupt cache-tree
This commit is contained in:
commit
ea0b767c1e
@ -5,6 +5,7 @@
|
|||||||
#include "commit.h"
|
#include "commit.h"
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
#include "tree-walk.h"
|
#include "tree-walk.h"
|
||||||
|
#include "cache-tree.h"
|
||||||
#include "unpack-trees.h"
|
#include "unpack-trees.h"
|
||||||
#include "dir.h"
|
#include "dir.h"
|
||||||
#include "run-command.h"
|
#include "run-command.h"
|
||||||
@ -364,14 +365,17 @@ static int merge_working_tree(struct checkout_opts *opts,
|
|||||||
int ret;
|
int ret;
|
||||||
struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
|
struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
|
||||||
int newfd = hold_locked_index(lock_file, 1);
|
int newfd = hold_locked_index(lock_file, 1);
|
||||||
|
int reprime_cache_tree = 0;
|
||||||
|
|
||||||
if (read_cache() < 0)
|
if (read_cache() < 0)
|
||||||
return error("corrupt index file");
|
return error("corrupt index file");
|
||||||
|
|
||||||
|
cache_tree_free(&active_cache_tree);
|
||||||
if (opts->force) {
|
if (opts->force) {
|
||||||
ret = reset_tree(new->commit->tree, opts, 1);
|
ret = reset_tree(new->commit->tree, opts, 1);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
reprime_cache_tree = 1;
|
||||||
} else {
|
} else {
|
||||||
struct tree_desc trees[2];
|
struct tree_desc trees[2];
|
||||||
struct tree *tree;
|
struct tree *tree;
|
||||||
@ -407,7 +411,9 @@ static int merge_working_tree(struct checkout_opts *opts,
|
|||||||
init_tree_desc(&trees[1], tree->buffer, tree->size);
|
init_tree_desc(&trees[1], tree->buffer, tree->size);
|
||||||
|
|
||||||
ret = unpack_trees(2, trees, &topts);
|
ret = unpack_trees(2, trees, &topts);
|
||||||
if (ret == -1) {
|
if (ret != -1) {
|
||||||
|
reprime_cache_tree = 1;
|
||||||
|
} else {
|
||||||
/*
|
/*
|
||||||
* Unpack couldn't do a trivial merge; either
|
* Unpack couldn't do a trivial merge; either
|
||||||
* give up or do a real merge, depending on
|
* give up or do a real merge, depending on
|
||||||
@ -451,6 +457,8 @@ static int merge_working_tree(struct checkout_opts *opts,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (reprime_cache_tree)
|
||||||
|
prime_cache_tree(&active_cache_tree, new->commit->tree);
|
||||||
if (write_cache(newfd, active_cache, active_nr) ||
|
if (write_cache(newfd, active_cache, active_nr) ||
|
||||||
commit_locked_index(lock_file))
|
commit_locked_index(lock_file))
|
||||||
die("unable to write new index file");
|
die("unable to write new index file");
|
||||||
|
@ -29,41 +29,6 @@ static int list_tree(unsigned char *sha1)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
|
|
||||||
{
|
|
||||||
struct tree_desc desc;
|
|
||||||
struct name_entry entry;
|
|
||||||
int cnt;
|
|
||||||
|
|
||||||
hashcpy(it->sha1, tree->object.sha1);
|
|
||||||
init_tree_desc(&desc, tree->buffer, tree->size);
|
|
||||||
cnt = 0;
|
|
||||||
while (tree_entry(&desc, &entry)) {
|
|
||||||
if (!S_ISDIR(entry.mode))
|
|
||||||
cnt++;
|
|
||||||
else {
|
|
||||||
struct cache_tree_sub *sub;
|
|
||||||
struct tree *subtree = lookup_tree(entry.sha1);
|
|
||||||
if (!subtree->object.parsed)
|
|
||||||
parse_tree(subtree);
|
|
||||||
sub = cache_tree_sub(it, entry.path);
|
|
||||||
sub->cache_tree = cache_tree();
|
|
||||||
prime_cache_tree_rec(sub->cache_tree, subtree);
|
|
||||||
cnt += sub->cache_tree->entry_count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
it->entry_count = cnt;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void prime_cache_tree(void)
|
|
||||||
{
|
|
||||||
if (!nr_trees)
|
|
||||||
return;
|
|
||||||
active_cache_tree = cache_tree();
|
|
||||||
prime_cache_tree_rec(active_cache_tree, trees[0]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char read_tree_usage[] = "git read-tree (<sha> | [[-m [--trivial] [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] [--index-output=<file>] <sha1> [<sha2> [<sha3>]])";
|
static const char read_tree_usage[] = "git read-tree (<sha> | [[-m [--trivial] [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] [--index-output=<file>] <sha1> [<sha2> [<sha3>]])";
|
||||||
|
|
||||||
static struct lock_file lock_file;
|
static struct lock_file lock_file;
|
||||||
@ -211,7 +176,6 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
|
|||||||
case 3:
|
case 3:
|
||||||
default:
|
default:
|
||||||
opts.fn = threeway_merge;
|
opts.fn = threeway_merge;
|
||||||
cache_tree_free(&active_cache_tree);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,6 +185,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
|
|||||||
opts.head_idx = 1;
|
opts.head_idx = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cache_tree_free(&active_cache_tree);
|
||||||
for (i = 0; i < nr_trees; i++) {
|
for (i = 0; i < nr_trees; i++) {
|
||||||
struct tree *tree = trees[i];
|
struct tree *tree = trees[i];
|
||||||
parse_tree(tree);
|
parse_tree(tree);
|
||||||
@ -234,11 +199,14 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
|
|||||||
* "-m ent" or "--reset ent" form), we can obtain a fully
|
* "-m ent" or "--reset ent" form), we can obtain a fully
|
||||||
* valid cache-tree because the index must match exactly
|
* valid cache-tree because the index must match exactly
|
||||||
* what came from the tree.
|
* what came from the tree.
|
||||||
|
*
|
||||||
|
* The same holds true if we are switching between two trees
|
||||||
|
* using read-tree -m A B. The index must match B after that.
|
||||||
*/
|
*/
|
||||||
if (nr_trees && !opts.prefix && (!opts.merge || (stage == 2))) {
|
if (nr_trees == 1 && !opts.prefix)
|
||||||
cache_tree_free(&active_cache_tree);
|
prime_cache_tree(&active_cache_tree, trees[0]);
|
||||||
prime_cache_tree();
|
else if (nr_trees == 2 && opts.merge)
|
||||||
}
|
prime_cache_tree(&active_cache_tree, trees[1]);
|
||||||
|
|
||||||
if (write_cache(newfd, active_cache, active_nr) ||
|
if (write_cache(newfd, active_cache, active_nr) ||
|
||||||
commit_locked_index(&lock_file))
|
commit_locked_index(&lock_file))
|
||||||
|
34
cache-tree.c
34
cache-tree.c
@ -1,5 +1,6 @@
|
|||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
|
#include "tree-walk.h"
|
||||||
#include "cache-tree.h"
|
#include "cache-tree.h"
|
||||||
|
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
@ -591,3 +592,36 @@ int write_cache_as_tree(unsigned char *sha1, int missing_ok, const char *prefix)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
|
||||||
|
{
|
||||||
|
struct tree_desc desc;
|
||||||
|
struct name_entry entry;
|
||||||
|
int cnt;
|
||||||
|
|
||||||
|
hashcpy(it->sha1, tree->object.sha1);
|
||||||
|
init_tree_desc(&desc, tree->buffer, tree->size);
|
||||||
|
cnt = 0;
|
||||||
|
while (tree_entry(&desc, &entry)) {
|
||||||
|
if (!S_ISDIR(entry.mode))
|
||||||
|
cnt++;
|
||||||
|
else {
|
||||||
|
struct cache_tree_sub *sub;
|
||||||
|
struct tree *subtree = lookup_tree(entry.sha1);
|
||||||
|
if (!subtree->object.parsed)
|
||||||
|
parse_tree(subtree);
|
||||||
|
sub = cache_tree_sub(it, entry.path);
|
||||||
|
sub->cache_tree = cache_tree();
|
||||||
|
prime_cache_tree_rec(sub->cache_tree, subtree);
|
||||||
|
cnt += sub->cache_tree->entry_count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
it->entry_count = cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void prime_cache_tree(struct cache_tree **it, struct tree *tree)
|
||||||
|
{
|
||||||
|
cache_tree_free(it);
|
||||||
|
*it = cache_tree();
|
||||||
|
prime_cache_tree_rec(*it, tree);
|
||||||
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef CACHE_TREE_H
|
#ifndef CACHE_TREE_H
|
||||||
#define CACHE_TREE_H
|
#define CACHE_TREE_H
|
||||||
|
|
||||||
|
#include "tree.h"
|
||||||
|
|
||||||
struct cache_tree;
|
struct cache_tree;
|
||||||
struct cache_tree_sub {
|
struct cache_tree_sub {
|
||||||
struct cache_tree *cache_tree;
|
struct cache_tree *cache_tree;
|
||||||
@ -33,4 +35,6 @@ int cache_tree_update(struct cache_tree *, struct cache_entry **, int, int, int)
|
|||||||
#define WRITE_TREE_PREFIX_ERROR (-3)
|
#define WRITE_TREE_PREFIX_ERROR (-3)
|
||||||
|
|
||||||
int write_cache_as_tree(unsigned char *sha1, int missing_ok, const char *prefix);
|
int write_cache_as_tree(unsigned char *sha1, int missing_ok, const char *prefix);
|
||||||
|
void prime_cache_tree(struct cache_tree **, struct tree *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user