提交 e092073d 编写于 作者: N Nguyễn Thái Ngọc Duy 提交者: Junio C Hamano

tree.c: make read_tree*() take 'struct repository *'

These functions call tree_entry_interesting() which will soon require
a 'struct index_state *' to be passed in. Instead of just changing the
function signature to take an index, update to take a repo instead
because these functions do need object database access.
Signed-off-by: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 0e94dab5
......@@ -285,7 +285,8 @@ int write_archive_entries(struct archiver_args *args,
git_attr_set_direction(GIT_ATTR_INDEX);
}
err = read_tree_recursive(args->tree, "", 0, 0, &args->pathspec,
err = read_tree_recursive(args->repo, args->tree, "",
0, 0, &args->pathspec,
queue_or_write_archive_entry,
&context);
if (err == READ_TREE_RECURSIVE)
......@@ -346,7 +347,8 @@ static int path_exists(struct archiver_args *args, const char *path)
ctx.args = args;
parse_pathspec(&ctx.pathspec, 0, 0, "", paths);
ctx.pathspec.recursive = 1;
ret = read_tree_recursive(args->tree, "", 0, 0, &ctx.pathspec,
ret = read_tree_recursive(args->repo, args->tree, "",
0, 0, &ctx.pathspec,
reject_entry, &ctx);
clear_pathspec(&ctx.pathspec);
return ret != 0;
......
......@@ -115,7 +115,8 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
static int read_tree_some(struct tree *tree, const struct pathspec *pathspec)
{
read_tree_recursive(tree, "", 0, 0, pathspec, update_some, NULL);
read_tree_recursive(the_repository, tree, "", 0, 0,
pathspec, update_some, NULL);
/* update the index with the given tree's info
* for all args, expanding wildcards, and exit
......
......@@ -641,8 +641,9 @@ int cmd_show(int argc, const char **argv, const char *prefix)
diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
name,
diff_get_color_opt(&rev.diffopt, DIFF_RESET));
read_tree_recursive((struct tree *)o, "", 0, 0, &match_all,
show_tree_object, rev.diffopt.file);
read_tree_recursive(the_repository, (struct tree *)o, "",
0, 0, &match_all, show_tree_object,
rev.diffopt.file);
rev.shown_one = 1;
break;
case OBJ_COMMIT:
......
......@@ -441,7 +441,7 @@ void overlay_tree_on_index(struct index_state *istate,
PATHSPEC_PREFER_CWD, prefix, matchbuf);
} else
memset(&pathspec, 0, sizeof(pathspec));
if (read_tree(tree, 1, &pathspec, istate))
if (read_tree(the_repository, tree, 1, &pathspec, istate))
die("unable to read tree entries %s", tree_name);
for (i = 0; i < istate->cache_nr; i++) {
......
......@@ -185,5 +185,6 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
tree = parse_tree_indirect(&oid);
if (!tree)
die("not a tree object");
return !!read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL);
return !!read_tree_recursive(the_repository, tree, "", 0, 0,
&pathspec, show_tree, NULL);
}
......@@ -463,7 +463,8 @@ static void get_files_dirs(struct merge_options *o, struct tree *tree)
{
struct pathspec match_all;
memset(&match_all, 0, sizeof(match_all));
read_tree_recursive(tree, "", 0, 0, &match_all, save_files_dirs, o);
read_tree_recursive(the_repository, tree, "", 0, 0,
&match_all, save_files_dirs, o);
}
static int get_tree_entry_if_blob(const struct object_id *tree,
......
......@@ -60,7 +60,8 @@ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base
ADD_CACHE_JUST_APPEND);
}
static int read_tree_1(struct tree *tree, struct strbuf *base,
static int read_tree_1(struct repository *r,
struct tree *tree, struct strbuf *base,
int stage, const struct pathspec *pathspec,
read_tree_fn_t fn, void *context)
{
......@@ -99,7 +100,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
else if (S_ISGITLINK(entry.mode)) {
struct commit *commit;
commit = lookup_commit(the_repository, entry.oid);
commit = lookup_commit(r, entry.oid);
if (!commit)
die("Commit %s in submodule path %s%s not found",
oid_to_hex(entry.oid),
......@@ -118,7 +119,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
len = tree_entry_len(&entry);
strbuf_add(base, entry.path, len);
strbuf_addch(base, '/');
retval = read_tree_1(lookup_tree(the_repository, &oid),
retval = read_tree_1(r, lookup_tree(r, &oid),
base, stage, pathspec,
fn, context);
strbuf_setlen(base, oldlen);
......@@ -128,7 +129,8 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
return 0;
}
int read_tree_recursive(struct tree *tree,
int read_tree_recursive(struct repository *r,
struct tree *tree,
const char *base, int baselen,
int stage, const struct pathspec *pathspec,
read_tree_fn_t fn, void *context)
......@@ -137,7 +139,7 @@ int read_tree_recursive(struct tree *tree,
int ret;
strbuf_add(&sb, base, baselen);
ret = read_tree_1(tree, &sb, stage, pathspec, fn, context);
ret = read_tree_1(r, tree, &sb, stage, pathspec, fn, context);
strbuf_release(&sb);
return ret;
}
......@@ -152,8 +154,8 @@ static int cmp_cache_name_compare(const void *a_, const void *b_)
ce2->name, ce2->ce_namelen, ce_stage(ce2));
}
int read_tree(struct tree *tree, int stage, struct pathspec *match,
struct index_state *istate)
int read_tree(struct repository *r, struct tree *tree, int stage,
struct pathspec *match, struct index_state *istate)
{
read_tree_fn_t fn = NULL;
int i, err;
......@@ -181,7 +183,7 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match,
if (!fn)
fn = read_one_entry_quick;
err = read_tree_recursive(tree, "", 0, stage, match, fn, istate);
err = read_tree_recursive(r, tree, "", 0, stage, match, fn, istate);
if (fn == read_one_entry || err)
return err;
......
......@@ -3,7 +3,7 @@
#include "object.h"
extern const char *tree_type;
struct repository;
struct strbuf;
struct tree {
......@@ -12,6 +12,8 @@ struct tree {
unsigned long size;
};
extern const char *tree_type;
struct tree *lookup_tree(struct repository *r, const struct object_id *oid);
int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
......@@ -29,12 +31,14 @@ struct tree *parse_tree_indirect(const struct object_id *oid);
#define READ_TREE_RECURSIVE 1
typedef int (*read_tree_fn_t)(const struct object_id *, struct strbuf *, const char *, unsigned int, int, void *);
extern int read_tree_recursive(struct tree *tree,
const char *base, int baselen,
int stage, const struct pathspec *pathspec,
read_tree_fn_t fn, void *context);
int read_tree_recursive(struct repository *r,
struct tree *tree,
const char *base, int baselen,
int stage, const struct pathspec *pathspec,
read_tree_fn_t fn, void *context);
extern int read_tree(struct tree *tree, int stage, struct pathspec *pathspec,
struct index_state *istate);
int read_tree(struct repository *r, struct tree *tree,
int stage, struct pathspec *pathspec,
struct index_state *istate);
#endif /* TREE_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册