1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-08 08:56:10 +02:00

tree-walk.c: remove the_repo from get_tree_entry()

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2019-06-27 16:28:49 +07:00 committed by Junio C Hamano
parent 5e57580733
commit 50ddb089ff
11 changed files with 38 additions and 26 deletions

View File

@ -418,7 +418,9 @@ static void parse_treeish_arg(const char **argv,
unsigned short mode; unsigned short mode;
int err; int err;
err = get_tree_entry(&tree->object.oid, prefix, &tree_oid, err = get_tree_entry(ar_args->repo,
&tree->object.oid,
prefix, &tree_oid,
&mode); &mode);
if (err || !S_ISDIR(mode)) if (err || !S_ISDIR(mode))
die(_("current working directory is untracked")); die(_("current working directory is untracked"));

View File

@ -101,7 +101,7 @@ static void verify_working_tree_path(struct repository *r,
struct object_id blob_oid; struct object_id blob_oid;
unsigned short mode; unsigned short mode;
if (!get_tree_entry(commit_oid, path, &blob_oid, &mode) && if (!get_tree_entry(r, commit_oid, path, &blob_oid, &mode) &&
oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB) oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB)
return; return;
} }
@ -532,7 +532,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,
{ {
if (!is_null_oid(&origin->blob_oid)) if (!is_null_oid(&origin->blob_oid))
return 0; return 0;
if (get_tree_entry(&origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode)) if (get_tree_entry(r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
goto error_out; goto error_out;
if (oid_object_info(r, &origin->blob_oid, NULL) != OBJ_BLOB) if (oid_object_info(r, &origin->blob_oid, NULL) != OBJ_BLOB)
goto error_out; goto error_out;

View File

@ -179,7 +179,7 @@ static int check_local_mod(struct object_id *head, int index_only)
* way as changed from the HEAD. * way as changed from the HEAD.
*/ */
if (no_head if (no_head
|| get_tree_entry(head, name, &oid, &mode) || get_tree_entry(the_repository, head, name, &oid, &mode)
|| ce->ce_mode != create_ce_mode(mode) || ce->ce_mode != create_ce_mode(mode)
|| !oideq(&ce->oid, &oid)) || !oideq(&ce->oid, &oid))
staged_changes = 1; staged_changes = 1;

View File

@ -601,7 +601,7 @@ static struct cache_entry *read_one_ent(const char *which,
struct object_id oid; struct object_id oid;
struct cache_entry *ce; struct cache_entry *ce;
if (get_tree_entry(ent, path, &oid, &mode)) { if (get_tree_entry(the_repository, ent, path, &oid, &mode)) {
if (which) if (which)
error("%s: not in %s branch.", path, which); error("%s: not in %s branch.", path, which);
return NULL; return NULL;

View File

@ -496,12 +496,13 @@ static struct commit *check_single_commit(struct rev_info *revs)
return (struct commit *) commit; return (struct commit *) commit;
} }
static void fill_blob_sha1(struct commit *commit, struct diff_filespec *spec) static void fill_blob_sha1(struct repository *r, struct commit *commit,
struct diff_filespec *spec)
{ {
unsigned short mode; unsigned short mode;
struct object_id oid; struct object_id oid;
if (get_tree_entry(&commit->object.oid, spec->path, &oid, &mode)) if (get_tree_entry(r, &commit->object.oid, spec->path, &oid, &mode))
die("There is no path %s in the commit", spec->path); die("There is no path %s in the commit", spec->path);
fill_filespec(spec, &oid, 1, mode); fill_filespec(spec, &oid, 1, mode);
@ -585,7 +586,7 @@ parse_lines(struct repository *r, struct commit *commit,
name_part); name_part);
spec = alloc_filespec(full_name); spec = alloc_filespec(full_name);
fill_blob_sha1(commit, spec); fill_blob_sha1(r, commit, spec);
fill_line_ends(r, spec, &lines, &ends); fill_line_ends(r, spec, &lines, &ends);
cb_data.spec = spec; cb_data.spec = spec;
cb_data.lines = lines; cb_data.lines = lines;

View File

@ -290,7 +290,7 @@ void shift_tree(const struct object_id *hash1,
if (!*del_prefix) if (!*del_prefix)
return; return;
if (get_tree_entry(hash2, del_prefix, shifted, &mode)) if (get_tree_entry(the_repository, hash2, del_prefix, shifted, &mode))
die("cannot find path %s in tree %s", die("cannot find path %s in tree %s",
del_prefix, oid_to_hex(hash2)); del_prefix, oid_to_hex(hash2));
return; return;
@ -317,12 +317,12 @@ void shift_tree_by(const struct object_id *hash1,
unsigned candidate = 0; unsigned candidate = 0;
/* Can hash2 be a tree at shift_prefix in tree hash1? */ /* Can hash2 be a tree at shift_prefix in tree hash1? */
if (!get_tree_entry(hash1, shift_prefix, &sub1, &mode1) && if (!get_tree_entry(the_repository, hash1, shift_prefix, &sub1, &mode1) &&
S_ISDIR(mode1)) S_ISDIR(mode1))
candidate |= 1; candidate |= 1;
/* Can hash1 be a tree at shift_prefix in tree hash2? */ /* Can hash1 be a tree at shift_prefix in tree hash2? */
if (!get_tree_entry(hash2, shift_prefix, &sub2, &mode2) && if (!get_tree_entry(the_repository, hash2, shift_prefix, &sub2, &mode2) &&
S_ISDIR(mode2)) S_ISDIR(mode2))
candidate |= 2; candidate |= 2;

View File

@ -475,7 +475,7 @@ static int get_tree_entry_if_blob(const struct object_id *tree,
{ {
int ret; int ret;
ret = get_tree_entry(tree, path, &dfs->oid, &dfs->mode); ret = get_tree_entry(the_repository, tree, path, &dfs->oid, &dfs->mode);
if (S_ISDIR(dfs->mode)) { if (S_ISDIR(dfs->mode)) {
oidcpy(&dfs->oid, &null_oid); oidcpy(&dfs->oid, &null_oid);
dfs->mode = 0; dfs->mode = 0;
@ -1905,7 +1905,8 @@ static int tree_has_path(struct tree *tree, const char *path)
struct object_id hashy; struct object_id hashy;
unsigned short mode_o; unsigned short mode_o;
return !get_tree_entry(&tree->object.oid, path, return !get_tree_entry(the_repository,
&tree->object.oid, path,
&hashy, &mode_o); &hashy, &mode_o);
} }
@ -2500,7 +2501,8 @@ static void apply_directory_rename_modifications(struct merge_options *opt,
* the various handle_rename_*() functions update the index * the various handle_rename_*() functions update the index
* explicitly rather than relying on unpack_trees() to have done it. * explicitly rather than relying on unpack_trees() to have done it.
*/ */
get_tree_entry(&tree->object.oid, get_tree_entry(opt->repo,
&tree->object.oid,
pair->two->path, pair->two->path,
&re->dst_entry->stages[stage].oid, &re->dst_entry->stages[stage].oid,
&re->dst_entry->stages[stage].mode); &re->dst_entry->stages[stage].mode);

View File

@ -1015,7 +1015,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
return; return;
if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid)) if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid))
die("Cannot use notes ref %s", notes_ref); die("Cannot use notes ref %s", notes_ref);
if (get_tree_entry(&object_oid, "", &oid, &mode)) if (get_tree_entry(the_repository, &object_oid, "", &oid, &mode))
die("Failed to read notes tree referenced by %s (%s)", die("Failed to read notes tree referenced by %s (%s)",
notes_ref, oid_to_hex(&object_oid)); notes_ref, oid_to_hex(&object_oid));

View File

@ -1677,7 +1677,8 @@ int repo_get_oid_blob(struct repository *r,
} }
/* Must be called only when object_name:filename doesn't exist. */ /* Must be called only when object_name:filename doesn't exist. */
static void diagnose_invalid_oid_path(const char *prefix, static void diagnose_invalid_oid_path(struct repository *r,
const char *prefix,
const char *filename, const char *filename,
const struct object_id *tree_oid, const struct object_id *tree_oid,
const char *object_name, const char *object_name,
@ -1695,7 +1696,7 @@ static void diagnose_invalid_oid_path(const char *prefix,
if (is_missing_file_error(errno)) { if (is_missing_file_error(errno)) {
char *fullname = xstrfmt("%s%s", prefix, filename); char *fullname = xstrfmt("%s%s", prefix, filename);
if (!get_tree_entry(tree_oid, fullname, &oid, &mode)) { if (!get_tree_entry(r, tree_oid, fullname, &oid, &mode)) {
die("Path '%s' exists, but not '%s'.\n" die("Path '%s' exists, but not '%s'.\n"
"Did you mean '%.*s:%s' aka '%.*s:./%s'?", "Did you mean '%.*s:%s' aka '%.*s:./%s'?",
fullname, fullname,
@ -1902,10 +1903,10 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
filename, oid, &oc->symlink_path, filename, oid, &oc->symlink_path,
&oc->mode); &oc->mode);
} else { } else {
ret = get_tree_entry(&tree_oid, filename, oid, ret = get_tree_entry(repo, &tree_oid, filename, oid,
&oc->mode); &oc->mode);
if (ret && only_to_die) { if (ret && only_to_die) {
diagnose_invalid_oid_path(prefix, diagnose_invalid_oid_path(repo, prefix,
filename, filename,
&tree_oid, &tree_oid,
name, len); name, len);

View File

@ -502,7 +502,9 @@ struct dir_state {
struct object_id oid; struct object_id oid;
}; };
static int find_tree_entry(struct tree_desc *t, const char *name, struct object_id *result, unsigned short *mode) static int find_tree_entry(struct repository *r, struct tree_desc *t,
const char *name, struct object_id *result,
unsigned short *mode)
{ {
int namelen = strlen(name); int namelen = strlen(name);
while (t->size) { while (t->size) {
@ -532,19 +534,23 @@ static int find_tree_entry(struct tree_desc *t, const char *name, struct object_
oidcpy(result, &oid); oidcpy(result, &oid);
return 0; return 0;
} }
return get_tree_entry(&oid, name + entrylen, result, mode); return get_tree_entry(r, &oid, name + entrylen, result, mode);
} }
return -1; return -1;
} }
int get_tree_entry(const struct object_id *tree_oid, const char *name, struct object_id *oid, unsigned short *mode) int get_tree_entry(struct repository *r,
const struct object_id *tree_oid,
const char *name,
struct object_id *oid,
unsigned short *mode)
{ {
int retval; int retval;
void *tree; void *tree;
unsigned long size; unsigned long size;
struct object_id root; struct object_id root;
tree = read_object_with_reference(the_repository, tree_oid, tree_type, &size, &root); tree = read_object_with_reference(r, tree_oid, tree_type, &size, &root);
if (!tree) if (!tree)
return -1; return -1;
@ -559,7 +565,7 @@ int get_tree_entry(const struct object_id *tree_oid, const char *name, struct ob
} else { } else {
struct tree_desc t; struct tree_desc t;
init_tree_desc(&t, tree, size); init_tree_desc(&t, tree, size);
retval = find_tree_entry(&t, name, oid, mode); retval = find_tree_entry(r, &t, name, oid, mode);
} }
free(tree); free(tree);
return retval; return retval;
@ -681,7 +687,7 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, c
} }
/* Look up the first (or only) path component in the tree. */ /* Look up the first (or only) path component in the tree. */
find_result = find_tree_entry(&t, namebuf.buf, find_result = find_tree_entry(the_repository, &t, namebuf.buf,
&current_tree_oid, mode); &current_tree_oid, mode);
if (find_result) { if (find_result) {
goto done; goto done;

View File

@ -68,7 +68,7 @@ struct traverse_info {
int show_all_errors; int show_all_errors;
}; };
int get_tree_entry(const struct object_id *, const char *, struct object_id *, unsigned short *); int get_tree_entry(struct repository *, const struct object_id *, const char *, struct object_id *, unsigned short *);
char *make_traverse_path(char *path, const struct traverse_info *info, const struct name_entry *n); char *make_traverse_path(char *path, const struct traverse_info *info, const struct name_entry *n);
void setup_traverse_info(struct traverse_info *info, const char *base); void setup_traverse_info(struct traverse_info *info, const char *base);