THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Browse Source

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>
tags/v2.23.0-rc0
Nguyễn Thái Ngọc Duy 3 months ago
parent
commit
50ddb089ff
11 changed files with 38 additions and 26 deletions
  1. 3
    1
      archive.c
  2. 2
    2
      blame.c
  3. 1
    1
      builtin/rm.c
  4. 1
    1
      builtin/update-index.c
  5. 4
    3
      line-log.c
  6. 3
    3
      match-trees.c
  7. 5
    3
      merge-recursive.c
  8. 1
    1
      notes.c
  9. 5
    4
      sha1-name.c
  10. 12
    6
      tree-walk.c
  11. 1
    1
      tree-walk.h

+ 3
- 1
archive.c View File

@@ -418,7 +418,9 @@ static void parse_treeish_arg(const char **argv,
unsigned short mode;
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);
if (err || !S_ISDIR(mode))
die(_("current working directory is untracked"));

+ 2
- 2
blame.c View File

@@ -101,7 +101,7 @@ static void verify_working_tree_path(struct repository *r,
struct object_id blob_oid;
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)
return;
}
@@ -532,7 +532,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,
{
if (!is_null_oid(&origin->blob_oid))
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;
if (oid_object_info(r, &origin->blob_oid, NULL) != OBJ_BLOB)
goto error_out;

+ 1
- 1
builtin/rm.c View File

@@ -179,7 +179,7 @@ static int check_local_mod(struct object_id *head, int index_only)
* way as changed from the 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)
|| !oideq(&ce->oid, &oid))
staged_changes = 1;

+ 1
- 1
builtin/update-index.c View File

@@ -601,7 +601,7 @@ static struct cache_entry *read_one_ent(const char *which,
struct object_id oid;
struct cache_entry *ce;

if (get_tree_entry(ent, path, &oid, &mode)) {
if (get_tree_entry(the_repository, ent, path, &oid, &mode)) {
if (which)
error("%s: not in %s branch.", path, which);
return NULL;

+ 4
- 3
line-log.c View File

@@ -496,12 +496,13 @@ static struct commit *check_single_commit(struct rev_info *revs)
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;
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);
fill_filespec(spec, &oid, 1, mode);

@@ -585,7 +586,7 @@ parse_lines(struct repository *r, struct commit *commit,
name_part);

spec = alloc_filespec(full_name);
fill_blob_sha1(commit, spec);
fill_blob_sha1(r, commit, spec);
fill_line_ends(r, spec, &lines, &ends);
cb_data.spec = spec;
cb_data.lines = lines;

+ 3
- 3
match-trees.c View File

@@ -290,7 +290,7 @@ void shift_tree(const struct object_id *hash1,
if (!*del_prefix)
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",
del_prefix, oid_to_hex(hash2));
return;
@@ -317,12 +317,12 @@ void shift_tree_by(const struct object_id *hash1,
unsigned candidate = 0;

/* 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))
candidate |= 1;

/* 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))
candidate |= 2;


+ 5
- 3
merge-recursive.c View File

@@ -475,7 +475,7 @@ static int get_tree_entry_if_blob(const struct object_id *tree,
{
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)) {
oidcpy(&dfs->oid, &null_oid);
dfs->mode = 0;
@@ -1905,7 +1905,8 @@ static int tree_has_path(struct tree *tree, const char *path)
struct object_id hashy;
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);
}

@@ -2500,7 +2501,8 @@ static void apply_directory_rename_modifications(struct merge_options *opt,
* the various handle_rename_*() functions update the index
* 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,
&re->dst_entry->stages[stage].oid,
&re->dst_entry->stages[stage].mode);

+ 1
- 1
notes.c View File

@@ -1015,7 +1015,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
return;
if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid))
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)",
notes_ref, oid_to_hex(&object_oid));


+ 5
- 4
sha1-name.c 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. */
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 struct object_id *tree_oid,
const char *object_name,
@@ -1695,7 +1696,7 @@ static void diagnose_invalid_oid_path(const char *prefix,
if (is_missing_file_error(errno)) {
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"
"Did you mean '%.*s:%s' aka '%.*s:./%s'?",
fullname,
@@ -1902,10 +1903,10 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
filename, oid, &oc->symlink_path,
&oc->mode);
} else {
ret = get_tree_entry(&tree_oid, filename, oid,
ret = get_tree_entry(repo, &tree_oid, filename, oid,
&oc->mode);
if (ret && only_to_die) {
diagnose_invalid_oid_path(prefix,
diagnose_invalid_oid_path(repo, prefix,
filename,
&tree_oid,
name, len);

+ 12
- 6
tree-walk.c View File

@@ -502,7 +502,9 @@ struct dir_state {
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);
while (t->size) {
@@ -532,19 +534,23 @@ static int find_tree_entry(struct tree_desc *t, const char *name, struct object_
oidcpy(result, &oid);
return 0;
}
return get_tree_entry(&oid, name + entrylen, result, mode);
return get_tree_entry(r, &oid, name + entrylen, result, mode);
}
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;
void *tree;
unsigned long size;
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)
return -1;

@@ -559,7 +565,7 @@ int get_tree_entry(const struct object_id *tree_oid, const char *name, struct ob
} else {
struct tree_desc t;
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);
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. */
find_result = find_tree_entry(&t, namebuf.buf,
find_result = find_tree_entry(the_repository, &t, namebuf.buf,
&current_tree_oid, mode);
if (find_result) {
goto done;

+ 1
- 1
tree-walk.h View File

@@ -68,7 +68,7 @@ struct traverse_info {
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);
void setup_traverse_info(struct traverse_info *info, const char *base);


Loading…
Cancel
Save