{"thread":{"id":"51368","subject":"[PATCH 0/6] Kill the_repository in tree-walk.c","startedAt":"2019-06-24T09:55:45Z","lastAt":"2019-06-28T16:17:33Z","messageCount":31,"participants":["Nguyễn Thái Ngọc Duy","Derrick Stolee","Duy Nguyen","Junio C Hamano","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"377850","messageId":"20190624095533.22162-1-pclouds@gmail.com","threadId":"51368","inReplyTo":null,"subject":"[PATCH 0/6] Kill the_repository in tree-walk.c","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-24T09:55:27Z","receivedAt":"2019-06-24T09:55:45Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This is the continuation of nd/sha1-name-c-wo-the-repository. In that\nseries I sealed off one place in sha1-name.c that cannot walk trees\nfrom arbitrary repositories. With tree-walk.c taking 'struct\nrepository *' directly, that check in there can now be removed.\n\nNguyễn Thái Ngọc Duy (6):\n  sha1-file.c: remove the_repo from read_object_with_reference()\n  tree-walk.c: remove the_repo from fill_tree_descriptor()\n  tree-walk.c: remove the_repo from get_tree_entry()\n  tree-walk.c: remove the_repo from get_tree_entry_follow_symlinks()\n  match-trees.c: remove the_repo from shift_tree*()\n  Use the right 'struct repository' instead of the_repository\n\n archive.c                   |  4 +++-\n blame.c                     |  4 ++--\n builtin/cat-file.c          |  3 ++-\n builtin/grep.c              |  6 ++++--\n builtin/merge-tree.c        | 22 +++++++++++--------\n builtin/pack-objects.c      |  3 ++-\n builtin/rebase.c            |  4 ++--\n builtin/reset.c             |  4 ++--\n builtin/rm.c                |  2 +-\n builtin/update-index.c      |  2 +-\n cache.h                     |  7 +++---\n fast-import.c               |  9 +++++---\n line-log.c                  |  7 +++---\n match-trees.c               | 12 ++++++-----\n merge-recursive.c           | 43 +++++++++++++++++++++----------------\n notes.c                     |  4 ++--\n sequencer.c                 |  6 +++---\n sha1-file.c                 |  5 +++--\n sha1-name.c                 | 25 +++++++--------------\n shallow.c                   |  3 ++-\n t/helper/test-match-trees.c |  2 +-\n tree-diff.c                 |  4 ++--\n tree-walk.c                 | 35 ++++++++++++++++++++----------\n tree-walk.h                 |  8 ++++---\n unpack-trees.c              |  2 +-\n 25 files changed, 129 insertions(+), 97 deletions(-)\n\n-- \n2.22.0.rc0.322.g2b0371e29a\n\n"},{"id":"377851","messageId":"20190624095533.22162-2-pclouds@gmail.com","threadId":"51368","inReplyTo":"20190624095533.22162-1-pclouds@gmail.com","subject":"[PATCH 1/6] sha1-file.c: remove the_repo from read_object_with_reference()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-24T09:55:28Z","receivedAt":"2019-06-24T09:55:49Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/cat-file.c     | 3 ++-\n builtin/grep.c         | 6 ++++--\n builtin/pack-objects.c | 3 ++-\n cache.h                | 3 ++-\n fast-import.c          | 9 ++++++---\n sha1-file.c            | 5 +++--\n tree-walk.c            | 7 ++++---\n 7 files changed, 23 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 0f092382e1..995d47c85a 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -172,7 +172,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \t\t\t * fall-back to the usual case.\n \t\t\t */\n \t\t}\n-\t\tbuf = read_object_with_reference(&oid, exp_type, &size, NULL);\n+\t\tbuf = read_object_with_reference(the_repository,\n+\t\t\t\t\t\t &oid, exp_type, &size, NULL);\n \t\tbreak;\n \n \tdefault:\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 580fd38f41..85da7ee542 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -458,7 +458,8 @@ static int grep_submodule(struct grep_opt *opt,\n \t\tobject = parse_object_or_die(oid, oid_to_hex(oid));\n \n \t\tgrep_read_lock();\n-\t\tdata = read_object_with_reference(&object->oid, tree_type,\n+\t\tdata = read_object_with_reference(opt->repo,\n+\t\t\t\t\t\t  &object->oid, tree_type,\n \t\t\t\t\t\t  &size, NULL);\n \t\tgrep_read_unlock();\n \n@@ -623,7 +624,8 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,\n \t\tint hit, len;\n \n \t\tgrep_read_lock();\n-\t\tdata = read_object_with_reference(&obj->oid, tree_type,\n+\t\tdata = read_object_with_reference(opt->repo,\n+\t\t\t\t\t\t  &obj->oid, tree_type,\n \t\t\t\t\t\t  &size, NULL);\n \t\tgrep_read_unlock();\n \ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex b2be8869c2..a030c24a4a 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -1428,7 +1428,8 @@ static void add_preferred_base(struct object_id *oid)\n \tif (window <= num_preferred_base++)\n \t\treturn;\n \n-\tdata = read_object_with_reference(oid, tree_type, &size, &tree_oid);\n+\tdata = read_object_with_reference(the_repository, oid,\n+\t\t\t\t\t  tree_type, &size, &tree_oid);\n \tif (!data)\n \t\treturn;\n \ndiff --git a/cache.h b/cache.h\nindex bf20337ef4..cd84cc9bbe 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1500,7 +1500,8 @@ int df_name_compare(const char *name1, int len1, int mode1, const char *name2, i\n int name_compare(const char *name1, size_t len1, const char *name2, size_t len2);\n int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2);\n \n-void *read_object_with_reference(const struct object_id *oid,\n+void *read_object_with_reference(struct repository *r,\n+\t\t\t\t const struct object_id *oid,\n \t\t\t\t const char *required_type,\n \t\t\t\t unsigned long *size,\n \t\t\t\t struct object_id *oid_ret);\ndiff --git a/fast-import.c b/fast-import.c\nindex 76a7bd3699..3970b50acc 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -2410,7 +2410,8 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa\n \t\toidcpy(&commit_oid, &commit_oe->idx.oid);\n \t} else if (!get_oid(p, &commit_oid)) {\n \t\tunsigned long size;\n-\t\tchar *buf = read_object_with_reference(&commit_oid,\n+\t\tchar *buf = read_object_with_reference(the_repository,\n+\t\t\t\t\t\t       &commit_oid,\n \t\t\t\t\t\t       commit_type, &size,\n \t\t\t\t\t\t       &commit_oid);\n \t\tif (!buf || size < the_hash_algo->hexsz + 6)\n@@ -2482,7 +2483,8 @@ static void parse_from_existing(struct branch *b)\n \t\tunsigned long size;\n \t\tchar *buf;\n \n-\t\tbuf = read_object_with_reference(&b->oid, commit_type, &size,\n+\t\tbuf = read_object_with_reference(the_repository,\n+\t\t\t\t\t\t &b->oid, commit_type, &size,\n \t\t\t\t\t\t &b->oid);\n \t\tparse_from_commit(b, buf, size);\n \t\tfree(buf);\n@@ -2560,7 +2562,8 @@ static struct hash_list *parse_merge(unsigned int *count)\n \t\t\toidcpy(&n->oid, &oe->idx.oid);\n \t\t} else if (!get_oid(from, &n->oid)) {\n \t\t\tunsigned long size;\n-\t\t\tchar *buf = read_object_with_reference(&n->oid,\n+\t\t\tchar *buf = read_object_with_reference(the_repository,\n+\t\t\t\t\t\t\t       &n->oid,\n \t\t\t\t\t\t\t       commit_type,\n \t\t\t\t\t\t\t       &size, &n->oid);\n \t\t\tif (!buf || size < the_hash_algo->hexsz + 6)\ndiff --git a/sha1-file.c b/sha1-file.c\nindex 888b6024d5..59b2e40cf3 100644\n--- a/sha1-file.c\n+++ b/sha1-file.c\n@@ -1505,7 +1505,8 @@ void *read_object_file_extended(struct repository *r,\n \treturn NULL;\n }\n \n-void *read_object_with_reference(const struct object_id *oid,\n+void *read_object_with_reference(struct repository *r,\n+\t\t\t\t const struct object_id *oid,\n \t\t\t\t const char *required_type_name,\n \t\t\t\t unsigned long *size,\n \t\t\t\t struct object_id *actual_oid_return)\n@@ -1521,7 +1522,7 @@ void *read_object_with_reference(const struct object_id *oid,\n \t\tint ref_length = -1;\n \t\tconst char *ref_type = NULL;\n \n-\t\tbuffer = read_object_file(&actual_oid, &type, &isize);\n+\t\tbuffer = repo_read_object_file(r, &actual_oid, &type, &isize);\n \t\tif (!buffer)\n \t\t\treturn NULL;\n \t\tif (type == required_type) {\ndiff --git a/tree-walk.c b/tree-walk.c\nindex ec32a47b2e..0c7722b220 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -87,7 +87,7 @@ void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid)\n \tvoid *buf = NULL;\n \n \tif (oid) {\n-\t\tbuf = read_object_with_reference(oid, tree_type, &size, NULL);\n+\t\tbuf = read_object_with_reference(the_repository, oid, tree_type, &size, NULL);\n \t\tif (!buf)\n \t\t\tdie(\"unable to read tree %s\", oid_to_hex(oid));\n \t}\n@@ -542,7 +542,7 @@ int get_tree_entry(const struct object_id *tree_oid, const char *name, struct ob\n \tunsigned long size;\n \tstruct object_id root;\n \n-\ttree = read_object_with_reference(tree_oid, tree_type, &size, &root);\n+\ttree = read_object_with_reference(the_repository, tree_oid, tree_type, &size, &root);\n \tif (!tree)\n \t\treturn -1;\n \n@@ -609,7 +609,8 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, c\n \t\t\tvoid *tree;\n \t\t\tstruct object_id root;\n \t\t\tunsigned long size;\n-\t\t\ttree = read_object_with_reference(&current_tree_oid,\n+\t\t\ttree = read_object_with_reference(the_repository,\n+\t\t\t\t\t\t\t  &current_tree_oid,\n \t\t\t\t\t\t\t  tree_type, &size,\n \t\t\t\t\t\t\t  &root);\n \t\t\tif (!tree)\n-- \n2.22.0.rc0.322.g2b0371e29a\n\n"},{"id":"377852","messageId":"20190624095533.22162-3-pclouds@gmail.com","threadId":"51368","inReplyTo":"20190624095533.22162-1-pclouds@gmail.com","subject":"[PATCH 2/6] tree-walk.c: remove the_repo from fill_tree_descriptor()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-24T09:55:29Z","receivedAt":"2019-06-24T09:55:53Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"While at there, clean up the_repo usage in builtin/merge-tree.c a tiny\nbit.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/merge-tree.c | 22 +++++++++++++---------\n builtin/rebase.c     |  4 ++--\n builtin/reset.c      |  4 ++--\n notes.c              |  2 +-\n sequencer.c          |  2 +-\n tree-diff.c          |  4 ++--\n tree-walk.c          |  6 ++++--\n tree-walk.h          |  4 +++-\n unpack-trees.c       |  2 +-\n 9 files changed, 29 insertions(+), 21 deletions(-)\n\ndiff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\nindex 34ca0258b1..97b54caeb9 100644\n--- a/builtin/merge-tree.c\n+++ b/builtin/merge-tree.c\n@@ -205,6 +205,7 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s\n static void unresolved_directory(const struct traverse_info *info,\n \t\t\t\t struct name_entry n[3])\n {\n+\tstruct repository *r = the_repository;\n \tchar *newbase;\n \tstruct name_entry *p;\n \tstruct tree_desc t[3];\n@@ -220,9 +221,9 @@ static void unresolved_directory(const struct traverse_info *info,\n \tnewbase = traverse_path(info, p);\n \n #define ENTRY_OID(e) (((e)->mode && S_ISDIR((e)->mode)) ? &(e)->oid : NULL)\n-\tbuf0 = fill_tree_descriptor(t + 0, ENTRY_OID(n + 0));\n-\tbuf1 = fill_tree_descriptor(t + 1, ENTRY_OID(n + 1));\n-\tbuf2 = fill_tree_descriptor(t + 2, ENTRY_OID(n + 2));\n+\tbuf0 = fill_tree_descriptor(r, t + 0, ENTRY_OID(n + 0));\n+\tbuf1 = fill_tree_descriptor(r, t + 1, ENTRY_OID(n + 1));\n+\tbuf2 = fill_tree_descriptor(r, t + 2, ENTRY_OID(n + 2));\n #undef ENTRY_OID\n \n \tmerge_trees(t, newbase);\n@@ -351,14 +352,16 @@ static void merge_trees(struct tree_desc t[3], const char *base)\n \ttraverse_trees(&the_index, 3, t, &info);\n }\n \n-static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)\n+static void *get_tree_descriptor(struct repository *r,\n+\t\t\t\t struct tree_desc *desc,\n+\t\t\t\t const char *rev)\n {\n \tstruct object_id oid;\n \tvoid *buf;\n \n-\tif (get_oid(rev, &oid))\n+\tif (repo_get_oid(r, rev, &oid))\n \t\tdie(\"unknown rev %s\", rev);\n-\tbuf = fill_tree_descriptor(desc, &oid);\n+\tbuf = fill_tree_descriptor(r, desc, &oid);\n \tif (!buf)\n \t\tdie(\"%s is not a tree\", rev);\n \treturn buf;\n@@ -366,15 +369,16 @@ static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)\n \n int cmd_merge_tree(int argc, const char **argv, const char *prefix)\n {\n+\tstruct repository *r = the_repository;\n \tstruct tree_desc t[3];\n \tvoid *buf1, *buf2, *buf3;\n \n \tif (argc != 4)\n \t\tusage(merge_tree_usage);\n \n-\tbuf1 = get_tree_descriptor(t+0, argv[1]);\n-\tbuf2 = get_tree_descriptor(t+1, argv[2]);\n-\tbuf3 = get_tree_descriptor(t+2, argv[3]);\n+\tbuf1 = get_tree_descriptor(r, t+0, argv[1]);\n+\tbuf2 = get_tree_descriptor(r, t+1, argv[2]);\n+\tbuf3 = get_tree_descriptor(r, t+2, argv[3]);\n \tmerge_trees(t, \"\");\n \tfree(buf1);\n \tfree(buf2);\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex b8116db487..28490f5f88 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -840,13 +840,13 @@ static int reset_head(struct object_id *oid, const char *action,\n \t\tgoto leave_reset_head;\n \t}\n \n-\tif (!reset_hard && !fill_tree_descriptor(&desc[nr++], &head_oid)) {\n+\tif (!reset_hard && !fill_tree_descriptor(the_repository, &desc[nr++], &head_oid)) {\n \t\tret = error(_(\"failed to find tree of %s\"),\n \t\t\t    oid_to_hex(&head_oid));\n \t\tgoto leave_reset_head;\n \t}\n \n-\tif (!fill_tree_descriptor(&desc[nr++], oid)) {\n+\tif (!fill_tree_descriptor(the_repository, &desc[nr++], oid)) {\n \t\tret = error(_(\"failed to find tree of %s\"), oid_to_hex(oid));\n \t\tgoto leave_reset_head;\n \t}\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 26ef9a7bd0..77c38f28c2 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -79,13 +79,13 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)\n \t\tstruct object_id head_oid;\n \t\tif (get_oid(\"HEAD\", &head_oid))\n \t\t\treturn error(_(\"You do not have a valid HEAD.\"));\n-\t\tif (!fill_tree_descriptor(desc + nr, &head_oid))\n+\t\tif (!fill_tree_descriptor(the_repository, desc + nr, &head_oid))\n \t\t\treturn error(_(\"Failed to find tree of HEAD.\"));\n \t\tnr++;\n \t\topts.fn = twoway_merge;\n \t}\n \n-\tif (!fill_tree_descriptor(desc + nr, oid)) {\n+\tif (!fill_tree_descriptor(the_repository, desc + nr, oid)) {\n \t\terror(_(\"Failed to find tree of %s.\"), oid_to_hex(oid));\n \t\tgoto out;\n \t}\ndiff --git a/notes.c b/notes.c\nindex 532ec37865..2522b87d77 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -397,7 +397,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,\n \tstruct name_entry entry;\n \tconst unsigned hashsz = the_hash_algo->rawsz;\n \n-\tbuf = fill_tree_descriptor(&desc, &subtree->val_oid);\n+\tbuf = fill_tree_descriptor(the_repository, &desc, &subtree->val_oid);\n \tif (!buf)\n \t\tdie(\"Could not read %s for notes-index\",\n \t\t     oid_to_hex(&subtree->val_oid));\ndiff --git a/sequencer.c b/sequencer.c\nindex ab74b6baf1..d565fcf2b1 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -3194,7 +3194,7 @@ static int do_reset(struct repository *r,\n \t\treturn error_resolve_conflict(_(action_name(opts)));\n \t}\n \n-\tif (!fill_tree_descriptor(&desc, &oid)) {\n+\tif (!fill_tree_descriptor(r, &desc, &oid)) {\n \t\terror(_(\"failed to find tree of %s\"), oid_to_hex(&oid));\n \t\trollback_lock_file(&lock);\n \t\tfree((void *)desc.buffer);\ndiff --git a/tree-diff.c b/tree-diff.c\nindex f1f641eb6a..33ded7f8b3 100644\n--- a/tree-diff.c\n+++ b/tree-diff.c\n@@ -422,8 +422,8 @@ static struct combine_diff_path *ll_diff_tree_paths(\n \t *   diff_tree_oid(parent, commit) )\n \t */\n \tfor (i = 0; i < nparent; ++i)\n-\t\ttptree[i] = fill_tree_descriptor(&tp[i], parents_oid[i]);\n-\tttree = fill_tree_descriptor(&t, oid);\n+\t\ttptree[i] = fill_tree_descriptor(opt->repo, &tp[i], parents_oid[i]);\n+\tttree = fill_tree_descriptor(opt->repo, &t, oid);\n \n \t/* Enable recursion indefinitely */\n \topt->pathspec.recursive = opt->flags.recursive;\ndiff --git a/tree-walk.c b/tree-walk.c\nindex 0c7722b220..c5569b3e9f 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -81,13 +81,15 @@ int init_tree_desc_gently(struct tree_desc *desc, const void *buffer, unsigned l\n \treturn result;\n }\n \n-void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid)\n+void *fill_tree_descriptor(struct repository *r,\n+\t\t\t   struct tree_desc *desc,\n+\t\t\t   const struct object_id *oid)\n {\n \tunsigned long size = 0;\n \tvoid *buf = NULL;\n \n \tif (oid) {\n-\t\tbuf = read_object_with_reference(the_repository, oid, tree_type, &size, NULL);\n+\t\tbuf = read_object_with_reference(r, oid, tree_type, &size, NULL);\n \t\tif (!buf)\n \t\t\tdie(\"unable to read tree %s\", oid_to_hex(oid));\n \t}\ndiff --git a/tree-walk.h b/tree-walk.h\nindex 161e2400f4..9aa1042642 100644\n--- a/tree-walk.h\n+++ b/tree-walk.h\n@@ -45,7 +45,9 @@ int init_tree_desc_gently(struct tree_desc *desc, const void *buf, unsigned long\n int tree_entry(struct tree_desc *, struct name_entry *);\n int tree_entry_gently(struct tree_desc *, struct name_entry *);\n \n-void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid);\n+void *fill_tree_descriptor(struct repository *r,\n+\t\t\t   struct tree_desc *desc,\n+\t\t\t   const struct object_id *oid);\n \n struct traverse_info;\n typedef int (*traverse_callback_t)(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *);\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex 50189909b8..cfe1c5ec6f 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -840,7 +840,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,\n \t\t\tconst struct object_id *oid = NULL;\n \t\t\tif (dirmask & 1)\n \t\t\t\toid = &names[i].oid;\n-\t\t\tbuf[nr_buf++] = fill_tree_descriptor(t + i, oid);\n+\t\t\tbuf[nr_buf++] = fill_tree_descriptor(the_repository, t + i, oid);\n \t\t}\n \t}\n \n-- \n2.22.0.rc0.322.g2b0371e29a\n\n"},{"id":"377853","messageId":"20190624095533.22162-4-pclouds@gmail.com","threadId":"51368","inReplyTo":"20190624095533.22162-1-pclouds@gmail.com","subject":"[PATCH 3/6] tree-walk.c: remove the_repo from get_tree_entry()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-24T09:55:30Z","receivedAt":"2019-06-24T09:55:58Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n archive.c              |  4 +++-\n blame.c                |  4 ++--\n builtin/rm.c           |  2 +-\n builtin/update-index.c |  2 +-\n line-log.c             |  7 ++++---\n match-trees.c          |  6 +++---\n merge-recursive.c      |  8 +++++---\n notes.c                |  2 +-\n sha1-name.c            |  9 +++++----\n tree-walk.c            | 18 ++++++++++++------\n tree-walk.h            |  2 +-\n 11 files changed, 38 insertions(+), 26 deletions(-)\n\ndiff --git a/archive.c b/archive.c\nindex 53141c1f0e..a8da0fcc4f 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -418,7 +418,9 @@ static void parse_treeish_arg(const char **argv,\n \t\tunsigned short mode;\n \t\tint err;\n \n-\t\terr = get_tree_entry(&tree->object.oid, prefix, &tree_oid,\n+\t\terr = get_tree_entry(ar_args->repo,\n+\t\t\t\t     &tree->object.oid,\n+\t\t\t\t     prefix, &tree_oid,\n \t\t\t\t     &mode);\n \t\tif (err || !S_ISDIR(mode))\n \t\t\tdie(_(\"current working directory is untracked\"));\ndiff --git a/blame.c b/blame.c\nindex 145eaf2faf..ef022809e9 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -101,7 +101,7 @@ static void verify_working_tree_path(struct repository *r,\n \t\tstruct object_id blob_oid;\n \t\tunsigned short mode;\n \n-\t\tif (!get_tree_entry(commit_oid, path, &blob_oid, &mode) &&\n+\t\tif (!get_tree_entry(r, commit_oid, path, &blob_oid, &mode) &&\n \t\t    oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB)\n \t\t\treturn;\n \t}\n@@ -532,7 +532,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,\n {\n \tif (!is_null_oid(&origin->blob_oid))\n \t\treturn 0;\n-\tif (get_tree_entry(&origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))\n+\tif (get_tree_entry(r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))\n \t\tgoto error_out;\n \tif (oid_object_info(r, &origin->blob_oid, NULL) != OBJ_BLOB)\n \t\tgoto error_out;\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex be8edc6d1e..2eacda42b4 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -179,7 +179,7 @@ static int check_local_mod(struct object_id *head, int index_only)\n \t\t * way as changed from the HEAD.\n \t\t */\n \t\tif (no_head\n-\t\t     || get_tree_entry(head, name, &oid, &mode)\n+\t\t     || get_tree_entry(the_repository, head, name, &oid, &mode)\n \t\t     || ce->ce_mode != create_ce_mode(mode)\n \t\t     || !oideq(&ce->oid, &oid))\n \t\t\tstaged_changes = 1;\ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex 3f8cc6ccb4..dff2f4b837 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -601,7 +601,7 @@ static struct cache_entry *read_one_ent(const char *which,\n \tstruct object_id oid;\n \tstruct cache_entry *ce;\n \n-\tif (get_tree_entry(ent, path, &oid, &mode)) {\n+\tif (get_tree_entry(the_repository, ent, path, &oid, &mode)) {\n \t\tif (which)\n \t\t\terror(\"%s: not in %s branch.\", path, which);\n \t\treturn NULL;\ndiff --git a/line-log.c b/line-log.c\nindex 0a17b21187..3aff1849e7 100644\n--- a/line-log.c\n+++ b/line-log.c\n@@ -496,12 +496,13 @@ static struct commit *check_single_commit(struct rev_info *revs)\n \treturn (struct commit *) commit;\n }\n \n-static void fill_blob_sha1(struct commit *commit, struct diff_filespec *spec)\n+static void fill_blob_sha1(struct repository *r, struct commit *commit,\n+\t\t\t   struct diff_filespec *spec)\n {\n \tunsigned short mode;\n \tstruct object_id oid;\n \n-\tif (get_tree_entry(&commit->object.oid, spec->path, &oid, &mode))\n+\tif (get_tree_entry(r, &commit->object.oid, spec->path, &oid, &mode))\n \t\tdie(\"There is no path %s in the commit\", spec->path);\n \tfill_filespec(spec, &oid, 1, mode);\n \n@@ -585,7 +586,7 @@ parse_lines(struct repository *r, struct commit *commit,\n \t\t\t\t\tname_part);\n \n \t\tspec = alloc_filespec(full_name);\n-\t\tfill_blob_sha1(commit, spec);\n+\t\tfill_blob_sha1(r, commit, spec);\n \t\tfill_line_ends(r, spec, &lines, &ends);\n \t\tcb_data.spec = spec;\n \t\tcb_data.lines = lines;\ndiff --git a/match-trees.c b/match-trees.c\nindex 9d1ec8d6b0..de7e8a6783 100644\n--- a/match-trees.c\n+++ b/match-trees.c\n@@ -290,7 +290,7 @@ void shift_tree(const struct object_id *hash1,\n \t\tif (!*del_prefix)\n \t\t\treturn;\n \n-\t\tif (get_tree_entry(hash2, del_prefix, shifted, &mode))\n+\t\tif (get_tree_entry(the_repository, hash2, del_prefix, shifted, &mode))\n \t\t\tdie(\"cannot find path %s in tree %s\",\n \t\t\t    del_prefix, oid_to_hex(hash2));\n \t\treturn;\n@@ -317,12 +317,12 @@ void shift_tree_by(const struct object_id *hash1,\n \tunsigned candidate = 0;\n \n \t/* Can hash2 be a tree at shift_prefix in tree hash1? */\n-\tif (!get_tree_entry(hash1, shift_prefix, &sub1, &mode1) &&\n+\tif (!get_tree_entry(the_repository, hash1, shift_prefix, &sub1, &mode1) &&\n \t    S_ISDIR(mode1))\n \t\tcandidate |= 1;\n \n \t/* Can hash1 be a tree at shift_prefix in tree hash2? */\n-\tif (!get_tree_entry(hash2, shift_prefix, &sub2, &mode2) &&\n+\tif (!get_tree_entry(the_repository, hash2, shift_prefix, &sub2, &mode2) &&\n \t    S_ISDIR(mode2))\n \t\tcandidate |= 2;\n \ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex d2e380b7ed..b051066795 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -475,7 +475,7 @@ static int get_tree_entry_if_blob(const struct object_id *tree,\n {\n \tint ret;\n \n-\tret = get_tree_entry(tree, path, &dfs->oid, &dfs->mode);\n+\tret = get_tree_entry(the_repository, tree, path, &dfs->oid, &dfs->mode);\n \tif (S_ISDIR(dfs->mode)) {\n \t\toidcpy(&dfs->oid, &null_oid);\n \t\tdfs->mode = 0;\n@@ -1905,7 +1905,8 @@ static int tree_has_path(struct tree *tree, const char *path)\n \tstruct object_id hashy;\n \tunsigned short mode_o;\n \n-\treturn !get_tree_entry(&tree->object.oid, path,\n+\treturn !get_tree_entry(the_repository,\n+\t\t\t       &tree->object.oid, path,\n \t\t\t       &hashy, &mode_o);\n }\n \n@@ -2500,7 +2501,8 @@ static void apply_directory_rename_modifications(struct merge_options *opt,\n \t * the various handle_rename_*() functions update the index\n \t * explicitly rather than relying on unpack_trees() to have done it.\n \t */\n-\tget_tree_entry(&tree->object.oid,\n+\tget_tree_entry(opt->repo,\n+\t\t       &tree->object.oid,\n \t\t       pair->two->path,\n \t\t       &re->dst_entry->stages[stage].oid,\n \t\t       &re->dst_entry->stages[stage].mode);\ndiff --git a/notes.c b/notes.c\nindex 2522b87d77..75c028b300 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -1015,7 +1015,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,\n \t\treturn;\n \tif (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid))\n \t\tdie(\"Cannot use notes ref %s\", notes_ref);\n-\tif (get_tree_entry(&object_oid, \"\", &oid, &mode))\n+\tif (get_tree_entry(the_repository, &object_oid, \"\", &oid, &mode))\n \t\tdie(\"Failed to read notes tree referenced by %s (%s)\",\n \t\t    notes_ref, oid_to_hex(&object_oid));\n \ndiff --git a/sha1-name.c b/sha1-name.c\nindex 728e6f1f61..e8fb215e5c 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1677,7 +1677,8 @@ int repo_get_oid_blob(struct repository *r,\n }\n \n /* Must be called only when object_name:filename doesn't exist. */\n-static void diagnose_invalid_oid_path(const char *prefix,\n+static void diagnose_invalid_oid_path(struct repository *r,\n+\t\t\t\t      const char *prefix,\n \t\t\t\t      const char *filename,\n \t\t\t\t      const struct object_id *tree_oid,\n \t\t\t\t      const char *object_name,\n@@ -1695,7 +1696,7 @@ static void diagnose_invalid_oid_path(const char *prefix,\n \tif (is_missing_file_error(errno)) {\n \t\tchar *fullname = xstrfmt(\"%s%s\", prefix, filename);\n \n-\t\tif (!get_tree_entry(tree_oid, fullname, &oid, &mode)) {\n+\t\tif (!get_tree_entry(r, tree_oid, fullname, &oid, &mode)) {\n \t\t\tdie(\"Path '%s' exists, but not '%s'.\\n\"\n \t\t\t    \"Did you mean '%.*s:%s' aka '%.*s:./%s'?\",\n \t\t\t    fullname,\n@@ -1902,10 +1903,10 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\t\t\tfilename, oid, &oc->symlink_path,\n \t\t\t\t\t&oc->mode);\n \t\t\t} else {\n-\t\t\t\tret = get_tree_entry(&tree_oid, filename, oid,\n+\t\t\t\tret = get_tree_entry(repo, &tree_oid, filename, oid,\n \t\t\t\t\t\t     &oc->mode);\n \t\t\t\tif (ret && only_to_die) {\n-\t\t\t\t\tdiagnose_invalid_oid_path(prefix,\n+\t\t\t\t\tdiagnose_invalid_oid_path(repo, prefix,\n \t\t\t\t\t\t\t\t   filename,\n \t\t\t\t\t\t\t\t   &tree_oid,\n \t\t\t\t\t\t\t\t   name, len);\ndiff --git a/tree-walk.c b/tree-walk.c\nindex c5569b3e9f..506e12a031 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -502,7 +502,9 @@ struct dir_state {\n \tstruct object_id oid;\n };\n \n-static int find_tree_entry(struct tree_desc *t, const char *name, struct object_id *result, unsigned short *mode)\n+static int find_tree_entry(struct repository *r, struct tree_desc *t,\n+\t\t\t   const char *name, struct object_id *result,\n+\t\t\t   unsigned short *mode)\n {\n \tint namelen = strlen(name);\n \twhile (t->size) {\n@@ -532,19 +534,23 @@ static int find_tree_entry(struct tree_desc *t, const char *name, struct object_\n \t\t\toidcpy(result, &oid);\n \t\t\treturn 0;\n \t\t}\n-\t\treturn get_tree_entry(&oid, name + entrylen, result, mode);\n+\t\treturn get_tree_entry(r, &oid, name + entrylen, result, mode);\n \t}\n \treturn -1;\n }\n \n-int get_tree_entry(const struct object_id *tree_oid, const char *name, struct object_id *oid, unsigned short *mode)\n+int get_tree_entry(struct repository *r,\n+\t\t   const struct object_id *tree_oid,\n+\t\t   const char *name,\n+\t\t   struct object_id *oid,\n+\t\t   unsigned short *mode)\n {\n \tint retval;\n \tvoid *tree;\n \tunsigned long size;\n \tstruct object_id root;\n \n-\ttree = read_object_with_reference(the_repository, tree_oid, tree_type, &size, &root);\n+\ttree = read_object_with_reference(r, tree_oid, tree_type, &size, &root);\n \tif (!tree)\n \t\treturn -1;\n \n@@ -559,7 +565,7 @@ int get_tree_entry(const struct object_id *tree_oid, const char *name, struct ob\n \t} else {\n \t\tstruct tree_desc t;\n \t\tinit_tree_desc(&t, tree, size);\n-\t\tretval = find_tree_entry(&t, name, oid, mode);\n+\t\tretval = find_tree_entry(r, &t, name, oid, mode);\n \t}\n \tfree(tree);\n \treturn retval;\n@@ -681,7 +687,7 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, c\n \t\t}\n \n \t\t/* Look up the first (or only) path component in the tree. */\n-\t\tfind_result = find_tree_entry(&t, namebuf.buf,\n+\t\tfind_result = find_tree_entry(the_repository, &t, namebuf.buf,\n \t\t\t\t\t      &current_tree_oid, mode);\n \t\tif (find_result) {\n \t\t\tgoto done;\ndiff --git a/tree-walk.h b/tree-walk.h\nindex 9aa1042642..639f79187f 100644\n--- a/tree-walk.h\n+++ b/tree-walk.h\n@@ -68,7 +68,7 @@ struct traverse_info {\n \tint show_all_errors;\n };\n \n-int get_tree_entry(const struct object_id *, const char *, struct object_id *, unsigned short *);\n+int get_tree_entry(struct repository *, const struct object_id *, const char *, struct object_id *, unsigned short *);\n char *make_traverse_path(char *path, const struct traverse_info *info, const struct name_entry *n);\n void setup_traverse_info(struct traverse_info *info, const char *base);\n \n-- \n2.22.0.rc0.322.g2b0371e29a\n\n"},{"id":"377854","messageId":"20190624095533.22162-5-pclouds@gmail.com","threadId":"51368","inReplyTo":"20190624095533.22162-1-pclouds@gmail.com","subject":"[PATCH 4/6] tree-walk.c: remove the_repo from get_tree_entry_follow_symlinks()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-24T09:55:31Z","receivedAt":"2019-06-24T09:56:02Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n sha1-name.c | 10 +---------\n tree-walk.c | 12 ++++++++----\n tree-walk.h |  2 +-\n 3 files changed, 10 insertions(+), 14 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex e8fb215e5c..3c9fa10af8 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1890,16 +1890,8 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\tnew_filename = resolve_relative_path(repo, filename);\n \t\t\tif (new_filename)\n \t\t\t\tfilename = new_filename;\n-\t\t\t/*\n-\t\t\t * NEEDSWORK: Eventually get_tree_entry*() should\n-\t\t\t * learn to take struct repository directly and we\n-\t\t\t * would not need to inject submodule odb to the\n-\t\t\t * in-core odb.\n-\t\t\t */\n-\t\t\tif (repo != the_repository)\n-\t\t\t\tadd_to_alternates_memory(repo->objects->odb->path);\n \t\t\tif (flags & GET_OID_FOLLOW_SYMLINKS) {\n-\t\t\t\tret = get_tree_entry_follow_symlinks(&tree_oid,\n+\t\t\t\tret = get_tree_entry_follow_symlinks(repo, &tree_oid,\n \t\t\t\t\tfilename, oid, &oc->symlink_path,\n \t\t\t\t\t&oc->mode);\n \t\t\t} else {\ndiff --git a/tree-walk.c b/tree-walk.c\nindex 506e12a031..c20b62f49e 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -593,7 +593,10 @@ int get_tree_entry(struct repository *r,\n  * See the code for enum get_oid_result for a description of\n  * the return values.\n  */\n-enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, const char *name, struct object_id *result, struct strbuf *result_path, unsigned short *mode)\n+enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,\n+\t\tstruct object_id *tree_oid, const char *name,\n+\t\tstruct object_id *result, struct strbuf *result_path,\n+\t\tunsigned short *mode)\n {\n \tint retval = MISSING_OBJECT;\n \tstruct dir_state *parents = NULL;\n@@ -617,7 +620,7 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, c\n \t\t\tvoid *tree;\n \t\t\tstruct object_id root;\n \t\t\tunsigned long size;\n-\t\t\ttree = read_object_with_reference(the_repository,\n+\t\t\ttree = read_object_with_reference(r,\n \t\t\t\t\t\t\t  &current_tree_oid,\n \t\t\t\t\t\t\t  tree_type, &size,\n \t\t\t\t\t\t\t  &root);\n@@ -687,7 +690,7 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, c\n \t\t}\n \n \t\t/* Look up the first (or only) path component in the tree. */\n-\t\tfind_result = find_tree_entry(the_repository, &t, namebuf.buf,\n+\t\tfind_result = find_tree_entry(r, &t, namebuf.buf,\n \t\t\t\t\t      &current_tree_oid, mode);\n \t\tif (find_result) {\n \t\t\tgoto done;\n@@ -731,7 +734,8 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, c\n \t\t\t */\n \t\t\tretval = DANGLING_SYMLINK;\n \n-\t\t\tcontents = read_object_file(&current_tree_oid, &type,\n+\t\t\tcontents = repo_read_object_file(r,\n+\t\t\t\t\t\t    &current_tree_oid, &type,\n \t\t\t\t\t\t    &link_len);\n \n \t\t\tif (!contents)\ndiff --git a/tree-walk.h b/tree-walk.h\nindex 639f79187f..2a5db29e8f 100644\n--- a/tree-walk.h\n+++ b/tree-walk.h\n@@ -53,7 +53,7 @@ struct traverse_info;\n typedef int (*traverse_callback_t)(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *);\n int traverse_trees(struct index_state *istate, int n, struct tree_desc *t, struct traverse_info *info);\n \n-enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, const char *name, struct object_id *result, struct strbuf *result_path, unsigned short *mode);\n+enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r, struct object_id *tree_oid, const char *name, struct object_id *result, struct strbuf *result_path, unsigned short *mode);\n \n struct traverse_info {\n \tconst char *traverse_path;\n-- \n2.22.0.rc0.322.g2b0371e29a\n\n"},{"id":"377855","messageId":"20190624095533.22162-6-pclouds@gmail.com","threadId":"51368","inReplyTo":"20190624095533.22162-1-pclouds@gmail.com","subject":"[PATCH 5/6] match-trees.c: remove the_repo from shift_tree*()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-24T09:55:32Z","receivedAt":"2019-06-24T09:56:07Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n cache.h                     |  4 ++--\n match-trees.c               | 12 +++++++-----\n merge-recursive.c           |  4 ++--\n t/helper/test-match-trees.c |  2 +-\n 4 files changed, 12 insertions(+), 10 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex cd84cc9bbe..ddefda2bb6 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1786,8 +1786,8 @@ int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int\n extern int diff_auto_refresh_index;\n \n /* match-trees.c */\n-void shift_tree(const struct object_id *, const struct object_id *, struct object_id *, int);\n-void shift_tree_by(const struct object_id *, const struct object_id *, struct object_id *, const char *);\n+void shift_tree(struct repository *, const struct object_id *, const struct object_id *, struct object_id *, int);\n+void shift_tree_by(struct repository *, const struct object_id *, const struct object_id *, struct object_id *, const char *);\n \n /*\n  * whitespace rules.\ndiff --git a/match-trees.c b/match-trees.c\nindex de7e8a6783..f6c194c1cc 100644\n--- a/match-trees.c\n+++ b/match-trees.c\n@@ -248,7 +248,8 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,\n  * other hand, it could cover tree one and we might need to pick a\n  * subtree of it.\n  */\n-void shift_tree(const struct object_id *hash1,\n+void shift_tree(struct repository *r,\n+\t\tconst struct object_id *hash1,\n \t\tconst struct object_id *hash2,\n \t\tstruct object_id *shifted,\n \t\tint depth_limit)\n@@ -290,7 +291,7 @@ void shift_tree(const struct object_id *hash1,\n \t\tif (!*del_prefix)\n \t\t\treturn;\n \n-\t\tif (get_tree_entry(the_repository, hash2, del_prefix, shifted, &mode))\n+\t\tif (get_tree_entry(r, hash2, del_prefix, shifted, &mode))\n \t\t\tdie(\"cannot find path %s in tree %s\",\n \t\t\t    del_prefix, oid_to_hex(hash2));\n \t\treturn;\n@@ -307,7 +308,8 @@ void shift_tree(const struct object_id *hash1,\n  * Unfortunately we cannot fundamentally tell which one to\n  * be prefixed, as recursive merge can work in either direction.\n  */\n-void shift_tree_by(const struct object_id *hash1,\n+void shift_tree_by(struct repository *r,\n+\t\t   const struct object_id *hash1,\n \t\t   const struct object_id *hash2,\n \t\t   struct object_id *shifted,\n \t\t   const char *shift_prefix)\n@@ -317,12 +319,12 @@ void shift_tree_by(const struct object_id *hash1,\n \tunsigned candidate = 0;\n \n \t/* Can hash2 be a tree at shift_prefix in tree hash1? */\n-\tif (!get_tree_entry(the_repository, hash1, shift_prefix, &sub1, &mode1) &&\n+\tif (!get_tree_entry(r, hash1, shift_prefix, &sub1, &mode1) &&\n \t    S_ISDIR(mode1))\n \t\tcandidate |= 1;\n \n \t/* Can hash1 be a tree at shift_prefix in tree hash2? */\n-\tif (!get_tree_entry(the_repository, hash2, shift_prefix, &sub2, &mode2) &&\n+\tif (!get_tree_entry(r, hash2, shift_prefix, &sub2, &mode2) &&\n \t    S_ISDIR(mode2))\n \t\tcandidate |= 2;\n \ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex b051066795..6d772eb0eb 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -153,9 +153,9 @@ static struct tree *shift_tree_object(struct repository *repo,\n \tstruct object_id shifted;\n \n \tif (!*subtree_shift) {\n-\t\tshift_tree(&one->object.oid, &two->object.oid, &shifted, 0);\n+\t\tshift_tree(repo, &one->object.oid, &two->object.oid, &shifted, 0);\n \t} else {\n-\t\tshift_tree_by(&one->object.oid, &two->object.oid, &shifted,\n+\t\tshift_tree_by(repo, &one->object.oid, &two->object.oid, &shifted,\n \t\t\t      subtree_shift);\n \t}\n \tif (oideq(&two->object.oid, &shifted))\ndiff --git a/t/helper/test-match-trees.c b/t/helper/test-match-trees.c\nindex 96857f26ac..b9fd427571 100644\n--- a/t/helper/test-match-trees.c\n+++ b/t/helper/test-match-trees.c\n@@ -20,7 +20,7 @@ int cmd__match_trees(int ac, const char **av)\n \tif (!two)\n \t\tdie(\"not a tree-ish %s\", av[2]);\n \n-\tshift_tree(&one->object.oid, &two->object.oid, &shifted, -1);\n+\tshift_tree(the_repository, &one->object.oid, &two->object.oid, &shifted, -1);\n \tprintf(\"shifted: %s\\n\", oid_to_hex(&shifted));\n \n \texit(0);\n-- \n2.22.0.rc0.322.g2b0371e29a\n\n"},{"id":"377856","messageId":"20190624095533.22162-7-pclouds@gmail.com","threadId":"51368","inReplyTo":"20190624095533.22162-1-pclouds@gmail.com","subject":"[PATCH 6/6] Use the right 'struct repository' instead of the_repository","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-24T09:55:33Z","receivedAt":"2019-06-24T09:56:11Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"There are a couple of places where 'struct repository' is already passed\naround, but the_repository is still used. Use the right repo.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n merge-recursive.c | 35 ++++++++++++++++++++---------------\n sequencer.c       |  4 ++--\n sha1-name.c       |  6 ++----\n shallow.c         |  3 ++-\n 4 files changed, 26 insertions(+), 22 deletions(-)\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 6d772eb0eb..12300131fc 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -465,17 +465,18 @@ static void get_files_dirs(struct merge_options *opt, struct tree *tree)\n {\n \tstruct pathspec match_all;\n \tmemset(&match_all, 0, sizeof(match_all));\n-\tread_tree_recursive(the_repository, tree, \"\", 0, 0,\n+\tread_tree_recursive(opt->repo, tree, \"\", 0, 0,\n \t\t\t    &match_all, save_files_dirs, opt);\n }\n \n-static int get_tree_entry_if_blob(const struct object_id *tree,\n+static int get_tree_entry_if_blob(struct repository *r,\n+\t\t\t\t  const struct object_id *tree,\n \t\t\t\t  const char *path,\n \t\t\t\t  struct diff_filespec *dfs)\n {\n \tint ret;\n \n-\tret = get_tree_entry(the_repository, tree, path, &dfs->oid, &dfs->mode);\n+\tret = get_tree_entry(r, tree, path, &dfs->oid, &dfs->mode);\n \tif (S_ISDIR(dfs->mode)) {\n \t\toidcpy(&dfs->oid, &null_oid);\n \t\tdfs->mode = 0;\n@@ -487,15 +488,16 @@ static int get_tree_entry_if_blob(const struct object_id *tree,\n  * Returns an index_entry instance which doesn't have to correspond to\n  * a real cache entry in Git's index.\n  */\n-static struct stage_data *insert_stage_data(const char *path,\n+static struct stage_data *insert_stage_data(struct repository *r,\n+\t\tconst char *path,\n \t\tstruct tree *o, struct tree *a, struct tree *b,\n \t\tstruct string_list *entries)\n {\n \tstruct string_list_item *item;\n \tstruct stage_data *e = xcalloc(1, sizeof(struct stage_data));\n-\tget_tree_entry_if_blob(&o->object.oid, path, &e->stages[1]);\n-\tget_tree_entry_if_blob(&a->object.oid, path, &e->stages[2]);\n-\tget_tree_entry_if_blob(&b->object.oid, path, &e->stages[3]);\n+\tget_tree_entry_if_blob(r, &o->object.oid, path, &e->stages[1]);\n+\tget_tree_entry_if_blob(r, &a->object.oid, path, &e->stages[2]);\n+\tget_tree_entry_if_blob(r, &b->object.oid, path, &e->stages[3]);\n \titem = string_list_insert(entries, path);\n \titem->util = e;\n \treturn e;\n@@ -1900,12 +1902,13 @@ static struct diff_queue_struct *get_diffpairs(struct merge_options *opt,\n \treturn ret;\n }\n \n-static int tree_has_path(struct tree *tree, const char *path)\n+static int tree_has_path(struct repository *r, struct tree *tree,\n+\t\t\t const char *path)\n {\n \tstruct object_id hashy;\n \tunsigned short mode_o;\n \n-\treturn !get_tree_entry(the_repository,\n+\treturn !get_tree_entry(r,\n \t\t\t       &tree->object.oid, path,\n \t\t\t       &hashy, &mode_o);\n }\n@@ -2057,7 +2060,7 @@ static char *handle_path_level_conflicts(struct merge_options *opt,\n \t */\n \tif (collision_ent->reported_already) {\n \t\tclean = 0;\n-\t} else if (tree_has_path(tree, new_path)) {\n+\t} else if (tree_has_path(opt->repo, tree, new_path)) {\n \t\tcollision_ent->reported_already = 1;\n \t\tstrbuf_add_separated_string_list(&collision_paths, \", \",\n \t\t\t\t\t\t &collision_ent->source_files);\n@@ -2135,7 +2138,7 @@ static void handle_directory_level_conflicts(struct merge_options *opt,\n \t\t\tstring_list_append(&remove_from_merge,\n \t\t\t\t\t   merge_ent->dir)->util = merge_ent;\n \t\t\tstrbuf_release(&merge_ent->new_dir);\n-\t\t} else if (tree_has_path(head, head_ent->dir)) {\n+\t\t} else if (tree_has_path(opt->repo, head, head_ent->dir)) {\n \t\t\t/* 2. This wasn't a directory rename after all */\n \t\t\tstring_list_append(&remove_from_head,\n \t\t\t\t\t   head_ent->dir)->util = head_ent;\n@@ -2149,7 +2152,7 @@ static void handle_directory_level_conflicts(struct merge_options *opt,\n \thashmap_iter_init(dir_re_merge, &iter);\n \twhile ((merge_ent = hashmap_iter_next(&iter))) {\n \t\thead_ent = dir_rename_find_entry(dir_re_head, merge_ent->dir);\n-\t\tif (tree_has_path(merge, merge_ent->dir)) {\n+\t\tif (tree_has_path(opt->repo, merge, merge_ent->dir)) {\n \t\t\t/* 2. This wasn't a directory rename after all */\n \t\t\tstring_list_append(&remove_from_merge,\n \t\t\t\t\t   merge_ent->dir)->util = merge_ent;\n@@ -2478,7 +2481,7 @@ static void apply_directory_rename_modifications(struct merge_options *opt,\n \t\tif (pair->status == 'R')\n \t\t\tre->dst_entry->processed = 1;\n \n-\t\tre->dst_entry = insert_stage_data(new_path,\n+\t\tre->dst_entry = insert_stage_data(opt->repo, new_path,\n \t\t\t\t\t\t  o_tree, a_tree, b_tree,\n \t\t\t\t\t\t  entries);\n \t\titem = string_list_insert(entries, new_path);\n@@ -2587,14 +2590,16 @@ static struct string_list *get_renames(struct merge_options *opt,\n \t\tre->dir_rename_original_dest = NULL;\n \t\titem = string_list_lookup(entries, re->pair->one->path);\n \t\tif (!item)\n-\t\t\tre->src_entry = insert_stage_data(re->pair->one->path,\n+\t\t\tre->src_entry = insert_stage_data(opt->repo,\n+\t\t\t\t\tre->pair->one->path,\n \t\t\t\t\to_tree, a_tree, b_tree, entries);\n \t\telse\n \t\t\tre->src_entry = item->util;\n \n \t\titem = string_list_lookup(entries, re->pair->two->path);\n \t\tif (!item)\n-\t\t\tre->dst_entry = insert_stage_data(re->pair->two->path,\n+\t\t\tre->dst_entry = insert_stage_data(opt->repo,\n+\t\t\t\t\tre->pair->two->path,\n \t\t\t\t\to_tree, a_tree, b_tree, entries);\n \t\telse\n \t\t\tre->dst_entry = item->util;\ndiff --git a/sequencer.c b/sequencer.c\nindex d565fcf2b1..64428ac28f 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -3733,7 +3733,7 @@ static int pick_commits(struct repository *r,\n \t\t\tunlink(rebase_path_author_script());\n \t\t\tunlink(rebase_path_stopped_sha());\n \t\t\tunlink(rebase_path_amend());\n-\t\t\tunlink(git_path_merge_head(the_repository));\n+\t\t\tunlink(git_path_merge_head(r));\n \t\t\tdelete_ref(NULL, \"REBASE_HEAD\", NULL, REF_NO_DEREF);\n \n \t\t\tif (item->command == TODO_BREAK)\n@@ -4107,7 +4107,7 @@ static int commit_staged_changes(struct repository *r,\n \t\t\t   opts, flags))\n \t\treturn error(_(\"could not commit staged changes.\"));\n \tunlink(rebase_path_amend());\n-\tunlink(git_path_merge_head(the_repository));\n+\tunlink(git_path_merge_head(r));\n \tif (final_fixup) {\n \t\tunlink(rebase_path_fixup_msg());\n \t\tunlink(rebase_path_squash_msg());\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 3c9fa10af8..6069fe006b 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -478,7 +478,7 @@ static enum get_oid_result get_short_oid(struct repository *r,\n \t * or migrated from loose to packed.\n \t */\n \tif (status == MISSING_OBJECT) {\n-\t\treprepare_packed_git(the_repository);\n+\t\treprepare_packed_git(r);\n \t\tfind_short_object_filename(&ds);\n \t\tfind_short_packed_object(&ds);\n \t\tstatus = finish_object_disambiguation(&ds, oid);\n@@ -1389,9 +1389,7 @@ int repo_get_oid_mb(struct repository *r,\n \ttwo = lookup_commit_reference_gently(r, &oid_tmp, 0);\n \tif (!two)\n \t\treturn -1;\n-\tif (r != the_repository)\n-\t\tBUG(\"sorry get_merge_bases() can't take struct repository yet\");\n-\tmbs = get_merge_bases(one, two);\n+\tmbs = repo_get_merge_bases(r, one, two);\n \tif (!mbs || mbs->next)\n \t\tst = -1;\n \telse {\ndiff --git a/shallow.c b/shallow.c\nindex ce45297940..5fa2b15d37 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -248,7 +248,8 @@ static void check_shallow_file_for_update(struct repository *r)\n \tif (r->parsed_objects->is_shallow == -1)\n \t\tBUG(\"shallow must be initialized by now\");\n \n-\tif (!stat_validity_check(r->parsed_objects->shallow_stat, git_path_shallow(the_repository)))\n+\tif (!stat_validity_check(r->parsed_objects->shallow_stat,\n+\t\t\t\t git_path_shallow(r)))\n \t\tdie(\"shallow file has changed since we read it\");\n }\n \n-- \n2.22.0.rc0.322.g2b0371e29a\n\n"},{"id":"377887","messageId":"a2d91c63-86ca-90e7-0087-09df269d3865@gmail.com","threadId":"51368","inReplyTo":"20190624095533.22162-3-pclouds@gmail.com","subject":"Re: [PATCH 2/6] tree-walk.c: remove the_repo from fill_tree_descriptor()","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2019-06-24T13:30:14Z","receivedAt":"2019-06-24T13:30:16Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 6/24/2019 5:55 AM, Nguyễn Thái Ngọc Duy wrote:\n> While at there, clean up the_repo usage in builtin/merge-tree.c a tiny\n> bit.\n> \n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  builtin/merge-tree.c | 22 +++++++++++++---------\n>  builtin/rebase.c     |  4 ++--\n>  builtin/reset.c      |  4 ++--\n>  notes.c              |  2 +-\n>  sequencer.c          |  2 +-\n>  tree-diff.c          |  4 ++--\n>  tree-walk.c          |  6 ++++--\n>  tree-walk.h          |  4 +++-\n>  unpack-trees.c       |  2 +-\n>  9 files changed, 29 insertions(+), 21 deletions(-)\n> \n> diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\n> index 34ca0258b1..97b54caeb9 100644\n> --- a/builtin/merge-tree.c\n> +++ b/builtin/merge-tree.c\n> @@ -205,6 +205,7 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s\n>  static void unresolved_directory(const struct traverse_info *info,\n>  \t\t\t\t struct name_entry n[3])\n>  {\n> +\tstruct repository *r = the_repository;\n\nI like this trick to make the change below minimal:\n> +\tbuf0 = fill_tree_descriptor(r, t + 0, ENTRY_OID(n + 0));\n> +\tbuf1 = fill_tree_descriptor(r, t + 1, ENTRY_OID(n + 1));\n> +\tbuf2 = fill_tree_descriptor(r, t + 2, ENTRY_OID(n + 2));\n\nI wonder if _every_ conversion should include this trick,\nso when we move to change that method we simply move the definition\nfrom the method block to the prototype. (No need to adjust what you've\ndone already, just an idea for future conversions.)\n\nThanks,\n-Stolee\n"},{"id":"377888","messageId":"0f13008e-bdf1-70cb-c4ff-e4c572cd5703@gmail.com","threadId":"51368","inReplyTo":"20190624095533.22162-4-pclouds@gmail.com","subject":"Re: [PATCH 3/6] tree-walk.c: remove the_repo from get_tree_entry()","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2019-06-24T14:20:01Z","receivedAt":"2019-06-24T14:20:04Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 6/24/2019 5:55 AM, Nguyễn Thái Ngọc Duy wrote:\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  archive.c              |  4 +++-\n>  blame.c                |  4 ++--\n>  builtin/rm.c           |  2 +-\n>  builtin/update-index.c |  2 +-\n>  line-log.c             |  7 ++++---\n>  match-trees.c          |  6 +++---\n>  merge-recursive.c      |  8 +++++---\n>  notes.c                |  2 +-\n>  sha1-name.c            |  9 +++++----\n>  tree-walk.c            | 18 ++++++++++++------\n>  tree-walk.h            |  2 +-\n>  11 files changed, 38 insertions(+), 26 deletions(-)\n> \n> diff --git a/archive.c b/archive.c\n> index 53141c1f0e..a8da0fcc4f 100644\n> --- a/archive.c\n> +++ b/archive.c\n> @@ -418,7 +418,9 @@ static void parse_treeish_arg(const char **argv,\n>  \t\tunsigned short mode;\n>  \t\tint err;\n>  \n> -\t\terr = get_tree_entry(&tree->object.oid, prefix, &tree_oid,\n> +\t\terr = get_tree_entry(ar_args->repo,\n\nIf I'm reading this correctly, this is a place where we previously converted\nto using a custom repository pointer but this function boundary reverted us\nto the_repository anyway. I know we have some tests around the commit-graph\nthat ensures it works with an arbitrary repository (and I frequently stumble\nover them when I add new dependencies). How can we add more testing around\nthese new conversions?\n\nThe rest looks straight-forward.\n\nThanks,\n-Stolee\n\n"},{"id":"377889","messageId":"166543de-bc25-ca2c-326a-4497688aa235@gmail.com","threadId":"51368","inReplyTo":"20190624095533.22162-7-pclouds@gmail.com","subject":"Re: [PATCH 6/6] Use the right 'struct repository' instead of the_repository","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2019-06-24T14:24:14Z","receivedAt":"2019-06-24T14:24:17Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 6/24/2019 5:55 AM, Nguyễn Thái Ngọc Duy wrote:\n> There are a couple of places where 'struct repository' is already passed\n> around, but the_repository is still used. Use the right repo.\n> \n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n\nnit: the subject line doesn't use the standard \"area: topic\" format (including\nthe capitalization of the first word). Perhaps:\n\ntreewide: use the right 'struct repository' instead of the_repository\n\nThe changes here are straight-forward, but how do we check if we are done?\n\nThanks,\n-Stolee\n"},{"id":"377890","messageId":"CACsJy8A7JT404tMFLs4-qS=S7Sj_dS4NGtXFd0q7xDq0senF_Q@mail.gmail.com","threadId":"51368","inReplyTo":"166543de-bc25-ca2c-326a-4497688aa235@gmail.com","subject":"Re: [PATCH 6/6] Use the right 'struct repository' instead of the_repository","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-24T14:45:43Z","receivedAt":"2019-06-24T14:46:11Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Jun 24, 2019 at 9:24 PM Derrick Stolee <stolee@gmail.com> wrote:\n>\n> On 6/24/2019 5:55 AM, Nguyễn Thái Ngọc Duy wrote:\n> > There are a couple of places where 'struct repository' is already passed\n> > around, but the_repository is still used. Use the right repo.\n> >\n> > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n>\n> nit: the subject line doesn't use the standard \"area: topic\" format\n\nbecause there's no specific area to this patch. I don't think sticking\nto a fixed convention for the sake of it is really sensible.\n\n> (including\n> the capitalization of the first word). Perhaps:\n>\n> treewide: use the right 'struct repository' instead of the_repository\n>\n> The changes here are straight-forward, but how do we check if we are done?\n\nAt this point, you can't. At some point we should be able to\noptionally disable the_repository, at least per file [2]. But even\nthen some function calls inside could still hide the_repository and\nyou would need something like [1] to reveal them.\n\nThe problem with [2] is it will cause a lot of problems when adding\nnew code until most of the code is converted. I will bring that up\nwhen the number of the_repository (outside builtin/) goes down below\n~50. With all my patches, I think we're at 300.\n\n[1] https://gitlab.com/pclouds/git/commit/902a4dbdef6829ca06e12dbf74b0690456733351\n[2] https://gitlab.com/pclouds/git/commit/f03f915294210baf038ee72d76ee998d9387028b\n-- \nDuy\n"},{"id":"377891","messageId":"CACsJy8CaUHTfUS9tMDTNC+S10Bpqz_-rujR6Jr0689AJHpf=UQ@mail.gmail.com","threadId":"51368","inReplyTo":"0f13008e-bdf1-70cb-c4ff-e4c572cd5703@gmail.com","subject":"Re: [PATCH 3/6] tree-walk.c: remove the_repo from get_tree_entry()","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-24T14:55:18Z","receivedAt":"2019-06-24T14:55:46Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Jun 24, 2019 at 9:20 PM Derrick Stolee <stolee@gmail.com> wrote:\n>\n> On 6/24/2019 5:55 AM, Nguyễn Thái Ngọc Duy wrote:\n> > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> > ---\n> >  archive.c              |  4 +++-\n> >  blame.c                |  4 ++--\n> >  builtin/rm.c           |  2 +-\n> >  builtin/update-index.c |  2 +-\n> >  line-log.c             |  7 ++++---\n> >  match-trees.c          |  6 +++---\n> >  merge-recursive.c      |  8 +++++---\n> >  notes.c                |  2 +-\n> >  sha1-name.c            |  9 +++++----\n> >  tree-walk.c            | 18 ++++++++++++------\n> >  tree-walk.h            |  2 +-\n> >  11 files changed, 38 insertions(+), 26 deletions(-)\n> >\n> > diff --git a/archive.c b/archive.c\n> > index 53141c1f0e..a8da0fcc4f 100644\n> > --- a/archive.c\n> > +++ b/archive.c\n> > @@ -418,7 +418,9 @@ static void parse_treeish_arg(const char **argv,\n> >               unsigned short mode;\n> >               int err;\n> >\n> > -             err = get_tree_entry(&tree->object.oid, prefix, &tree_oid,\n> > +             err = get_tree_entry(ar_args->repo,\n>\n> If I'm reading this correctly, this is a place where we previously converted\n> to using a custom repository pointer but this function boundary reverted us\n> to the_repository anyway. I know we have some tests around the commit-graph\n> that ensures it works with an arbitrary repository (and I frequently stumble\n> over them when I add new dependencies). How can we add more testing around\n> these new conversions?\n\nRight now it's really patchy. There's no guarantee that the_repo is\nnot used somwhere in the callchain (or will not be in the future). My\nmain aim is _not_ break it when used with the_repo. These new\nconversions hopefully will get more used outside the default the_repo\nsetting (e.g. new developments in git-submodule, or git-worktree).\nEventually the_repo should be gone (or referenced in very few places),\nthen the conversion will get more coverage. Really mixing repos though\nwill not be as well tested until actually used (by submodule and\nfriends).\n-- \nDuy\n"},{"id":"378068","messageId":"xmqqblyke2hx.fsf@gitster-ct.c.googlers.com","threadId":"51368","inReplyTo":"a2d91c63-86ca-90e7-0087-09df269d3865@gmail.com","subject":"Re: [PATCH 2/6] tree-walk.c: remove the_repo from fill_tree_descriptor()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-06-26T16:27:06Z","receivedAt":"2019-06-26T16:27:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Derrick Stolee <stolee@gmail.com> writes:\n\n>> diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\n>> index 34ca0258b1..97b54caeb9 100644\n>> --- a/builtin/merge-tree.c\n>> +++ b/builtin/merge-tree.c\n>> @@ -205,6 +205,7 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s\n>>  static void unresolved_directory(const struct traverse_info *info,\n>>  \t\t\t\t struct name_entry n[3])\n>>  {\n>> +\tstruct repository *r = the_repository;\n>\n> I like this trick to make the change below minimal:\n>> +\tbuf0 = fill_tree_descriptor(r, t + 0, ENTRY_OID(n + 0));\n>> +\tbuf1 = fill_tree_descriptor(r, t + 1, ENTRY_OID(n + 1));\n>> +\tbuf2 = fill_tree_descriptor(r, t + 2, ENTRY_OID(n + 2));\n>\n> I wonder if _every_ conversion should include this trick,\n> so when we move to change that method we simply move the definition\n> from the method block to the prototype. (No need to adjust what you've\n> done already, just an idea for future conversions.)\n\nHmm, interesting.  So those callers in builtin/rebase.c::reset_head()\nand other places that adds the_repository as the new first parameter\ncan take a local variable \"r\" (or perhaps a bit more descriptive,\ne.g. \"repo\") that is initialized to \"the_repository\" (and never\nreassigned at least at this step) in this same patch?\n"},{"id":"378069","messageId":"2f4c3024-d787-6865-f3f9-a3f43a27a94f@gmail.com","threadId":"51368","inReplyTo":"xmqqblyke2hx.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH 2/6] tree-walk.c: remove the_repo from fill_tree_descriptor()","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2019-06-26T16:47:25Z","receivedAt":"2019-06-26T16:47:29Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 6/26/2019 12:27 PM, Junio C Hamano wrote:\n> Derrick Stolee <stolee@gmail.com> writes:\n> \n>>> diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\n>>> index 34ca0258b1..97b54caeb9 100644\n>>> --- a/builtin/merge-tree.c\n>>> +++ b/builtin/merge-tree.c\n>>> @@ -205,6 +205,7 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s\n>>>  static void unresolved_directory(const struct traverse_info *info,\n>>>  \t\t\t\t struct name_entry n[3])\n>>>  {\n>>> +\tstruct repository *r = the_repository;\n>>\n>> I like this trick to make the change below minimal:\n>>> +\tbuf0 = fill_tree_descriptor(r, t + 0, ENTRY_OID(n + 0));\n>>> +\tbuf1 = fill_tree_descriptor(r, t + 1, ENTRY_OID(n + 1));\n>>> +\tbuf2 = fill_tree_descriptor(r, t + 2, ENTRY_OID(n + 2));\n>>\n>> I wonder if _every_ conversion should include this trick,\n>> so when we move to change that method we simply move the definition\n>> from the method block to the prototype. (No need to adjust what you've\n>> done already, just an idea for future conversions.)\n> \n> Hmm, interesting.  So those callers in builtin/rebase.c::reset_head()\n> and other places that adds the_repository as the new first parameter\n> can take a local variable \"r\" (or perhaps a bit more descriptive,\n> e.g. \"repo\") that is initialized to \"the_repository\" (and never\n> reassigned at least at this step) in this same patch?\n\nYes, that is what I was thinking. It means that we can stop munging\nthe function calls for the method that is converted. When the caller\nis updated, the call site already uses \"r\" but we change how \"r\" is\ninitialized (as a parameter instead of a local variable).\n\nThanks,\n-Stolee\n"},{"id":"378070","messageId":"xmqq5zose00p.fsf@gitster-ct.c.googlers.com","threadId":"51368","inReplyTo":"20190624095533.22162-1-pclouds@gmail.com","subject":"Re: [PATCH 0/6] Kill the_repository in tree-walk.c","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-06-26T17:20:38Z","receivedAt":"2019-06-26T17:20:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> This is the continuation of nd/sha1-name-c-wo-the-repository. In that\n> series I sealed off one place in sha1-name.c that cannot walk trees\n> from arbitrary repositories. With tree-walk.c taking 'struct\n> repository *' directly, that check in there can now be removed.\n\nThanks.\n\nWith these queued on 'master', t7814 seems to become flaky (tried\nrunning it with --stress, with and without these patches).  Are we\ntouching a wrong index file in some codepaths or something?\n"},{"id":"378132","messageId":"nycvar.QRO.7.76.6.1906271101140.44@tvgsbejvaqbjf.bet","threadId":"51368","inReplyTo":"20190624095533.22162-7-pclouds@gmail.com","subject":"Re: [PATCH 6/6] Use the right 'struct repository' instead of the_repository","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2019-06-27T09:06:24Z","receivedAt":"2019-06-27T09:06:10Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Duy,\n\nOn Mon, 24 Jun 2019, Nguyễn Thái Ngọc Duy wrote:\n\n> There are a couple of places where 'struct repository' is already passed\n> around, but the_repository is still used. Use the right repo.\n\nThis patch series breaks t7814 on Linux, macOS and Windows, with GCC and\nclang (read: _every_ single job in the CI except for documentation and\ncoccinelle).\n\nFor details, see\nhttps://dev.azure.com/gitgitgadget/git/_build/results?buildId=11536&view=ms.vss-test-web.build-test-results-tab\n\nThe first test case to break is t7814.9 basic grep tree:\n\n-- snipsnap --\nexpecting success:\n\tcat >expect <<-\\EOF &&\n\tHEAD:a:(1|2)d(3|4)\n\tHEAD:b/b:(3|4)\n\tHEAD:submodule/a:(1|2)d(3|4)\n\tHEAD:submodule/sub/a:(1|2)d(3|4)\n\tEOF\n\n\tgit grep -e \"(3|4)\" --recurse-submodules HEAD >actual &&\n\ttest_cmp expect actual\n\n++ cat\n++ git grep -e '(3|4)' --recurse-submodules HEAD\nfatal: unable to read tree (e6d32f554b2f8e48c3b8feece1653e933facb34a)\nerror: last command exited with $?=128\n"},{"id":"378138","messageId":"20190627092852.11326-1-pclouds@gmail.com","threadId":"51368","inReplyTo":"20190624095533.22162-1-pclouds@gmail.com","subject":"[PATCH v2 0/6] Kill the_repository in tree-walk.c","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-27T09:28:46Z","receivedAt":"2019-06-27T09:29:24Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"v2 fixes t7814 flakiness. The problem is git-grep can operate on\nmultiple repos and I read objects from the wrong repo (supermodule)\ninstead of the submodule one.\n\nThere are still the_repository hidden in git-grep code paths, and the\nhack of asborbing submodule's object db to the_repo's in order to make\nit work.  And I can't quite understand how t7814 sometimes passed.\n\nI'll revisit this after this series is done and will try to get rid of\nadd_to_alternates_memory() in git-grep.\n\nNguyễn Thái Ngọc Duy (6):\n  sha1-file.c: remove the_repo from read_object_with_reference()\n  tree-walk.c: remove the_repo from fill_tree_descriptor()\n  tree-walk.c: remove the_repo from get_tree_entry()\n  tree-walk.c: remove the_repo from get_tree_entry_follow_symlinks()\n  match-trees.c: remove the_repo from shift_tree*()\n  Use the right 'struct repository' instead of the_repository\n\n archive.c                   |  4 +++-\n blame.c                     |  4 ++--\n builtin/cat-file.c          |  3 ++-\n builtin/grep.c              |  6 ++++--\n builtin/merge-tree.c        | 22 +++++++++++--------\n builtin/pack-objects.c      |  3 ++-\n builtin/rebase.c            |  4 ++--\n builtin/reset.c             |  4 ++--\n builtin/rm.c                |  2 +-\n builtin/update-index.c      |  2 +-\n cache.h                     |  7 +++---\n fast-import.c               |  9 +++++---\n line-log.c                  |  7 +++---\n match-trees.c               | 12 ++++++-----\n merge-recursive.c           | 43 +++++++++++++++++++++----------------\n notes.c                     |  4 ++--\n sequencer.c                 |  6 +++---\n sha1-file.c                 |  5 +++--\n sha1-name.c                 | 25 +++++++--------------\n shallow.c                   |  3 ++-\n t/helper/test-match-trees.c |  2 +-\n tree-diff.c                 |  4 ++--\n tree-walk.c                 | 35 ++++++++++++++++++++----------\n tree-walk.h                 |  8 ++++---\n unpack-trees.c              |  2 +-\n 25 files changed, 129 insertions(+), 97 deletions(-)\n\nRange-diff dựa trên v1:\n1:  35d7cdbe6a ! 1:  9e73c39f9a sha1-file.c: remove the_repo from read_object_with_reference()\n    @@ -3,7 +3,6 @@\n         sha1-file.c: remove the_repo from read_object_with_reference()\n     \n         Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n    -    Signed-off-by: Junio C Hamano <gitster@pobox.com>\n     \n      diff --git a/builtin/cat-file.c b/builtin/cat-file.c\n      --- a/builtin/cat-file.c\n    @@ -27,7 +26,7 @@\n      \n      \t\tgrep_read_lock();\n     -\t\tdata = read_object_with_reference(&object->oid, tree_type,\n    -+\t\tdata = read_object_with_reference(opt->repo,\n    ++\t\tdata = read_object_with_reference(&subrepo,\n     +\t\t\t\t\t\t  &object->oid, tree_type,\n      \t\t\t\t\t\t  &size, NULL);\n      \t\tgrep_read_unlock();\n2:  4ff146fb64 = 2:  b9107f7503 tree-walk.c: remove the_repo from fill_tree_descriptor()\n3:  47f956bd0f = 3:  87ed67bde5 tree-walk.c: remove the_repo from get_tree_entry()\n4:  e19c4b9ce6 = 4:  557b61f2ba tree-walk.c: remove the_repo from get_tree_entry_follow_symlinks()\n5:  3fe87a7fde = 5:  53f09e0437 match-trees.c: remove the_repo from shift_tree*()\n6:  6d0449f1a7 = 6:  d5d4d2ba65 Use the right 'struct repository' instead of the_repository\n-- \n2.22.0.rc0.322.g2b0371e29a\n\n"},{"id":"378139","messageId":"20190627092852.11326-2-pclouds@gmail.com","threadId":"51368","inReplyTo":"20190627092852.11326-1-pclouds@gmail.com","subject":"[PATCH v2 1/6] sha1-file.c: remove the_repo from read_object_with_reference()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-27T09:28:47Z","receivedAt":"2019-06-27T09:29:29Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/cat-file.c     | 3 ++-\n builtin/grep.c         | 6 ++++--\n builtin/pack-objects.c | 3 ++-\n cache.h                | 3 ++-\n fast-import.c          | 9 ++++++---\n sha1-file.c            | 5 +++--\n tree-walk.c            | 7 ++++---\n 7 files changed, 23 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 0f092382e1..995d47c85a 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -172,7 +172,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \t\t\t * fall-back to the usual case.\n \t\t\t */\n \t\t}\n-\t\tbuf = read_object_with_reference(&oid, exp_type, &size, NULL);\n+\t\tbuf = read_object_with_reference(the_repository,\n+\t\t\t\t\t\t &oid, exp_type, &size, NULL);\n \t\tbreak;\n \n \tdefault:\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 580fd38f41..560051784e 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -458,7 +458,8 @@ static int grep_submodule(struct grep_opt *opt,\n \t\tobject = parse_object_or_die(oid, oid_to_hex(oid));\n \n \t\tgrep_read_lock();\n-\t\tdata = read_object_with_reference(&object->oid, tree_type,\n+\t\tdata = read_object_with_reference(&subrepo,\n+\t\t\t\t\t\t  &object->oid, tree_type,\n \t\t\t\t\t\t  &size, NULL);\n \t\tgrep_read_unlock();\n \n@@ -623,7 +624,8 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,\n \t\tint hit, len;\n \n \t\tgrep_read_lock();\n-\t\tdata = read_object_with_reference(&obj->oid, tree_type,\n+\t\tdata = read_object_with_reference(opt->repo,\n+\t\t\t\t\t\t  &obj->oid, tree_type,\n \t\t\t\t\t\t  &size, NULL);\n \t\tgrep_read_unlock();\n \ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex b2be8869c2..a030c24a4a 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -1428,7 +1428,8 @@ static void add_preferred_base(struct object_id *oid)\n \tif (window <= num_preferred_base++)\n \t\treturn;\n \n-\tdata = read_object_with_reference(oid, tree_type, &size, &tree_oid);\n+\tdata = read_object_with_reference(the_repository, oid,\n+\t\t\t\t\t  tree_type, &size, &tree_oid);\n \tif (!data)\n \t\treturn;\n \ndiff --git a/cache.h b/cache.h\nindex bf20337ef4..cd84cc9bbe 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1500,7 +1500,8 @@ int df_name_compare(const char *name1, int len1, int mode1, const char *name2, i\n int name_compare(const char *name1, size_t len1, const char *name2, size_t len2);\n int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2);\n \n-void *read_object_with_reference(const struct object_id *oid,\n+void *read_object_with_reference(struct repository *r,\n+\t\t\t\t const struct object_id *oid,\n \t\t\t\t const char *required_type,\n \t\t\t\t unsigned long *size,\n \t\t\t\t struct object_id *oid_ret);\ndiff --git a/fast-import.c b/fast-import.c\nindex 76a7bd3699..3970b50acc 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -2410,7 +2410,8 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa\n \t\toidcpy(&commit_oid, &commit_oe->idx.oid);\n \t} else if (!get_oid(p, &commit_oid)) {\n \t\tunsigned long size;\n-\t\tchar *buf = read_object_with_reference(&commit_oid,\n+\t\tchar *buf = read_object_with_reference(the_repository,\n+\t\t\t\t\t\t       &commit_oid,\n \t\t\t\t\t\t       commit_type, &size,\n \t\t\t\t\t\t       &commit_oid);\n \t\tif (!buf || size < the_hash_algo->hexsz + 6)\n@@ -2482,7 +2483,8 @@ static void parse_from_existing(struct branch *b)\n \t\tunsigned long size;\n \t\tchar *buf;\n \n-\t\tbuf = read_object_with_reference(&b->oid, commit_type, &size,\n+\t\tbuf = read_object_with_reference(the_repository,\n+\t\t\t\t\t\t &b->oid, commit_type, &size,\n \t\t\t\t\t\t &b->oid);\n \t\tparse_from_commit(b, buf, size);\n \t\tfree(buf);\n@@ -2560,7 +2562,8 @@ static struct hash_list *parse_merge(unsigned int *count)\n \t\t\toidcpy(&n->oid, &oe->idx.oid);\n \t\t} else if (!get_oid(from, &n->oid)) {\n \t\t\tunsigned long size;\n-\t\t\tchar *buf = read_object_with_reference(&n->oid,\n+\t\t\tchar *buf = read_object_with_reference(the_repository,\n+\t\t\t\t\t\t\t       &n->oid,\n \t\t\t\t\t\t\t       commit_type,\n \t\t\t\t\t\t\t       &size, &n->oid);\n \t\t\tif (!buf || size < the_hash_algo->hexsz + 6)\ndiff --git a/sha1-file.c b/sha1-file.c\nindex 888b6024d5..59b2e40cf3 100644\n--- a/sha1-file.c\n+++ b/sha1-file.c\n@@ -1505,7 +1505,8 @@ void *read_object_file_extended(struct repository *r,\n \treturn NULL;\n }\n \n-void *read_object_with_reference(const struct object_id *oid,\n+void *read_object_with_reference(struct repository *r,\n+\t\t\t\t const struct object_id *oid,\n \t\t\t\t const char *required_type_name,\n \t\t\t\t unsigned long *size,\n \t\t\t\t struct object_id *actual_oid_return)\n@@ -1521,7 +1522,7 @@ void *read_object_with_reference(const struct object_id *oid,\n \t\tint ref_length = -1;\n \t\tconst char *ref_type = NULL;\n \n-\t\tbuffer = read_object_file(&actual_oid, &type, &isize);\n+\t\tbuffer = repo_read_object_file(r, &actual_oid, &type, &isize);\n \t\tif (!buffer)\n \t\t\treturn NULL;\n \t\tif (type == required_type) {\ndiff --git a/tree-walk.c b/tree-walk.c\nindex ec32a47b2e..0c7722b220 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -87,7 +87,7 @@ void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid)\n \tvoid *buf = NULL;\n \n \tif (oid) {\n-\t\tbuf = read_object_with_reference(oid, tree_type, &size, NULL);\n+\t\tbuf = read_object_with_reference(the_repository, oid, tree_type, &size, NULL);\n \t\tif (!buf)\n \t\t\tdie(\"unable to read tree %s\", oid_to_hex(oid));\n \t}\n@@ -542,7 +542,7 @@ int get_tree_entry(const struct object_id *tree_oid, const char *name, struct ob\n \tunsigned long size;\n \tstruct object_id root;\n \n-\ttree = read_object_with_reference(tree_oid, tree_type, &size, &root);\n+\ttree = read_object_with_reference(the_repository, tree_oid, tree_type, &size, &root);\n \tif (!tree)\n \t\treturn -1;\n \n@@ -609,7 +609,8 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, c\n \t\t\tvoid *tree;\n \t\t\tstruct object_id root;\n \t\t\tunsigned long size;\n-\t\t\ttree = read_object_with_reference(&current_tree_oid,\n+\t\t\ttree = read_object_with_reference(the_repository,\n+\t\t\t\t\t\t\t  &current_tree_oid,\n \t\t\t\t\t\t\t  tree_type, &size,\n \t\t\t\t\t\t\t  &root);\n \t\t\tif (!tree)\n-- \n2.22.0.rc0.322.g2b0371e29a\n\n"},{"id":"378140","messageId":"20190627092852.11326-3-pclouds@gmail.com","threadId":"51368","inReplyTo":"20190627092852.11326-1-pclouds@gmail.com","subject":"[PATCH v2 2/6] tree-walk.c: remove the_repo from fill_tree_descriptor()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-27T09:28:48Z","receivedAt":"2019-06-27T09:29:34Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"While at there, clean up the_repo usage in builtin/merge-tree.c a tiny\nbit.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin/merge-tree.c | 22 +++++++++++++---------\n builtin/rebase.c     |  4 ++--\n builtin/reset.c      |  4 ++--\n notes.c              |  2 +-\n sequencer.c          |  2 +-\n tree-diff.c          |  4 ++--\n tree-walk.c          |  6 ++++--\n tree-walk.h          |  4 +++-\n unpack-trees.c       |  2 +-\n 9 files changed, 29 insertions(+), 21 deletions(-)\n\ndiff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\nindex 34ca0258b1..97b54caeb9 100644\n--- a/builtin/merge-tree.c\n+++ b/builtin/merge-tree.c\n@@ -205,6 +205,7 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s\n static void unresolved_directory(const struct traverse_info *info,\n \t\t\t\t struct name_entry n[3])\n {\n+\tstruct repository *r = the_repository;\n \tchar *newbase;\n \tstruct name_entry *p;\n \tstruct tree_desc t[3];\n@@ -220,9 +221,9 @@ static void unresolved_directory(const struct traverse_info *info,\n \tnewbase = traverse_path(info, p);\n \n #define ENTRY_OID(e) (((e)->mode && S_ISDIR((e)->mode)) ? &(e)->oid : NULL)\n-\tbuf0 = fill_tree_descriptor(t + 0, ENTRY_OID(n + 0));\n-\tbuf1 = fill_tree_descriptor(t + 1, ENTRY_OID(n + 1));\n-\tbuf2 = fill_tree_descriptor(t + 2, ENTRY_OID(n + 2));\n+\tbuf0 = fill_tree_descriptor(r, t + 0, ENTRY_OID(n + 0));\n+\tbuf1 = fill_tree_descriptor(r, t + 1, ENTRY_OID(n + 1));\n+\tbuf2 = fill_tree_descriptor(r, t + 2, ENTRY_OID(n + 2));\n #undef ENTRY_OID\n \n \tmerge_trees(t, newbase);\n@@ -351,14 +352,16 @@ static void merge_trees(struct tree_desc t[3], const char *base)\n \ttraverse_trees(&the_index, 3, t, &info);\n }\n \n-static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)\n+static void *get_tree_descriptor(struct repository *r,\n+\t\t\t\t struct tree_desc *desc,\n+\t\t\t\t const char *rev)\n {\n \tstruct object_id oid;\n \tvoid *buf;\n \n-\tif (get_oid(rev, &oid))\n+\tif (repo_get_oid(r, rev, &oid))\n \t\tdie(\"unknown rev %s\", rev);\n-\tbuf = fill_tree_descriptor(desc, &oid);\n+\tbuf = fill_tree_descriptor(r, desc, &oid);\n \tif (!buf)\n \t\tdie(\"%s is not a tree\", rev);\n \treturn buf;\n@@ -366,15 +369,16 @@ static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)\n \n int cmd_merge_tree(int argc, const char **argv, const char *prefix)\n {\n+\tstruct repository *r = the_repository;\n \tstruct tree_desc t[3];\n \tvoid *buf1, *buf2, *buf3;\n \n \tif (argc != 4)\n \t\tusage(merge_tree_usage);\n \n-\tbuf1 = get_tree_descriptor(t+0, argv[1]);\n-\tbuf2 = get_tree_descriptor(t+1, argv[2]);\n-\tbuf3 = get_tree_descriptor(t+2, argv[3]);\n+\tbuf1 = get_tree_descriptor(r, t+0, argv[1]);\n+\tbuf2 = get_tree_descriptor(r, t+1, argv[2]);\n+\tbuf3 = get_tree_descriptor(r, t+2, argv[3]);\n \tmerge_trees(t, \"\");\n \tfree(buf1);\n \tfree(buf2);\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex b8116db487..28490f5f88 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -840,13 +840,13 @@ static int reset_head(struct object_id *oid, const char *action,\n \t\tgoto leave_reset_head;\n \t}\n \n-\tif (!reset_hard && !fill_tree_descriptor(&desc[nr++], &head_oid)) {\n+\tif (!reset_hard && !fill_tree_descriptor(the_repository, &desc[nr++], &head_oid)) {\n \t\tret = error(_(\"failed to find tree of %s\"),\n \t\t\t    oid_to_hex(&head_oid));\n \t\tgoto leave_reset_head;\n \t}\n \n-\tif (!fill_tree_descriptor(&desc[nr++], oid)) {\n+\tif (!fill_tree_descriptor(the_repository, &desc[nr++], oid)) {\n \t\tret = error(_(\"failed to find tree of %s\"), oid_to_hex(oid));\n \t\tgoto leave_reset_head;\n \t}\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 26ef9a7bd0..77c38f28c2 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -79,13 +79,13 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)\n \t\tstruct object_id head_oid;\n \t\tif (get_oid(\"HEAD\", &head_oid))\n \t\t\treturn error(_(\"You do not have a valid HEAD.\"));\n-\t\tif (!fill_tree_descriptor(desc + nr, &head_oid))\n+\t\tif (!fill_tree_descriptor(the_repository, desc + nr, &head_oid))\n \t\t\treturn error(_(\"Failed to find tree of HEAD.\"));\n \t\tnr++;\n \t\topts.fn = twoway_merge;\n \t}\n \n-\tif (!fill_tree_descriptor(desc + nr, oid)) {\n+\tif (!fill_tree_descriptor(the_repository, desc + nr, oid)) {\n \t\terror(_(\"Failed to find tree of %s.\"), oid_to_hex(oid));\n \t\tgoto out;\n \t}\ndiff --git a/notes.c b/notes.c\nindex 532ec37865..2522b87d77 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -397,7 +397,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,\n \tstruct name_entry entry;\n \tconst unsigned hashsz = the_hash_algo->rawsz;\n \n-\tbuf = fill_tree_descriptor(&desc, &subtree->val_oid);\n+\tbuf = fill_tree_descriptor(the_repository, &desc, &subtree->val_oid);\n \tif (!buf)\n \t\tdie(\"Could not read %s for notes-index\",\n \t\t     oid_to_hex(&subtree->val_oid));\ndiff --git a/sequencer.c b/sequencer.c\nindex ab74b6baf1..d565fcf2b1 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -3194,7 +3194,7 @@ static int do_reset(struct repository *r,\n \t\treturn error_resolve_conflict(_(action_name(opts)));\n \t}\n \n-\tif (!fill_tree_descriptor(&desc, &oid)) {\n+\tif (!fill_tree_descriptor(r, &desc, &oid)) {\n \t\terror(_(\"failed to find tree of %s\"), oid_to_hex(&oid));\n \t\trollback_lock_file(&lock);\n \t\tfree((void *)desc.buffer);\ndiff --git a/tree-diff.c b/tree-diff.c\nindex f1f641eb6a..33ded7f8b3 100644\n--- a/tree-diff.c\n+++ b/tree-diff.c\n@@ -422,8 +422,8 @@ static struct combine_diff_path *ll_diff_tree_paths(\n \t *   diff_tree_oid(parent, commit) )\n \t */\n \tfor (i = 0; i < nparent; ++i)\n-\t\ttptree[i] = fill_tree_descriptor(&tp[i], parents_oid[i]);\n-\tttree = fill_tree_descriptor(&t, oid);\n+\t\ttptree[i] = fill_tree_descriptor(opt->repo, &tp[i], parents_oid[i]);\n+\tttree = fill_tree_descriptor(opt->repo, &t, oid);\n \n \t/* Enable recursion indefinitely */\n \topt->pathspec.recursive = opt->flags.recursive;\ndiff --git a/tree-walk.c b/tree-walk.c\nindex 0c7722b220..c5569b3e9f 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -81,13 +81,15 @@ int init_tree_desc_gently(struct tree_desc *desc, const void *buffer, unsigned l\n \treturn result;\n }\n \n-void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid)\n+void *fill_tree_descriptor(struct repository *r,\n+\t\t\t   struct tree_desc *desc,\n+\t\t\t   const struct object_id *oid)\n {\n \tunsigned long size = 0;\n \tvoid *buf = NULL;\n \n \tif (oid) {\n-\t\tbuf = read_object_with_reference(the_repository, oid, tree_type, &size, NULL);\n+\t\tbuf = read_object_with_reference(r, oid, tree_type, &size, NULL);\n \t\tif (!buf)\n \t\t\tdie(\"unable to read tree %s\", oid_to_hex(oid));\n \t}\ndiff --git a/tree-walk.h b/tree-walk.h\nindex 161e2400f4..9aa1042642 100644\n--- a/tree-walk.h\n+++ b/tree-walk.h\n@@ -45,7 +45,9 @@ int init_tree_desc_gently(struct tree_desc *desc, const void *buf, unsigned long\n int tree_entry(struct tree_desc *, struct name_entry *);\n int tree_entry_gently(struct tree_desc *, struct name_entry *);\n \n-void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid);\n+void *fill_tree_descriptor(struct repository *r,\n+\t\t\t   struct tree_desc *desc,\n+\t\t\t   const struct object_id *oid);\n \n struct traverse_info;\n typedef int (*traverse_callback_t)(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *);\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex 50189909b8..cfe1c5ec6f 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -840,7 +840,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,\n \t\t\tconst struct object_id *oid = NULL;\n \t\t\tif (dirmask & 1)\n \t\t\t\toid = &names[i].oid;\n-\t\t\tbuf[nr_buf++] = fill_tree_descriptor(t + i, oid);\n+\t\t\tbuf[nr_buf++] = fill_tree_descriptor(the_repository, t + i, oid);\n \t\t}\n \t}\n \n-- \n2.22.0.rc0.322.g2b0371e29a\n\n"},{"id":"378141","messageId":"20190627092852.11326-4-pclouds@gmail.com","threadId":"51368","inReplyTo":"20190627092852.11326-1-pclouds@gmail.com","subject":"[PATCH v2 3/6] tree-walk.c: remove the_repo from get_tree_entry()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-27T09:28:49Z","receivedAt":"2019-06-27T09:29:39Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n archive.c              |  4 +++-\n blame.c                |  4 ++--\n builtin/rm.c           |  2 +-\n builtin/update-index.c |  2 +-\n line-log.c             |  7 ++++---\n match-trees.c          |  6 +++---\n merge-recursive.c      |  8 +++++---\n notes.c                |  2 +-\n sha1-name.c            |  9 +++++----\n tree-walk.c            | 18 ++++++++++++------\n tree-walk.h            |  2 +-\n 11 files changed, 38 insertions(+), 26 deletions(-)\n\ndiff --git a/archive.c b/archive.c\nindex 53141c1f0e..a8da0fcc4f 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -418,7 +418,9 @@ static void parse_treeish_arg(const char **argv,\n \t\tunsigned short mode;\n \t\tint err;\n \n-\t\terr = get_tree_entry(&tree->object.oid, prefix, &tree_oid,\n+\t\terr = get_tree_entry(ar_args->repo,\n+\t\t\t\t     &tree->object.oid,\n+\t\t\t\t     prefix, &tree_oid,\n \t\t\t\t     &mode);\n \t\tif (err || !S_ISDIR(mode))\n \t\t\tdie(_(\"current working directory is untracked\"));\ndiff --git a/blame.c b/blame.c\nindex 145eaf2faf..ef022809e9 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -101,7 +101,7 @@ static void verify_working_tree_path(struct repository *r,\n \t\tstruct object_id blob_oid;\n \t\tunsigned short mode;\n \n-\t\tif (!get_tree_entry(commit_oid, path, &blob_oid, &mode) &&\n+\t\tif (!get_tree_entry(r, commit_oid, path, &blob_oid, &mode) &&\n \t\t    oid_object_info(r, &blob_oid, NULL) == OBJ_BLOB)\n \t\t\treturn;\n \t}\n@@ -532,7 +532,7 @@ static int fill_blob_sha1_and_mode(struct repository *r,\n {\n \tif (!is_null_oid(&origin->blob_oid))\n \t\treturn 0;\n-\tif (get_tree_entry(&origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))\n+\tif (get_tree_entry(r, &origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))\n \t\tgoto error_out;\n \tif (oid_object_info(r, &origin->blob_oid, NULL) != OBJ_BLOB)\n \t\tgoto error_out;\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex be8edc6d1e..2eacda42b4 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -179,7 +179,7 @@ static int check_local_mod(struct object_id *head, int index_only)\n \t\t * way as changed from the HEAD.\n \t\t */\n \t\tif (no_head\n-\t\t     || get_tree_entry(head, name, &oid, &mode)\n+\t\t     || get_tree_entry(the_repository, head, name, &oid, &mode)\n \t\t     || ce->ce_mode != create_ce_mode(mode)\n \t\t     || !oideq(&ce->oid, &oid))\n \t\t\tstaged_changes = 1;\ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex 3f8cc6ccb4..dff2f4b837 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -601,7 +601,7 @@ static struct cache_entry *read_one_ent(const char *which,\n \tstruct object_id oid;\n \tstruct cache_entry *ce;\n \n-\tif (get_tree_entry(ent, path, &oid, &mode)) {\n+\tif (get_tree_entry(the_repository, ent, path, &oid, &mode)) {\n \t\tif (which)\n \t\t\terror(\"%s: not in %s branch.\", path, which);\n \t\treturn NULL;\ndiff --git a/line-log.c b/line-log.c\nindex 0a17b21187..3aff1849e7 100644\n--- a/line-log.c\n+++ b/line-log.c\n@@ -496,12 +496,13 @@ static struct commit *check_single_commit(struct rev_info *revs)\n \treturn (struct commit *) commit;\n }\n \n-static void fill_blob_sha1(struct commit *commit, struct diff_filespec *spec)\n+static void fill_blob_sha1(struct repository *r, struct commit *commit,\n+\t\t\t   struct diff_filespec *spec)\n {\n \tunsigned short mode;\n \tstruct object_id oid;\n \n-\tif (get_tree_entry(&commit->object.oid, spec->path, &oid, &mode))\n+\tif (get_tree_entry(r, &commit->object.oid, spec->path, &oid, &mode))\n \t\tdie(\"There is no path %s in the commit\", spec->path);\n \tfill_filespec(spec, &oid, 1, mode);\n \n@@ -585,7 +586,7 @@ parse_lines(struct repository *r, struct commit *commit,\n \t\t\t\t\tname_part);\n \n \t\tspec = alloc_filespec(full_name);\n-\t\tfill_blob_sha1(commit, spec);\n+\t\tfill_blob_sha1(r, commit, spec);\n \t\tfill_line_ends(r, spec, &lines, &ends);\n \t\tcb_data.spec = spec;\n \t\tcb_data.lines = lines;\ndiff --git a/match-trees.c b/match-trees.c\nindex 9d1ec8d6b0..de7e8a6783 100644\n--- a/match-trees.c\n+++ b/match-trees.c\n@@ -290,7 +290,7 @@ void shift_tree(const struct object_id *hash1,\n \t\tif (!*del_prefix)\n \t\t\treturn;\n \n-\t\tif (get_tree_entry(hash2, del_prefix, shifted, &mode))\n+\t\tif (get_tree_entry(the_repository, hash2, del_prefix, shifted, &mode))\n \t\t\tdie(\"cannot find path %s in tree %s\",\n \t\t\t    del_prefix, oid_to_hex(hash2));\n \t\treturn;\n@@ -317,12 +317,12 @@ void shift_tree_by(const struct object_id *hash1,\n \tunsigned candidate = 0;\n \n \t/* Can hash2 be a tree at shift_prefix in tree hash1? */\n-\tif (!get_tree_entry(hash1, shift_prefix, &sub1, &mode1) &&\n+\tif (!get_tree_entry(the_repository, hash1, shift_prefix, &sub1, &mode1) &&\n \t    S_ISDIR(mode1))\n \t\tcandidate |= 1;\n \n \t/* Can hash1 be a tree at shift_prefix in tree hash2? */\n-\tif (!get_tree_entry(hash2, shift_prefix, &sub2, &mode2) &&\n+\tif (!get_tree_entry(the_repository, hash2, shift_prefix, &sub2, &mode2) &&\n \t    S_ISDIR(mode2))\n \t\tcandidate |= 2;\n \ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex d2e380b7ed..b051066795 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -475,7 +475,7 @@ static int get_tree_entry_if_blob(const struct object_id *tree,\n {\n \tint ret;\n \n-\tret = get_tree_entry(tree, path, &dfs->oid, &dfs->mode);\n+\tret = get_tree_entry(the_repository, tree, path, &dfs->oid, &dfs->mode);\n \tif (S_ISDIR(dfs->mode)) {\n \t\toidcpy(&dfs->oid, &null_oid);\n \t\tdfs->mode = 0;\n@@ -1905,7 +1905,8 @@ static int tree_has_path(struct tree *tree, const char *path)\n \tstruct object_id hashy;\n \tunsigned short mode_o;\n \n-\treturn !get_tree_entry(&tree->object.oid, path,\n+\treturn !get_tree_entry(the_repository,\n+\t\t\t       &tree->object.oid, path,\n \t\t\t       &hashy, &mode_o);\n }\n \n@@ -2500,7 +2501,8 @@ static void apply_directory_rename_modifications(struct merge_options *opt,\n \t * the various handle_rename_*() functions update the index\n \t * explicitly rather than relying on unpack_trees() to have done it.\n \t */\n-\tget_tree_entry(&tree->object.oid,\n+\tget_tree_entry(opt->repo,\n+\t\t       &tree->object.oid,\n \t\t       pair->two->path,\n \t\t       &re->dst_entry->stages[stage].oid,\n \t\t       &re->dst_entry->stages[stage].mode);\ndiff --git a/notes.c b/notes.c\nindex 2522b87d77..75c028b300 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -1015,7 +1015,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,\n \t\treturn;\n \tif (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid))\n \t\tdie(\"Cannot use notes ref %s\", notes_ref);\n-\tif (get_tree_entry(&object_oid, \"\", &oid, &mode))\n+\tif (get_tree_entry(the_repository, &object_oid, \"\", &oid, &mode))\n \t\tdie(\"Failed to read notes tree referenced by %s (%s)\",\n \t\t    notes_ref, oid_to_hex(&object_oid));\n \ndiff --git a/sha1-name.c b/sha1-name.c\nindex 728e6f1f61..e8fb215e5c 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1677,7 +1677,8 @@ int repo_get_oid_blob(struct repository *r,\n }\n \n /* Must be called only when object_name:filename doesn't exist. */\n-static void diagnose_invalid_oid_path(const char *prefix,\n+static void diagnose_invalid_oid_path(struct repository *r,\n+\t\t\t\t      const char *prefix,\n \t\t\t\t      const char *filename,\n \t\t\t\t      const struct object_id *tree_oid,\n \t\t\t\t      const char *object_name,\n@@ -1695,7 +1696,7 @@ static void diagnose_invalid_oid_path(const char *prefix,\n \tif (is_missing_file_error(errno)) {\n \t\tchar *fullname = xstrfmt(\"%s%s\", prefix, filename);\n \n-\t\tif (!get_tree_entry(tree_oid, fullname, &oid, &mode)) {\n+\t\tif (!get_tree_entry(r, tree_oid, fullname, &oid, &mode)) {\n \t\t\tdie(\"Path '%s' exists, but not '%s'.\\n\"\n \t\t\t    \"Did you mean '%.*s:%s' aka '%.*s:./%s'?\",\n \t\t\t    fullname,\n@@ -1902,10 +1903,10 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\t\t\tfilename, oid, &oc->symlink_path,\n \t\t\t\t\t&oc->mode);\n \t\t\t} else {\n-\t\t\t\tret = get_tree_entry(&tree_oid, filename, oid,\n+\t\t\t\tret = get_tree_entry(repo, &tree_oid, filename, oid,\n \t\t\t\t\t\t     &oc->mode);\n \t\t\t\tif (ret && only_to_die) {\n-\t\t\t\t\tdiagnose_invalid_oid_path(prefix,\n+\t\t\t\t\tdiagnose_invalid_oid_path(repo, prefix,\n \t\t\t\t\t\t\t\t   filename,\n \t\t\t\t\t\t\t\t   &tree_oid,\n \t\t\t\t\t\t\t\t   name, len);\ndiff --git a/tree-walk.c b/tree-walk.c\nindex c5569b3e9f..506e12a031 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -502,7 +502,9 @@ struct dir_state {\n \tstruct object_id oid;\n };\n \n-static int find_tree_entry(struct tree_desc *t, const char *name, struct object_id *result, unsigned short *mode)\n+static int find_tree_entry(struct repository *r, struct tree_desc *t,\n+\t\t\t   const char *name, struct object_id *result,\n+\t\t\t   unsigned short *mode)\n {\n \tint namelen = strlen(name);\n \twhile (t->size) {\n@@ -532,19 +534,23 @@ static int find_tree_entry(struct tree_desc *t, const char *name, struct object_\n \t\t\toidcpy(result, &oid);\n \t\t\treturn 0;\n \t\t}\n-\t\treturn get_tree_entry(&oid, name + entrylen, result, mode);\n+\t\treturn get_tree_entry(r, &oid, name + entrylen, result, mode);\n \t}\n \treturn -1;\n }\n \n-int get_tree_entry(const struct object_id *tree_oid, const char *name, struct object_id *oid, unsigned short *mode)\n+int get_tree_entry(struct repository *r,\n+\t\t   const struct object_id *tree_oid,\n+\t\t   const char *name,\n+\t\t   struct object_id *oid,\n+\t\t   unsigned short *mode)\n {\n \tint retval;\n \tvoid *tree;\n \tunsigned long size;\n \tstruct object_id root;\n \n-\ttree = read_object_with_reference(the_repository, tree_oid, tree_type, &size, &root);\n+\ttree = read_object_with_reference(r, tree_oid, tree_type, &size, &root);\n \tif (!tree)\n \t\treturn -1;\n \n@@ -559,7 +565,7 @@ int get_tree_entry(const struct object_id *tree_oid, const char *name, struct ob\n \t} else {\n \t\tstruct tree_desc t;\n \t\tinit_tree_desc(&t, tree, size);\n-\t\tretval = find_tree_entry(&t, name, oid, mode);\n+\t\tretval = find_tree_entry(r, &t, name, oid, mode);\n \t}\n \tfree(tree);\n \treturn retval;\n@@ -681,7 +687,7 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, c\n \t\t}\n \n \t\t/* Look up the first (or only) path component in the tree. */\n-\t\tfind_result = find_tree_entry(&t, namebuf.buf,\n+\t\tfind_result = find_tree_entry(the_repository, &t, namebuf.buf,\n \t\t\t\t\t      &current_tree_oid, mode);\n \t\tif (find_result) {\n \t\t\tgoto done;\ndiff --git a/tree-walk.h b/tree-walk.h\nindex 9aa1042642..639f79187f 100644\n--- a/tree-walk.h\n+++ b/tree-walk.h\n@@ -68,7 +68,7 @@ struct traverse_info {\n \tint show_all_errors;\n };\n \n-int get_tree_entry(const struct object_id *, const char *, struct object_id *, unsigned short *);\n+int get_tree_entry(struct repository *, const struct object_id *, const char *, struct object_id *, unsigned short *);\n char *make_traverse_path(char *path, const struct traverse_info *info, const struct name_entry *n);\n void setup_traverse_info(struct traverse_info *info, const char *base);\n \n-- \n2.22.0.rc0.322.g2b0371e29a\n\n"},{"id":"378142","messageId":"20190627092852.11326-5-pclouds@gmail.com","threadId":"51368","inReplyTo":"20190627092852.11326-1-pclouds@gmail.com","subject":"[PATCH v2 4/6] tree-walk.c: remove the_repo from get_tree_entry_follow_symlinks()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-27T09:28:50Z","receivedAt":"2019-06-27T09:29:43Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n sha1-name.c | 10 +---------\n tree-walk.c | 12 ++++++++----\n tree-walk.h |  2 +-\n 3 files changed, 10 insertions(+), 14 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex e8fb215e5c..3c9fa10af8 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1890,16 +1890,8 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\tnew_filename = resolve_relative_path(repo, filename);\n \t\t\tif (new_filename)\n \t\t\t\tfilename = new_filename;\n-\t\t\t/*\n-\t\t\t * NEEDSWORK: Eventually get_tree_entry*() should\n-\t\t\t * learn to take struct repository directly and we\n-\t\t\t * would not need to inject submodule odb to the\n-\t\t\t * in-core odb.\n-\t\t\t */\n-\t\t\tif (repo != the_repository)\n-\t\t\t\tadd_to_alternates_memory(repo->objects->odb->path);\n \t\t\tif (flags & GET_OID_FOLLOW_SYMLINKS) {\n-\t\t\t\tret = get_tree_entry_follow_symlinks(&tree_oid,\n+\t\t\t\tret = get_tree_entry_follow_symlinks(repo, &tree_oid,\n \t\t\t\t\tfilename, oid, &oc->symlink_path,\n \t\t\t\t\t&oc->mode);\n \t\t\t} else {\ndiff --git a/tree-walk.c b/tree-walk.c\nindex 506e12a031..c20b62f49e 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -593,7 +593,10 @@ int get_tree_entry(struct repository *r,\n  * See the code for enum get_oid_result for a description of\n  * the return values.\n  */\n-enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, const char *name, struct object_id *result, struct strbuf *result_path, unsigned short *mode)\n+enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,\n+\t\tstruct object_id *tree_oid, const char *name,\n+\t\tstruct object_id *result, struct strbuf *result_path,\n+\t\tunsigned short *mode)\n {\n \tint retval = MISSING_OBJECT;\n \tstruct dir_state *parents = NULL;\n@@ -617,7 +620,7 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, c\n \t\t\tvoid *tree;\n \t\t\tstruct object_id root;\n \t\t\tunsigned long size;\n-\t\t\ttree = read_object_with_reference(the_repository,\n+\t\t\ttree = read_object_with_reference(r,\n \t\t\t\t\t\t\t  &current_tree_oid,\n \t\t\t\t\t\t\t  tree_type, &size,\n \t\t\t\t\t\t\t  &root);\n@@ -687,7 +690,7 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, c\n \t\t}\n \n \t\t/* Look up the first (or only) path component in the tree. */\n-\t\tfind_result = find_tree_entry(the_repository, &t, namebuf.buf,\n+\t\tfind_result = find_tree_entry(r, &t, namebuf.buf,\n \t\t\t\t\t      &current_tree_oid, mode);\n \t\tif (find_result) {\n \t\t\tgoto done;\n@@ -731,7 +734,8 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, c\n \t\t\t */\n \t\t\tretval = DANGLING_SYMLINK;\n \n-\t\t\tcontents = read_object_file(&current_tree_oid, &type,\n+\t\t\tcontents = repo_read_object_file(r,\n+\t\t\t\t\t\t    &current_tree_oid, &type,\n \t\t\t\t\t\t    &link_len);\n \n \t\t\tif (!contents)\ndiff --git a/tree-walk.h b/tree-walk.h\nindex 639f79187f..2a5db29e8f 100644\n--- a/tree-walk.h\n+++ b/tree-walk.h\n@@ -53,7 +53,7 @@ struct traverse_info;\n typedef int (*traverse_callback_t)(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *);\n int traverse_trees(struct index_state *istate, int n, struct tree_desc *t, struct traverse_info *info);\n \n-enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, const char *name, struct object_id *result, struct strbuf *result_path, unsigned short *mode);\n+enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r, struct object_id *tree_oid, const char *name, struct object_id *result, struct strbuf *result_path, unsigned short *mode);\n \n struct traverse_info {\n \tconst char *traverse_path;\n-- \n2.22.0.rc0.322.g2b0371e29a\n\n"},{"id":"378143","messageId":"20190627092852.11326-6-pclouds@gmail.com","threadId":"51368","inReplyTo":"20190627092852.11326-1-pclouds@gmail.com","subject":"[PATCH v2 5/6] match-trees.c: remove the_repo from shift_tree*()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-27T09:28:51Z","receivedAt":"2019-06-27T09:29:49Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n cache.h                     |  4 ++--\n match-trees.c               | 12 +++++++-----\n merge-recursive.c           |  4 ++--\n t/helper/test-match-trees.c |  2 +-\n 4 files changed, 12 insertions(+), 10 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex cd84cc9bbe..ddefda2bb6 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1786,8 +1786,8 @@ int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int\n extern int diff_auto_refresh_index;\n \n /* match-trees.c */\n-void shift_tree(const struct object_id *, const struct object_id *, struct object_id *, int);\n-void shift_tree_by(const struct object_id *, const struct object_id *, struct object_id *, const char *);\n+void shift_tree(struct repository *, const struct object_id *, const struct object_id *, struct object_id *, int);\n+void shift_tree_by(struct repository *, const struct object_id *, const struct object_id *, struct object_id *, const char *);\n \n /*\n  * whitespace rules.\ndiff --git a/match-trees.c b/match-trees.c\nindex de7e8a6783..f6c194c1cc 100644\n--- a/match-trees.c\n+++ b/match-trees.c\n@@ -248,7 +248,8 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,\n  * other hand, it could cover tree one and we might need to pick a\n  * subtree of it.\n  */\n-void shift_tree(const struct object_id *hash1,\n+void shift_tree(struct repository *r,\n+\t\tconst struct object_id *hash1,\n \t\tconst struct object_id *hash2,\n \t\tstruct object_id *shifted,\n \t\tint depth_limit)\n@@ -290,7 +291,7 @@ void shift_tree(const struct object_id *hash1,\n \t\tif (!*del_prefix)\n \t\t\treturn;\n \n-\t\tif (get_tree_entry(the_repository, hash2, del_prefix, shifted, &mode))\n+\t\tif (get_tree_entry(r, hash2, del_prefix, shifted, &mode))\n \t\t\tdie(\"cannot find path %s in tree %s\",\n \t\t\t    del_prefix, oid_to_hex(hash2));\n \t\treturn;\n@@ -307,7 +308,8 @@ void shift_tree(const struct object_id *hash1,\n  * Unfortunately we cannot fundamentally tell which one to\n  * be prefixed, as recursive merge can work in either direction.\n  */\n-void shift_tree_by(const struct object_id *hash1,\n+void shift_tree_by(struct repository *r,\n+\t\t   const struct object_id *hash1,\n \t\t   const struct object_id *hash2,\n \t\t   struct object_id *shifted,\n \t\t   const char *shift_prefix)\n@@ -317,12 +319,12 @@ void shift_tree_by(const struct object_id *hash1,\n \tunsigned candidate = 0;\n \n \t/* Can hash2 be a tree at shift_prefix in tree hash1? */\n-\tif (!get_tree_entry(the_repository, hash1, shift_prefix, &sub1, &mode1) &&\n+\tif (!get_tree_entry(r, hash1, shift_prefix, &sub1, &mode1) &&\n \t    S_ISDIR(mode1))\n \t\tcandidate |= 1;\n \n \t/* Can hash1 be a tree at shift_prefix in tree hash2? */\n-\tif (!get_tree_entry(the_repository, hash2, shift_prefix, &sub2, &mode2) &&\n+\tif (!get_tree_entry(r, hash2, shift_prefix, &sub2, &mode2) &&\n \t    S_ISDIR(mode2))\n \t\tcandidate |= 2;\n \ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex b051066795..6d772eb0eb 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -153,9 +153,9 @@ static struct tree *shift_tree_object(struct repository *repo,\n \tstruct object_id shifted;\n \n \tif (!*subtree_shift) {\n-\t\tshift_tree(&one->object.oid, &two->object.oid, &shifted, 0);\n+\t\tshift_tree(repo, &one->object.oid, &two->object.oid, &shifted, 0);\n \t} else {\n-\t\tshift_tree_by(&one->object.oid, &two->object.oid, &shifted,\n+\t\tshift_tree_by(repo, &one->object.oid, &two->object.oid, &shifted,\n \t\t\t      subtree_shift);\n \t}\n \tif (oideq(&two->object.oid, &shifted))\ndiff --git a/t/helper/test-match-trees.c b/t/helper/test-match-trees.c\nindex 96857f26ac..b9fd427571 100644\n--- a/t/helper/test-match-trees.c\n+++ b/t/helper/test-match-trees.c\n@@ -20,7 +20,7 @@ int cmd__match_trees(int ac, const char **av)\n \tif (!two)\n \t\tdie(\"not a tree-ish %s\", av[2]);\n \n-\tshift_tree(&one->object.oid, &two->object.oid, &shifted, -1);\n+\tshift_tree(the_repository, &one->object.oid, &two->object.oid, &shifted, -1);\n \tprintf(\"shifted: %s\\n\", oid_to_hex(&shifted));\n \n \texit(0);\n-- \n2.22.0.rc0.322.g2b0371e29a\n\n"},{"id":"378144","messageId":"20190627092852.11326-7-pclouds@gmail.com","threadId":"51368","inReplyTo":"20190627092852.11326-1-pclouds@gmail.com","subject":"[PATCH v2 6/6] Use the right 'struct repository' instead of the_repository","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-27T09:28:52Z","receivedAt":"2019-06-27T09:29:54Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"There are a couple of places where 'struct repository' is already passed\naround, but the_repository is still used. Use the right repo.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n merge-recursive.c | 35 ++++++++++++++++++++---------------\n sequencer.c       |  4 ++--\n sha1-name.c       |  6 ++----\n shallow.c         |  3 ++-\n 4 files changed, 26 insertions(+), 22 deletions(-)\n\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 6d772eb0eb..12300131fc 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -465,17 +465,18 @@ static void get_files_dirs(struct merge_options *opt, struct tree *tree)\n {\n \tstruct pathspec match_all;\n \tmemset(&match_all, 0, sizeof(match_all));\n-\tread_tree_recursive(the_repository, tree, \"\", 0, 0,\n+\tread_tree_recursive(opt->repo, tree, \"\", 0, 0,\n \t\t\t    &match_all, save_files_dirs, opt);\n }\n \n-static int get_tree_entry_if_blob(const struct object_id *tree,\n+static int get_tree_entry_if_blob(struct repository *r,\n+\t\t\t\t  const struct object_id *tree,\n \t\t\t\t  const char *path,\n \t\t\t\t  struct diff_filespec *dfs)\n {\n \tint ret;\n \n-\tret = get_tree_entry(the_repository, tree, path, &dfs->oid, &dfs->mode);\n+\tret = get_tree_entry(r, tree, path, &dfs->oid, &dfs->mode);\n \tif (S_ISDIR(dfs->mode)) {\n \t\toidcpy(&dfs->oid, &null_oid);\n \t\tdfs->mode = 0;\n@@ -487,15 +488,16 @@ static int get_tree_entry_if_blob(const struct object_id *tree,\n  * Returns an index_entry instance which doesn't have to correspond to\n  * a real cache entry in Git's index.\n  */\n-static struct stage_data *insert_stage_data(const char *path,\n+static struct stage_data *insert_stage_data(struct repository *r,\n+\t\tconst char *path,\n \t\tstruct tree *o, struct tree *a, struct tree *b,\n \t\tstruct string_list *entries)\n {\n \tstruct string_list_item *item;\n \tstruct stage_data *e = xcalloc(1, sizeof(struct stage_data));\n-\tget_tree_entry_if_blob(&o->object.oid, path, &e->stages[1]);\n-\tget_tree_entry_if_blob(&a->object.oid, path, &e->stages[2]);\n-\tget_tree_entry_if_blob(&b->object.oid, path, &e->stages[3]);\n+\tget_tree_entry_if_blob(r, &o->object.oid, path, &e->stages[1]);\n+\tget_tree_entry_if_blob(r, &a->object.oid, path, &e->stages[2]);\n+\tget_tree_entry_if_blob(r, &b->object.oid, path, &e->stages[3]);\n \titem = string_list_insert(entries, path);\n \titem->util = e;\n \treturn e;\n@@ -1900,12 +1902,13 @@ static struct diff_queue_struct *get_diffpairs(struct merge_options *opt,\n \treturn ret;\n }\n \n-static int tree_has_path(struct tree *tree, const char *path)\n+static int tree_has_path(struct repository *r, struct tree *tree,\n+\t\t\t const char *path)\n {\n \tstruct object_id hashy;\n \tunsigned short mode_o;\n \n-\treturn !get_tree_entry(the_repository,\n+\treturn !get_tree_entry(r,\n \t\t\t       &tree->object.oid, path,\n \t\t\t       &hashy, &mode_o);\n }\n@@ -2057,7 +2060,7 @@ static char *handle_path_level_conflicts(struct merge_options *opt,\n \t */\n \tif (collision_ent->reported_already) {\n \t\tclean = 0;\n-\t} else if (tree_has_path(tree, new_path)) {\n+\t} else if (tree_has_path(opt->repo, tree, new_path)) {\n \t\tcollision_ent->reported_already = 1;\n \t\tstrbuf_add_separated_string_list(&collision_paths, \", \",\n \t\t\t\t\t\t &collision_ent->source_files);\n@@ -2135,7 +2138,7 @@ static void handle_directory_level_conflicts(struct merge_options *opt,\n \t\t\tstring_list_append(&remove_from_merge,\n \t\t\t\t\t   merge_ent->dir)->util = merge_ent;\n \t\t\tstrbuf_release(&merge_ent->new_dir);\n-\t\t} else if (tree_has_path(head, head_ent->dir)) {\n+\t\t} else if (tree_has_path(opt->repo, head, head_ent->dir)) {\n \t\t\t/* 2. This wasn't a directory rename after all */\n \t\t\tstring_list_append(&remove_from_head,\n \t\t\t\t\t   head_ent->dir)->util = head_ent;\n@@ -2149,7 +2152,7 @@ static void handle_directory_level_conflicts(struct merge_options *opt,\n \thashmap_iter_init(dir_re_merge, &iter);\n \twhile ((merge_ent = hashmap_iter_next(&iter))) {\n \t\thead_ent = dir_rename_find_entry(dir_re_head, merge_ent->dir);\n-\t\tif (tree_has_path(merge, merge_ent->dir)) {\n+\t\tif (tree_has_path(opt->repo, merge, merge_ent->dir)) {\n \t\t\t/* 2. This wasn't a directory rename after all */\n \t\t\tstring_list_append(&remove_from_merge,\n \t\t\t\t\t   merge_ent->dir)->util = merge_ent;\n@@ -2478,7 +2481,7 @@ static void apply_directory_rename_modifications(struct merge_options *opt,\n \t\tif (pair->status == 'R')\n \t\t\tre->dst_entry->processed = 1;\n \n-\t\tre->dst_entry = insert_stage_data(new_path,\n+\t\tre->dst_entry = insert_stage_data(opt->repo, new_path,\n \t\t\t\t\t\t  o_tree, a_tree, b_tree,\n \t\t\t\t\t\t  entries);\n \t\titem = string_list_insert(entries, new_path);\n@@ -2587,14 +2590,16 @@ static struct string_list *get_renames(struct merge_options *opt,\n \t\tre->dir_rename_original_dest = NULL;\n \t\titem = string_list_lookup(entries, re->pair->one->path);\n \t\tif (!item)\n-\t\t\tre->src_entry = insert_stage_data(re->pair->one->path,\n+\t\t\tre->src_entry = insert_stage_data(opt->repo,\n+\t\t\t\t\tre->pair->one->path,\n \t\t\t\t\to_tree, a_tree, b_tree, entries);\n \t\telse\n \t\t\tre->src_entry = item->util;\n \n \t\titem = string_list_lookup(entries, re->pair->two->path);\n \t\tif (!item)\n-\t\t\tre->dst_entry = insert_stage_data(re->pair->two->path,\n+\t\t\tre->dst_entry = insert_stage_data(opt->repo,\n+\t\t\t\t\tre->pair->two->path,\n \t\t\t\t\to_tree, a_tree, b_tree, entries);\n \t\telse\n \t\t\tre->dst_entry = item->util;\ndiff --git a/sequencer.c b/sequencer.c\nindex d565fcf2b1..64428ac28f 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -3733,7 +3733,7 @@ static int pick_commits(struct repository *r,\n \t\t\tunlink(rebase_path_author_script());\n \t\t\tunlink(rebase_path_stopped_sha());\n \t\t\tunlink(rebase_path_amend());\n-\t\t\tunlink(git_path_merge_head(the_repository));\n+\t\t\tunlink(git_path_merge_head(r));\n \t\t\tdelete_ref(NULL, \"REBASE_HEAD\", NULL, REF_NO_DEREF);\n \n \t\t\tif (item->command == TODO_BREAK)\n@@ -4107,7 +4107,7 @@ static int commit_staged_changes(struct repository *r,\n \t\t\t   opts, flags))\n \t\treturn error(_(\"could not commit staged changes.\"));\n \tunlink(rebase_path_amend());\n-\tunlink(git_path_merge_head(the_repository));\n+\tunlink(git_path_merge_head(r));\n \tif (final_fixup) {\n \t\tunlink(rebase_path_fixup_msg());\n \t\tunlink(rebase_path_squash_msg());\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 3c9fa10af8..6069fe006b 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -478,7 +478,7 @@ static enum get_oid_result get_short_oid(struct repository *r,\n \t * or migrated from loose to packed.\n \t */\n \tif (status == MISSING_OBJECT) {\n-\t\treprepare_packed_git(the_repository);\n+\t\treprepare_packed_git(r);\n \t\tfind_short_object_filename(&ds);\n \t\tfind_short_packed_object(&ds);\n \t\tstatus = finish_object_disambiguation(&ds, oid);\n@@ -1389,9 +1389,7 @@ int repo_get_oid_mb(struct repository *r,\n \ttwo = lookup_commit_reference_gently(r, &oid_tmp, 0);\n \tif (!two)\n \t\treturn -1;\n-\tif (r != the_repository)\n-\t\tBUG(\"sorry get_merge_bases() can't take struct repository yet\");\n-\tmbs = get_merge_bases(one, two);\n+\tmbs = repo_get_merge_bases(r, one, two);\n \tif (!mbs || mbs->next)\n \t\tst = -1;\n \telse {\ndiff --git a/shallow.c b/shallow.c\nindex ce45297940..5fa2b15d37 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -248,7 +248,8 @@ static void check_shallow_file_for_update(struct repository *r)\n \tif (r->parsed_objects->is_shallow == -1)\n \t\tBUG(\"shallow must be initialized by now\");\n \n-\tif (!stat_validity_check(r->parsed_objects->shallow_stat, git_path_shallow(the_repository)))\n+\tif (!stat_validity_check(r->parsed_objects->shallow_stat,\n+\t\t\t\t git_path_shallow(r)))\n \t\tdie(\"shallow file has changed since we read it\");\n }\n \n-- \n2.22.0.rc0.322.g2b0371e29a\n\n"},{"id":"378154","messageId":"nycvar.QRO.7.76.6.1906271448290.44@tvgsbejvaqbjf.bet","threadId":"51368","inReplyTo":"20190624095533.22162-2-pclouds@gmail.com","subject":"Re: [PATCH 1/6] sha1-file.c: remove the_repo from read_object_with_reference()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2019-06-27T12:54:52Z","receivedAt":"2019-06-27T12:54:38Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Duy,\n\nOn Mon, 24 Jun 2019, Nguyễn Thái Ngọc Duy wrote:\n\n> diff --git a/builtin/grep.c b/builtin/grep.c\n> index 580fd38f41..85da7ee542 100644\n> --- a/builtin/grep.c\n> +++ b/builtin/grep.c\n> @@ -458,7 +458,8 @@ static int grep_submodule(struct grep_opt *opt,\n>  \t\tobject = parse_object_or_die(oid, oid_to_hex(oid));\n>\n>  \t\tgrep_read_lock();\n> -\t\tdata = read_object_with_reference(&object->oid, tree_type,\n> +\t\tdata = read_object_with_reference(opt->repo,\n> +\t\t\t\t\t\t  &object->oid, tree_type,\n\nJunio's hunch was absolutely spot on. This conversion is incorrect. If you\nreplace this `opt->repo` and...\n\n>  \t\t\t\t\t\t  &size, NULL);\n>  \t\tgrep_read_unlock();\n>\n> @@ -623,7 +624,8 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,\n>  \t\tint hit, len;\n>\n>  \t\tgrep_read_lock();\n> -\t\tdata = read_object_with_reference(&obj->oid, tree_type,\n> +\t\tdata = read_object_with_reference(opt->repo,\n\n... this one with `the_repository`, t7814 starts passing again.\n\nIt makes me very wary of this patch series that this bug has only been\ncaught by a CI build. You probably did not run the test suite before\nsending this patch series.\n\nI also wonder what the rationale was to deviate from the strategy used in\nthe remainder of the call sites, where no attempt was made to use an\nalready-available repository pointer that might, or might not, be the\ncorrect one.\n\nIt strikes me as a pretty important goal of this patch series to _not_\nchange any behavior, and this bug makes me dubious that all diligence has\nbeen done to assure that.\n\nCiao,\nJohannes\n"},{"id":"378155","messageId":"nycvar.QRO.7.76.6.1906271458240.44@tvgsbejvaqbjf.bet","threadId":"51368","inReplyTo":"xmqq5zose00p.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH 0/6] Kill the_repository in tree-walk.c","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2019-06-27T13:04:29Z","receivedAt":"2019-06-27T13:04:15Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Junio,\n\nOn Wed, 26 Jun 2019, Junio C Hamano wrote:\n\n> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n>\n> > This is the continuation of nd/sha1-name-c-wo-the-repository. In that\n> > series I sealed off one place in sha1-name.c that cannot walk trees\n> > from arbitrary repositories. With tree-walk.c taking 'struct\n> > repository *' directly, that check in there can now be removed.\n>\n> Thanks.\n>\n> With these queued on 'master', t7814 seems to become flaky (tried\n> running it with --stress, with and without these patches).  Are we\n> touching a wrong index file in some codepaths or something?\n\nIt's not flaky, as it fails consistently, and yes, we're touching the\nwrong repository in at least this one code path. I think I would have\nwished for a more careful conversion in this patch series, as it does\ntouch critical code paths.\n\nGiven that this bug was only caught by a failing CI build, it does make me\nwonder what other bugs are hidden and would slip into our code base just\nbecause of gaps in the code coverage.\n\nCiao,\nDscho\n"},{"id":"378156","messageId":"CACsJy8Avw0hh61Rr-xAWpOT_J8GKwFq=e4BYtFOfXHvpfpR0rw@mail.gmail.com","threadId":"51368","inReplyTo":"nycvar.QRO.7.76.6.1906271448290.44@tvgsbejvaqbjf.bet","subject":"Re: [PATCH 1/6] sha1-file.c: remove the_repo from read_object_with_reference()","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-27T13:12:22Z","receivedAt":"2019-06-27T13:12:51Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, Jun 27, 2019 at 7:54 PM Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n>\n> Hi Duy,\n>\n> On Mon, 24 Jun 2019, Nguyễn Thái Ngọc Duy wrote:\n>\n> > diff --git a/builtin/grep.c b/builtin/grep.c\n> > index 580fd38f41..85da7ee542 100644\n> > --- a/builtin/grep.c\n> > +++ b/builtin/grep.c\n> > @@ -458,7 +458,8 @@ static int grep_submodule(struct grep_opt *opt,\n> >               object = parse_object_or_die(oid, oid_to_hex(oid));\n> >\n> >               grep_read_lock();\n> > -             data = read_object_with_reference(&object->oid, tree_type,\n> > +             data = read_object_with_reference(opt->repo,\n> > +                                               &object->oid, tree_type,\n>\n> Junio's hunch was absolutely spot on. This conversion is incorrect. If you\n> replace this `opt->repo` and...\n>\n> >                                                 &size, NULL);\n> >               grep_read_unlock();\n> >\n> > @@ -623,7 +624,8 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,\n> >               int hit, len;\n> >\n> >               grep_read_lock();\n> > -             data = read_object_with_reference(&obj->oid, tree_type,\n> > +             data = read_object_with_reference(opt->repo,\n>\n> ... this one with `the_repository`, t7814 starts passing again.\n>\n> It makes me very wary of this patch series that this bug has only been\n> caught by a CI build. You probably did not run the test suite before\n> sending this patch series.\n\nI did. After Junio reported, I've ran a lot more and had the same\npass/fail-sometimes behavior.\n\n> I also wonder what the rationale was to deviate from the strategy used in\n> the remainder of the call sites, where no attempt was made to use an\n> already-available repository pointer that might, or might not, be the\n> correct one.\n\nMy strategy has always been \"use the right repo if available, fall\nback to the_repo otherwise\". This code path has struct repo, my\nmistake was not realize soon enough that there are two repos, not once\n(Ironically I made the conversion to add subrepo here).\n\n> It strikes me as a pretty important goal of this patch series to _not_\n> change any behavior, and this bug makes me dubious that all diligence has\n> been done to assure that.\n\nSooner or later all the_repo must be converted, what makes _this_\nseries different from other conversion series? Yes I slipped, I should\nhave been more careful to the parts related to submodule.\n-- \nDuy\n"},{"id":"378171","messageId":"7fbc8fc5-b834-c3f6-5d73-27caa55b01d9@gmail.com","threadId":"51368","inReplyTo":"nycvar.QRO.7.76.6.1906271458240.44@tvgsbejvaqbjf.bet","subject":"Re: [PATCH 0/6] Kill the_repository in tree-walk.c","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2019-06-27T17:09:36Z","receivedAt":"2019-06-27T17:09:39Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 6/27/2019 9:04 AM, Johannes Schindelin wrote:\n> Given that this bug was only caught by a failing CI build, it does make me\n> wonder what other bugs are hidden and would slip into our code base just\n> because of gaps in the code coverage.\n\nHere are the lines introduced by this series that are not covered by the\ntest suite. I'm not asking you to write tests to cover these lines, but\nplease re-examine the lines to be sure the correct conversion was made.\n\nThanks,\n-Stolee\n\n> Uncovered code in 'pu' not in 'jch'\n> --------------------------------------------------------\n> \n> archive.c\n> 47f956bd 421) err = get_tree_entry(ar_args->repo,\n> 47f956bd 422)      &tree->object.oid,\n> \n> fast-import.c\n> 35d7cdbe 2565) char *buf = read_object_with_reference(the_repository,\n> 35d7cdbe 2566)        &n->oid,\n> \n> match-trees.c\n> 3fe87a7f 294) if (get_tree_entry(r, hash2, del_prefix, shifted, &mode))\n> \n> t/helper/test-match-trees.c\n> 3fe87a7f 23) shift_tree(the_repository, &one->object.oid, &two->object.oid, &shifted, -1);\n>\n> Nguyễn Thái Ngọc Duy\t35d7cdbe sha1-file.c: remove the_repo from read_object_with_reference()\n> Nguyễn Thái Ngọc Duy\t3fe87a7f match-trees.c: remove the_repo from shift_tree*()\n> Nguyễn Thái Ngọc Duy\t47f956bd tree-walk.c: remove the_repo from get_tree_entry()\n\n"},{"id":"378194","messageId":"xmqqr27eak47.fsf@gitster-ct.c.googlers.com","threadId":"51368","inReplyTo":"20190627092852.11326-1-pclouds@gmail.com","subject":"Re: [PATCH v2 0/6] Kill the_repository in tree-walk.c","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-06-27T19:44:40Z","receivedAt":"2019-06-27T19:44:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n>  tree-walk.h                 |  8 ++++---\n>  unpack-trees.c              |  2 +-\n>  25 files changed, 129 insertions(+), 97 deletions(-)\n>\n> Range-diff dựa trên v1:\n> 1:  35d7cdbe6a ! 1:  9e73c39f9a sha1-file.c: remove the_repo from read_object_with_reference()\n\nI see inconsistent l10n here.  \n\nI see merit in both \n\n (1) forcing the C locale when preparing project-wide communications\n     like patch e-mails, even when end-user's UI is usually showing\n     in another locale, for maximum reach, or\n\n (2) honoring the locale end-user's even when preparing project-wide\n     communications, to help with mono-culture projects.\n\nWhichever stance we take, we should be consistent ;-)\n"},{"id":"378243","messageId":"20190628093528.20372-1-pclouds@gmail.com","threadId":"51368","inReplyTo":"20190627092852.11326-1-pclouds@gmail.com","subject":"[PATCH v2 7/6] t7814: do not generate same commits in different repos","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-06-28T09:35:28Z","receivedAt":"2019-06-28T09:35:43Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"t7814 has repo tree like this\n\n  initial-repo\n    submodule\n      sub\n\nIn each repo 'submodule' and 'sub', a commit is made to add the same\ninitial file 'a' with the same message 'add a'. If tests run fast\nenough, the two commits are made in the same second, resulting\nidentical commits.\n\nThere is nothing wrong with that per-se. But it could make the test\nflaky. Currently all submodule odbs are merged back in the main\none (because we can't, or couldn't, access separate submodule repos\notherwise). But eventually we need to access objects from the right\nrepo.\n\nBecause the same commit could sometimes be present in both 'submodule'\nand 'sub', if there is a bug looking up objects in the wrong repo,\nsometimes it will go unnoticed because it finds the needed object in the\nwrong repo anyway.\n\nFix this by changing commit time after every commit. This makes all\ncommits unique. Of course there are still identical blobs in different\nrepos, but because we often lookup commit first, then tree and blob,\nunique commits are already quite safe.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n > And I can't quite understand how t7814 sometimes passed.\n\n I do now. This patch makes it fail consistently for me.\n \n This patch technically has nothing to do with this series, but I'll\n try to sneak it in because it was started from there.\n\n t/t7814-grep-recurse-submodules.sh | 18 +++++++++++++++++-\n 1 file changed, 17 insertions(+), 1 deletion(-)\n\ndiff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh\nindex 134a694516..a11366b4ce 100755\n--- a/t/t7814-grep-recurse-submodules.sh\n+++ b/t/t7814-grep-recurse-submodules.sh\n@@ -14,12 +14,14 @@ test_expect_success 'setup directory structure and submodule' '\n \techo \"(3|4)\" >b/b &&\n \tgit add a b &&\n \tgit commit -m \"add a and b\" &&\n+\ttest_tick &&\n \tgit init submodule &&\n \techo \"(1|2)d(3|4)\" >submodule/a &&\n \tgit -C submodule add a &&\n \tgit -C submodule commit -m \"add a\" &&\n \tgit submodule add ./submodule &&\n-\tgit commit -m \"added submodule\"\n+\tgit commit -m \"added submodule\" &&\n+\ttest_tick\n '\n \n test_expect_success 'grep correctly finds patterns in a submodule' '\n@@ -65,11 +67,14 @@ test_expect_success 'grep and nested submodules' '\n \techo \"(1|2)d(3|4)\" >submodule/sub/a &&\n \tgit -C submodule/sub add a &&\n \tgit -C submodule/sub commit -m \"add a\" &&\n+\ttest_tick &&\n \tgit -C submodule submodule add ./sub &&\n \tgit -C submodule add sub &&\n \tgit -C submodule commit -m \"added sub\" &&\n+\ttest_tick &&\n \tgit add submodule &&\n \tgit commit -m \"updated submodule\" &&\n+\ttest_tick &&\n \n \tcat >expect <<-\\EOF &&\n \ta:(1|2)d(3|4)\n@@ -179,15 +184,18 @@ test_expect_success !MINGW 'grep recurse submodule colon in name' '\n \techo \"(1|2)d(3|4)\" >\"parent/fi:le\" &&\n \tgit -C parent add \"fi:le\" &&\n \tgit -C parent commit -m \"add fi:le\" &&\n+\ttest_tick &&\n \n \tgit init \"su:b\" &&\n \ttest_when_finished \"rm -rf su:b\" &&\n \techo \"(1|2)d(3|4)\" >\"su:b/fi:le\" &&\n \tgit -C \"su:b\" add \"fi:le\" &&\n \tgit -C \"su:b\" commit -m \"add fi:le\" &&\n+\ttest_tick &&\n \n \tgit -C parent submodule add \"../su:b\" \"su:b\" &&\n \tgit -C parent commit -m \"add submodule\" &&\n+\ttest_tick &&\n \n \tcat >expect <<-\\EOF &&\n \tfi:le:(1|2)d(3|4)\n@@ -210,15 +218,18 @@ test_expect_success 'grep history with moved submoules' '\n \techo \"(1|2)d(3|4)\" >parent/file &&\n \tgit -C parent add file &&\n \tgit -C parent commit -m \"add file\" &&\n+\ttest_tick &&\n \n \tgit init sub &&\n \ttest_when_finished \"rm -rf sub\" &&\n \techo \"(1|2)d(3|4)\" >sub/file &&\n \tgit -C sub add file &&\n \tgit -C sub commit -m \"add file\" &&\n+\ttest_tick &&\n \n \tgit -C parent submodule add ../sub dir/sub &&\n \tgit -C parent commit -m \"add submodule\" &&\n+\ttest_tick &&\n \n \tcat >expect <<-\\EOF &&\n \tdir/sub/file:(1|2)d(3|4)\n@@ -229,6 +240,7 @@ test_expect_success 'grep history with moved submoules' '\n \n \tgit -C parent mv dir/sub sub-moved &&\n \tgit -C parent commit -m \"moved submodule\" &&\n+\ttest_tick &&\n \n \tcat >expect <<-\\EOF &&\n \tfile:(1|2)d(3|4)\n@@ -251,6 +263,7 @@ test_expect_success 'grep using relative path' '\n \techo \"(1|2)d(3|4)\" >sub/file &&\n \tgit -C sub add file &&\n \tgit -C sub commit -m \"add file\" &&\n+\ttest_tick &&\n \n \tgit init parent &&\n \techo \"(1|2)d(3|4)\" >parent/file &&\n@@ -260,6 +273,7 @@ test_expect_success 'grep using relative path' '\n \tgit -C parent add src/file2 &&\n \tgit -C parent submodule add ../sub &&\n \tgit -C parent commit -m \"add files and submodule\" &&\n+\ttest_tick &&\n \n \t# From top works\n \tcat >expect <<-\\EOF &&\n@@ -293,6 +307,7 @@ test_expect_success 'grep from a subdir' '\n \techo \"(1|2)d(3|4)\" >sub/file &&\n \tgit -C sub add file &&\n \tgit -C sub commit -m \"add file\" &&\n+\ttest_tick &&\n \n \tgit init parent &&\n \tmkdir parent/src &&\n@@ -301,6 +316,7 @@ test_expect_success 'grep from a subdir' '\n \tgit -C parent submodule add ../sub src/sub &&\n \tgit -C parent submodule add ../sub sub &&\n \tgit -C parent commit -m \"add files and submodules\" &&\n+\ttest_tick &&\n \n \t# Verify grep from root works\n \tcat >expect <<-\\EOF &&\n-- \n2.22.0.rc0.322.g2b0371e29a\n\n"},{"id":"378264","messageId":"nycvar.QRO.7.76.6.1906281440400.44@tvgsbejvaqbjf.bet","threadId":"51368","inReplyTo":"20190627092852.11326-2-pclouds@gmail.com","subject":"Re: [PATCH v2 1/6] sha1-file.c: remove the_repo from read_object_with_reference()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2019-06-28T12:46:53Z","receivedAt":"2019-06-28T12:46:37Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Duy,\n\nOn Thu, 27 Jun 2019, Nguyễn Thái Ngọc Duy wrote:\n\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n\nThis commit is _awfully_ short given that...\n\n> diff --git a/builtin/grep.c b/builtin/grep.c\n> index 580fd38f41..560051784e 100644\n> --- a/builtin/grep.c\n> +++ b/builtin/grep.c\n> @@ -458,7 +458,8 @@ static int grep_submodule(struct grep_opt *opt,\n>  \t\tobject = parse_object_or_die(oid, oid_to_hex(oid));\n>\n>  \t\tgrep_read_lock();\n> -\t\tdata = read_object_with_reference(&object->oid, tree_type,\n> +\t\tdata = read_object_with_reference(&subrepo,\n> +\t\t\t\t\t\t  &object->oid, tree_type,\n\n... this change and...\n\n>  \t\t\t\t\t\t  &size, NULL);\n>  \t\tgrep_read_unlock();\n>\n> @@ -623,7 +624,8 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,\n>  \t\tint hit, len;\n>\n>  \t\tgrep_read_lock();\n> -\t\tdata = read_object_with_reference(&obj->oid, tree_type,\n> +\t\tdata = read_object_with_reference(opt->repo,\n> +\t\t\t\t\t\t  &obj->oid, tree_type,\n\n... this change is totally not what would be intuitively the easiest: to\nuse `the_repository` in all built-ins.\n\nIt might take quite a lot of convincing that these changes are correct, in\nparticular in light of the regressions introduced by the first iteration\n(to paraphrase Warren Buffet [*1*]: one slip in a patch series touching as\ncentral parts as this one will need a lot of time to restore trust in\nsubsequent iterations' correctness.)\n\nIn short: with such an empty commit message, this patch is no good. It's\nas if it was optimized to pass the test suite on Linux instead of a best\neffort to make the conversion as correct as you can make it.\n\nCiao,\nJohannes\n\nFootnote *1*:\nhttps://www.forbes.com/sites/jamesberman/2014/04/20/the-three-essential-warren-buffett-quotes-to-live-by/\n"},{"id":"378274","messageId":"xmqqtvc98z1n.fsf@gitster-ct.c.googlers.com","threadId":"51368","inReplyTo":"20190628093528.20372-1-pclouds@gmail.com","subject":"Re: [PATCH v2 7/6] t7814: do not generate same commits in different repos","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-06-28T16:17:24Z","receivedAt":"2019-06-28T16:17:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> t7814 has repo tree like this\n>\n>   initial-repo\n>     submodule\n>       sub\n>\n> In each repo 'submodule' and 'sub', a commit is made to add the same\n> initial file 'a' with the same message 'add a'. If tests run fast\n> enough, the two commits are made in the same second, resulting\n> identical commits.\n>\n> There is nothing wrong with that per-se. But it could make the test\n> flaky. Currently all submodule odbs are merged back in the main\n> one (because we can't, or couldn't, access separate submodule repos\n> otherwise). But eventually we need to access objects from the right\n> repo.\n>\n> Because the same commit could sometimes be present in both 'submodule'\n> and 'sub', if there is a bug looking up objects in the wrong repo,\n> sometimes it will go unnoticed because it finds the needed object in the\n> wrong repo anyway.\n>\n> Fix this by changing commit time after every commit. This makes all\n> commits unique. Of course there are still identical blobs in different\n> repos, but because we often lookup commit first, then tree and blob,\n> unique commits are already quite safe.\n>\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  > And I can't quite understand how t7814 sometimes passed.\n>\n>  I do now. This patch makes it fail consistently for me.\n\nWell analysed.  Very well done.  Thanks.\n"}]}