tree-walk.c: remove the_repo from get_tree_entry()
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Thu, 27 Jun 2019 09:28:49 +0000 (16:28 +0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 27 Jun 2019 19:45:17 +0000 (12:45 -0700)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
archive.c
blame.c
builtin/rm.c
builtin/update-index.c
line-log.c
match-trees.c
merge-recursive.c
notes.c
sha1-name.c
tree-walk.c
tree-walk.h
index 53141c1f0ee12b4ce14efef1e4026d7ba7d2b665..a8da0fcc4f0cc47e585b3b378109fbd84496ed15 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -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"));
diff --git a/blame.c b/blame.c
index 145eaf2faf9cf56977da61572c93783ea702b0f9..ef022809e9de1dbdfa2f07788e93c03489bc04db 100644 (file)
--- a/blame.c
+++ b/blame.c
@@ -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;
index be8edc6d1e1185fa0224b516c0e4f73ceb590aa3..2eacda42b4a8fff746e846891fce0107d80efbe1 100644 (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;
index 3f8cc6ccb47c2f8927e91076a8844d2cfd8a0bb2..dff2f4b837208deebeb34f4af687c18df7dbfe76 100644 (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;
index 0a17b21187b6620c3c5c82e53271d56bc0c6deb8..3aff1849e7d5c7dba5c14b2fa34f7af64064a42d 100644 (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;
index 9d1ec8d6b01e13b20b34c836130cd9557fdd1d80..de7e8a6783148f8dde8c41a7a80e6930804149aa 100644 (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;
 
index d2e380b7ed845e6fb2cd5616754a3f12a11c7b18..b051066795303b73098de3af91c2f42cea118a87 100644 (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);
diff --git a/notes.c b/notes.c
index 2522b87d77b11c731343a5159abf43fff60b539d..75c028b3005a8af8f39e9bceb7ab6e4b3b5dff83 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -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));
 
index 728e6f1f61ea4641272e59e6287b6b47bfe0c74e..e8fb215e5c19c8d63196d2071ff6537044b45af4 100644 (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);
index c5569b3e9f711b8badc86c352e9281b350f03b5c..506e12a031c2301e0fdc40aab3e4b2296cca1b6b 100644 (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;
index 9aa10426420db7376fb819ee860d2969eeda95d2..639f79187fa106c687bfb00bba38f8e2c6880987 100644 (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);