{"thread":{"id":"50841","subject":"[PATCH 01/31] packfile.c: add repo_approximate_object_count()","startedAt":"2019-03-30T11:20:34Z","lastAt":"2019-04-16T09:37:57Z","messageCount":153,"participants":["Nguyễn Thái Ngọc Duy","SZEDER Gábor","Duy Nguyen","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":31},"messages":[{"id":"372765","messageId":"20190330111927.18645-2-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 01/31] packfile.c: add repo_approximate_object_count()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:18:57Z","receivedAt":"2019-03-30T11:20:34Z","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 packfile.c | 14 +++++++-------\n packfile.h |  3 ++-\n 2 files changed, 9 insertions(+), 8 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex 16bcb75262..2ad4fab2f8 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -893,25 +893,25 @@ static void prepare_packed_git(struct repository *r);\n  * all unreachable objects about to be pruned, in which case they're not really\n  * interesting as a measure of repo size in the first place.\n  */\n-unsigned long approximate_object_count(void)\n+unsigned long repo_approximate_object_count(struct repository *r)\n {\n-\tif (!the_repository->objects->approximate_object_count_valid) {\n+\tif (!r->objects->approximate_object_count_valid) {\n \t\tunsigned long count;\n \t\tstruct multi_pack_index *m;\n \t\tstruct packed_git *p;\n \n-\t\tprepare_packed_git(the_repository);\n+\t\tprepare_packed_git(r);\n \t\tcount = 0;\n-\t\tfor (m = get_multi_pack_index(the_repository); m; m = m->next)\n+\t\tfor (m = get_multi_pack_index(r); m; m = m->next)\n \t\t\tcount += m->num_objects;\n-\t\tfor (p = the_repository->objects->packed_git; p; p = p->next) {\n+\t\tfor (p = r->objects->packed_git; p; p = p->next) {\n \t\t\tif (open_pack_index(p))\n \t\t\t\tcontinue;\n \t\t\tcount += p->num_objects;\n \t\t}\n-\t\tthe_repository->objects->approximate_object_count = count;\n+\t\tr->objects->approximate_object_count = count;\n \t}\n-\treturn the_repository->objects->approximate_object_count;\n+\treturn r->objects->approximate_object_count;\n }\n \n static void *get_next_packed_git(const void *p)\ndiff --git a/packfile.h b/packfile.h\nindex d70c6d9afb..f04440f984 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -57,7 +57,8 @@ struct packed_git *get_all_packs(struct repository *r);\n  * Give a rough count of objects in the repository. This sacrifices accuracy\n  * for speed.\n  */\n-unsigned long approximate_object_count(void);\n+unsigned long repo_approximate_object_count(struct repository *r);\n+#define approximate_object_count() repo_approximate_object_count(the_repository)\n \n extern struct packed_git *find_sha1_pack(const unsigned char *sha1,\n \t\t\t\t\t struct packed_git *packs);\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372766","messageId":"20190330111927.18645-3-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 02/31] refs.c: add refs_ref_exists()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:18:58Z","receivedAt":"2019-03-30T11:20: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>\n---\n refs.c | 7 ++++++-\n 1 file changed, 6 insertions(+), 1 deletion(-)\n\ndiff --git a/refs.c b/refs.c\nindex 142888a40a..b869f32d8b 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -241,9 +241,14 @@ int read_ref(const char *refname, struct object_id *oid)\n \treturn read_ref_full(refname, RESOLVE_REF_READING, oid, NULL);\n }\n \n+static int refs_ref_exists(struct ref_store *refs, const char *refname)\n+{\n+\treturn !!refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING, NULL, NULL);\n+}\n+\n int ref_exists(const char *refname)\n {\n-\treturn !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, NULL, NULL);\n+\treturn refs_ref_exists(get_main_ref_store(the_repository), refname);\n }\n \n static int match_ref_pattern(const char *refname,\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372767","messageId":"20190330111927.18645-1-pclouds@gmail.com","threadId":"50841","inReplyTo":null,"subject":"[PATCH 00/31] Kill the_repository in sha1-name.c","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:18:56Z","receivedAt":"2019-03-30T11:20:43Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This whole series is to fix a known issue from\nao/submodule-wo-gitmodules-checked-out. Commit 76e9bdc437 (submodule:\nsupport reading .gitmodules when it's not in the working tree -\n2018-10-25) makes \"git grep --recurse-submodules\" print\n\n    warning: nested submodules ... not supported yet\n\none line per submodule. And it's really annoying when a repo has lots\nof (non-nested) submodules.\n\nFixing it requires resolving an extended SHA-1 syntax from a separate\nrepository. Which basically means the whole sha1-name.c has to be\naware of 'struct repository' (and a bit more from refs.c as well).\n\nTechnically merge-recursive.c, tree-walk.c and config.c have to take\n'struct repository *' too, but I reduce the scope a bit since it's\nalready long.\n\nThe main fix is 28/31. The rest is just converting code to use 'struct\nrepository *'. Patches after 28/31 are technically not needed, but\nsince I have converted most of sha1-name.c, might as well convert the\nrest.\n\nThere is a new function get_oidf() from another series on 'pu', which\ncan't be converted right now of course. But it could be fixed easily\nlater. It also causes a conflict in cache.h but resolving is straight\nforward.\n\nNguyễn Thái Ngọc Duy (31):\n  packfile.c: add repo_approximate_object_count()\n  refs.c: add refs_ref_exists()\n  refs.c: add refs_shorten_unambiguous_ref()\n  refs.c: remove the_repo from substitute_branch_name()\n  refs.c: remove the_repo from expand_ref()\n  refs.c: add repo_dwim_ref()\n  refs.c: add repo_dwim_log()\n  refs.c: remove the_repo from read_ref_at()\n  commit.c: add repo_get_commit_tree()\n  sha1-name.c: remove the_repo from sort_ambiguous()\n  sha1-name.c: remove the_repo from find_abbrev_len_packed()\n  sha1-name.c: add repo_find_unique_abbrev_r()\n  sha1-name.c: store and use repo in struct disambiguate_state\n  sha1-name.c: add repo_for_each_abbrev()\n  sha1-name.c: remove the_repo from get_short_oid()\n  sha1-name.c: remove the_repo from interpret_nth_prior_checkout()\n  sha1-name.c: remove the_repo from interpret_branch_mark()\n  sha1-name.c: add repo_interpret_branch_name()\n  sha1-name.c: remove the_repo from get_oid_oneline()\n  sha1-name.c: remove the_repo from get_describe_name()\n  sha1-name.c: remove the_repo from get_oid_basic()\n  sha1-name.c: remove the_repo from get_oid_1()\n  sha1-name.c: remove the_repo from handle_one_ref()\n  sha1-name.c: remove the_repo from diagnose_invalid_index_path()\n  sha1-name.c: remove the_repo from resolve_relative_path()\n  sha1-name.c: remove the_repo from get_oid_with_context_1()\n  sha1-name.c: add repo_get_oid()\n  submodule-config.c: use repo_get_oid for reading .gitmodules\n  sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name\n  sha1-name.c: remove the_repo from other get_oid_*\n  sha1-name.c: remove the_repo from get_oid_mb()\n\n builtin/show-branch.c              |   6 +-\n cache.h                            |  50 ++--\n commit.c                           |   5 +-\n commit.h                           |   3 +-\n dir.c                              |   8 +\n dir.h                              |   4 +-\n packfile.c                         |  14 +-\n packfile.h                         |   3 +-\n refs.c                             |  71 ++++--\n refs.h                             |   9 +-\n setup.c                            |   7 +-\n sha1-name.c                        | 388 ++++++++++++++++++-----------\n submodule-config.c                 |  20 +-\n t/t7814-grep-recurse-submodules.sh |   6 +-\n upload-pack.c                      |   2 +-\n 15 files changed, 371 insertions(+), 225 deletions(-)\n\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372768","messageId":"20190330111927.18645-4-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 03/31] refs.c: add refs_shorten_unambiguous_ref()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:18:59Z","receivedAt":"2019-03-30T11:20:44Z","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 refs.c | 11 +++++++++--\n refs.h |  2 ++\n 2 files changed, 11 insertions(+), 2 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex b869f32d8b..3dde824aab 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1169,7 +1169,8 @@ int update_ref(const char *msg, const char *refname,\n \t\t\t       old_oid, flags, onerr);\n }\n \n-char *shorten_unambiguous_ref(const char *refname, int strict)\n+char *refs_shorten_unambiguous_ref(struct ref_store *refs,\n+\t\t\t\t   const char *refname, int strict)\n {\n \tint i;\n \tstatic char **scanf_fmts;\n@@ -1247,7 +1248,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)\n \t\t\tstrbuf_reset(&resolved_buf);\n \t\t\tstrbuf_addf(&resolved_buf, rule,\n \t\t\t\t    short_name_len, short_name);\n-\t\t\tif (ref_exists(resolved_buf.buf))\n+\t\t\tif (refs_ref_exists(refs, resolved_buf.buf))\n \t\t\t\tbreak;\n \t\t}\n \n@@ -1266,6 +1267,12 @@ char *shorten_unambiguous_ref(const char *refname, int strict)\n \treturn xstrdup(refname);\n }\n \n+char *shorten_unambiguous_ref(const char *refname, int strict)\n+{\n+\treturn refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),\n+\t\t\t\t\t    refname, strict);\n+}\n+\n static struct string_list *hide_refs;\n \n int parse_hide_refs_config(const char *var, const char *value, const char *section)\ndiff --git a/refs.h b/refs.h\nindex 308fa1f03b..5627570241 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -462,6 +462,8 @@ int check_refname_format(const char *refname, int flags);\n \n const char *prettify_refname(const char *refname);\n \n+char *refs_shorten_unambiguous_ref(struct ref_store *refs,\n+\t\t\t\t   const char *refname, int strict);\n char *shorten_unambiguous_ref(const char *refname, int strict);\n \n /** rename ref, return 0 on success **/\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372769","messageId":"20190330111927.18645-5-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 04/31] refs.c: remove the_repo from substitute_branch_name()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:00Z","receivedAt":"2019-03-30T11:20:50Z","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     | 8 ++++++--\n refs.c      | 9 +++++----\n sha1-name.c | 8 ++++++--\n 3 files changed, 17 insertions(+), 8 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex ac92421f3a..fcb24b5781 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1468,8 +1468,12 @@ extern int parse_oid_hex(const char *hex, struct object_id *oid, const char **en\n #define INTERPRET_BRANCH_LOCAL (1<<0)\n #define INTERPRET_BRANCH_REMOTE (1<<1)\n #define INTERPRET_BRANCH_HEAD (1<<2)\n-extern int interpret_branch_name(const char *str, int len, struct strbuf *,\n-\t\t\t\t unsigned allowed);\n+int repo_interpret_branch_name(struct repository *r,\n+\t\t\t       const char *str, int len,\n+\t\t\t       struct strbuf *buf,\n+\t\t\t       unsigned allowed);\n+#define interpret_branch_name(str, len, buf, allowed) \\\n+\trepo_interpret_branch_name(the_repository, str, len, buf, allowed)\n extern int get_oid_mb(const char *str, struct object_id *oid);\n \n extern int validate_headref(const char *ref);\ndiff --git a/refs.c b/refs.c\nindex 3dde824aab..44df049796 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -539,10 +539,11 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n  * later free()ing) if the string passed in is a magic short-hand form\n  * to name a branch.\n  */\n-static char *substitute_branch_name(const char **string, int *len)\n+static char *substitute_branch_name(struct repository *r,\n+\t\t\t\t    const char **string, int *len)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n-\tint ret = interpret_branch_name(*string, *len, &buf, 0);\n+\tint ret = repo_interpret_branch_name(r, *string, *len, &buf, 0);\n \n \tif (ret == *len) {\n \t\tsize_t size;\n@@ -556,7 +557,7 @@ static char *substitute_branch_name(const char **string, int *len)\n \n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)\n {\n-\tchar *last_branch = substitute_branch_name(&str, &len);\n+\tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n \tint   refs_found  = expand_ref(str, len, oid, ref);\n \tfree(last_branch);\n \treturn refs_found;\n@@ -596,7 +597,7 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)\n \n int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n {\n-\tchar *last_branch = substitute_branch_name(&str, &len);\n+\tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n \tconst char **p;\n \tint logs_found = 0;\n \tstruct strbuf path = STRBUF_INIT;\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 6dda2c16df..d535bb82f7 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1427,13 +1427,17 @@ static int interpret_branch_mark(const char *name, int namelen,\n \treturn len + at;\n }\n \n-int interpret_branch_name(const char *name, int namelen, struct strbuf *buf,\n-\t\t\t  unsigned allowed)\n+int repo_interpret_branch_name(struct repository *r,\n+\t\t\t       const char *name, int namelen,\n+\t\t\t       struct strbuf *buf,\n+\t\t\t       unsigned allowed)\n {\n \tchar *at;\n \tconst char *start;\n \tint len;\n \n+\tif (r != the_repository)\n+\t\tBUG(\"interpret_branch_name() does not really use 'r' yet\");\n \tif (!namelen)\n \t\tnamelen = strlen(name);\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372770","messageId":"20190330111927.18645-6-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 05/31] refs.c: remove the_repo from expand_ref()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:01Z","receivedAt":"2019-03-30T11:20:54Z","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 refs.c        | 10 ++++++----\n refs.h        |  2 +-\n upload-pack.c |  2 +-\n 3 files changed, 8 insertions(+), 6 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 44df049796..1f5864aa36 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -558,12 +558,13 @@ static char *substitute_branch_name(struct repository *r,\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)\n {\n \tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n-\tint   refs_found  = expand_ref(str, len, oid, ref);\n+\tint   refs_found  = expand_ref(the_repository, str, len, oid, ref);\n \tfree(last_branch);\n \treturn refs_found;\n }\n \n-int expand_ref(const char *str, int len, struct object_id *oid, char **ref)\n+int expand_ref(struct repository *repo, const char *str, int len,\n+\t       struct object_id *oid, char **ref)\n {\n \tconst char **p, *r;\n \tint refs_found = 0;\n@@ -578,8 +579,9 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)\n \t\tthis_result = refs_found ? &oid_from_ref : oid;\n \t\tstrbuf_reset(&fullref);\n \t\tstrbuf_addf(&fullref, *p, len, str);\n-\t\tr = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,\n-\t\t\t\t       this_result, &flag);\n+\t\tr = refs_resolve_ref_unsafe(get_main_ref_store(repo),\n+\t\t\t\t\t    fullref.buf, RESOLVE_REF_READING,\n+\t\t\t\t\t    this_result, &flag);\n \t\tif (r) {\n \t\t\tif (!refs_found++)\n \t\t\t\t*ref = xstrdup(r);\ndiff --git a/refs.h b/refs.h\nindex 5627570241..b630d5bde7 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -148,7 +148,7 @@ int refname_match(const char *abbrev_name, const char *full_name);\n struct argv_array;\n void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);\n \n-int expand_ref(const char *str, int len, struct object_id *oid, char **ref);\n+int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n \ndiff --git a/upload-pack.c b/upload-pack.c\nindex d098ef5982..56505d60c3 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -834,7 +834,7 @@ static int process_deepen_not(const char *line, struct string_list *deepen_not,\n \tif (skip_prefix(line, \"deepen-not \", &arg)) {\n \t\tchar *ref = NULL;\n \t\tstruct object_id oid;\n-\t\tif (expand_ref(arg, strlen(arg), &oid, &ref) != 1)\n+\t\tif (expand_ref(the_repository, arg, strlen(arg), &oid, &ref) != 1)\n \t\t\tdie(\"git upload-pack: ambiguous deepen-not: %s\", line);\n \t\tstring_list_append(deepen_not, ref);\n \t\tfree(ref);\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372771","messageId":"20190330111927.18645-7-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 06/31] refs.c: add repo_dwim_ref()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:02Z","receivedAt":"2019-03-30T11:21:01Z","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 refs.c | 12 +++++++++---\n refs.h |  1 +\n 2 files changed, 10 insertions(+), 3 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 1f5864aa36..bd0fec5776 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -555,14 +555,20 @@ static char *substitute_branch_name(struct repository *r,\n \treturn NULL;\n }\n \n-int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)\n+int repo_dwim_ref(struct repository *r, const char *str, int len,\n+\t\t  struct object_id *oid, char **ref)\n {\n-\tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n-\tint   refs_found  = expand_ref(the_repository, str, len, oid, ref);\n+\tchar *last_branch = substitute_branch_name(r, &str, &len);\n+\tint   refs_found  = expand_ref(r, str, len, oid, ref);\n \tfree(last_branch);\n \treturn refs_found;\n }\n \n+int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)\n+{\n+\treturn repo_dwim_ref(the_repository, str, len, oid, ref);\n+}\n+\n int expand_ref(struct repository *repo, const char *str, int len,\n \t       struct object_id *oid, char **ref)\n {\ndiff --git a/refs.h b/refs.h\nindex b630d5bde7..fd3dc1d0f4 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -149,6 +149,7 @@ struct argv_array;\n void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);\n \n int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n+int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372772","messageId":"20190330111927.18645-8-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 07/31] refs.c: add repo_dwim_log()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:03Z","receivedAt":"2019-03-30T11:21:05Z","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 refs.c | 21 +++++++++++++++------\n refs.h |  1 +\n 2 files changed, 16 insertions(+), 6 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex bd0fec5776..edea001446 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -603,9 +603,11 @@ int expand_ref(struct repository *repo, const char *str, int len,\n \treturn refs_found;\n }\n \n-int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n+int repo_dwim_log(struct repository *r, const char *str, int len,\n+\t\t  struct object_id *oid, char **log)\n {\n-\tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n+\tstruct ref_store *refs = get_main_ref_store(r);\n+\tchar *last_branch = substitute_branch_name(r, &str, &len);\n \tconst char **p;\n \tint logs_found = 0;\n \tstruct strbuf path = STRBUF_INIT;\n@@ -617,13 +619,15 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n \n \t\tstrbuf_reset(&path);\n \t\tstrbuf_addf(&path, *p, len, str);\n-\t\tref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,\n-\t\t\t\t\t &hash, NULL);\n+\t\tref = refs_resolve_ref_unsafe(refs, path.buf,\n+\t\t\t\t\t      RESOLVE_REF_READING,\n+\t\t\t\t\t      &hash, NULL);\n \t\tif (!ref)\n \t\t\tcontinue;\n-\t\tif (reflog_exists(path.buf))\n+\t\tif (refs_reflog_exists(refs, path.buf))\n \t\t\tit = path.buf;\n-\t\telse if (strcmp(ref, path.buf) && reflog_exists(ref))\n+\t\telse if (strcmp(ref, path.buf) &&\n+\t\t\t refs_reflog_exists(refs, ref))\n \t\t\tit = ref;\n \t\telse\n \t\t\tcontinue;\n@@ -639,6 +643,11 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n \treturn logs_found;\n }\n \n+int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n+{\n+\treturn repo_dwim_log(the_repository, str, len, oid, log);\n+}\n+\n static int is_per_worktree_ref(const char *refname)\n {\n \treturn !strcmp(refname, \"HEAD\") ||\ndiff --git a/refs.h b/refs.h\nindex fd3dc1d0f4..859dffe691 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -150,6 +150,7 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);\n \n int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n+int repo_dwim_log(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372773","messageId":"20190330111927.18645-9-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 08/31] refs.c: remove the_repo from read_ref_at()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:04Z","receivedAt":"2019-03-30T11:21:09Z","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/show-branch.c | 6 ++++--\n refs.c                | 7 ++++---\n refs.h                | 3 ++-\n sha1-name.c           | 3 ++-\n 4 files changed, 12 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/show-branch.c b/builtin/show-branch.c\nindex 934e514944..082daeac32 100644\n--- a/builtin/show-branch.c\n+++ b/builtin/show-branch.c\n@@ -753,7 +753,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\t\t/* Ah, that is a date spec... */\n \t\t\t\ttimestamp_t at;\n \t\t\t\tat = approxidate(reflog_base);\n-\t\t\t\tread_ref_at(ref, flags, at, -1, &oid, NULL,\n+\t\t\t\tread_ref_at(get_main_ref_store(the_repository),\n+\t\t\t\t\t    ref, flags, at, -1, &oid, NULL,\n \t\t\t\t\t    NULL, NULL, &base);\n \t\t\t}\n \t\t}\n@@ -765,7 +766,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\ttimestamp_t timestamp;\n \t\t\tint tz;\n \n-\t\t\tif (read_ref_at(ref, flags, 0, base + i, &oid, &logmsg,\n+\t\t\tif (read_ref_at(get_main_ref_store(the_repository),\n+\t\t\t\t\tref, flags, 0, base + i, &oid, &logmsg,\n \t\t\t\t\t&timestamp, &tz, NULL)) {\n \t\t\t\treflog = i;\n \t\t\t\tbreak;\ndiff --git a/refs.c b/refs.c\nindex edea001446..92d1f6dbdd 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -967,7 +967,8 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid\n \treturn 1;\n }\n \n-int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, int cnt,\n+int read_ref_at(struct ref_store *refs, const char *refname,\n+\t\tunsigned int flags, timestamp_t at_time, int cnt,\n \t\tstruct object_id *oid, char **msg,\n \t\ttimestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt)\n {\n@@ -983,7 +984,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in\n \tcb.cutoff_cnt = cutoff_cnt;\n \tcb.oid = oid;\n \n-\tfor_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);\n+\trefs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent, &cb);\n \n \tif (!cb.reccnt) {\n \t\tif (flags & GET_OID_QUIETLY)\n@@ -994,7 +995,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in\n \tif (cb.found_it)\n \t\treturn 0;\n \n-\tfor_each_reflog_ent(refname, read_ref_at_ent_oldest, &cb);\n+\trefs_for_each_reflog_ent(refs, refname, read_ref_at_ent_oldest, &cb);\n \n \treturn 1;\n }\ndiff --git a/refs.h b/refs.h\nindex 859dffe691..8f9cbf8a93 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -388,7 +388,8 @@ int refs_create_reflog(struct ref_store *refs, const char *refname,\n int safe_create_reflog(const char *refname, int force_create, struct strbuf *err);\n \n /** Reads log for the value of ref during at_time. **/\n-int read_ref_at(const char *refname, unsigned int flags,\n+int read_ref_at(struct ref_store *refs,\n+\t\tconst char *refname, unsigned int flags,\n \t\ttimestamp_t at_time, int cnt,\n \t\tstruct object_id *oid, char **msg,\n \t\ttimestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt);\ndiff --git a/sha1-name.c b/sha1-name.c\nindex d535bb82f7..15a1107998 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -849,7 +849,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\t\t\treturn -1;\n \t\t\t}\n \t\t}\n-\t\tif (read_ref_at(real_ref, flags, at_time, nth, oid, NULL,\n+\t\tif (read_ref_at(get_main_ref_store(the_repository),\n+\t\t\t\treal_ref, flags, at_time, nth, oid, NULL,\n \t\t\t\t&co_time, &co_tz, &co_cnt)) {\n \t\t\tif (!len) {\n \t\t\t\tif (starts_with(real_ref, \"refs/heads/\")) {\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372774","messageId":"20190330111927.18645-10-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 09/31] commit.c: add repo_get_commit_tree()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:05Z","receivedAt":"2019-03-30T11:21:14Z","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 commit.c | 5 +++--\n commit.h | 3 ++-\n 2 files changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex a5333c7ac6..f0a5506f04 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -340,7 +340,8 @@ void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)\n \t}\n }\n \n-struct tree *get_commit_tree(const struct commit *commit)\n+struct tree *repo_get_commit_tree(struct repository *r,\n+\t\t\t\t  const struct commit *commit)\n {\n \tif (commit->maybe_tree || !commit->object.parsed)\n \t\treturn commit->maybe_tree;\n@@ -348,7 +349,7 @@ struct tree *get_commit_tree(const struct commit *commit)\n \tif (commit->graph_pos == COMMIT_NOT_FROM_GRAPH)\n \t\tBUG(\"commit has NULL tree, but was not loaded from commit-graph\");\n \n-\treturn get_commit_tree_in_graph(the_repository, commit);\n+\treturn get_commit_tree_in_graph(r, commit);\n }\n \n struct object_id *get_commit_tree_oid(const struct commit *commit)\ndiff --git a/commit.h b/commit.h\nindex 42728c2906..b576201be8 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -143,7 +143,8 @@ void repo_unuse_commit_buffer(struct repository *r,\n  */\n void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);\n \n-struct tree *get_commit_tree(const struct commit *);\n+struct tree *repo_get_commit_tree(struct repository *, const struct commit *);\n+#define get_commit_tree(c) repo_get_commit_tree(the_repository, c)\n struct object_id *get_commit_tree_oid(const struct commit *);\n \n /*\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372775","messageId":"20190330111927.18645-11-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 10/31] sha1-name.c: remove the_repo from sort_ambiguous()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:06Z","receivedAt":"2019-03-30T11:21:19Z","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 | 15 ++++++++++++---\n 1 file changed, 12 insertions(+), 3 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 15a1107998..7558ce51a3 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -383,10 +383,11 @@ static int collect_ambiguous(const struct object_id *oid, void *data)\n \treturn 0;\n }\n \n+static struct repository *sort_ambiguous_repo;\n static int sort_ambiguous(const void *a, const void *b)\n {\n-\tint a_type = oid_object_info(the_repository, a, NULL);\n-\tint b_type = oid_object_info(the_repository, b, NULL);\n+\tint a_type = oid_object_info(sort_ambiguous_repo, a, NULL);\n+\tint b_type = oid_object_info(sort_ambiguous_repo, b, NULL);\n \tint a_type_sort;\n \tint b_type_sort;\n \n@@ -411,6 +412,14 @@ static int sort_ambiguous(const void *a, const void *b)\n \treturn a_type_sort > b_type_sort ? 1 : -1;\n }\n \n+static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)\n+{\n+\t/* mutex will be needed if this code is to be made thread safe */\n+\tsort_ambiguous_repo = r;\n+\tQSORT(a->oid, a->nr, sort_ambiguous);\n+\tsort_ambiguous_repo = NULL;\n+}\n+\n static enum get_oid_result get_short_oid(const char *name, int len,\n \t\t\t\t\t struct object_id *oid,\n \t\t\t\t\t unsigned flags)\n@@ -458,7 +467,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \n \t\tadvise(_(\"The candidates are:\"));\n \t\tfor_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect);\n-\t\tQSORT(collect.oid, collect.nr, sort_ambiguous);\n+\t\tsort_ambiguous_oid_array(the_repository, &collect);\n \n \t\tif (oid_array_for_each(&collect, show_ambiguous_object, &ds))\n \t\t\tBUG(\"show_ambiguous_object shouldn't return non-zero\");\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372776","messageId":"20190330111927.18645-12-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 11/31] sha1-name.c: remove the_repo from find_abbrev_len_packed()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:07Z","receivedAt":"2019-03-30T11:21:24Z","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 | 6 ++++--\n 1 file changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 7558ce51a3..b9381aaba6 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -514,6 +514,7 @@ struct min_abbrev_data {\n \tunsigned int init_len;\n \tunsigned int cur_len;\n \tchar *hex;\n+\tstruct repository *repo;\n \tconst struct object_id *oid;\n };\n \n@@ -619,9 +620,9 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)\n \tstruct multi_pack_index *m;\n \tstruct packed_git *p;\n \n-\tfor (m = get_multi_pack_index(the_repository); m; m = m->next)\n+\tfor (m = get_multi_pack_index(mad->repo); m; m = m->next)\n \t\tfind_abbrev_len_for_midx(m, mad);\n-\tfor (p = get_packed_git(the_repository); p; p = p->next)\n+\tfor (p = get_packed_git(mad->repo); p; p = p->next)\n \t\tfind_abbrev_len_for_pack(p, mad);\n }\n \n@@ -658,6 +659,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)\n \tif (len == hexsz || !len)\n \t\treturn hexsz;\n \n+\tmad.repo = the_repository;\n \tmad.init_len = len;\n \tmad.cur_len = len;\n \tmad.hex = hex;\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372777","messageId":"20190330111927.18645-13-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 12/31] sha1-name.c: add repo_find_unique_abbrev_r()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:08Z","receivedAt":"2019-03-30T11:21: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 cache.h     |  6 ++++--\n sha1-name.c | 15 +++++++++------\n 2 files changed, 13 insertions(+), 8 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex fcb24b5781..4f8ebb0a67 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1045,8 +1045,10 @@ extern void check_repository_format(void);\n  * Note that while this version avoids the static buffer, it is not fully\n  * reentrant, as it calls into other non-reentrant git code.\n  */\n-extern const char *find_unique_abbrev(const struct object_id *oid, int len);\n-extern int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len);\n+const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len);\n+#define find_unique_abbrev(oid, len) repo_find_unique_abbrev(the_repository, oid, len)\n+int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);\n+#define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len)\n \n extern const unsigned char null_sha1[GIT_MAX_RAWSZ];\n extern const struct object_id null_oid;\ndiff --git a/sha1-name.c b/sha1-name.c\nindex b9381aaba6..9b57787b76 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -626,15 +626,16 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)\n \t\tfind_abbrev_len_for_pack(p, mad);\n }\n \n-int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)\n+int repo_find_unique_abbrev_r(struct repository *r, char *hex,\n+\t\t\t      const struct object_id *oid, int len)\n {\n \tstruct disambiguate_state ds;\n \tstruct min_abbrev_data mad;\n \tstruct object_id oid_ret;\n-\tconst unsigned hexsz = the_hash_algo->hexsz;\n+\tconst unsigned hexsz = r->hash_algo->hexsz;\n \n \tif (len < 0) {\n-\t\tunsigned long count = approximate_object_count();\n+\t\tunsigned long count = repo_approximate_object_count(r);\n \t\t/*\n \t\t * Add one because the MSB only tells us the highest bit set,\n \t\t * not including the value of all the _other_ bits (so \"15\"\n@@ -659,7 +660,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)\n \tif (len == hexsz || !len)\n \t\treturn hexsz;\n \n-\tmad.repo = the_repository;\n+\tmad.repo = r;\n \tmad.init_len = len;\n \tmad.cur_len = len;\n \tmad.hex = hex;\n@@ -681,13 +682,15 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)\n \treturn mad.cur_len;\n }\n \n-const char *find_unique_abbrev(const struct object_id *oid, int len)\n+const char *repo_find_unique_abbrev(struct repository *r,\n+\t\t\t\t    const struct object_id *oid,\n+\t\t\t\t    int len)\n {\n \tstatic int bufno;\n \tstatic char hexbuffer[4][GIT_MAX_HEXSZ + 1];\n \tchar *hex = hexbuffer[bufno];\n \tbufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);\n-\tfind_unique_abbrev_r(hex, oid, len);\n+\trepo_find_unique_abbrev_r(r, hex, oid, len);\n \treturn hex;\n }\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372778","messageId":"20190330111927.18645-14-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 13/31] sha1-name.c: store and use repo in struct disambiguate_state","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:09Z","receivedAt":"2019-03-30T11:21:35Z","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 | 95 +++++++++++++++++++++++++++++++++--------------------\n 1 file changed, 59 insertions(+), 36 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 9b57787b76..a75992eb54 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -17,13 +17,14 @@\n \n static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);\n \n-typedef int (*disambiguate_hint_fn)(const struct object_id *, void *);\n+typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);\n \n struct disambiguate_state {\n \tint len; /* length of prefix in hex chars */\n \tchar hex_pfx[GIT_MAX_HEXSZ + 1];\n \tstruct object_id bin_pfx;\n \n+\tstruct repository *repo;\n \tdisambiguate_hint_fn fn;\n \tvoid *cb_data;\n \tstruct object_id candidate;\n@@ -38,7 +39,7 @@ struct disambiguate_state {\n static void update_candidates(struct disambiguate_state *ds, const struct object_id *current)\n {\n \tif (ds->always_call_fn) {\n-\t\tds->ambiguous = ds->fn(current, ds->cb_data) ? 1 : 0;\n+\t\tds->ambiguous = ds->fn(ds->repo, current, ds->cb_data) ? 1 : 0;\n \t\treturn;\n \t}\n \tif (!ds->candidate_exists) {\n@@ -58,7 +59,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object\n \t}\n \n \tif (!ds->candidate_checked) {\n-\t\tds->candidate_ok = ds->fn(&ds->candidate, ds->cb_data);\n+\t\tds->candidate_ok = ds->fn(ds->repo, &ds->candidate, ds->cb_data);\n \t\tds->disambiguate_fn_used = 1;\n \t\tds->candidate_checked = 1;\n \t}\n@@ -71,7 +72,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object\n \t}\n \n \t/* if we reach this point, we know ds->candidate satisfies fn */\n-\tif (ds->fn(current, ds->cb_data)) {\n+\tif (ds->fn(ds->repo, current, ds->cb_data)) {\n \t\t/*\n \t\t * if both current and candidate satisfy fn, we cannot\n \t\t * disambiguate.\n@@ -89,9 +90,7 @@ static void find_short_object_filename(struct disambiguate_state *ds)\n {\n \tstruct object_directory *odb;\n \n-\tfor (odb = the_repository->objects->odb;\n-\t     odb && !ds->ambiguous;\n-\t     odb = odb->next) {\n+\tfor (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next) {\n \t\tint pos;\n \t\tstruct oid_array *loose_objects;\n \n@@ -182,10 +181,10 @@ static void find_short_packed_object(struct disambiguate_state *ds)\n \tstruct multi_pack_index *m;\n \tstruct packed_git *p;\n \n-\tfor (m = get_multi_pack_index(the_repository); m && !ds->ambiguous;\n+\tfor (m = get_multi_pack_index(ds->repo); m && !ds->ambiguous;\n \t     m = m->next)\n \t\tunique_in_midx(m, ds);\n-\tfor (p = get_packed_git(the_repository); p && !ds->ambiguous;\n+\tfor (p = get_packed_git(ds->repo); p && !ds->ambiguous;\n \t     p = p->next)\n \t\tunique_in_pack(p, ds);\n }\n@@ -215,7 +214,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,\n \t\t * same repository!\n \t\t */\n \t\tds->candidate_ok = (!ds->disambiguate_fn_used ||\n-\t\t\t\t    ds->fn(&ds->candidate, ds->cb_data));\n+\t\t\t\t    ds->fn(ds->repo, &ds->candidate, ds->cb_data));\n \n \tif (!ds->candidate_ok)\n \t\treturn SHORT_NAME_AMBIGUOUS;\n@@ -224,59 +223,67 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,\n \treturn 0;\n }\n \n-static int disambiguate_commit_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_commit_only(struct repository *r,\n+\t\t\t\t    const struct object_id *oid,\n+\t\t\t\t    void *cb_data_unused)\n {\n-\tint kind = oid_object_info(the_repository, oid, NULL);\n+\tint kind = oid_object_info(r, oid, NULL);\n \treturn kind == OBJ_COMMIT;\n }\n \n-static int disambiguate_committish_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_committish_only(struct repository *r,\n+\t\t\t\t\tconst struct object_id *oid,\n+\t\t\t\t\tvoid *cb_data_unused)\n {\n \tstruct object *obj;\n \tint kind;\n \n-\tkind = oid_object_info(the_repository, oid, NULL);\n+\tkind = oid_object_info(r, oid, NULL);\n \tif (kind == OBJ_COMMIT)\n \t\treturn 1;\n \tif (kind != OBJ_TAG)\n \t\treturn 0;\n \n \t/* We need to do this the hard way... */\n-\tobj = deref_tag(the_repository, parse_object(the_repository, oid),\n-\t\t\tNULL, 0);\n+\tobj = deref_tag(r, parse_object(r, oid), NULL, 0);\n \tif (obj && obj->type == OBJ_COMMIT)\n \t\treturn 1;\n \treturn 0;\n }\n \n-static int disambiguate_tree_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_tree_only(struct repository *r,\n+\t\t\t\t  const struct object_id *oid,\n+\t\t\t\t  void *cb_data_unused)\n {\n-\tint kind = oid_object_info(the_repository, oid, NULL);\n+\tint kind = oid_object_info(r, oid, NULL);\n \treturn kind == OBJ_TREE;\n }\n \n-static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_treeish_only(struct repository *r,\n+\t\t\t\t     const struct object_id *oid,\n+\t\t\t\t     void *cb_data_unused)\n {\n \tstruct object *obj;\n \tint kind;\n \n-\tkind = oid_object_info(the_repository, oid, NULL);\n+\tkind = oid_object_info(r, oid, NULL);\n \tif (kind == OBJ_TREE || kind == OBJ_COMMIT)\n \t\treturn 1;\n \tif (kind != OBJ_TAG)\n \t\treturn 0;\n \n \t/* We need to do this the hard way... */\n-\tobj = deref_tag(the_repository, parse_object(the_repository, oid),\n-\t\t\tNULL, 0);\n+\tobj = deref_tag(r, parse_object(r, oid), NULL, 0);\n \tif (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))\n \t\treturn 1;\n \treturn 0;\n }\n \n-static int disambiguate_blob_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_blob_only(struct repository *r,\n+\t\t\t\t  const struct object_id *oid,\n+\t\t\t\t  void *cb_data_unused)\n {\n-\tint kind = oid_object_info(the_repository, oid, NULL);\n+\tint kind = oid_object_info(r, oid, NULL);\n \treturn kind == OBJ_BLOB;\n }\n \n@@ -310,7 +317,8 @@ int set_disambiguate_hint_config(const char *var, const char *value)\n \treturn error(\"unknown hint type for '%s': %s\", var, value);\n }\n \n-static int init_object_disambiguation(const char *name, int len,\n+static int init_object_disambiguation(struct repository *r,\n+\t\t\t\t      const char *name, int len,\n \t\t\t\t      struct disambiguate_state *ds)\n {\n \tint i;\n@@ -341,7 +349,8 @@ static int init_object_disambiguation(const char *name, int len,\n \n \tds->len = len;\n \tds->hex_pfx[len] = '\\0';\n-\tprepare_alt_odb(the_repository);\n+\tds->repo = r;\n+\tprepare_alt_odb(r);\n \treturn 0;\n }\n \n@@ -351,25 +360,25 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)\n \tstruct strbuf desc = STRBUF_INIT;\n \tint type;\n \n-\tif (ds->fn && !ds->fn(oid, ds->cb_data))\n+\tif (ds->fn && !ds->fn(ds->repo, oid, ds->cb_data))\n \t\treturn 0;\n \n-\ttype = oid_object_info(the_repository, oid, NULL);\n+\ttype = oid_object_info(ds->repo, oid, NULL);\n \tif (type == OBJ_COMMIT) {\n-\t\tstruct commit *commit = lookup_commit(the_repository, oid);\n+\t\tstruct commit *commit = lookup_commit(ds->repo, oid);\n \t\tif (commit) {\n \t\t\tstruct pretty_print_context pp = {0};\n \t\t\tpp.date_mode.type = DATE_SHORT;\n \t\t\tformat_commit_message(commit, \" %ad - %s\", &desc, &pp);\n \t\t}\n \t} else if (type == OBJ_TAG) {\n-\t\tstruct tag *tag = lookup_tag(the_repository, oid);\n+\t\tstruct tag *tag = lookup_tag(ds->repo, oid);\n \t\tif (!parse_tag(tag) && tag->tag)\n \t\t\tstrbuf_addf(&desc, \" %s\", tag->tag);\n \t}\n \n \tadvise(\"  %s %s%s\",\n-\t       find_unique_abbrev(oid, DEFAULT_ABBREV),\n+\t       repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV),\n \t       type_name(type) ? type_name(type) : \"unknown type\",\n \t       desc.buf);\n \n@@ -383,6 +392,13 @@ static int collect_ambiguous(const struct object_id *oid, void *data)\n \treturn 0;\n }\n \n+static int repo_collect_ambiguous(struct repository *r,\n+\t\t\t\t  const struct object_id *oid,\n+\t\t\t\t  void *data)\n+{\n+\treturn collect_ambiguous(oid, data);\n+}\n+\n static struct repository *sort_ambiguous_repo;\n static int sort_ambiguous(const void *a, const void *b)\n {\n@@ -428,7 +444,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \tstruct disambiguate_state ds;\n \tint quietly = !!(flags & GET_OID_QUIETLY);\n \n-\tif (init_object_disambiguation(name, len, &ds) < 0)\n+\tif (init_object_disambiguation(the_repository, name, len, &ds) < 0)\n \t\treturn -1;\n \n \tif (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))\n@@ -483,11 +499,11 @@ int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)\n \tstruct disambiguate_state ds;\n \tint ret;\n \n-\tif (init_object_disambiguation(prefix, strlen(prefix), &ds) < 0)\n+\tif (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0)\n \t\treturn -1;\n \n \tds.always_call_fn = 1;\n-\tds.fn = collect_ambiguous;\n+\tds.fn = repo_collect_ambiguous;\n \tds.cb_data = &collect;\n \tfind_short_object_filename(&ds);\n \tfind_short_packed_object(&ds);\n@@ -543,6 +559,13 @@ static int extend_abbrev_len(const struct object_id *oid, void *cb_data)\n \treturn 0;\n }\n \n+static int repo_extend_abbrev_len(struct repository *r,\n+\t\t\t\t  const struct object_id *oid,\n+\t\t\t\t  void *cb_data)\n+{\n+\treturn extend_abbrev_len(oid, cb_data);\n+}\n+\n static void find_abbrev_len_for_midx(struct multi_pack_index *m,\n \t\t\t\t     struct min_abbrev_data *mad)\n {\n@@ -668,10 +691,10 @@ int repo_find_unique_abbrev_r(struct repository *r, char *hex,\n \n \tfind_abbrev_len_packed(&mad);\n \n-\tif (init_object_disambiguation(hex, mad.cur_len, &ds) < 0)\n+\tif (init_object_disambiguation(r, hex, mad.cur_len, &ds) < 0)\n \t\treturn -1;\n \n-\tds.fn = extend_abbrev_len;\n+\tds.fn = repo_extend_abbrev_len;\n \tds.always_call_fn = 1;\n \tds.cb_data = (void *)&mad;\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372779","messageId":"20190330111927.18645-15-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 14/31] sha1-name.c: add repo_for_each_abbrev()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:10Z","receivedAt":"2019-03-30T11:21:40Z","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     | 3 ++-\n sha1-name.c | 5 +++--\n 2 files changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 4f8ebb0a67..0cb95c0d4f 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1392,7 +1392,8 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c\n \t\t\t\tstruct object_context *oc);\n \n typedef int each_abbrev_fn(const struct object_id *oid, void *);\n-extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);\n+int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);\n+#define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data)\n \n extern int set_disambiguate_hint_config(const char *var, const char *value);\n \ndiff --git a/sha1-name.c b/sha1-name.c\nindex a75992eb54..cdcf84b826 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -493,13 +493,14 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \treturn status;\n }\n \n-int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)\n+int repo_for_each_abbrev(struct repository *r, const char *prefix,\n+\t\t\t each_abbrev_fn fn, void *cb_data)\n {\n \tstruct oid_array collect = OID_ARRAY_INIT;\n \tstruct disambiguate_state ds;\n \tint ret;\n \n-\tif (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0)\n+\tif (init_object_disambiguation(r, prefix, strlen(prefix), &ds) < 0)\n \t\treturn -1;\n \n \tds.always_call_fn = 1;\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372780","messageId":"20190330111927.18645-16-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 15/31] sha1-name.c: remove the_repo from get_short_oid()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:11Z","receivedAt":"2019-03-30T11:21:45Z","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 | 17 ++++++++++-------\n 1 file changed, 10 insertions(+), 7 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex cdcf84b826..2643b75b54 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -436,7 +436,8 @@ static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)\n \tsort_ambiguous_repo = NULL;\n }\n \n-static enum get_oid_result get_short_oid(const char *name, int len,\n+static enum get_oid_result get_short_oid(struct repository *r,\n+\t\t\t\t\t const char *name, int len,\n \t\t\t\t\t struct object_id *oid,\n \t\t\t\t\t unsigned flags)\n {\n@@ -444,7 +445,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \tstruct disambiguate_state ds;\n \tint quietly = !!(flags & GET_OID_QUIETLY);\n \n-\tif (init_object_disambiguation(the_repository, name, len, &ds) < 0)\n+\tif (init_object_disambiguation(r, name, len, &ds) < 0)\n \t\treturn -1;\n \n \tif (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))\n@@ -482,8 +483,8 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \t\t\tds.fn = NULL;\n \n \t\tadvise(_(\"The candidates are:\"));\n-\t\tfor_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect);\n-\t\tsort_ambiguous_oid_array(the_repository, &collect);\n+\t\trepo_for_each_abbrev(r, ds.hex_pfx, collect_ambiguous, &collect);\n+\t\tsort_ambiguous_oid_array(r, &collect);\n \n \t\tif (oid_array_for_each(&collect, show_ambiguous_object, &ds))\n \t\t\tBUG(\"show_ambiguous_object shouldn't return non-zero\");\n@@ -855,7 +856,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \n \tif (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&\n \t    (refs_found > 1 ||\n-\t     !get_short_oid(str, len, &tmp_oid, GET_OID_QUIETLY)))\n+\t     !get_short_oid(the_repository,\n+\t\t\t    str, len, &tmp_oid, GET_OID_QUIETLY)))\n \t\twarning(warn_msg, len, str);\n \n \tif (reflog_len) {\n@@ -1109,7 +1111,8 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)\n \t\t\tif (ch == 'g' && cp[-1] == '-') {\n \t\t\t\tcp++;\n \t\t\t\tlen -= cp - name;\n-\t\t\t\treturn get_short_oid(cp, len, oid, flags);\n+\t\t\t\treturn get_short_oid(the_repository,\n+\t\t\t\t\t\t     cp, len, oid, flags);\n \t\t\t}\n \t\t}\n \t}\n@@ -1163,7 +1166,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,\n \tif (!ret)\n \t\treturn FOUND;\n \n-\treturn get_short_oid(name, len, oid, lookup_flags);\n+\treturn get_short_oid(the_repository, name, len, oid, lookup_flags);\n }\n \n /*\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372781","messageId":"20190330111927.18645-17-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 16/31] sha1-name.c: remove the_repo from interpret_nth_prior_checkout()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:12Z","receivedAt":"2019-03-30T11:21:50Z","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 | 17 ++++++++++-------\n 1 file changed, 10 insertions(+), 7 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 2643b75b54..af8bf5b351 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -771,7 +771,7 @@ static inline int push_mark(const char *string, int len)\n }\n \n static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);\n-static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);\n+static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);\n \n static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\t\t  unsigned int flags)\n@@ -835,7 +835,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tint detached;\n \n-\t\tif (interpret_nth_prior_checkout(str, len, &buf) > 0) {\n+\t\tif (interpret_nth_prior_checkout(the_repository, str, len, &buf) > 0) {\n \t\t\tdetached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));\n \t\t\tstrbuf_release(&buf);\n \t\t\tif (detached)\n@@ -1288,7 +1288,8 @@ static int grab_nth_branch_switch(struct object_id *ooid, struct object_id *noid\n  * Parse @{-N} syntax, return the number of characters parsed\n  * if successful; otherwise signal an error with negative value.\n  */\n-static int interpret_nth_prior_checkout(const char *name, int namelen,\n+static int interpret_nth_prior_checkout(struct repository *r,\n+\t\t\t\t\tconst char *name, int namelen,\n \t\t\t\t\tstruct strbuf *buf)\n {\n \tlong nth;\n@@ -1312,12 +1313,14 @@ static int interpret_nth_prior_checkout(const char *name, int namelen,\n \tcb.remaining = nth;\n \tstrbuf_init(&cb.buf, 20);\n \n-\tretval = 0;\n-\tif (0 < for_each_reflog_ent_reverse(\"HEAD\", grab_nth_branch_switch, &cb)) {\n+\tretval = refs_for_each_reflog_ent_reverse(get_main_ref_store(r),\n+\t\t\t\"HEAD\", grab_nth_branch_switch, &cb);\n+\tif (0 < retval) {\n \t\tstrbuf_reset(buf);\n \t\tstrbuf_addbuf(buf, &cb.buf);\n \t\tretval = brace - name + 1;\n-\t}\n+\t} else\n+\t\tretval = 0;\n \n \tstrbuf_release(&cb.buf);\n \treturn retval;\n@@ -1484,7 +1487,7 @@ int repo_interpret_branch_name(struct repository *r,\n \t\tnamelen = strlen(name);\n \n \tif (!allowed || (allowed & INTERPRET_BRANCH_LOCAL)) {\n-\t\tlen = interpret_nth_prior_checkout(name, namelen, buf);\n+\t\tlen = interpret_nth_prior_checkout(the_repository, name, namelen, buf);\n \t\tif (!len) {\n \t\t\treturn len; /* syntax Ok, not enough switches */\n \t\t} else if (len > 0) {\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372782","messageId":"20190330111927.18645-18-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 17/31] sha1-name.c: remove the_repo from interpret_branch_mark()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:13Z","receivedAt":"2019-03-30T11:21:54Z","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 | 13 +++++++------\n 1 file changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex af8bf5b351..7d9512ac44 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1412,9 +1412,9 @@ static int reinterpret(const char *name, int namelen, int len,\n \treturn ret - used + len;\n }\n \n-static void set_shortened_ref(struct strbuf *buf, const char *ref)\n+static void set_shortened_ref(struct repository *r, struct strbuf *buf, const char *ref)\n {\n-\tchar *s = shorten_unambiguous_ref(ref, 0);\n+\tchar *s = refs_shorten_unambiguous_ref(get_main_ref_store(r), ref, 0);\n \tstrbuf_reset(buf);\n \tstrbuf_addstr(buf, s);\n \tfree(s);\n@@ -1435,7 +1435,8 @@ static int branch_interpret_allowed(const char *refname, unsigned allowed)\n \treturn 0;\n }\n \n-static int interpret_branch_mark(const char *name, int namelen,\n+static int interpret_branch_mark(struct repository *r,\n+\t\t\t\t const char *name, int namelen,\n \t\t\t\t int at, struct strbuf *buf,\n \t\t\t\t int (*get_mark)(const char *, int),\n \t\t\t\t const char *(*get_data)(struct branch *,\n@@ -1468,7 +1469,7 @@ static int interpret_branch_mark(const char *name, int namelen,\n \tif (!branch_interpret_allowed(value, allowed))\n \t\treturn -1;\n \n-\tset_shortened_ref(buf, value);\n+\tset_shortened_ref(r, buf, value);\n \treturn len + at;\n }\n \n@@ -1509,13 +1510,13 @@ int repo_interpret_branch_name(struct repository *r,\n \t\t\t\t\t\t   allowed);\n \t\t}\n \n-\t\tlen = interpret_branch_mark(name, namelen, at - name, buf,\n+\t\tlen = interpret_branch_mark(the_repository, name, namelen, at - name, buf,\n \t\t\t\t\t    upstream_mark, branch_get_upstream,\n \t\t\t\t\t    allowed);\n \t\tif (len > 0)\n \t\t\treturn len;\n \n-\t\tlen = interpret_branch_mark(name, namelen, at - name, buf,\n+\t\tlen = interpret_branch_mark(the_repository, name, namelen, at - name, buf,\n \t\t\t\t\t    push_mark, branch_get_push,\n \t\t\t\t\t    allowed);\n \t\tif (len > 0)\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372783","messageId":"20190330111927.18645-19-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 18/31] sha1-name.c: add repo_interpret_branch_name()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:14Z","receivedAt":"2019-03-30T11:22:00Z","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 | 17 ++++++++---------\n 1 file changed, 8 insertions(+), 9 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 7d9512ac44..49c62d5254 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1390,7 +1390,8 @@ static int interpret_empty_at(const char *name, int namelen, int len, struct str\n \treturn 1;\n }\n \n-static int reinterpret(const char *name, int namelen, int len,\n+static int reinterpret(struct repository *r,\n+\t\t       const char *name, int namelen, int len,\n \t\t       struct strbuf *buf, unsigned allowed)\n {\n \t/* we have extra data, which might need further processing */\n@@ -1399,7 +1400,7 @@ static int reinterpret(const char *name, int namelen, int len,\n \tint ret;\n \n \tstrbuf_add(buf, name + len, namelen - len);\n-\tret = interpret_branch_name(buf->buf, buf->len, &tmp, allowed);\n+\tret = repo_interpret_branch_name(r, buf->buf, buf->len, &tmp, allowed);\n \t/* that data was not interpreted, remove our cruft */\n \tif (ret < 0) {\n \t\tstrbuf_setlen(buf, used);\n@@ -1482,20 +1483,18 @@ int repo_interpret_branch_name(struct repository *r,\n \tconst char *start;\n \tint len;\n \n-\tif (r != the_repository)\n-\t\tBUG(\"interpret_branch_name() does not really use 'r' yet\");\n \tif (!namelen)\n \t\tnamelen = strlen(name);\n \n \tif (!allowed || (allowed & INTERPRET_BRANCH_LOCAL)) {\n-\t\tlen = interpret_nth_prior_checkout(the_repository, name, namelen, buf);\n+\t\tlen = interpret_nth_prior_checkout(r, name, namelen, buf);\n \t\tif (!len) {\n \t\t\treturn len; /* syntax Ok, not enough switches */\n \t\t} else if (len > 0) {\n \t\t\tif (len == namelen)\n \t\t\t\treturn len; /* consumed all */\n \t\t\telse\n-\t\t\t\treturn reinterpret(name, namelen, len, buf, allowed);\n+\t\t\t\treturn reinterpret(r, name, namelen, len, buf, allowed);\n \t\t}\n \t}\n \n@@ -1506,17 +1505,17 @@ int repo_interpret_branch_name(struct repository *r,\n \t\tif (!allowed || (allowed & INTERPRET_BRANCH_HEAD)) {\n \t\t\tlen = interpret_empty_at(name, namelen, at - name, buf);\n \t\t\tif (len > 0)\n-\t\t\t\treturn reinterpret(name, namelen, len, buf,\n+\t\t\t\treturn reinterpret(r, name, namelen, len, buf,\n \t\t\t\t\t\t   allowed);\n \t\t}\n \n-\t\tlen = interpret_branch_mark(the_repository, name, namelen, at - name, buf,\n+\t\tlen = interpret_branch_mark(r, name, namelen, at - name, buf,\n \t\t\t\t\t    upstream_mark, branch_get_upstream,\n \t\t\t\t\t    allowed);\n \t\tif (len > 0)\n \t\t\treturn len;\n \n-\t\tlen = interpret_branch_mark(the_repository, name, namelen, at - name, buf,\n+\t\tlen = interpret_branch_mark(r, name, namelen, at - name, buf,\n \t\t\t\t\t    push_mark, branch_get_push,\n \t\t\t\t\t    allowed);\n \t\tif (len > 0)\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372784","messageId":"20190330111927.18645-20-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 19/31] sha1-name.c: remove the_repo from get_oid_oneline()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:15Z","receivedAt":"2019-03-30T11:22:05Z","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 | 13 +++++++------\n 1 file changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 49c62d5254..fb80306f1a 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -15,7 +15,7 @@\n #include \"midx.h\"\n #include \"commit-reach.h\"\n \n-static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);\n+static int get_oid_oneline(struct repository *r, const char *, struct object_id *, struct commit_list *);\n \n typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);\n \n@@ -1090,7 +1090,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \n \t\tprefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));\n \t\tcommit_list_insert((struct commit *)o, &list);\n-\t\tret = get_oid_oneline(prefix, oid, list);\n+\t\tret = get_oid_oneline(the_repository, prefix, oid, list);\n \t\tfree(prefix);\n \t\treturn ret;\n \t}\n@@ -1204,8 +1204,9 @@ static int handle_one_ref(const char *path, const struct object_id *oid,\n \treturn 0;\n }\n \n-static int get_oid_oneline(const char *prefix, struct object_id *oid,\n-\t\t\t    struct commit_list *list)\n+static int get_oid_oneline(struct repository *r,\n+\t\t\t   const char *prefix, struct object_id *oid,\n+\t\t\t   struct commit_list *list)\n {\n \tstruct commit_list *backup = NULL, *l;\n \tint found = 0;\n@@ -1236,7 +1237,7 @@ static int get_oid_oneline(const char *prefix, struct object_id *oid,\n \t\tint matches;\n \n \t\tcommit = pop_most_recent_commit(&list, ONELINE_SEEN);\n-\t\tif (!parse_object(the_repository, &commit->object.oid))\n+\t\tif (!parse_object(r, &commit->object.oid))\n \t\t\tcontinue;\n \t\tbuf = get_commit_buffer(commit, NULL);\n \t\tp = strstr(buf, \"\\n\\n\");\n@@ -1760,7 +1761,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\tfor_each_ref(handle_one_ref, &list);\n \t\t\thead_ref(handle_one_ref, &list);\n \t\t\tcommit_list_sort_by_date(&list);\n-\t\t\treturn get_oid_oneline(name + 2, oid, list);\n+\t\t\treturn get_oid_oneline(repo, name + 2, oid, list);\n \t\t}\n \t\tif (namelen < 3 ||\n \t\t    name[2] != ':' ||\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372785","messageId":"20190330111927.18645-21-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 20/31] sha1-name.c: remove the_repo from get_describe_name()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:16Z","receivedAt":"2019-03-30T11:22:10Z","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 | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex fb80306f1a..1cda854f02 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1097,7 +1097,9 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \treturn 0;\n }\n \n-static int get_describe_name(const char *name, int len, struct object_id *oid)\n+static int get_describe_name(struct repository *r,\n+\t\t\t     const char *name, int len,\n+\t\t\t     struct object_id *oid)\n {\n \tconst char *cp;\n \tunsigned flags = GET_OID_QUIETLY | GET_OID_COMMIT;\n@@ -1111,7 +1113,7 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)\n \t\t\tif (ch == 'g' && cp[-1] == '-') {\n \t\t\t\tcp++;\n \t\t\t\tlen -= cp - name;\n-\t\t\t\treturn get_short_oid(the_repository,\n+\t\t\t\treturn get_short_oid(r,\n \t\t\t\t\t\t     cp, len, oid, flags);\n \t\t\t}\n \t\t}\n@@ -1162,7 +1164,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,\n \t\treturn FOUND;\n \n \t/* It could be describe output that is \"SOMETHING-gXXXX\" */\n-\tret = get_describe_name(name, len, oid);\n+\tret = get_describe_name(the_repository, name, len, oid);\n \tif (!ret)\n \t\treturn FOUND;\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372786","messageId":"20190330111927.18645-22-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 21/31] sha1-name.c: remove the_repo from get_oid_basic()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:17Z","receivedAt":"2019-03-30T11:22:15Z","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 | 25 ++++++++++++-------------\n 1 file changed, 12 insertions(+), 13 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 1cda854f02..d4c135aea8 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -773,8 +773,8 @@ static inline int push_mark(const char *string, int len)\n static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);\n static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);\n \n-static int get_oid_basic(const char *str, int len, struct object_id *oid,\n-\t\t\t  unsigned int flags)\n+static int get_oid_basic(struct repository *r, const char *str, int len,\n+\t\t\t struct object_id *oid, unsigned int flags)\n {\n \tstatic const char *warn_msg = \"refname '%.*s' is ambiguous.\";\n \tstatic const char *object_name_msg = N_(\n@@ -792,9 +792,9 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \tint refs_found = 0;\n \tint at, reflog_len, nth_prior = 0;\n \n-\tif (len == the_hash_algo->hexsz && !get_oid_hex(str, oid)) {\n+\tif (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {\n \t\tif (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {\n-\t\t\trefs_found = dwim_ref(str, len, &tmp_oid, &real_ref);\n+\t\t\trefs_found = repo_dwim_ref(r, str, len, &tmp_oid, &real_ref);\n \t\t\tif (refs_found > 0) {\n \t\t\t\twarning(warn_msg, len, str);\n \t\t\t\tif (advice_object_name_warning)\n@@ -835,8 +835,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tint detached;\n \n-\t\tif (interpret_nth_prior_checkout(the_repository, str, len, &buf) > 0) {\n-\t\t\tdetached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));\n+\t\tif (interpret_nth_prior_checkout(r, str, len, &buf) > 0) {\n+\t\t\tdetached = (buf.len == r->hash_algo->hexsz && !get_oid_hex(buf.buf, oid));\n \t\t\tstrbuf_release(&buf);\n \t\t\tif (detached)\n \t\t\t\treturn 0;\n@@ -845,19 +845,18 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \n \tif (!len && reflog_len)\n \t\t/* allow \"@{...}\" to mean the current branch reflog */\n-\t\trefs_found = dwim_ref(\"HEAD\", 4, oid, &real_ref);\n+\t\trefs_found = repo_dwim_ref(r, \"HEAD\", 4, oid, &real_ref);\n \telse if (reflog_len)\n-\t\trefs_found = dwim_log(str, len, oid, &real_ref);\n+\t\trefs_found = repo_dwim_log(r, str, len, oid, &real_ref);\n \telse\n-\t\trefs_found = dwim_ref(str, len, oid, &real_ref);\n+\t\trefs_found = repo_dwim_ref(r, str, len, oid, &real_ref);\n \n \tif (!refs_found)\n \t\treturn -1;\n \n \tif (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&\n \t    (refs_found > 1 ||\n-\t     !get_short_oid(the_repository,\n-\t\t\t    str, len, &tmp_oid, GET_OID_QUIETLY)))\n+\t     !get_short_oid(r, str, len, &tmp_oid, GET_OID_QUIETLY)))\n \t\twarning(warn_msg, len, str);\n \n \tif (reflog_len) {\n@@ -889,7 +888,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\t\t\treturn -1;\n \t\t\t}\n \t\t}\n-\t\tif (read_ref_at(get_main_ref_store(the_repository),\n+\t\tif (read_ref_at(get_main_ref_store(r),\n \t\t\t\treal_ref, flags, at_time, nth, oid, NULL,\n \t\t\t\t&co_time, &co_tz, &co_cnt)) {\n \t\t\tif (!len) {\n@@ -1159,7 +1158,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,\n \tif (!ret)\n \t\treturn FOUND;\n \n-\tret = get_oid_basic(name, len, oid, lookup_flags);\n+\tret = get_oid_basic(the_repository, name, len, oid, lookup_flags);\n \tif (!ret)\n \t\treturn FOUND;\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372787","messageId":"20190330111927.18645-23-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 22/31] sha1-name.c: remove the_repo from get_oid_1()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:18Z","receivedAt":"2019-03-30T11:22:21Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"There is a cyclic dependency between one of these functions so they\ncannot be converted one by one, so all related functions are converted\nat once.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n cache.h     |  7 +++++--\n sha1-name.c | 59 ++++++++++++++++++++++++++++-------------------------\n 2 files changed, 36 insertions(+), 30 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 0cb95c0d4f..2149dc4f56 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1491,8 +1491,11 @@ extern void *read_object_with_reference(const struct object_id *oid,\n \t\t\t\t\tunsigned long *size,\n \t\t\t\t\tstruct object_id *oid_ret);\n \n-extern struct object *peel_to_type(const char *name, int namelen,\n-\t\t\t\t   struct object *o, enum object_type);\n+struct object *repo_peel_to_type(struct repository *r,\n+\t\t\t\t const char *name, int namelen,\n+\t\t\t\t struct object *o, enum object_type);\n+#define peel_to_type(name, namelen, obj, type) \\\n+\trepo_peel_to_type(the_repository, name, namelen, obj, type)\n \n enum date_mode_type {\n \tDATE_NORMAL = 0,\ndiff --git a/sha1-name.c b/sha1-name.c\nindex d4c135aea8..5741a9f821 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -770,7 +770,7 @@ static inline int push_mark(const char *string, int len)\n \treturn at_mark(string, len, suffix, ARRAY_SIZE(suffix));\n }\n \n-static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);\n+static enum get_oid_result get_oid_1(struct repository *r, const char *name, int len, struct object_id *oid, unsigned lookup_flags);\n static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);\n \n static int get_oid_basic(struct repository *r, const char *str, int len,\n@@ -921,18 +921,19 @@ static int get_oid_basic(struct repository *r, const char *str, int len,\n \treturn 0;\n }\n \n-static enum get_oid_result get_parent(const char *name, int len,\n+static enum get_oid_result get_parent(struct repository *r,\n+\t\t\t\t      const char *name, int len,\n \t\t\t\t      struct object_id *result, int idx)\n {\n \tstruct object_id oid;\n-\tenum get_oid_result ret = get_oid_1(name, len, &oid,\n+\tenum get_oid_result ret = get_oid_1(r, name, len, &oid,\n \t\t\t\t\t    GET_OID_COMMITTISH);\n \tstruct commit *commit;\n \tstruct commit_list *p;\n \n \tif (ret)\n \t\treturn ret;\n-\tcommit = lookup_commit_reference(the_repository, &oid);\n+\tcommit = lookup_commit_reference(r, &oid);\n \tif (parse_commit(commit))\n \t\treturn MISSING_OBJECT;\n \tif (!idx) {\n@@ -950,7 +951,8 @@ static enum get_oid_result get_parent(const char *name, int len,\n \treturn MISSING_OBJECT;\n }\n \n-static enum get_oid_result get_nth_ancestor(const char *name, int len,\n+static enum get_oid_result get_nth_ancestor(struct repository *r,\n+\t\t\t\t\t    const char *name, int len,\n \t\t\t\t\t    struct object_id *result,\n \t\t\t\t\t    int generation)\n {\n@@ -958,10 +960,10 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,\n \tstruct commit *commit;\n \tint ret;\n \n-\tret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);\n+\tret = get_oid_1(r, name, len, &oid, GET_OID_COMMITTISH);\n \tif (ret)\n \t\treturn ret;\n-\tcommit = lookup_commit_reference(the_repository, &oid);\n+\tcommit = lookup_commit_reference(r, &oid);\n \tif (!commit)\n \t\treturn MISSING_OBJECT;\n \n@@ -974,20 +976,20 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,\n \treturn FOUND;\n }\n \n-struct object *peel_to_type(const char *name, int namelen,\n-\t\t\t    struct object *o, enum object_type expected_type)\n+struct object *repo_peel_to_type(struct repository *r, const char *name, int namelen,\n+\t\t\t\t struct object *o, enum object_type expected_type)\n {\n \tif (name && !namelen)\n \t\tnamelen = strlen(name);\n \twhile (1) {\n-\t\tif (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))\n+\t\tif (!o || (!o->parsed && !parse_object(r, &o->oid)))\n \t\t\treturn NULL;\n \t\tif (expected_type == OBJ_ANY || o->type == expected_type)\n \t\t\treturn o;\n \t\tif (o->type == OBJ_TAG)\n \t\t\to = ((struct tag*) o)->tagged;\n \t\telse if (o->type == OBJ_COMMIT)\n-\t\t\to = &(get_commit_tree(((struct commit *)o))->object);\n+\t\t\to = &(repo_get_commit_tree(r, ((struct commit *)o))->object);\n \t\telse {\n \t\t\tif (name)\n \t\t\t\terror(\"%.*s: expected %s type, but the object \"\n@@ -999,8 +1001,8 @@ struct object *peel_to_type(const char *name, int namelen,\n \t}\n }\n \n-static int peel_onion(const char *name, int len, struct object_id *oid,\n-\t\t      unsigned lookup_flags)\n+static int peel_onion(struct repository *r, const char *name, int len,\n+\t\t      struct object_id *oid, unsigned lookup_flags)\n {\n \tstruct object_id outer;\n \tconst char *sp;\n@@ -1050,15 +1052,15 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \telse if (expected_type == OBJ_TREE)\n \t\tlookup_flags |= GET_OID_TREEISH;\n \n-\tif (get_oid_1(name, sp - name - 2, &outer, lookup_flags))\n+\tif (get_oid_1(r, name, sp - name - 2, &outer, lookup_flags))\n \t\treturn -1;\n \n-\to = parse_object(the_repository, &outer);\n+\to = parse_object(r, &outer);\n \tif (!o)\n \t\treturn -1;\n \tif (!expected_type) {\n-\t\to = deref_tag(the_repository, o, name, sp - name - 2);\n-\t\tif (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))\n+\t\to = deref_tag(r, o, name, sp - name - 2);\n+\t\tif (!o || (!o->parsed && !parse_object(r, &o->oid)))\n \t\t\treturn -1;\n \t\toidcpy(oid, &o->oid);\n \t\treturn 0;\n@@ -1069,7 +1071,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \t * if we do not get the needed object, we should\n \t * barf.\n \t */\n-\to = peel_to_type(name, len, o, expected_type);\n+\to = repo_peel_to_type(r, name, len, o, expected_type);\n \tif (!o)\n \t\treturn -1;\n \n@@ -1089,7 +1091,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \n \t\tprefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));\n \t\tcommit_list_insert((struct commit *)o, &list);\n-\t\tret = get_oid_oneline(the_repository, prefix, oid, list);\n+\t\tret = get_oid_oneline(r, prefix, oid, list);\n \t\tfree(prefix);\n \t\treturn ret;\n \t}\n@@ -1120,7 +1122,8 @@ static int get_describe_name(struct repository *r,\n \treturn -1;\n }\n \n-static enum get_oid_result get_oid_1(const char *name, int len,\n+static enum get_oid_result get_oid_1(struct repository *r,\n+\t\t\t\t     const char *name, int len,\n \t\t\t\t     struct object_id *oid,\n \t\t\t\t     unsigned lookup_flags)\n {\n@@ -1149,25 +1152,25 @@ static enum get_oid_result get_oid_1(const char *name, int len,\n \t\tif (!num && len1 == len - 1)\n \t\t\tnum = 1;\n \t\tif (has_suffix == '^')\n-\t\t\treturn get_parent(name, len1, oid, num);\n+\t\t\treturn get_parent(r, name, len1, oid, num);\n \t\t/* else if (has_suffix == '~') -- goes without saying */\n-\t\treturn get_nth_ancestor(name, len1, oid, num);\n+\t\treturn get_nth_ancestor(r, name, len1, oid, num);\n \t}\n \n-\tret = peel_onion(name, len, oid, lookup_flags);\n+\tret = peel_onion(r, name, len, oid, lookup_flags);\n \tif (!ret)\n \t\treturn FOUND;\n \n-\tret = get_oid_basic(the_repository, name, len, oid, lookup_flags);\n+\tret = get_oid_basic(r, name, len, oid, lookup_flags);\n \tif (!ret)\n \t\treturn FOUND;\n \n \t/* It could be describe output that is \"SOMETHING-gXXXX\" */\n-\tret = get_describe_name(the_repository, name, len, oid);\n+\tret = get_describe_name(r, name, len, oid);\n \tif (!ret)\n \t\treturn FOUND;\n \n-\treturn get_short_oid(the_repository, name, len, oid, lookup_flags);\n+\treturn get_short_oid(r, name, len, oid, lookup_flags);\n }\n \n /*\n@@ -1741,7 +1744,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \tmemset(oc, 0, sizeof(*oc));\n \toc->mode = S_IFINVALID;\n \tstrbuf_init(&oc->symlink_path, 0);\n-\tret = get_oid_1(name, namelen, oid, flags);\n+\tret = get_oid_1(repo, name, namelen, oid, flags);\n \tif (!ret)\n \t\treturn ret;\n \t/*\n@@ -1822,7 +1825,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\tsub_flags &= ~GET_OID_DISAMBIGUATORS;\n \t\tsub_flags |= GET_OID_TREEISH;\n \n-\t\tif (!get_oid_1(name, len, &tree_oid, sub_flags)) {\n+\t\tif (!get_oid_1(repo, name, len, &tree_oid, sub_flags)) {\n \t\t\tconst char *filename = cp+1;\n \t\t\tchar *new_filename = NULL;\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372788","messageId":"20190330111927.18645-24-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 23/31] sha1-name.c: remove the_repo from handle_one_ref()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:19Z","receivedAt":"2019-03-30T11:22:26Z","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 | 19 ++++++++++++++-----\n 1 file changed, 14 insertions(+), 5 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 5741a9f821..d9050776dd 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1189,15 +1189,21 @@ static enum get_oid_result get_oid_1(struct repository *r,\n /* Remember to update object flag allocation in object.h */\n #define ONELINE_SEEN (1u<<20)\n \n+struct handle_one_ref_cb {\n+\tstruct repository *repo;\n+\tstruct commit_list **list;\n+};\n+\n static int handle_one_ref(const char *path, const struct object_id *oid,\n \t\t\t  int flag, void *cb_data)\n {\n-\tstruct commit_list **list = cb_data;\n-\tstruct object *object = parse_object(the_repository, oid);\n+\tstruct handle_one_ref_cb *cb = cb_data;\n+\tstruct commit_list **list = cb->list;\n+\tstruct object *object = parse_object(cb->repo, oid);\n \tif (!object)\n \t\treturn 0;\n \tif (object->type == OBJ_TAG) {\n-\t\tobject = deref_tag(the_repository, object, path,\n+\t\tobject = deref_tag(cb->repo, object, path,\n \t\t\t\t   strlen(path));\n \t\tif (!object)\n \t\t\treturn 0;\n@@ -1760,10 +1766,13 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\tchar *new_path = NULL;\n \t\tint pos;\n \t\tif (!only_to_die && namelen > 2 && name[1] == '/') {\n+\t\t\tstruct handle_one_ref_cb cb;\n \t\t\tstruct commit_list *list = NULL;\n \n-\t\t\tfor_each_ref(handle_one_ref, &list);\n-\t\t\thead_ref(handle_one_ref, &list);\n+\t\t\tcb.repo = repo;\n+\t\t\tcb.list = &list;\n+\t\t\trefs_for_each_ref(repo->refs, handle_one_ref, &cb);\n+\t\t\trefs_head_ref(repo->refs, handle_one_ref, &cb);\n \t\t\tcommit_list_sort_by_date(&list);\n \t\t\treturn get_oid_oneline(repo, name + 2, oid, list);\n \t\t}\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372789","messageId":"20190330111927.18645-25-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 24/31] sha1-name.c: remove the_repo from diagnose_invalid_index_path()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:20Z","receivedAt":"2019-03-30T11:22:30Z","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 dir.c       | 8 ++++++++\n dir.h       | 4 +++-\n sha1-name.c | 7 ++++---\n 3 files changed, 15 insertions(+), 4 deletions(-)\n\ndiff --git a/dir.c b/dir.c\nindex b2cabadf25..e6d97343f4 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -2315,6 +2315,14 @@ int file_exists(const char *f)\n \treturn lstat(f, &sb) == 0;\n }\n \n+int repo_file_exists(struct repository *repo, const char *path)\n+{\n+\tif (repo != the_repository)\n+\t\tBUG(\"do not know how to check file existence in arbitrary repo\");\n+\n+\treturn file_exists(path);\n+}\n+\n static int cmp_icase(char a, char b)\n {\n \tif (a == b)\ndiff --git a/dir.h b/dir.h\nindex e3ec26143d..47c5409ced 100644\n--- a/dir.h\n+++ b/dir.h\n@@ -269,7 +269,9 @@ extern void add_exclude(const char *string, const char *base,\n \t\t\tint baselen, struct exclude_list *el, int srcpos);\n extern void clear_exclude_list(struct exclude_list *el);\n extern void clear_directory(struct dir_struct *dir);\n-extern int file_exists(const char *);\n+\n+int repo_file_exists(struct repository *repo, const char *path);\n+int file_exists(const char *);\n \n extern int is_inside_dir(const char *dir);\n extern int dir_inside_of(const char *subdir, const char *dir);\ndiff --git a/sha1-name.c b/sha1-name.c\nindex d9050776dd..6caf3f4e3a 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1664,11 +1664,12 @@ static void diagnose_invalid_oid_path(const char *prefix,\n }\n \n /* Must be called only when :stage:filename doesn't exist. */\n-static void diagnose_invalid_index_path(struct index_state *istate,\n+static void diagnose_invalid_index_path(struct repository *r,\n \t\t\t\t\tint stage,\n \t\t\t\t\tconst char *prefix,\n \t\t\t\t\tconst char *filename)\n {\n+\tstruct index_state *istate = r->index;\n \tconst struct cache_entry *ce;\n \tint pos;\n \tunsigned namelen = strlen(filename);\n@@ -1708,7 +1709,7 @@ static void diagnose_invalid_index_path(struct index_state *istate,\n \t\t\t    ce_stage(ce), filename);\n \t}\n \n-\tif (file_exists(filename))\n+\tif (repo_file_exists(r, filename))\n \t\tdie(\"Path '%s' exists on disk, but not in the index.\", filename);\n \tif (is_missing_file_error(errno))\n \t\tdie(\"Path '%s' does not exist (neither on disk nor in the index).\",\n@@ -1814,7 +1815,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\tpos++;\n \t\t}\n \t\tif (only_to_die && name[1] && name[1] != '/')\n-\t\t\tdiagnose_invalid_index_path(repo->index, stage, prefix, cp);\n+\t\t\tdiagnose_invalid_index_path(repo, stage, prefix, cp);\n \t\tfree(new_path);\n \t\treturn -1;\n \t}\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372790","messageId":"20190330111927.18645-26-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 25/31] sha1-name.c: remove the_repo from resolve_relative_path()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:21Z","receivedAt":"2019-03-30T11:22:35Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\"remove\" is not entirely correct. But at least the function is aware\nthat if the given repo is not the_repository, then $CWD and\nis_inside_work_tree() means nothing.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n sha1-name.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 6caf3f4e3a..6b53ea2eeb 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1719,12 +1719,12 @@ static void diagnose_invalid_index_path(struct repository *r,\n }\n \n \n-static char *resolve_relative_path(const char *rel)\n+static char *resolve_relative_path(struct repository *r, const char *rel)\n {\n \tif (!starts_with(rel, \"./\") && !starts_with(rel, \"../\"))\n \t\treturn NULL;\n \n-\tif (!is_inside_work_tree())\n+\tif (r != the_repository || !is_inside_work_tree())\n \t\tdie(\"relative path syntax can't be used outside working tree.\");\n \n \t/* die() inside prefix_path() if resolved path is outside worktree */\n@@ -1785,7 +1785,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\tstage = name[1] - '0';\n \t\t\tcp = name + 3;\n \t\t}\n-\t\tnew_path = resolve_relative_path(cp);\n+\t\tnew_path = resolve_relative_path(repo, cp);\n \t\tif (!new_path) {\n \t\t\tnamelen = namelen - (cp - name);\n \t\t} else {\n@@ -1839,7 +1839,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\tconst char *filename = cp+1;\n \t\t\tchar *new_filename = NULL;\n \n-\t\t\tnew_filename = resolve_relative_path(filename);\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\tif (flags & GET_OID_FOLLOW_SYMLINKS) {\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372791","messageId":"20190330111927.18645-27-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 26/31] sha1-name.c: remove the_repo from get_oid_with_context_1()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:22Z","receivedAt":"2019-03-30T11:22:40Z","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 | 11 ++++++++++-\n 1 file changed, 10 insertions(+), 1 deletion(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 6b53ea2eeb..64a50d1291 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -12,6 +12,7 @@\n #include \"packfile.h\"\n #include \"object-store.h\"\n #include \"repository.h\"\n+#include \"submodule.h\"\n #include \"midx.h\"\n #include \"commit-reach.h\"\n \n@@ -1797,7 +1798,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\toc->path = xstrdup(cp);\n \n \t\tif (!repo->index->cache)\n-\t\t\trepo_read_index(the_repository);\n+\t\t\trepo_read_index(repo);\n \t\tpos = index_name_pos(repo->index, cp, namelen);\n \t\tif (pos < 0)\n \t\t\tpos = -pos - 1;\n@@ -1842,6 +1843,14 @@ 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\t\tfilename, oid, &oc->symlink_path,\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372792","messageId":"20190330111927.18645-28-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 27/31] sha1-name.c: add repo_get_oid()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:23Z","receivedAt":"2019-03-30T11:22:45Z","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     | 3 ++-\n sha1-name.c | 4 ++--\n 2 files changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 2149dc4f56..f6e87194d0 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1380,7 +1380,8 @@ enum get_oid_result {\n \t\t       */\n };\n \n-extern int get_oid(const char *str, struct object_id *oid);\n+int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);\n+#define get_oid(str, oid) repo_get_oid(the_repository, str, oid)\n extern int get_oid_commit(const char *str, struct object_id *oid);\n extern int get_oid_committish(const char *str, struct object_id *oid);\n extern int get_oid_tree(const char *str, struct object_id *oid);\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 64a50d1291..953df0d692 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1573,10 +1573,10 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)\n  * This is like \"get_oid_basic()\", except it allows \"object ID expressions\",\n  * notably \"xyz^\" for \"parent of xyz\"\n  */\n-int get_oid(const char *name, struct object_id *oid)\n+int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository, name, 0, oid, &unused);\n+\treturn get_oid_with_context(r, name, 0, oid, &unused);\n }\n \n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372793","messageId":"20190330111927.18645-29-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 28/31] submodule-config.c: use repo_get_oid for reading .gitmodules","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:24Z","receivedAt":"2019-03-30T11:22:50Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Since 76e9bdc437 (submodule: support reading .gitmodules when it's not\nin the working tree - 2018-10-25), every time you do\n\n    git grep --recurse-submodules\n\nyou are likely to see one warning line per submodule (unless all those\nsubmodules also have submodules). On a superproject with plenty of\nsubmodules (I've seen one with 67) this is really annoying.\n\nThe warning was there because we could not resolve extended SHA-1\nsyntax on a submodule. We can now. Make use of the new API and get rid\nof the warning.\n\nIt would be even better if config_with_options() supports multiple\nrepositories too. But one step at a time.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n submodule-config.c                 | 20 +++++++-------------\n t/t7814-grep-recurse-submodules.sh |  6 +-----\n 2 files changed, 8 insertions(+), 18 deletions(-)\n\ndiff --git a/submodule-config.c b/submodule-config.c\nindex 66653e86b9..4264ee216f 100644\n--- a/submodule-config.c\n+++ b/submodule-config.c\n@@ -625,23 +625,16 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void\n \t\tconst struct config_options opts = { 0 };\n \t\tstruct object_id oid;\n \t\tchar *file;\n+\t\tchar *oidstr = NULL;\n \n \t\tfile = repo_worktree_path(repo, GITMODULES_FILE);\n \t\tif (file_exists(file)) {\n \t\t\tconfig_source.file = file;\n-\t\t} else if (repo->submodule_prefix) {\n-\t\t\t/*\n-\t\t\t * When get_oid and config_with_options, used below,\n-\t\t\t * become able to work on a specific repository, this\n-\t\t\t * warning branch can be removed.\n-\t\t\t */\n-\t\t\twarning(\"nested submodules without %s in the working tree are not supported yet\",\n-\t\t\t\tGITMODULES_FILE);\n-\t\t\tgoto out;\n-\t\t} else if (get_oid(GITMODULES_INDEX, &oid) >= 0) {\n-\t\t\tconfig_source.blob = GITMODULES_INDEX;\n-\t\t} else if (get_oid(GITMODULES_HEAD, &oid) >= 0) {\n-\t\t\tconfig_source.blob = GITMODULES_HEAD;\n+\t\t} else if (repo_get_oid(repo, GITMODULES_INDEX, &oid) >= 0 ||\n+\t\t\t   repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {\n+\t\t\tconfig_source.blob = oidstr = xstrdup(oid_to_hex(&oid));\n+\t\t\tif (repo != the_repository)\n+\t\t\t\tadd_to_alternates_memory(repo->objects->odb->path);\n \t\t} else {\n \t\t\tgoto out;\n \t\t}\n@@ -649,6 +642,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void\n \t\tconfig_with_options(fn, data, &config_source, &opts);\n \n out:\n+\t\tfree(oidstr);\n \t\tfree(file);\n \t}\n }\ndiff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh\nindex fa475d52fa..134a694516 100755\n--- a/t/t7814-grep-recurse-submodules.sh\n+++ b/t/t7814-grep-recurse-submodules.sh\n@@ -380,11 +380,7 @@ test_expect_success 'grep --recurse-submodules should pass the pattern type alon\n \tfi\n '\n \n-# Recursing down into nested submodules which do not have .gitmodules in their\n-# working tree does not work yet. This is because config_from_gitmodules()\n-# uses get_oid() and the latter is still not able to get objects from an\n-# arbitrary repository (the nested submodule, in this case).\n-test_expect_failure 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '\n+test_expect_success 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '\n \ttest_when_finished \"git -C submodule checkout .gitmodules\" &&\n \trm submodule/.gitmodules &&\n \tgit grep --recurse-submodules -e \"(.|.)[\\d]\" >actual &&\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372794","messageId":"20190330111927.18645-30-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 29/31] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:25Z","receivedAt":"2019-03-30T11:22:55Z","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 setup.c     | 7 ++++---\n sha1-name.c | 6 ++++--\n 3 files changed, 11 insertions(+), 6 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex f6e87194d0..3718b3db8a 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1387,7 +1387,9 @@ extern int get_oid_committish(const char *str, struct object_id *oid);\n extern int get_oid_tree(const char *str, struct object_id *oid);\n extern int get_oid_treeish(const char *str, struct object_id *oid);\n extern int get_oid_blob(const char *str, struct object_id *oid);\n-extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);\n+void maybe_die_on_misspelt_object_name(struct repository *repo,\n+\t\t\t\t       const char *name,\n+\t\t\t\t       const char *prefix);\n extern enum get_oid_result get_oid_with_context(struct repository *repo, const char *str,\n \t\t\t\tunsigned flags, struct object_id *oid,\n \t\t\t\tstruct object_context *oc);\ndiff --git a/setup.c b/setup.c\nindex d0c958c3b2..8dcb4631f7 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -164,7 +164,8 @@ int check_filename(const char *prefix, const char *arg)\n \tdie_errno(_(\"failed to stat '%s'\"), arg);\n }\n \n-static void NORETURN die_verify_filename(const char *prefix,\n+static void NORETURN die_verify_filename(struct repository *r,\n+\t\t\t\t\t const char *prefix,\n \t\t\t\t\t const char *arg,\n \t\t\t\t\t int diagnose_misspelt_rev)\n {\n@@ -179,7 +180,7 @@ static void NORETURN die_verify_filename(const char *prefix,\n \t * let maybe_die_on_misspelt_object_name() even trigger.\n \t */\n \tif (!(arg[0] == ':' && !isalnum(arg[1])))\n-\t\tmaybe_die_on_misspelt_object_name(arg, prefix);\n+\t\tmaybe_die_on_misspelt_object_name(r, arg, prefix);\n \n \t/* ... or fall back the most general message. */\n \tdie(_(\"ambiguous argument '%s': unknown revision or path not in the working tree.\\n\"\n@@ -234,7 +235,7 @@ void verify_filename(const char *prefix,\n \t\tdie(_(\"option '%s' must come before non-option arguments\"), arg);\n \tif (looks_like_pathspec(arg) || check_filename(prefix, arg))\n \t\treturn;\n-\tdie_verify_filename(prefix, arg, diagnose_misspelt_rev);\n+\tdie_verify_filename(the_repository, prefix, arg, diagnose_misspelt_rev);\n }\n \n /*\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 953df0d692..b94d381bef 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1885,11 +1885,13 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n  * exist in 'HEAD'\" when given \"HEAD:doc\", or it may return in which case\n  * you have a chance to diagnose the error further.\n  */\n-void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)\n+void maybe_die_on_misspelt_object_name(struct repository *r,\n+\t\t\t\t       const char *name,\n+\t\t\t\t       const char *prefix)\n {\n \tstruct object_context oc;\n \tstruct object_id oid;\n-\tget_oid_with_context_1(the_repository, name, GET_OID_ONLY_TO_DIE,\n+\tget_oid_with_context_1(r, name, GET_OID_ONLY_TO_DIE,\n \t\t\t       prefix, &oid, &oc);\n }\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372795","messageId":"20190330111927.18645-31-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 30/31] sha1-name.c: remove the_repo from other get_oid_*","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:26Z","receivedAt":"2019-03-30T11:23:00Z","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     | 18 ++++++++++++------\n sha1-name.c | 35 ++++++++++++++++++++---------------\n 2 files changed, 32 insertions(+), 21 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 3718b3db8a..871a167bf8 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1381,12 +1381,11 @@ enum get_oid_result {\n };\n \n int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);\n-#define get_oid(str, oid) repo_get_oid(the_repository, str, oid)\n-extern int get_oid_commit(const char *str, struct object_id *oid);\n-extern int get_oid_committish(const char *str, struct object_id *oid);\n-extern int get_oid_tree(const char *str, struct object_id *oid);\n-extern int get_oid_treeish(const char *str, struct object_id *oid);\n-extern int get_oid_blob(const char *str, struct object_id *oid);\n+int repo_get_oid_commit(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_committish(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid);\n void maybe_die_on_misspelt_object_name(struct repository *repo,\n \t\t\t\t       const char *name,\n \t\t\t\t       const char *prefix);\n@@ -1394,6 +1393,13 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c\n \t\t\t\tunsigned flags, struct object_id *oid,\n \t\t\t\tstruct object_context *oc);\n \n+#define get_oid(str, oid)\t\trepo_get_oid(the_repository, str, oid)\n+#define get_oid_commit(str, oid)\trepo_get_oid_commit(the_repository, str, oid)\n+#define get_oid_committish(str, oid)\trepo_get_oid_committish(the_repository, str, oid)\n+#define get_oid_tree(str, oid)\t\trepo_get_oid_tree(the_repository, str, oid)\n+#define get_oid_treeish(str, oid)\trepo_get_oid_treeish(the_repository, str, oid)\n+#define get_oid_blob(str, oid)\t\trepo_get_oid_blob(the_repository, str, oid)\n+\n typedef int each_abbrev_fn(const struct object_id *oid, void *);\n int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);\n #define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data)\ndiff --git a/sha1-name.c b/sha1-name.c\nindex b94d381bef..d49496397d 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1590,43 +1590,48 @@ int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)\n  * commit-ish. It is merely to give a hint to the disambiguation\n  * machinery.\n  */\n-int get_oid_committish(const char *name, struct object_id *oid)\n+int repo_get_oid_committish(struct repository *r,\n+\t\t\t    const char *name,\n+\t\t\t    struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_COMMITTISH,\n+\treturn get_oid_with_context(r, name, GET_OID_COMMITTISH,\n \t\t\t\t    oid, &unused);\n }\n \n-int get_oid_treeish(const char *name, struct object_id *oid)\n+int repo_get_oid_treeish(struct repository *r,\n+\t\t\t const char *name,\n+\t\t\t struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_TREEISH,\n+\treturn get_oid_with_context(r, name, GET_OID_TREEISH,\n \t\t\t\t    oid, &unused);\n }\n \n-int get_oid_commit(const char *name, struct object_id *oid)\n+int repo_get_oid_commit(struct repository *r,\n+\t\t\tconst char *name,\n+\t\t\tstruct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_COMMIT,\n+\treturn get_oid_with_context(r, name, GET_OID_COMMIT,\n \t\t\t\t    oid, &unused);\n }\n \n-int get_oid_tree(const char *name, struct object_id *oid)\n+int repo_get_oid_tree(struct repository *r,\n+\t\t      const char *name,\n+\t\t      struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_TREE,\n+\treturn get_oid_with_context(r, name, GET_OID_TREE,\n \t\t\t\t    oid, &unused);\n }\n \n-int get_oid_blob(const char *name, struct object_id *oid)\n+int repo_get_oid_blob(struct repository *r,\n+\t\t      const char *name,\n+\t\t      struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_BLOB,\n+\treturn get_oid_with_context(r, name, GET_OID_BLOB,\n \t\t\t\t    oid, &unused);\n }\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372796","messageId":"20190330111927.18645-32-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH 31/31] sha1-name.c: remove the_repo from get_oid_mb()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-03-30T11:19:27Z","receivedAt":"2019-03-30T11:23:05Z","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     |  3 ++-\n sha1-name.c | 18 +++++++++++-------\n 2 files changed, 13 insertions(+), 8 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 871a167bf8..9a600a8b50 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1386,6 +1386,7 @@ int repo_get_oid_committish(struct repository *r, const char *str, struct object\n int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid);\n int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid);\n int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_mb(struct repository *r, const char *str, struct object_id *oid);\n void maybe_die_on_misspelt_object_name(struct repository *repo,\n \t\t\t\t       const char *name,\n \t\t\t\t       const char *prefix);\n@@ -1399,6 +1400,7 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c\n #define get_oid_tree(str, oid)\t\trepo_get_oid_tree(the_repository, str, oid)\n #define get_oid_treeish(str, oid)\trepo_get_oid_treeish(the_repository, str, oid)\n #define get_oid_blob(str, oid)\t\trepo_get_oid_blob(the_repository, str, oid)\n+#define get_oid_mb(str, oid) \t\trepo_get_oid_mb(the_repository, str, oid)\n \n typedef int each_abbrev_fn(const struct object_id *oid, void *);\n int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);\n@@ -1486,7 +1488,6 @@ int repo_interpret_branch_name(struct repository *r,\n \t\t\t       unsigned allowed);\n #define interpret_branch_name(str, len, buf, allowed) \\\n \trepo_interpret_branch_name(the_repository, str, len, buf, allowed)\n-extern int get_oid_mb(const char *str, struct object_id *oid);\n \n extern int validate_headref(const char *ref);\n \ndiff --git a/sha1-name.c b/sha1-name.c\nindex d49496397d..cf314ebb29 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1338,7 +1338,9 @@ static int interpret_nth_prior_checkout(struct repository *r,\n \treturn retval;\n }\n \n-int get_oid_mb(const char *name, struct object_id *oid)\n+int repo_get_oid_mb(struct repository *r,\n+\t\t    const char *name,\n+\t\t    struct object_id *oid)\n {\n \tstruct commit *one, *two;\n \tstruct commit_list *mbs;\n@@ -1348,27 +1350,29 @@ int get_oid_mb(const char *name, struct object_id *oid)\n \n \tdots = strstr(name, \"...\");\n \tif (!dots)\n-\t\treturn get_oid(name, oid);\n+\t\treturn repo_get_oid(r, name, oid);\n \tif (dots == name)\n-\t\tst = get_oid(\"HEAD\", &oid_tmp);\n+\t\tst = repo_get_oid(r, \"HEAD\", &oid_tmp);\n \telse {\n \t\tstruct strbuf sb;\n \t\tstrbuf_init(&sb, dots - name);\n \t\tstrbuf_add(&sb, name, dots - name);\n-\t\tst = get_oid_committish(sb.buf, &oid_tmp);\n+\t\tst = repo_get_oid_committish(r, sb.buf, &oid_tmp);\n \t\tstrbuf_release(&sb);\n \t}\n \tif (st)\n \t\treturn st;\n-\tone = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);\n+\tone = lookup_commit_reference_gently(r, &oid_tmp, 0);\n \tif (!one)\n \t\treturn -1;\n \n-\tif (get_oid_committish(dots[3] ? (dots + 3) : \"HEAD\", &oid_tmp))\n+\tif (repo_get_oid_committish(r, dots[3] ? (dots + 3) : \"HEAD\", &oid_tmp))\n \t\treturn -1;\n-\ttwo = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);\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 \tif (!mbs || mbs->next)\n \t\tst = -1;\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"372985","messageId":"20190402153953.GL32732@szeder.dev","threadId":"50841","inReplyTo":"20190330111927.18645-10-pclouds@gmail.com","subject":"Re: [PATCH 09/31] commit.c: add repo_get_commit_tree()","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2019-04-02T15:39:53Z","receivedAt":"2019-04-02T15:40:00Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Sat, Mar 30, 2019 at 06:19:05PM +0700, Nguyễn Thái Ngọc Duy wrote:\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  commit.c | 5 +++--\n>  commit.h | 3 ++-\n>  2 files changed, 5 insertions(+), 3 deletions(-)\n> \n> diff --git a/commit.c b/commit.c\n> index a5333c7ac6..f0a5506f04 100644\n> --- a/commit.c\n> +++ b/commit.c\n> @@ -340,7 +340,8 @@ void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)\n>  \t}\n>  }\n>  \n> -struct tree *get_commit_tree(const struct commit *commit)\n> +struct tree *repo_get_commit_tree(struct repository *r,\n> +\t\t\t\t  const struct commit *commit)\n>  {\n>  \tif (commit->maybe_tree || !commit->object.parsed)\n>  \t\treturn commit->maybe_tree;\n\nBy renaming this function this patch triggers Coccinelle and\n'commit.cocci', as it specifically whitelists get_commit_tree() as one\nof the few functions that can legitimately access commit->maybe_tree;\nfor detail see 279ffad17d (coccinelle: avoid wrong transformation\nsuggestions from commit.cocci, 2018-04-30).\n\nPlease update 'commit.cocci' accordingly:\n\n\ndiff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\nindex c49aa558f0..55679cbbed 100644\n--- a/contrib/coccinelle/commit.cocci\n+++ b/contrib/coccinelle/commit.cocci\n@@ -12,7 +12,7 @@ expression c;\n \n // These excluded functions must access c->maybe_tree direcly.\n @@\n-identifier f !~ \"^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n+identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n expression c;\n @@\n   f(...) {<...\n\n"},{"id":"373015","messageId":"20190403113457.20399-1-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190330111927.18645-1-pclouds@gmail.com","subject":"[PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:25Z","receivedAt":"2019-04-03T11:35:11Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"v2 fixes commit.cocci, found by Szeder. While at there I see there are\ntwo other changes suggested by cocci that haven't made it to 'pu' so I\nadded them in the new 01/32.\n\nNguyễn Thái Ngọc Duy (32):\n  rebase: 'make coccicheck' cleanup\n  packfile.c: add repo_approximate_object_count()\n  refs.c: add refs_ref_exists()\n  refs.c: add refs_shorten_unambiguous_ref()\n  refs.c: remove the_repo from substitute_branch_name()\n  refs.c: remove the_repo from expand_ref()\n  refs.c: add repo_dwim_ref()\n  refs.c: add repo_dwim_log()\n  refs.c: remove the_repo from read_ref_at()\n  commit.c: add repo_get_commit_tree()\n  sha1-name.c: remove the_repo from sort_ambiguous()\n  sha1-name.c: remove the_repo from find_abbrev_len_packed()\n  sha1-name.c: add repo_find_unique_abbrev_r()\n  sha1-name.c: store and use repo in struct disambiguate_state\n  sha1-name.c: add repo_for_each_abbrev()\n  sha1-name.c: remove the_repo from get_short_oid()\n  sha1-name.c: remove the_repo from interpret_nth_prior_checkout()\n  sha1-name.c: remove the_repo from interpret_branch_mark()\n  sha1-name.c: add repo_interpret_branch_name()\n  sha1-name.c: remove the_repo from get_oid_oneline()\n  sha1-name.c: remove the_repo from get_describe_name()\n  sha1-name.c: remove the_repo from get_oid_basic()\n  sha1-name.c: remove the_repo from get_oid_1()\n  sha1-name.c: remove the_repo from handle_one_ref()\n  sha1-name.c: remove the_repo from diagnose_invalid_index_path()\n  sha1-name.c: remove the_repo from resolve_relative_path()\n  sha1-name.c: remove the_repo from get_oid_with_context_1()\n  sha1-name.c: add repo_get_oid()\n  submodule-config.c: use repo_get_oid for reading .gitmodules\n  sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name\n  sha1-name.c: remove the_repo from other get_oid_*\n  sha1-name.c: remove the_repo from get_oid_mb()\n\n builtin/rebase.c                   |   5 +-\n builtin/show-branch.c              |   6 +-\n cache.h                            |  50 ++--\n commit.c                           |   5 +-\n commit.h                           |   3 +-\n contrib/coccinelle/commit.cocci    |   4 +-\n dir.c                              |   8 +\n dir.h                              |   4 +-\n packfile.c                         |  14 +-\n packfile.h                         |   3 +-\n refs.c                             |  71 ++++--\n refs.h                             |   9 +-\n setup.c                            |   7 +-\n sha1-name.c                        | 388 ++++++++++++++++++-----------\n submodule-config.c                 |  20 +-\n t/t7814-grep-recurse-submodules.sh |   6 +-\n upload-pack.c                      |   2 +-\n 17 files changed, 375 insertions(+), 230 deletions(-)\n\nRange-diff dựa trên v1:\n -:  ---------- >  1:  b992f6c799 rebase: 'make coccicheck' cleanup\n 1:  0988bf416e =  2:  e76c73a75a packfile.c: add repo_approximate_object_count()\n 2:  d55d5a044d =  3:  962a168516 refs.c: add refs_ref_exists()\n 3:  a01ebfaa28 =  4:  d06bea7909 refs.c: add refs_shorten_unambiguous_ref()\n 4:  6bf6bdb358 =  5:  fb880154e6 refs.c: remove the_repo from substitute_branch_name()\n 5:  7db71d20f0 =  6:  6fd7960522 refs.c: remove the_repo from expand_ref()\n 6:  c0bbe2ea45 =  7:  f5ad3133bc refs.c: add repo_dwim_ref()\n 7:  c7b5e8d9fe =  8:  7552a4085a refs.c: add repo_dwim_log()\n 8:  91229dad66 =  9:  962fff4c9c refs.c: remove the_repo from read_ref_at()\n 9:  ae7d2bfcee ! 10:  68876a150f commit.c: add repo_get_commit_tree()\n    @@ -38,3 +38,22 @@\n      struct object_id *get_commit_tree_oid(const struct commit *);\n      \n      /*\n    +\n    + diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\n    + --- a/contrib/coccinelle/commit.cocci\n    + +++ b/contrib/coccinelle/commit.cocci\n    +@@\n    + \n    + // These excluded functions must access c->maybe_tree direcly.\n    + @@\n    +-identifier f !~ \"^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n    ++identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n    + expression c;\n    + @@\n    +   f(...) {<...\n    + - c->maybe_tree\n    +-+ get_commit_tree(c)\n    +++ repo_get_commit_tree(the_repository, c)\n    +   ...>}\n    + \n    + @@\n10:  b6bd4c86e3 = 11:  9817d150b2 sha1-name.c: remove the_repo from sort_ambiguous()\n11:  8aaaf14786 = 12:  7ce23aaeb5 sha1-name.c: remove the_repo from find_abbrev_len_packed()\n12:  76305c1faa = 13:  2d99af106f sha1-name.c: add repo_find_unique_abbrev_r()\n13:  f07d196f41 = 14:  f63626e937 sha1-name.c: store and use repo in struct disambiguate_state\n14:  0e6ef61f31 = 15:  ce9f7ebab8 sha1-name.c: add repo_for_each_abbrev()\n15:  0e74d78d74 = 16:  8cb8278d6e sha1-name.c: remove the_repo from get_short_oid()\n16:  a5d0f20892 = 17:  9210dd01b8 sha1-name.c: remove the_repo from interpret_nth_prior_checkout()\n17:  15dd2005b4 = 18:  a161ed33d2 sha1-name.c: remove the_repo from interpret_branch_mark()\n18:  23627fd251 = 19:  6bf4df0131 sha1-name.c: add repo_interpret_branch_name()\n19:  167ac516e8 = 20:  94f707cb7f sha1-name.c: remove the_repo from get_oid_oneline()\n20:  57bfc2f7f6 = 21:  2a1dd6368c sha1-name.c: remove the_repo from get_describe_name()\n21:  1134a0c34e = 22:  f958b565db sha1-name.c: remove the_repo from get_oid_basic()\n22:  c04c381031 = 23:  ec821007b2 sha1-name.c: remove the_repo from get_oid_1()\n23:  c9a33014f6 = 24:  317a365f30 sha1-name.c: remove the_repo from handle_one_ref()\n24:  2f8bd84d50 = 25:  3a46ea22b2 sha1-name.c: remove the_repo from diagnose_invalid_index_path()\n25:  c2924466da = 26:  59a8cb9749 sha1-name.c: remove the_repo from resolve_relative_path()\n26:  3b9545a48c = 27:  d1f4df1915 sha1-name.c: remove the_repo from get_oid_with_context_1()\n27:  333dc19eae = 28:  3034e9cf1e sha1-name.c: add repo_get_oid()\n28:  a6b08a7a2d = 29:  9c72941ec9 submodule-config.c: use repo_get_oid for reading .gitmodules\n29:  42a0ce718e = 30:  40acfb6b82 sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name\n30:  39aab4331a = 31:  3b8be75e77 sha1-name.c: remove the_repo from other get_oid_*\n31:  1d1c4a0d5f = 32:  59cadc5deb sha1-name.c: remove the_repo from get_oid_mb()\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373017","messageId":"20190403113457.20399-2-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 01/32] rebase: 'make coccicheck' cleanup","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:26Z","receivedAt":"2019-04-03T11:35:16Z","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/rebase.c | 5 ++---\n 1 file changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 77deebc65c..c064909329 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -1592,8 +1592,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\t\t\tbranch_name = options.head_name;\n \n \t\t} else {\n-\t\t\tfree(options.head_name);\n-\t\t\toptions.head_name = NULL;\n+\t\t\tFREE_AND_NULL(options.head_name);\n \t\t\tbranch_name = \"HEAD\";\n \t\t}\n \t\tif (get_oid(\"HEAD\", &options.orig_head))\n@@ -1793,7 +1792,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t * we just fast-forwarded.\n \t */\n \tstrbuf_reset(&msg);\n-\tif (!oidcmp(&merge_base, &options.orig_head)) {\n+\tif (oideq(&merge_base, &options.orig_head)) {\n \t\tprintf(_(\"Fast-forwarded %s to %s.\\n\"),\n \t\t\tbranch_name, options.onto_name);\n \t\tstrbuf_addf(&msg, \"rebase finished: %s onto %s\",\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373018","messageId":"20190403113457.20399-3-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 02/32] packfile.c: add repo_approximate_object_count()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:27Z","receivedAt":"2019-04-03T11:35:21Z","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 packfile.c | 14 +++++++-------\n packfile.h |  3 ++-\n 2 files changed, 9 insertions(+), 8 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex 16bcb75262..2ad4fab2f8 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -893,25 +893,25 @@ static void prepare_packed_git(struct repository *r);\n  * all unreachable objects about to be pruned, in which case they're not really\n  * interesting as a measure of repo size in the first place.\n  */\n-unsigned long approximate_object_count(void)\n+unsigned long repo_approximate_object_count(struct repository *r)\n {\n-\tif (!the_repository->objects->approximate_object_count_valid) {\n+\tif (!r->objects->approximate_object_count_valid) {\n \t\tunsigned long count;\n \t\tstruct multi_pack_index *m;\n \t\tstruct packed_git *p;\n \n-\t\tprepare_packed_git(the_repository);\n+\t\tprepare_packed_git(r);\n \t\tcount = 0;\n-\t\tfor (m = get_multi_pack_index(the_repository); m; m = m->next)\n+\t\tfor (m = get_multi_pack_index(r); m; m = m->next)\n \t\t\tcount += m->num_objects;\n-\t\tfor (p = the_repository->objects->packed_git; p; p = p->next) {\n+\t\tfor (p = r->objects->packed_git; p; p = p->next) {\n \t\t\tif (open_pack_index(p))\n \t\t\t\tcontinue;\n \t\t\tcount += p->num_objects;\n \t\t}\n-\t\tthe_repository->objects->approximate_object_count = count;\n+\t\tr->objects->approximate_object_count = count;\n \t}\n-\treturn the_repository->objects->approximate_object_count;\n+\treturn r->objects->approximate_object_count;\n }\n \n static void *get_next_packed_git(const void *p)\ndiff --git a/packfile.h b/packfile.h\nindex d70c6d9afb..f04440f984 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -57,7 +57,8 @@ struct packed_git *get_all_packs(struct repository *r);\n  * Give a rough count of objects in the repository. This sacrifices accuracy\n  * for speed.\n  */\n-unsigned long approximate_object_count(void);\n+unsigned long repo_approximate_object_count(struct repository *r);\n+#define approximate_object_count() repo_approximate_object_count(the_repository)\n \n extern struct packed_git *find_sha1_pack(const unsigned char *sha1,\n \t\t\t\t\t struct packed_git *packs);\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373019","messageId":"20190403113457.20399-4-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 03/32] refs.c: add refs_ref_exists()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:28Z","receivedAt":"2019-04-03T11:35:26Z","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 refs.c | 7 ++++++-\n 1 file changed, 6 insertions(+), 1 deletion(-)\n\ndiff --git a/refs.c b/refs.c\nindex 142888a40a..b869f32d8b 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -241,9 +241,14 @@ int read_ref(const char *refname, struct object_id *oid)\n \treturn read_ref_full(refname, RESOLVE_REF_READING, oid, NULL);\n }\n \n+static int refs_ref_exists(struct ref_store *refs, const char *refname)\n+{\n+\treturn !!refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING, NULL, NULL);\n+}\n+\n int ref_exists(const char *refname)\n {\n-\treturn !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, NULL, NULL);\n+\treturn refs_ref_exists(get_main_ref_store(the_repository), refname);\n }\n \n static int match_ref_pattern(const char *refname,\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373020","messageId":"20190403113457.20399-5-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 04/32] refs.c: add refs_shorten_unambiguous_ref()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:29Z","receivedAt":"2019-04-03T11:35:32Z","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 refs.c | 11 +++++++++--\n refs.h |  2 ++\n 2 files changed, 11 insertions(+), 2 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex b869f32d8b..3dde824aab 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1169,7 +1169,8 @@ int update_ref(const char *msg, const char *refname,\n \t\t\t       old_oid, flags, onerr);\n }\n \n-char *shorten_unambiguous_ref(const char *refname, int strict)\n+char *refs_shorten_unambiguous_ref(struct ref_store *refs,\n+\t\t\t\t   const char *refname, int strict)\n {\n \tint i;\n \tstatic char **scanf_fmts;\n@@ -1247,7 +1248,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)\n \t\t\tstrbuf_reset(&resolved_buf);\n \t\t\tstrbuf_addf(&resolved_buf, rule,\n \t\t\t\t    short_name_len, short_name);\n-\t\t\tif (ref_exists(resolved_buf.buf))\n+\t\t\tif (refs_ref_exists(refs, resolved_buf.buf))\n \t\t\t\tbreak;\n \t\t}\n \n@@ -1266,6 +1267,12 @@ char *shorten_unambiguous_ref(const char *refname, int strict)\n \treturn xstrdup(refname);\n }\n \n+char *shorten_unambiguous_ref(const char *refname, int strict)\n+{\n+\treturn refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),\n+\t\t\t\t\t    refname, strict);\n+}\n+\n static struct string_list *hide_refs;\n \n int parse_hide_refs_config(const char *var, const char *value, const char *section)\ndiff --git a/refs.h b/refs.h\nindex 308fa1f03b..5627570241 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -462,6 +462,8 @@ int check_refname_format(const char *refname, int flags);\n \n const char *prettify_refname(const char *refname);\n \n+char *refs_shorten_unambiguous_ref(struct ref_store *refs,\n+\t\t\t\t   const char *refname, int strict);\n char *shorten_unambiguous_ref(const char *refname, int strict);\n \n /** rename ref, return 0 on success **/\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373021","messageId":"20190403113457.20399-6-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 05/32] refs.c: remove the_repo from substitute_branch_name()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:30Z","receivedAt":"2019-04-03T11:35:38Z","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     | 8 ++++++--\n refs.c      | 9 +++++----\n sha1-name.c | 8 ++++++--\n 3 files changed, 17 insertions(+), 8 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex ac92421f3a..fcb24b5781 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1468,8 +1468,12 @@ extern int parse_oid_hex(const char *hex, struct object_id *oid, const char **en\n #define INTERPRET_BRANCH_LOCAL (1<<0)\n #define INTERPRET_BRANCH_REMOTE (1<<1)\n #define INTERPRET_BRANCH_HEAD (1<<2)\n-extern int interpret_branch_name(const char *str, int len, struct strbuf *,\n-\t\t\t\t unsigned allowed);\n+int repo_interpret_branch_name(struct repository *r,\n+\t\t\t       const char *str, int len,\n+\t\t\t       struct strbuf *buf,\n+\t\t\t       unsigned allowed);\n+#define interpret_branch_name(str, len, buf, allowed) \\\n+\trepo_interpret_branch_name(the_repository, str, len, buf, allowed)\n extern int get_oid_mb(const char *str, struct object_id *oid);\n \n extern int validate_headref(const char *ref);\ndiff --git a/refs.c b/refs.c\nindex 3dde824aab..44df049796 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -539,10 +539,11 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n  * later free()ing) if the string passed in is a magic short-hand form\n  * to name a branch.\n  */\n-static char *substitute_branch_name(const char **string, int *len)\n+static char *substitute_branch_name(struct repository *r,\n+\t\t\t\t    const char **string, int *len)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n-\tint ret = interpret_branch_name(*string, *len, &buf, 0);\n+\tint ret = repo_interpret_branch_name(r, *string, *len, &buf, 0);\n \n \tif (ret == *len) {\n \t\tsize_t size;\n@@ -556,7 +557,7 @@ static char *substitute_branch_name(const char **string, int *len)\n \n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)\n {\n-\tchar *last_branch = substitute_branch_name(&str, &len);\n+\tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n \tint   refs_found  = expand_ref(str, len, oid, ref);\n \tfree(last_branch);\n \treturn refs_found;\n@@ -596,7 +597,7 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)\n \n int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n {\n-\tchar *last_branch = substitute_branch_name(&str, &len);\n+\tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n \tconst char **p;\n \tint logs_found = 0;\n \tstruct strbuf path = STRBUF_INIT;\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 6dda2c16df..d535bb82f7 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1427,13 +1427,17 @@ static int interpret_branch_mark(const char *name, int namelen,\n \treturn len + at;\n }\n \n-int interpret_branch_name(const char *name, int namelen, struct strbuf *buf,\n-\t\t\t  unsigned allowed)\n+int repo_interpret_branch_name(struct repository *r,\n+\t\t\t       const char *name, int namelen,\n+\t\t\t       struct strbuf *buf,\n+\t\t\t       unsigned allowed)\n {\n \tchar *at;\n \tconst char *start;\n \tint len;\n \n+\tif (r != the_repository)\n+\t\tBUG(\"interpret_branch_name() does not really use 'r' yet\");\n \tif (!namelen)\n \t\tnamelen = strlen(name);\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373022","messageId":"20190403113457.20399-7-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 06/32] refs.c: remove the_repo from expand_ref()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:31Z","receivedAt":"2019-04-03T11:35:42Z","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 refs.c        | 10 ++++++----\n refs.h        |  2 +-\n upload-pack.c |  2 +-\n 3 files changed, 8 insertions(+), 6 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 44df049796..1f5864aa36 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -558,12 +558,13 @@ static char *substitute_branch_name(struct repository *r,\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)\n {\n \tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n-\tint   refs_found  = expand_ref(str, len, oid, ref);\n+\tint   refs_found  = expand_ref(the_repository, str, len, oid, ref);\n \tfree(last_branch);\n \treturn refs_found;\n }\n \n-int expand_ref(const char *str, int len, struct object_id *oid, char **ref)\n+int expand_ref(struct repository *repo, const char *str, int len,\n+\t       struct object_id *oid, char **ref)\n {\n \tconst char **p, *r;\n \tint refs_found = 0;\n@@ -578,8 +579,9 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)\n \t\tthis_result = refs_found ? &oid_from_ref : oid;\n \t\tstrbuf_reset(&fullref);\n \t\tstrbuf_addf(&fullref, *p, len, str);\n-\t\tr = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,\n-\t\t\t\t       this_result, &flag);\n+\t\tr = refs_resolve_ref_unsafe(get_main_ref_store(repo),\n+\t\t\t\t\t    fullref.buf, RESOLVE_REF_READING,\n+\t\t\t\t\t    this_result, &flag);\n \t\tif (r) {\n \t\t\tif (!refs_found++)\n \t\t\t\t*ref = xstrdup(r);\ndiff --git a/refs.h b/refs.h\nindex 5627570241..b630d5bde7 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -148,7 +148,7 @@ int refname_match(const char *abbrev_name, const char *full_name);\n struct argv_array;\n void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);\n \n-int expand_ref(const char *str, int len, struct object_id *oid, char **ref);\n+int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n \ndiff --git a/upload-pack.c b/upload-pack.c\nindex d098ef5982..56505d60c3 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -834,7 +834,7 @@ static int process_deepen_not(const char *line, struct string_list *deepen_not,\n \tif (skip_prefix(line, \"deepen-not \", &arg)) {\n \t\tchar *ref = NULL;\n \t\tstruct object_id oid;\n-\t\tif (expand_ref(arg, strlen(arg), &oid, &ref) != 1)\n+\t\tif (expand_ref(the_repository, arg, strlen(arg), &oid, &ref) != 1)\n \t\t\tdie(\"git upload-pack: ambiguous deepen-not: %s\", line);\n \t\tstring_list_append(deepen_not, ref);\n \t\tfree(ref);\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373023","messageId":"20190403113457.20399-8-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 07/32] refs.c: add repo_dwim_ref()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:32Z","receivedAt":"2019-04-03T11:35:48Z","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 refs.c | 12 +++++++++---\n refs.h |  1 +\n 2 files changed, 10 insertions(+), 3 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 1f5864aa36..bd0fec5776 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -555,14 +555,20 @@ static char *substitute_branch_name(struct repository *r,\n \treturn NULL;\n }\n \n-int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)\n+int repo_dwim_ref(struct repository *r, const char *str, int len,\n+\t\t  struct object_id *oid, char **ref)\n {\n-\tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n-\tint   refs_found  = expand_ref(the_repository, str, len, oid, ref);\n+\tchar *last_branch = substitute_branch_name(r, &str, &len);\n+\tint   refs_found  = expand_ref(r, str, len, oid, ref);\n \tfree(last_branch);\n \treturn refs_found;\n }\n \n+int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)\n+{\n+\treturn repo_dwim_ref(the_repository, str, len, oid, ref);\n+}\n+\n int expand_ref(struct repository *repo, const char *str, int len,\n \t       struct object_id *oid, char **ref)\n {\ndiff --git a/refs.h b/refs.h\nindex b630d5bde7..fd3dc1d0f4 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -149,6 +149,7 @@ struct argv_array;\n void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);\n \n int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n+int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373024","messageId":"20190403113457.20399-9-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 08/32] refs.c: add repo_dwim_log()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:33Z","receivedAt":"2019-04-03T11:35:53Z","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 refs.c | 21 +++++++++++++++------\n refs.h |  1 +\n 2 files changed, 16 insertions(+), 6 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex bd0fec5776..edea001446 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -603,9 +603,11 @@ int expand_ref(struct repository *repo, const char *str, int len,\n \treturn refs_found;\n }\n \n-int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n+int repo_dwim_log(struct repository *r, const char *str, int len,\n+\t\t  struct object_id *oid, char **log)\n {\n-\tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n+\tstruct ref_store *refs = get_main_ref_store(r);\n+\tchar *last_branch = substitute_branch_name(r, &str, &len);\n \tconst char **p;\n \tint logs_found = 0;\n \tstruct strbuf path = STRBUF_INIT;\n@@ -617,13 +619,15 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n \n \t\tstrbuf_reset(&path);\n \t\tstrbuf_addf(&path, *p, len, str);\n-\t\tref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,\n-\t\t\t\t\t &hash, NULL);\n+\t\tref = refs_resolve_ref_unsafe(refs, path.buf,\n+\t\t\t\t\t      RESOLVE_REF_READING,\n+\t\t\t\t\t      &hash, NULL);\n \t\tif (!ref)\n \t\t\tcontinue;\n-\t\tif (reflog_exists(path.buf))\n+\t\tif (refs_reflog_exists(refs, path.buf))\n \t\t\tit = path.buf;\n-\t\telse if (strcmp(ref, path.buf) && reflog_exists(ref))\n+\t\telse if (strcmp(ref, path.buf) &&\n+\t\t\t refs_reflog_exists(refs, ref))\n \t\t\tit = ref;\n \t\telse\n \t\t\tcontinue;\n@@ -639,6 +643,11 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n \treturn logs_found;\n }\n \n+int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n+{\n+\treturn repo_dwim_log(the_repository, str, len, oid, log);\n+}\n+\n static int is_per_worktree_ref(const char *refname)\n {\n \treturn !strcmp(refname, \"HEAD\") ||\ndiff --git a/refs.h b/refs.h\nindex fd3dc1d0f4..859dffe691 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -150,6 +150,7 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);\n \n int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n+int repo_dwim_log(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373025","messageId":"20190403113457.20399-10-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 09/32] refs.c: remove the_repo from read_ref_at()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:34Z","receivedAt":"2019-04-03T11:35:59Z","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/show-branch.c | 6 ++++--\n refs.c                | 7 ++++---\n refs.h                | 3 ++-\n sha1-name.c           | 3 ++-\n 4 files changed, 12 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/show-branch.c b/builtin/show-branch.c\nindex 934e514944..082daeac32 100644\n--- a/builtin/show-branch.c\n+++ b/builtin/show-branch.c\n@@ -753,7 +753,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\t\t/* Ah, that is a date spec... */\n \t\t\t\ttimestamp_t at;\n \t\t\t\tat = approxidate(reflog_base);\n-\t\t\t\tread_ref_at(ref, flags, at, -1, &oid, NULL,\n+\t\t\t\tread_ref_at(get_main_ref_store(the_repository),\n+\t\t\t\t\t    ref, flags, at, -1, &oid, NULL,\n \t\t\t\t\t    NULL, NULL, &base);\n \t\t\t}\n \t\t}\n@@ -765,7 +766,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\ttimestamp_t timestamp;\n \t\t\tint tz;\n \n-\t\t\tif (read_ref_at(ref, flags, 0, base + i, &oid, &logmsg,\n+\t\t\tif (read_ref_at(get_main_ref_store(the_repository),\n+\t\t\t\t\tref, flags, 0, base + i, &oid, &logmsg,\n \t\t\t\t\t&timestamp, &tz, NULL)) {\n \t\t\t\treflog = i;\n \t\t\t\tbreak;\ndiff --git a/refs.c b/refs.c\nindex edea001446..92d1f6dbdd 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -967,7 +967,8 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid\n \treturn 1;\n }\n \n-int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, int cnt,\n+int read_ref_at(struct ref_store *refs, const char *refname,\n+\t\tunsigned int flags, timestamp_t at_time, int cnt,\n \t\tstruct object_id *oid, char **msg,\n \t\ttimestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt)\n {\n@@ -983,7 +984,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in\n \tcb.cutoff_cnt = cutoff_cnt;\n \tcb.oid = oid;\n \n-\tfor_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);\n+\trefs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent, &cb);\n \n \tif (!cb.reccnt) {\n \t\tif (flags & GET_OID_QUIETLY)\n@@ -994,7 +995,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in\n \tif (cb.found_it)\n \t\treturn 0;\n \n-\tfor_each_reflog_ent(refname, read_ref_at_ent_oldest, &cb);\n+\trefs_for_each_reflog_ent(refs, refname, read_ref_at_ent_oldest, &cb);\n \n \treturn 1;\n }\ndiff --git a/refs.h b/refs.h\nindex 859dffe691..8f9cbf8a93 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -388,7 +388,8 @@ int refs_create_reflog(struct ref_store *refs, const char *refname,\n int safe_create_reflog(const char *refname, int force_create, struct strbuf *err);\n \n /** Reads log for the value of ref during at_time. **/\n-int read_ref_at(const char *refname, unsigned int flags,\n+int read_ref_at(struct ref_store *refs,\n+\t\tconst char *refname, unsigned int flags,\n \t\ttimestamp_t at_time, int cnt,\n \t\tstruct object_id *oid, char **msg,\n \t\ttimestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt);\ndiff --git a/sha1-name.c b/sha1-name.c\nindex d535bb82f7..15a1107998 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -849,7 +849,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\t\t\treturn -1;\n \t\t\t}\n \t\t}\n-\t\tif (read_ref_at(real_ref, flags, at_time, nth, oid, NULL,\n+\t\tif (read_ref_at(get_main_ref_store(the_repository),\n+\t\t\t\treal_ref, flags, at_time, nth, oid, NULL,\n \t\t\t\t&co_time, &co_tz, &co_cnt)) {\n \t\t\tif (!len) {\n \t\t\t\tif (starts_with(real_ref, \"refs/heads/\")) {\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373026","messageId":"20190403113457.20399-11-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 10/32] commit.c: add repo_get_commit_tree()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:35Z","receivedAt":"2019-04-03T11:36:04Z","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 commit.c                        | 5 +++--\n commit.h                        | 3 ++-\n contrib/coccinelle/commit.cocci | 4 ++--\n 3 files changed, 7 insertions(+), 5 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex a5333c7ac6..f0a5506f04 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -340,7 +340,8 @@ void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)\n \t}\n }\n \n-struct tree *get_commit_tree(const struct commit *commit)\n+struct tree *repo_get_commit_tree(struct repository *r,\n+\t\t\t\t  const struct commit *commit)\n {\n \tif (commit->maybe_tree || !commit->object.parsed)\n \t\treturn commit->maybe_tree;\n@@ -348,7 +349,7 @@ struct tree *get_commit_tree(const struct commit *commit)\n \tif (commit->graph_pos == COMMIT_NOT_FROM_GRAPH)\n \t\tBUG(\"commit has NULL tree, but was not loaded from commit-graph\");\n \n-\treturn get_commit_tree_in_graph(the_repository, commit);\n+\treturn get_commit_tree_in_graph(r, commit);\n }\n \n struct object_id *get_commit_tree_oid(const struct commit *commit)\ndiff --git a/commit.h b/commit.h\nindex 42728c2906..b576201be8 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -143,7 +143,8 @@ void repo_unuse_commit_buffer(struct repository *r,\n  */\n void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);\n \n-struct tree *get_commit_tree(const struct commit *);\n+struct tree *repo_get_commit_tree(struct repository *, const struct commit *);\n+#define get_commit_tree(c) repo_get_commit_tree(the_repository, c)\n struct object_id *get_commit_tree_oid(const struct commit *);\n \n /*\ndiff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\nindex c49aa558f0..f5bc639981 100644\n--- a/contrib/coccinelle/commit.cocci\n+++ b/contrib/coccinelle/commit.cocci\n@@ -12,12 +12,12 @@ expression c;\n \n // These excluded functions must access c->maybe_tree direcly.\n @@\n-identifier f !~ \"^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n+identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n expression c;\n @@\n   f(...) {<...\n - c->maybe_tree\n-+ get_commit_tree(c)\n++ repo_get_commit_tree(the_repository, c)\n   ...>}\n \n @@\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373028","messageId":"20190403113457.20399-12-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 11/32] sha1-name.c: remove the_repo from sort_ambiguous()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:36Z","receivedAt":"2019-04-03T11:36:10Z","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 | 15 ++++++++++++---\n 1 file changed, 12 insertions(+), 3 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 15a1107998..7558ce51a3 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -383,10 +383,11 @@ static int collect_ambiguous(const struct object_id *oid, void *data)\n \treturn 0;\n }\n \n+static struct repository *sort_ambiguous_repo;\n static int sort_ambiguous(const void *a, const void *b)\n {\n-\tint a_type = oid_object_info(the_repository, a, NULL);\n-\tint b_type = oid_object_info(the_repository, b, NULL);\n+\tint a_type = oid_object_info(sort_ambiguous_repo, a, NULL);\n+\tint b_type = oid_object_info(sort_ambiguous_repo, b, NULL);\n \tint a_type_sort;\n \tint b_type_sort;\n \n@@ -411,6 +412,14 @@ static int sort_ambiguous(const void *a, const void *b)\n \treturn a_type_sort > b_type_sort ? 1 : -1;\n }\n \n+static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)\n+{\n+\t/* mutex will be needed if this code is to be made thread safe */\n+\tsort_ambiguous_repo = r;\n+\tQSORT(a->oid, a->nr, sort_ambiguous);\n+\tsort_ambiguous_repo = NULL;\n+}\n+\n static enum get_oid_result get_short_oid(const char *name, int len,\n \t\t\t\t\t struct object_id *oid,\n \t\t\t\t\t unsigned flags)\n@@ -458,7 +467,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \n \t\tadvise(_(\"The candidates are:\"));\n \t\tfor_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect);\n-\t\tQSORT(collect.oid, collect.nr, sort_ambiguous);\n+\t\tsort_ambiguous_oid_array(the_repository, &collect);\n \n \t\tif (oid_array_for_each(&collect, show_ambiguous_object, &ds))\n \t\t\tBUG(\"show_ambiguous_object shouldn't return non-zero\");\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373029","messageId":"20190403113457.20399-13-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 12/32] sha1-name.c: remove the_repo from find_abbrev_len_packed()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:37Z","receivedAt":"2019-04-03T11:36:15Z","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 | 6 ++++--\n 1 file changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 7558ce51a3..b9381aaba6 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -514,6 +514,7 @@ struct min_abbrev_data {\n \tunsigned int init_len;\n \tunsigned int cur_len;\n \tchar *hex;\n+\tstruct repository *repo;\n \tconst struct object_id *oid;\n };\n \n@@ -619,9 +620,9 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)\n \tstruct multi_pack_index *m;\n \tstruct packed_git *p;\n \n-\tfor (m = get_multi_pack_index(the_repository); m; m = m->next)\n+\tfor (m = get_multi_pack_index(mad->repo); m; m = m->next)\n \t\tfind_abbrev_len_for_midx(m, mad);\n-\tfor (p = get_packed_git(the_repository); p; p = p->next)\n+\tfor (p = get_packed_git(mad->repo); p; p = p->next)\n \t\tfind_abbrev_len_for_pack(p, mad);\n }\n \n@@ -658,6 +659,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)\n \tif (len == hexsz || !len)\n \t\treturn hexsz;\n \n+\tmad.repo = the_repository;\n \tmad.init_len = len;\n \tmad.cur_len = len;\n \tmad.hex = hex;\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373030","messageId":"20190403113457.20399-14-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 13/32] sha1-name.c: add repo_find_unique_abbrev_r()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:38Z","receivedAt":"2019-04-03T11:36:21Z","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     |  6 ++++--\n sha1-name.c | 15 +++++++++------\n 2 files changed, 13 insertions(+), 8 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex fcb24b5781..4f8ebb0a67 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1045,8 +1045,10 @@ extern void check_repository_format(void);\n  * Note that while this version avoids the static buffer, it is not fully\n  * reentrant, as it calls into other non-reentrant git code.\n  */\n-extern const char *find_unique_abbrev(const struct object_id *oid, int len);\n-extern int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len);\n+const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len);\n+#define find_unique_abbrev(oid, len) repo_find_unique_abbrev(the_repository, oid, len)\n+int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);\n+#define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len)\n \n extern const unsigned char null_sha1[GIT_MAX_RAWSZ];\n extern const struct object_id null_oid;\ndiff --git a/sha1-name.c b/sha1-name.c\nindex b9381aaba6..9b57787b76 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -626,15 +626,16 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)\n \t\tfind_abbrev_len_for_pack(p, mad);\n }\n \n-int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)\n+int repo_find_unique_abbrev_r(struct repository *r, char *hex,\n+\t\t\t      const struct object_id *oid, int len)\n {\n \tstruct disambiguate_state ds;\n \tstruct min_abbrev_data mad;\n \tstruct object_id oid_ret;\n-\tconst unsigned hexsz = the_hash_algo->hexsz;\n+\tconst unsigned hexsz = r->hash_algo->hexsz;\n \n \tif (len < 0) {\n-\t\tunsigned long count = approximate_object_count();\n+\t\tunsigned long count = repo_approximate_object_count(r);\n \t\t/*\n \t\t * Add one because the MSB only tells us the highest bit set,\n \t\t * not including the value of all the _other_ bits (so \"15\"\n@@ -659,7 +660,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)\n \tif (len == hexsz || !len)\n \t\treturn hexsz;\n \n-\tmad.repo = the_repository;\n+\tmad.repo = r;\n \tmad.init_len = len;\n \tmad.cur_len = len;\n \tmad.hex = hex;\n@@ -681,13 +682,15 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)\n \treturn mad.cur_len;\n }\n \n-const char *find_unique_abbrev(const struct object_id *oid, int len)\n+const char *repo_find_unique_abbrev(struct repository *r,\n+\t\t\t\t    const struct object_id *oid,\n+\t\t\t\t    int len)\n {\n \tstatic int bufno;\n \tstatic char hexbuffer[4][GIT_MAX_HEXSZ + 1];\n \tchar *hex = hexbuffer[bufno];\n \tbufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);\n-\tfind_unique_abbrev_r(hex, oid, len);\n+\trepo_find_unique_abbrev_r(r, hex, oid, len);\n \treturn hex;\n }\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373031","messageId":"20190403113457.20399-15-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 14/32] sha1-name.c: store and use repo in struct disambiguate_state","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:39Z","receivedAt":"2019-04-03T11:36:26Z","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 | 95 +++++++++++++++++++++++++++++++++--------------------\n 1 file changed, 59 insertions(+), 36 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 9b57787b76..a75992eb54 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -17,13 +17,14 @@\n \n static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);\n \n-typedef int (*disambiguate_hint_fn)(const struct object_id *, void *);\n+typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);\n \n struct disambiguate_state {\n \tint len; /* length of prefix in hex chars */\n \tchar hex_pfx[GIT_MAX_HEXSZ + 1];\n \tstruct object_id bin_pfx;\n \n+\tstruct repository *repo;\n \tdisambiguate_hint_fn fn;\n \tvoid *cb_data;\n \tstruct object_id candidate;\n@@ -38,7 +39,7 @@ struct disambiguate_state {\n static void update_candidates(struct disambiguate_state *ds, const struct object_id *current)\n {\n \tif (ds->always_call_fn) {\n-\t\tds->ambiguous = ds->fn(current, ds->cb_data) ? 1 : 0;\n+\t\tds->ambiguous = ds->fn(ds->repo, current, ds->cb_data) ? 1 : 0;\n \t\treturn;\n \t}\n \tif (!ds->candidate_exists) {\n@@ -58,7 +59,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object\n \t}\n \n \tif (!ds->candidate_checked) {\n-\t\tds->candidate_ok = ds->fn(&ds->candidate, ds->cb_data);\n+\t\tds->candidate_ok = ds->fn(ds->repo, &ds->candidate, ds->cb_data);\n \t\tds->disambiguate_fn_used = 1;\n \t\tds->candidate_checked = 1;\n \t}\n@@ -71,7 +72,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object\n \t}\n \n \t/* if we reach this point, we know ds->candidate satisfies fn */\n-\tif (ds->fn(current, ds->cb_data)) {\n+\tif (ds->fn(ds->repo, current, ds->cb_data)) {\n \t\t/*\n \t\t * if both current and candidate satisfy fn, we cannot\n \t\t * disambiguate.\n@@ -89,9 +90,7 @@ static void find_short_object_filename(struct disambiguate_state *ds)\n {\n \tstruct object_directory *odb;\n \n-\tfor (odb = the_repository->objects->odb;\n-\t     odb && !ds->ambiguous;\n-\t     odb = odb->next) {\n+\tfor (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next) {\n \t\tint pos;\n \t\tstruct oid_array *loose_objects;\n \n@@ -182,10 +181,10 @@ static void find_short_packed_object(struct disambiguate_state *ds)\n \tstruct multi_pack_index *m;\n \tstruct packed_git *p;\n \n-\tfor (m = get_multi_pack_index(the_repository); m && !ds->ambiguous;\n+\tfor (m = get_multi_pack_index(ds->repo); m && !ds->ambiguous;\n \t     m = m->next)\n \t\tunique_in_midx(m, ds);\n-\tfor (p = get_packed_git(the_repository); p && !ds->ambiguous;\n+\tfor (p = get_packed_git(ds->repo); p && !ds->ambiguous;\n \t     p = p->next)\n \t\tunique_in_pack(p, ds);\n }\n@@ -215,7 +214,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,\n \t\t * same repository!\n \t\t */\n \t\tds->candidate_ok = (!ds->disambiguate_fn_used ||\n-\t\t\t\t    ds->fn(&ds->candidate, ds->cb_data));\n+\t\t\t\t    ds->fn(ds->repo, &ds->candidate, ds->cb_data));\n \n \tif (!ds->candidate_ok)\n \t\treturn SHORT_NAME_AMBIGUOUS;\n@@ -224,59 +223,67 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,\n \treturn 0;\n }\n \n-static int disambiguate_commit_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_commit_only(struct repository *r,\n+\t\t\t\t    const struct object_id *oid,\n+\t\t\t\t    void *cb_data_unused)\n {\n-\tint kind = oid_object_info(the_repository, oid, NULL);\n+\tint kind = oid_object_info(r, oid, NULL);\n \treturn kind == OBJ_COMMIT;\n }\n \n-static int disambiguate_committish_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_committish_only(struct repository *r,\n+\t\t\t\t\tconst struct object_id *oid,\n+\t\t\t\t\tvoid *cb_data_unused)\n {\n \tstruct object *obj;\n \tint kind;\n \n-\tkind = oid_object_info(the_repository, oid, NULL);\n+\tkind = oid_object_info(r, oid, NULL);\n \tif (kind == OBJ_COMMIT)\n \t\treturn 1;\n \tif (kind != OBJ_TAG)\n \t\treturn 0;\n \n \t/* We need to do this the hard way... */\n-\tobj = deref_tag(the_repository, parse_object(the_repository, oid),\n-\t\t\tNULL, 0);\n+\tobj = deref_tag(r, parse_object(r, oid), NULL, 0);\n \tif (obj && obj->type == OBJ_COMMIT)\n \t\treturn 1;\n \treturn 0;\n }\n \n-static int disambiguate_tree_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_tree_only(struct repository *r,\n+\t\t\t\t  const struct object_id *oid,\n+\t\t\t\t  void *cb_data_unused)\n {\n-\tint kind = oid_object_info(the_repository, oid, NULL);\n+\tint kind = oid_object_info(r, oid, NULL);\n \treturn kind == OBJ_TREE;\n }\n \n-static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_treeish_only(struct repository *r,\n+\t\t\t\t     const struct object_id *oid,\n+\t\t\t\t     void *cb_data_unused)\n {\n \tstruct object *obj;\n \tint kind;\n \n-\tkind = oid_object_info(the_repository, oid, NULL);\n+\tkind = oid_object_info(r, oid, NULL);\n \tif (kind == OBJ_TREE || kind == OBJ_COMMIT)\n \t\treturn 1;\n \tif (kind != OBJ_TAG)\n \t\treturn 0;\n \n \t/* We need to do this the hard way... */\n-\tobj = deref_tag(the_repository, parse_object(the_repository, oid),\n-\t\t\tNULL, 0);\n+\tobj = deref_tag(r, parse_object(r, oid), NULL, 0);\n \tif (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))\n \t\treturn 1;\n \treturn 0;\n }\n \n-static int disambiguate_blob_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_blob_only(struct repository *r,\n+\t\t\t\t  const struct object_id *oid,\n+\t\t\t\t  void *cb_data_unused)\n {\n-\tint kind = oid_object_info(the_repository, oid, NULL);\n+\tint kind = oid_object_info(r, oid, NULL);\n \treturn kind == OBJ_BLOB;\n }\n \n@@ -310,7 +317,8 @@ int set_disambiguate_hint_config(const char *var, const char *value)\n \treturn error(\"unknown hint type for '%s': %s\", var, value);\n }\n \n-static int init_object_disambiguation(const char *name, int len,\n+static int init_object_disambiguation(struct repository *r,\n+\t\t\t\t      const char *name, int len,\n \t\t\t\t      struct disambiguate_state *ds)\n {\n \tint i;\n@@ -341,7 +349,8 @@ static int init_object_disambiguation(const char *name, int len,\n \n \tds->len = len;\n \tds->hex_pfx[len] = '\\0';\n-\tprepare_alt_odb(the_repository);\n+\tds->repo = r;\n+\tprepare_alt_odb(r);\n \treturn 0;\n }\n \n@@ -351,25 +360,25 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)\n \tstruct strbuf desc = STRBUF_INIT;\n \tint type;\n \n-\tif (ds->fn && !ds->fn(oid, ds->cb_data))\n+\tif (ds->fn && !ds->fn(ds->repo, oid, ds->cb_data))\n \t\treturn 0;\n \n-\ttype = oid_object_info(the_repository, oid, NULL);\n+\ttype = oid_object_info(ds->repo, oid, NULL);\n \tif (type == OBJ_COMMIT) {\n-\t\tstruct commit *commit = lookup_commit(the_repository, oid);\n+\t\tstruct commit *commit = lookup_commit(ds->repo, oid);\n \t\tif (commit) {\n \t\t\tstruct pretty_print_context pp = {0};\n \t\t\tpp.date_mode.type = DATE_SHORT;\n \t\t\tformat_commit_message(commit, \" %ad - %s\", &desc, &pp);\n \t\t}\n \t} else if (type == OBJ_TAG) {\n-\t\tstruct tag *tag = lookup_tag(the_repository, oid);\n+\t\tstruct tag *tag = lookup_tag(ds->repo, oid);\n \t\tif (!parse_tag(tag) && tag->tag)\n \t\t\tstrbuf_addf(&desc, \" %s\", tag->tag);\n \t}\n \n \tadvise(\"  %s %s%s\",\n-\t       find_unique_abbrev(oid, DEFAULT_ABBREV),\n+\t       repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV),\n \t       type_name(type) ? type_name(type) : \"unknown type\",\n \t       desc.buf);\n \n@@ -383,6 +392,13 @@ static int collect_ambiguous(const struct object_id *oid, void *data)\n \treturn 0;\n }\n \n+static int repo_collect_ambiguous(struct repository *r,\n+\t\t\t\t  const struct object_id *oid,\n+\t\t\t\t  void *data)\n+{\n+\treturn collect_ambiguous(oid, data);\n+}\n+\n static struct repository *sort_ambiguous_repo;\n static int sort_ambiguous(const void *a, const void *b)\n {\n@@ -428,7 +444,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \tstruct disambiguate_state ds;\n \tint quietly = !!(flags & GET_OID_QUIETLY);\n \n-\tif (init_object_disambiguation(name, len, &ds) < 0)\n+\tif (init_object_disambiguation(the_repository, name, len, &ds) < 0)\n \t\treturn -1;\n \n \tif (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))\n@@ -483,11 +499,11 @@ int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)\n \tstruct disambiguate_state ds;\n \tint ret;\n \n-\tif (init_object_disambiguation(prefix, strlen(prefix), &ds) < 0)\n+\tif (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0)\n \t\treturn -1;\n \n \tds.always_call_fn = 1;\n-\tds.fn = collect_ambiguous;\n+\tds.fn = repo_collect_ambiguous;\n \tds.cb_data = &collect;\n \tfind_short_object_filename(&ds);\n \tfind_short_packed_object(&ds);\n@@ -543,6 +559,13 @@ static int extend_abbrev_len(const struct object_id *oid, void *cb_data)\n \treturn 0;\n }\n \n+static int repo_extend_abbrev_len(struct repository *r,\n+\t\t\t\t  const struct object_id *oid,\n+\t\t\t\t  void *cb_data)\n+{\n+\treturn extend_abbrev_len(oid, cb_data);\n+}\n+\n static void find_abbrev_len_for_midx(struct multi_pack_index *m,\n \t\t\t\t     struct min_abbrev_data *mad)\n {\n@@ -668,10 +691,10 @@ int repo_find_unique_abbrev_r(struct repository *r, char *hex,\n \n \tfind_abbrev_len_packed(&mad);\n \n-\tif (init_object_disambiguation(hex, mad.cur_len, &ds) < 0)\n+\tif (init_object_disambiguation(r, hex, mad.cur_len, &ds) < 0)\n \t\treturn -1;\n \n-\tds.fn = extend_abbrev_len;\n+\tds.fn = repo_extend_abbrev_len;\n \tds.always_call_fn = 1;\n \tds.cb_data = (void *)&mad;\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373032","messageId":"20190403113457.20399-16-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 15/32] sha1-name.c: add repo_for_each_abbrev()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:40Z","receivedAt":"2019-04-03T11:36:31Z","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     | 3 ++-\n sha1-name.c | 5 +++--\n 2 files changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 4f8ebb0a67..0cb95c0d4f 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1392,7 +1392,8 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c\n \t\t\t\tstruct object_context *oc);\n \n typedef int each_abbrev_fn(const struct object_id *oid, void *);\n-extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);\n+int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);\n+#define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data)\n \n extern int set_disambiguate_hint_config(const char *var, const char *value);\n \ndiff --git a/sha1-name.c b/sha1-name.c\nindex a75992eb54..cdcf84b826 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -493,13 +493,14 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \treturn status;\n }\n \n-int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)\n+int repo_for_each_abbrev(struct repository *r, const char *prefix,\n+\t\t\t each_abbrev_fn fn, void *cb_data)\n {\n \tstruct oid_array collect = OID_ARRAY_INIT;\n \tstruct disambiguate_state ds;\n \tint ret;\n \n-\tif (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0)\n+\tif (init_object_disambiguation(r, prefix, strlen(prefix), &ds) < 0)\n \t\treturn -1;\n \n \tds.always_call_fn = 1;\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373033","messageId":"20190403113457.20399-17-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 16/32] sha1-name.c: remove the_repo from get_short_oid()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:41Z","receivedAt":"2019-04-03T11:36:36Z","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 | 17 ++++++++++-------\n 1 file changed, 10 insertions(+), 7 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex cdcf84b826..2643b75b54 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -436,7 +436,8 @@ static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)\n \tsort_ambiguous_repo = NULL;\n }\n \n-static enum get_oid_result get_short_oid(const char *name, int len,\n+static enum get_oid_result get_short_oid(struct repository *r,\n+\t\t\t\t\t const char *name, int len,\n \t\t\t\t\t struct object_id *oid,\n \t\t\t\t\t unsigned flags)\n {\n@@ -444,7 +445,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \tstruct disambiguate_state ds;\n \tint quietly = !!(flags & GET_OID_QUIETLY);\n \n-\tif (init_object_disambiguation(the_repository, name, len, &ds) < 0)\n+\tif (init_object_disambiguation(r, name, len, &ds) < 0)\n \t\treturn -1;\n \n \tif (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))\n@@ -482,8 +483,8 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \t\t\tds.fn = NULL;\n \n \t\tadvise(_(\"The candidates are:\"));\n-\t\tfor_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect);\n-\t\tsort_ambiguous_oid_array(the_repository, &collect);\n+\t\trepo_for_each_abbrev(r, ds.hex_pfx, collect_ambiguous, &collect);\n+\t\tsort_ambiguous_oid_array(r, &collect);\n \n \t\tif (oid_array_for_each(&collect, show_ambiguous_object, &ds))\n \t\t\tBUG(\"show_ambiguous_object shouldn't return non-zero\");\n@@ -855,7 +856,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \n \tif (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&\n \t    (refs_found > 1 ||\n-\t     !get_short_oid(str, len, &tmp_oid, GET_OID_QUIETLY)))\n+\t     !get_short_oid(the_repository,\n+\t\t\t    str, len, &tmp_oid, GET_OID_QUIETLY)))\n \t\twarning(warn_msg, len, str);\n \n \tif (reflog_len) {\n@@ -1109,7 +1111,8 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)\n \t\t\tif (ch == 'g' && cp[-1] == '-') {\n \t\t\t\tcp++;\n \t\t\t\tlen -= cp - name;\n-\t\t\t\treturn get_short_oid(cp, len, oid, flags);\n+\t\t\t\treturn get_short_oid(the_repository,\n+\t\t\t\t\t\t     cp, len, oid, flags);\n \t\t\t}\n \t\t}\n \t}\n@@ -1163,7 +1166,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,\n \tif (!ret)\n \t\treturn FOUND;\n \n-\treturn get_short_oid(name, len, oid, lookup_flags);\n+\treturn get_short_oid(the_repository, name, len, oid, lookup_flags);\n }\n \n /*\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373034","messageId":"20190403113457.20399-18-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 17/32] sha1-name.c: remove the_repo from interpret_nth_prior_checkout()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:42Z","receivedAt":"2019-04-03T11:36:42Z","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 | 17 ++++++++++-------\n 1 file changed, 10 insertions(+), 7 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 2643b75b54..af8bf5b351 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -771,7 +771,7 @@ static inline int push_mark(const char *string, int len)\n }\n \n static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);\n-static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);\n+static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);\n \n static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\t\t  unsigned int flags)\n@@ -835,7 +835,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tint detached;\n \n-\t\tif (interpret_nth_prior_checkout(str, len, &buf) > 0) {\n+\t\tif (interpret_nth_prior_checkout(the_repository, str, len, &buf) > 0) {\n \t\t\tdetached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));\n \t\t\tstrbuf_release(&buf);\n \t\t\tif (detached)\n@@ -1288,7 +1288,8 @@ static int grab_nth_branch_switch(struct object_id *ooid, struct object_id *noid\n  * Parse @{-N} syntax, return the number of characters parsed\n  * if successful; otherwise signal an error with negative value.\n  */\n-static int interpret_nth_prior_checkout(const char *name, int namelen,\n+static int interpret_nth_prior_checkout(struct repository *r,\n+\t\t\t\t\tconst char *name, int namelen,\n \t\t\t\t\tstruct strbuf *buf)\n {\n \tlong nth;\n@@ -1312,12 +1313,14 @@ static int interpret_nth_prior_checkout(const char *name, int namelen,\n \tcb.remaining = nth;\n \tstrbuf_init(&cb.buf, 20);\n \n-\tretval = 0;\n-\tif (0 < for_each_reflog_ent_reverse(\"HEAD\", grab_nth_branch_switch, &cb)) {\n+\tretval = refs_for_each_reflog_ent_reverse(get_main_ref_store(r),\n+\t\t\t\"HEAD\", grab_nth_branch_switch, &cb);\n+\tif (0 < retval) {\n \t\tstrbuf_reset(buf);\n \t\tstrbuf_addbuf(buf, &cb.buf);\n \t\tretval = brace - name + 1;\n-\t}\n+\t} else\n+\t\tretval = 0;\n \n \tstrbuf_release(&cb.buf);\n \treturn retval;\n@@ -1484,7 +1487,7 @@ int repo_interpret_branch_name(struct repository *r,\n \t\tnamelen = strlen(name);\n \n \tif (!allowed || (allowed & INTERPRET_BRANCH_LOCAL)) {\n-\t\tlen = interpret_nth_prior_checkout(name, namelen, buf);\n+\t\tlen = interpret_nth_prior_checkout(the_repository, name, namelen, buf);\n \t\tif (!len) {\n \t\t\treturn len; /* syntax Ok, not enough switches */\n \t\t} else if (len > 0) {\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373035","messageId":"20190403113457.20399-19-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 18/32] sha1-name.c: remove the_repo from interpret_branch_mark()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:43Z","receivedAt":"2019-04-03T11:36:48Z","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 | 13 +++++++------\n 1 file changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex af8bf5b351..7d9512ac44 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1412,9 +1412,9 @@ static int reinterpret(const char *name, int namelen, int len,\n \treturn ret - used + len;\n }\n \n-static void set_shortened_ref(struct strbuf *buf, const char *ref)\n+static void set_shortened_ref(struct repository *r, struct strbuf *buf, const char *ref)\n {\n-\tchar *s = shorten_unambiguous_ref(ref, 0);\n+\tchar *s = refs_shorten_unambiguous_ref(get_main_ref_store(r), ref, 0);\n \tstrbuf_reset(buf);\n \tstrbuf_addstr(buf, s);\n \tfree(s);\n@@ -1435,7 +1435,8 @@ static int branch_interpret_allowed(const char *refname, unsigned allowed)\n \treturn 0;\n }\n \n-static int interpret_branch_mark(const char *name, int namelen,\n+static int interpret_branch_mark(struct repository *r,\n+\t\t\t\t const char *name, int namelen,\n \t\t\t\t int at, struct strbuf *buf,\n \t\t\t\t int (*get_mark)(const char *, int),\n \t\t\t\t const char *(*get_data)(struct branch *,\n@@ -1468,7 +1469,7 @@ static int interpret_branch_mark(const char *name, int namelen,\n \tif (!branch_interpret_allowed(value, allowed))\n \t\treturn -1;\n \n-\tset_shortened_ref(buf, value);\n+\tset_shortened_ref(r, buf, value);\n \treturn len + at;\n }\n \n@@ -1509,13 +1510,13 @@ int repo_interpret_branch_name(struct repository *r,\n \t\t\t\t\t\t   allowed);\n \t\t}\n \n-\t\tlen = interpret_branch_mark(name, namelen, at - name, buf,\n+\t\tlen = interpret_branch_mark(the_repository, name, namelen, at - name, buf,\n \t\t\t\t\t    upstream_mark, branch_get_upstream,\n \t\t\t\t\t    allowed);\n \t\tif (len > 0)\n \t\t\treturn len;\n \n-\t\tlen = interpret_branch_mark(name, namelen, at - name, buf,\n+\t\tlen = interpret_branch_mark(the_repository, name, namelen, at - name, buf,\n \t\t\t\t\t    push_mark, branch_get_push,\n \t\t\t\t\t    allowed);\n \t\tif (len > 0)\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373036","messageId":"20190403113457.20399-20-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 19/32] sha1-name.c: add repo_interpret_branch_name()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:44Z","receivedAt":"2019-04-03T11:36:53Z","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 | 17 ++++++++---------\n 1 file changed, 8 insertions(+), 9 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 7d9512ac44..49c62d5254 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1390,7 +1390,8 @@ static int interpret_empty_at(const char *name, int namelen, int len, struct str\n \treturn 1;\n }\n \n-static int reinterpret(const char *name, int namelen, int len,\n+static int reinterpret(struct repository *r,\n+\t\t       const char *name, int namelen, int len,\n \t\t       struct strbuf *buf, unsigned allowed)\n {\n \t/* we have extra data, which might need further processing */\n@@ -1399,7 +1400,7 @@ static int reinterpret(const char *name, int namelen, int len,\n \tint ret;\n \n \tstrbuf_add(buf, name + len, namelen - len);\n-\tret = interpret_branch_name(buf->buf, buf->len, &tmp, allowed);\n+\tret = repo_interpret_branch_name(r, buf->buf, buf->len, &tmp, allowed);\n \t/* that data was not interpreted, remove our cruft */\n \tif (ret < 0) {\n \t\tstrbuf_setlen(buf, used);\n@@ -1482,20 +1483,18 @@ int repo_interpret_branch_name(struct repository *r,\n \tconst char *start;\n \tint len;\n \n-\tif (r != the_repository)\n-\t\tBUG(\"interpret_branch_name() does not really use 'r' yet\");\n \tif (!namelen)\n \t\tnamelen = strlen(name);\n \n \tif (!allowed || (allowed & INTERPRET_BRANCH_LOCAL)) {\n-\t\tlen = interpret_nth_prior_checkout(the_repository, name, namelen, buf);\n+\t\tlen = interpret_nth_prior_checkout(r, name, namelen, buf);\n \t\tif (!len) {\n \t\t\treturn len; /* syntax Ok, not enough switches */\n \t\t} else if (len > 0) {\n \t\t\tif (len == namelen)\n \t\t\t\treturn len; /* consumed all */\n \t\t\telse\n-\t\t\t\treturn reinterpret(name, namelen, len, buf, allowed);\n+\t\t\t\treturn reinterpret(r, name, namelen, len, buf, allowed);\n \t\t}\n \t}\n \n@@ -1506,17 +1505,17 @@ int repo_interpret_branch_name(struct repository *r,\n \t\tif (!allowed || (allowed & INTERPRET_BRANCH_HEAD)) {\n \t\t\tlen = interpret_empty_at(name, namelen, at - name, buf);\n \t\t\tif (len > 0)\n-\t\t\t\treturn reinterpret(name, namelen, len, buf,\n+\t\t\t\treturn reinterpret(r, name, namelen, len, buf,\n \t\t\t\t\t\t   allowed);\n \t\t}\n \n-\t\tlen = interpret_branch_mark(the_repository, name, namelen, at - name, buf,\n+\t\tlen = interpret_branch_mark(r, name, namelen, at - name, buf,\n \t\t\t\t\t    upstream_mark, branch_get_upstream,\n \t\t\t\t\t    allowed);\n \t\tif (len > 0)\n \t\t\treturn len;\n \n-\t\tlen = interpret_branch_mark(the_repository, name, namelen, at - name, buf,\n+\t\tlen = interpret_branch_mark(r, name, namelen, at - name, buf,\n \t\t\t\t\t    push_mark, branch_get_push,\n \t\t\t\t\t    allowed);\n \t\tif (len > 0)\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373037","messageId":"20190403113457.20399-21-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 20/32] sha1-name.c: remove the_repo from get_oid_oneline()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:45Z","receivedAt":"2019-04-03T11:36: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 sha1-name.c | 13 +++++++------\n 1 file changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 49c62d5254..fb80306f1a 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -15,7 +15,7 @@\n #include \"midx.h\"\n #include \"commit-reach.h\"\n \n-static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);\n+static int get_oid_oneline(struct repository *r, const char *, struct object_id *, struct commit_list *);\n \n typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);\n \n@@ -1090,7 +1090,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \n \t\tprefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));\n \t\tcommit_list_insert((struct commit *)o, &list);\n-\t\tret = get_oid_oneline(prefix, oid, list);\n+\t\tret = get_oid_oneline(the_repository, prefix, oid, list);\n \t\tfree(prefix);\n \t\treturn ret;\n \t}\n@@ -1204,8 +1204,9 @@ static int handle_one_ref(const char *path, const struct object_id *oid,\n \treturn 0;\n }\n \n-static int get_oid_oneline(const char *prefix, struct object_id *oid,\n-\t\t\t    struct commit_list *list)\n+static int get_oid_oneline(struct repository *r,\n+\t\t\t   const char *prefix, struct object_id *oid,\n+\t\t\t   struct commit_list *list)\n {\n \tstruct commit_list *backup = NULL, *l;\n \tint found = 0;\n@@ -1236,7 +1237,7 @@ static int get_oid_oneline(const char *prefix, struct object_id *oid,\n \t\tint matches;\n \n \t\tcommit = pop_most_recent_commit(&list, ONELINE_SEEN);\n-\t\tif (!parse_object(the_repository, &commit->object.oid))\n+\t\tif (!parse_object(r, &commit->object.oid))\n \t\t\tcontinue;\n \t\tbuf = get_commit_buffer(commit, NULL);\n \t\tp = strstr(buf, \"\\n\\n\");\n@@ -1760,7 +1761,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\tfor_each_ref(handle_one_ref, &list);\n \t\t\thead_ref(handle_one_ref, &list);\n \t\t\tcommit_list_sort_by_date(&list);\n-\t\t\treturn get_oid_oneline(name + 2, oid, list);\n+\t\t\treturn get_oid_oneline(repo, name + 2, oid, list);\n \t\t}\n \t\tif (namelen < 3 ||\n \t\t    name[2] != ':' ||\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373038","messageId":"20190403113457.20399-22-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 21/32] sha1-name.c: remove the_repo from get_describe_name()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:46Z","receivedAt":"2019-04-03T11:37:03Z","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 | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex fb80306f1a..1cda854f02 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1097,7 +1097,9 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \treturn 0;\n }\n \n-static int get_describe_name(const char *name, int len, struct object_id *oid)\n+static int get_describe_name(struct repository *r,\n+\t\t\t     const char *name, int len,\n+\t\t\t     struct object_id *oid)\n {\n \tconst char *cp;\n \tunsigned flags = GET_OID_QUIETLY | GET_OID_COMMIT;\n@@ -1111,7 +1113,7 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)\n \t\t\tif (ch == 'g' && cp[-1] == '-') {\n \t\t\t\tcp++;\n \t\t\t\tlen -= cp - name;\n-\t\t\t\treturn get_short_oid(the_repository,\n+\t\t\t\treturn get_short_oid(r,\n \t\t\t\t\t\t     cp, len, oid, flags);\n \t\t\t}\n \t\t}\n@@ -1162,7 +1164,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,\n \t\treturn FOUND;\n \n \t/* It could be describe output that is \"SOMETHING-gXXXX\" */\n-\tret = get_describe_name(name, len, oid);\n+\tret = get_describe_name(the_repository, name, len, oid);\n \tif (!ret)\n \t\treturn FOUND;\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373039","messageId":"20190403113457.20399-23-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 22/32] sha1-name.c: remove the_repo from get_oid_basic()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:47Z","receivedAt":"2019-04-03T11:37:08Z","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 | 25 ++++++++++++-------------\n 1 file changed, 12 insertions(+), 13 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 1cda854f02..d4c135aea8 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -773,8 +773,8 @@ static inline int push_mark(const char *string, int len)\n static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);\n static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);\n \n-static int get_oid_basic(const char *str, int len, struct object_id *oid,\n-\t\t\t  unsigned int flags)\n+static int get_oid_basic(struct repository *r, const char *str, int len,\n+\t\t\t struct object_id *oid, unsigned int flags)\n {\n \tstatic const char *warn_msg = \"refname '%.*s' is ambiguous.\";\n \tstatic const char *object_name_msg = N_(\n@@ -792,9 +792,9 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \tint refs_found = 0;\n \tint at, reflog_len, nth_prior = 0;\n \n-\tif (len == the_hash_algo->hexsz && !get_oid_hex(str, oid)) {\n+\tif (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {\n \t\tif (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {\n-\t\t\trefs_found = dwim_ref(str, len, &tmp_oid, &real_ref);\n+\t\t\trefs_found = repo_dwim_ref(r, str, len, &tmp_oid, &real_ref);\n \t\t\tif (refs_found > 0) {\n \t\t\t\twarning(warn_msg, len, str);\n \t\t\t\tif (advice_object_name_warning)\n@@ -835,8 +835,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tint detached;\n \n-\t\tif (interpret_nth_prior_checkout(the_repository, str, len, &buf) > 0) {\n-\t\t\tdetached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));\n+\t\tif (interpret_nth_prior_checkout(r, str, len, &buf) > 0) {\n+\t\t\tdetached = (buf.len == r->hash_algo->hexsz && !get_oid_hex(buf.buf, oid));\n \t\t\tstrbuf_release(&buf);\n \t\t\tif (detached)\n \t\t\t\treturn 0;\n@@ -845,19 +845,18 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \n \tif (!len && reflog_len)\n \t\t/* allow \"@{...}\" to mean the current branch reflog */\n-\t\trefs_found = dwim_ref(\"HEAD\", 4, oid, &real_ref);\n+\t\trefs_found = repo_dwim_ref(r, \"HEAD\", 4, oid, &real_ref);\n \telse if (reflog_len)\n-\t\trefs_found = dwim_log(str, len, oid, &real_ref);\n+\t\trefs_found = repo_dwim_log(r, str, len, oid, &real_ref);\n \telse\n-\t\trefs_found = dwim_ref(str, len, oid, &real_ref);\n+\t\trefs_found = repo_dwim_ref(r, str, len, oid, &real_ref);\n \n \tif (!refs_found)\n \t\treturn -1;\n \n \tif (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&\n \t    (refs_found > 1 ||\n-\t     !get_short_oid(the_repository,\n-\t\t\t    str, len, &tmp_oid, GET_OID_QUIETLY)))\n+\t     !get_short_oid(r, str, len, &tmp_oid, GET_OID_QUIETLY)))\n \t\twarning(warn_msg, len, str);\n \n \tif (reflog_len) {\n@@ -889,7 +888,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\t\t\treturn -1;\n \t\t\t}\n \t\t}\n-\t\tif (read_ref_at(get_main_ref_store(the_repository),\n+\t\tif (read_ref_at(get_main_ref_store(r),\n \t\t\t\treal_ref, flags, at_time, nth, oid, NULL,\n \t\t\t\t&co_time, &co_tz, &co_cnt)) {\n \t\t\tif (!len) {\n@@ -1159,7 +1158,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,\n \tif (!ret)\n \t\treturn FOUND;\n \n-\tret = get_oid_basic(name, len, oid, lookup_flags);\n+\tret = get_oid_basic(the_repository, name, len, oid, lookup_flags);\n \tif (!ret)\n \t\treturn FOUND;\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373040","messageId":"20190403113457.20399-24-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 23/32] sha1-name.c: remove the_repo from get_oid_1()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:48Z","receivedAt":"2019-04-03T11:37:14Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"There is a cyclic dependency between one of these functions so they\ncannot be converted one by one, so all related functions are converted\nat once.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n cache.h     |  7 +++++--\n sha1-name.c | 59 ++++++++++++++++++++++++++++-------------------------\n 2 files changed, 36 insertions(+), 30 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 0cb95c0d4f..2149dc4f56 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1491,8 +1491,11 @@ extern void *read_object_with_reference(const struct object_id *oid,\n \t\t\t\t\tunsigned long *size,\n \t\t\t\t\tstruct object_id *oid_ret);\n \n-extern struct object *peel_to_type(const char *name, int namelen,\n-\t\t\t\t   struct object *o, enum object_type);\n+struct object *repo_peel_to_type(struct repository *r,\n+\t\t\t\t const char *name, int namelen,\n+\t\t\t\t struct object *o, enum object_type);\n+#define peel_to_type(name, namelen, obj, type) \\\n+\trepo_peel_to_type(the_repository, name, namelen, obj, type)\n \n enum date_mode_type {\n \tDATE_NORMAL = 0,\ndiff --git a/sha1-name.c b/sha1-name.c\nindex d4c135aea8..5741a9f821 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -770,7 +770,7 @@ static inline int push_mark(const char *string, int len)\n \treturn at_mark(string, len, suffix, ARRAY_SIZE(suffix));\n }\n \n-static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);\n+static enum get_oid_result get_oid_1(struct repository *r, const char *name, int len, struct object_id *oid, unsigned lookup_flags);\n static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);\n \n static int get_oid_basic(struct repository *r, const char *str, int len,\n@@ -921,18 +921,19 @@ static int get_oid_basic(struct repository *r, const char *str, int len,\n \treturn 0;\n }\n \n-static enum get_oid_result get_parent(const char *name, int len,\n+static enum get_oid_result get_parent(struct repository *r,\n+\t\t\t\t      const char *name, int len,\n \t\t\t\t      struct object_id *result, int idx)\n {\n \tstruct object_id oid;\n-\tenum get_oid_result ret = get_oid_1(name, len, &oid,\n+\tenum get_oid_result ret = get_oid_1(r, name, len, &oid,\n \t\t\t\t\t    GET_OID_COMMITTISH);\n \tstruct commit *commit;\n \tstruct commit_list *p;\n \n \tif (ret)\n \t\treturn ret;\n-\tcommit = lookup_commit_reference(the_repository, &oid);\n+\tcommit = lookup_commit_reference(r, &oid);\n \tif (parse_commit(commit))\n \t\treturn MISSING_OBJECT;\n \tif (!idx) {\n@@ -950,7 +951,8 @@ static enum get_oid_result get_parent(const char *name, int len,\n \treturn MISSING_OBJECT;\n }\n \n-static enum get_oid_result get_nth_ancestor(const char *name, int len,\n+static enum get_oid_result get_nth_ancestor(struct repository *r,\n+\t\t\t\t\t    const char *name, int len,\n \t\t\t\t\t    struct object_id *result,\n \t\t\t\t\t    int generation)\n {\n@@ -958,10 +960,10 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,\n \tstruct commit *commit;\n \tint ret;\n \n-\tret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);\n+\tret = get_oid_1(r, name, len, &oid, GET_OID_COMMITTISH);\n \tif (ret)\n \t\treturn ret;\n-\tcommit = lookup_commit_reference(the_repository, &oid);\n+\tcommit = lookup_commit_reference(r, &oid);\n \tif (!commit)\n \t\treturn MISSING_OBJECT;\n \n@@ -974,20 +976,20 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,\n \treturn FOUND;\n }\n \n-struct object *peel_to_type(const char *name, int namelen,\n-\t\t\t    struct object *o, enum object_type expected_type)\n+struct object *repo_peel_to_type(struct repository *r, const char *name, int namelen,\n+\t\t\t\t struct object *o, enum object_type expected_type)\n {\n \tif (name && !namelen)\n \t\tnamelen = strlen(name);\n \twhile (1) {\n-\t\tif (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))\n+\t\tif (!o || (!o->parsed && !parse_object(r, &o->oid)))\n \t\t\treturn NULL;\n \t\tif (expected_type == OBJ_ANY || o->type == expected_type)\n \t\t\treturn o;\n \t\tif (o->type == OBJ_TAG)\n \t\t\to = ((struct tag*) o)->tagged;\n \t\telse if (o->type == OBJ_COMMIT)\n-\t\t\to = &(get_commit_tree(((struct commit *)o))->object);\n+\t\t\to = &(repo_get_commit_tree(r, ((struct commit *)o))->object);\n \t\telse {\n \t\t\tif (name)\n \t\t\t\terror(\"%.*s: expected %s type, but the object \"\n@@ -999,8 +1001,8 @@ struct object *peel_to_type(const char *name, int namelen,\n \t}\n }\n \n-static int peel_onion(const char *name, int len, struct object_id *oid,\n-\t\t      unsigned lookup_flags)\n+static int peel_onion(struct repository *r, const char *name, int len,\n+\t\t      struct object_id *oid, unsigned lookup_flags)\n {\n \tstruct object_id outer;\n \tconst char *sp;\n@@ -1050,15 +1052,15 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \telse if (expected_type == OBJ_TREE)\n \t\tlookup_flags |= GET_OID_TREEISH;\n \n-\tif (get_oid_1(name, sp - name - 2, &outer, lookup_flags))\n+\tif (get_oid_1(r, name, sp - name - 2, &outer, lookup_flags))\n \t\treturn -1;\n \n-\to = parse_object(the_repository, &outer);\n+\to = parse_object(r, &outer);\n \tif (!o)\n \t\treturn -1;\n \tif (!expected_type) {\n-\t\to = deref_tag(the_repository, o, name, sp - name - 2);\n-\t\tif (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))\n+\t\to = deref_tag(r, o, name, sp - name - 2);\n+\t\tif (!o || (!o->parsed && !parse_object(r, &o->oid)))\n \t\t\treturn -1;\n \t\toidcpy(oid, &o->oid);\n \t\treturn 0;\n@@ -1069,7 +1071,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \t * if we do not get the needed object, we should\n \t * barf.\n \t */\n-\to = peel_to_type(name, len, o, expected_type);\n+\to = repo_peel_to_type(r, name, len, o, expected_type);\n \tif (!o)\n \t\treturn -1;\n \n@@ -1089,7 +1091,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \n \t\tprefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));\n \t\tcommit_list_insert((struct commit *)o, &list);\n-\t\tret = get_oid_oneline(the_repository, prefix, oid, list);\n+\t\tret = get_oid_oneline(r, prefix, oid, list);\n \t\tfree(prefix);\n \t\treturn ret;\n \t}\n@@ -1120,7 +1122,8 @@ static int get_describe_name(struct repository *r,\n \treturn -1;\n }\n \n-static enum get_oid_result get_oid_1(const char *name, int len,\n+static enum get_oid_result get_oid_1(struct repository *r,\n+\t\t\t\t     const char *name, int len,\n \t\t\t\t     struct object_id *oid,\n \t\t\t\t     unsigned lookup_flags)\n {\n@@ -1149,25 +1152,25 @@ static enum get_oid_result get_oid_1(const char *name, int len,\n \t\tif (!num && len1 == len - 1)\n \t\t\tnum = 1;\n \t\tif (has_suffix == '^')\n-\t\t\treturn get_parent(name, len1, oid, num);\n+\t\t\treturn get_parent(r, name, len1, oid, num);\n \t\t/* else if (has_suffix == '~') -- goes without saying */\n-\t\treturn get_nth_ancestor(name, len1, oid, num);\n+\t\treturn get_nth_ancestor(r, name, len1, oid, num);\n \t}\n \n-\tret = peel_onion(name, len, oid, lookup_flags);\n+\tret = peel_onion(r, name, len, oid, lookup_flags);\n \tif (!ret)\n \t\treturn FOUND;\n \n-\tret = get_oid_basic(the_repository, name, len, oid, lookup_flags);\n+\tret = get_oid_basic(r, name, len, oid, lookup_flags);\n \tif (!ret)\n \t\treturn FOUND;\n \n \t/* It could be describe output that is \"SOMETHING-gXXXX\" */\n-\tret = get_describe_name(the_repository, name, len, oid);\n+\tret = get_describe_name(r, name, len, oid);\n \tif (!ret)\n \t\treturn FOUND;\n \n-\treturn get_short_oid(the_repository, name, len, oid, lookup_flags);\n+\treturn get_short_oid(r, name, len, oid, lookup_flags);\n }\n \n /*\n@@ -1741,7 +1744,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \tmemset(oc, 0, sizeof(*oc));\n \toc->mode = S_IFINVALID;\n \tstrbuf_init(&oc->symlink_path, 0);\n-\tret = get_oid_1(name, namelen, oid, flags);\n+\tret = get_oid_1(repo, name, namelen, oid, flags);\n \tif (!ret)\n \t\treturn ret;\n \t/*\n@@ -1822,7 +1825,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\tsub_flags &= ~GET_OID_DISAMBIGUATORS;\n \t\tsub_flags |= GET_OID_TREEISH;\n \n-\t\tif (!get_oid_1(name, len, &tree_oid, sub_flags)) {\n+\t\tif (!get_oid_1(repo, name, len, &tree_oid, sub_flags)) {\n \t\t\tconst char *filename = cp+1;\n \t\t\tchar *new_filename = NULL;\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373041","messageId":"20190403113457.20399-25-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 24/32] sha1-name.c: remove the_repo from handle_one_ref()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:49Z","receivedAt":"2019-04-03T11:37:19Z","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 | 19 ++++++++++++++-----\n 1 file changed, 14 insertions(+), 5 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 5741a9f821..d9050776dd 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1189,15 +1189,21 @@ static enum get_oid_result get_oid_1(struct repository *r,\n /* Remember to update object flag allocation in object.h */\n #define ONELINE_SEEN (1u<<20)\n \n+struct handle_one_ref_cb {\n+\tstruct repository *repo;\n+\tstruct commit_list **list;\n+};\n+\n static int handle_one_ref(const char *path, const struct object_id *oid,\n \t\t\t  int flag, void *cb_data)\n {\n-\tstruct commit_list **list = cb_data;\n-\tstruct object *object = parse_object(the_repository, oid);\n+\tstruct handle_one_ref_cb *cb = cb_data;\n+\tstruct commit_list **list = cb->list;\n+\tstruct object *object = parse_object(cb->repo, oid);\n \tif (!object)\n \t\treturn 0;\n \tif (object->type == OBJ_TAG) {\n-\t\tobject = deref_tag(the_repository, object, path,\n+\t\tobject = deref_tag(cb->repo, object, path,\n \t\t\t\t   strlen(path));\n \t\tif (!object)\n \t\t\treturn 0;\n@@ -1760,10 +1766,13 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\tchar *new_path = NULL;\n \t\tint pos;\n \t\tif (!only_to_die && namelen > 2 && name[1] == '/') {\n+\t\t\tstruct handle_one_ref_cb cb;\n \t\t\tstruct commit_list *list = NULL;\n \n-\t\t\tfor_each_ref(handle_one_ref, &list);\n-\t\t\thead_ref(handle_one_ref, &list);\n+\t\t\tcb.repo = repo;\n+\t\t\tcb.list = &list;\n+\t\t\trefs_for_each_ref(repo->refs, handle_one_ref, &cb);\n+\t\t\trefs_head_ref(repo->refs, handle_one_ref, &cb);\n \t\t\tcommit_list_sort_by_date(&list);\n \t\t\treturn get_oid_oneline(repo, name + 2, oid, list);\n \t\t}\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373042","messageId":"20190403113457.20399-26-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 25/32] sha1-name.c: remove the_repo from diagnose_invalid_index_path()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:50Z","receivedAt":"2019-04-03T11:37:24Z","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 dir.c       | 8 ++++++++\n dir.h       | 4 +++-\n sha1-name.c | 7 ++++---\n 3 files changed, 15 insertions(+), 4 deletions(-)\n\ndiff --git a/dir.c b/dir.c\nindex b2cabadf25..e6d97343f4 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -2315,6 +2315,14 @@ int file_exists(const char *f)\n \treturn lstat(f, &sb) == 0;\n }\n \n+int repo_file_exists(struct repository *repo, const char *path)\n+{\n+\tif (repo != the_repository)\n+\t\tBUG(\"do not know how to check file existence in arbitrary repo\");\n+\n+\treturn file_exists(path);\n+}\n+\n static int cmp_icase(char a, char b)\n {\n \tif (a == b)\ndiff --git a/dir.h b/dir.h\nindex e3ec26143d..47c5409ced 100644\n--- a/dir.h\n+++ b/dir.h\n@@ -269,7 +269,9 @@ extern void add_exclude(const char *string, const char *base,\n \t\t\tint baselen, struct exclude_list *el, int srcpos);\n extern void clear_exclude_list(struct exclude_list *el);\n extern void clear_directory(struct dir_struct *dir);\n-extern int file_exists(const char *);\n+\n+int repo_file_exists(struct repository *repo, const char *path);\n+int file_exists(const char *);\n \n extern int is_inside_dir(const char *dir);\n extern int dir_inside_of(const char *subdir, const char *dir);\ndiff --git a/sha1-name.c b/sha1-name.c\nindex d9050776dd..6caf3f4e3a 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1664,11 +1664,12 @@ static void diagnose_invalid_oid_path(const char *prefix,\n }\n \n /* Must be called only when :stage:filename doesn't exist. */\n-static void diagnose_invalid_index_path(struct index_state *istate,\n+static void diagnose_invalid_index_path(struct repository *r,\n \t\t\t\t\tint stage,\n \t\t\t\t\tconst char *prefix,\n \t\t\t\t\tconst char *filename)\n {\n+\tstruct index_state *istate = r->index;\n \tconst struct cache_entry *ce;\n \tint pos;\n \tunsigned namelen = strlen(filename);\n@@ -1708,7 +1709,7 @@ static void diagnose_invalid_index_path(struct index_state *istate,\n \t\t\t    ce_stage(ce), filename);\n \t}\n \n-\tif (file_exists(filename))\n+\tif (repo_file_exists(r, filename))\n \t\tdie(\"Path '%s' exists on disk, but not in the index.\", filename);\n \tif (is_missing_file_error(errno))\n \t\tdie(\"Path '%s' does not exist (neither on disk nor in the index).\",\n@@ -1814,7 +1815,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\tpos++;\n \t\t}\n \t\tif (only_to_die && name[1] && name[1] != '/')\n-\t\t\tdiagnose_invalid_index_path(repo->index, stage, prefix, cp);\n+\t\t\tdiagnose_invalid_index_path(repo, stage, prefix, cp);\n \t\tfree(new_path);\n \t\treturn -1;\n \t}\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373043","messageId":"20190403113457.20399-27-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 26/32] sha1-name.c: remove the_repo from resolve_relative_path()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:51Z","receivedAt":"2019-04-03T11:37:30Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\"remove\" is not entirely correct. But at least the function is aware\nthat if the given repo is not the_repository, then $CWD and\nis_inside_work_tree() means nothing.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n sha1-name.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 6caf3f4e3a..6b53ea2eeb 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1719,12 +1719,12 @@ static void diagnose_invalid_index_path(struct repository *r,\n }\n \n \n-static char *resolve_relative_path(const char *rel)\n+static char *resolve_relative_path(struct repository *r, const char *rel)\n {\n \tif (!starts_with(rel, \"./\") && !starts_with(rel, \"../\"))\n \t\treturn NULL;\n \n-\tif (!is_inside_work_tree())\n+\tif (r != the_repository || !is_inside_work_tree())\n \t\tdie(\"relative path syntax can't be used outside working tree.\");\n \n \t/* die() inside prefix_path() if resolved path is outside worktree */\n@@ -1785,7 +1785,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\tstage = name[1] - '0';\n \t\t\tcp = name + 3;\n \t\t}\n-\t\tnew_path = resolve_relative_path(cp);\n+\t\tnew_path = resolve_relative_path(repo, cp);\n \t\tif (!new_path) {\n \t\t\tnamelen = namelen - (cp - name);\n \t\t} else {\n@@ -1839,7 +1839,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\tconst char *filename = cp+1;\n \t\t\tchar *new_filename = NULL;\n \n-\t\t\tnew_filename = resolve_relative_path(filename);\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\tif (flags & GET_OID_FOLLOW_SYMLINKS) {\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373044","messageId":"20190403113457.20399-28-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 27/32] sha1-name.c: remove the_repo from get_oid_with_context_1()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:52Z","receivedAt":"2019-04-03T11:37:35Z","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 | 11 ++++++++++-\n 1 file changed, 10 insertions(+), 1 deletion(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 6b53ea2eeb..64a50d1291 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -12,6 +12,7 @@\n #include \"packfile.h\"\n #include \"object-store.h\"\n #include \"repository.h\"\n+#include \"submodule.h\"\n #include \"midx.h\"\n #include \"commit-reach.h\"\n \n@@ -1797,7 +1798,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\toc->path = xstrdup(cp);\n \n \t\tif (!repo->index->cache)\n-\t\t\trepo_read_index(the_repository);\n+\t\t\trepo_read_index(repo);\n \t\tpos = index_name_pos(repo->index, cp, namelen);\n \t\tif (pos < 0)\n \t\t\tpos = -pos - 1;\n@@ -1842,6 +1843,14 @@ 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\t\tfilename, oid, &oc->symlink_path,\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373045","messageId":"20190403113457.20399-29-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 28/32] sha1-name.c: add repo_get_oid()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:53Z","receivedAt":"2019-04-03T11:37:40Z","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     | 3 ++-\n sha1-name.c | 4 ++--\n 2 files changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 2149dc4f56..f6e87194d0 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1380,7 +1380,8 @@ enum get_oid_result {\n \t\t       */\n };\n \n-extern int get_oid(const char *str, struct object_id *oid);\n+int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);\n+#define get_oid(str, oid) repo_get_oid(the_repository, str, oid)\n extern int get_oid_commit(const char *str, struct object_id *oid);\n extern int get_oid_committish(const char *str, struct object_id *oid);\n extern int get_oid_tree(const char *str, struct object_id *oid);\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 64a50d1291..953df0d692 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1573,10 +1573,10 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)\n  * This is like \"get_oid_basic()\", except it allows \"object ID expressions\",\n  * notably \"xyz^\" for \"parent of xyz\"\n  */\n-int get_oid(const char *name, struct object_id *oid)\n+int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository, name, 0, oid, &unused);\n+\treturn get_oid_with_context(r, name, 0, oid, &unused);\n }\n \n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373046","messageId":"20190403113457.20399-30-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 29/32] submodule-config.c: use repo_get_oid for reading .gitmodules","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:54Z","receivedAt":"2019-04-03T11:37:46Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Since 76e9bdc437 (submodule: support reading .gitmodules when it's not\nin the working tree - 2018-10-25), every time you do\n\n    git grep --recurse-submodules\n\nyou are likely to see one warning line per submodule (unless all those\nsubmodules also have submodules). On a superproject with plenty of\nsubmodules (I've seen one with 67) this is really annoying.\n\nThe warning was there because we could not resolve extended SHA-1\nsyntax on a submodule. We can now. Make use of the new API and get rid\nof the warning.\n\nIt would be even better if config_with_options() supports multiple\nrepositories too. But one step at a time.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n submodule-config.c                 | 20 +++++++-------------\n t/t7814-grep-recurse-submodules.sh |  6 +-----\n 2 files changed, 8 insertions(+), 18 deletions(-)\n\ndiff --git a/submodule-config.c b/submodule-config.c\nindex 66653e86b9..4264ee216f 100644\n--- a/submodule-config.c\n+++ b/submodule-config.c\n@@ -625,23 +625,16 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void\n \t\tconst struct config_options opts = { 0 };\n \t\tstruct object_id oid;\n \t\tchar *file;\n+\t\tchar *oidstr = NULL;\n \n \t\tfile = repo_worktree_path(repo, GITMODULES_FILE);\n \t\tif (file_exists(file)) {\n \t\t\tconfig_source.file = file;\n-\t\t} else if (repo->submodule_prefix) {\n-\t\t\t/*\n-\t\t\t * When get_oid and config_with_options, used below,\n-\t\t\t * become able to work on a specific repository, this\n-\t\t\t * warning branch can be removed.\n-\t\t\t */\n-\t\t\twarning(\"nested submodules without %s in the working tree are not supported yet\",\n-\t\t\t\tGITMODULES_FILE);\n-\t\t\tgoto out;\n-\t\t} else if (get_oid(GITMODULES_INDEX, &oid) >= 0) {\n-\t\t\tconfig_source.blob = GITMODULES_INDEX;\n-\t\t} else if (get_oid(GITMODULES_HEAD, &oid) >= 0) {\n-\t\t\tconfig_source.blob = GITMODULES_HEAD;\n+\t\t} else if (repo_get_oid(repo, GITMODULES_INDEX, &oid) >= 0 ||\n+\t\t\t   repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {\n+\t\t\tconfig_source.blob = oidstr = xstrdup(oid_to_hex(&oid));\n+\t\t\tif (repo != the_repository)\n+\t\t\t\tadd_to_alternates_memory(repo->objects->odb->path);\n \t\t} else {\n \t\t\tgoto out;\n \t\t}\n@@ -649,6 +642,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void\n \t\tconfig_with_options(fn, data, &config_source, &opts);\n \n out:\n+\t\tfree(oidstr);\n \t\tfree(file);\n \t}\n }\ndiff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh\nindex fa475d52fa..134a694516 100755\n--- a/t/t7814-grep-recurse-submodules.sh\n+++ b/t/t7814-grep-recurse-submodules.sh\n@@ -380,11 +380,7 @@ test_expect_success 'grep --recurse-submodules should pass the pattern type alon\n \tfi\n '\n \n-# Recursing down into nested submodules which do not have .gitmodules in their\n-# working tree does not work yet. This is because config_from_gitmodules()\n-# uses get_oid() and the latter is still not able to get objects from an\n-# arbitrary repository (the nested submodule, in this case).\n-test_expect_failure 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '\n+test_expect_success 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '\n \ttest_when_finished \"git -C submodule checkout .gitmodules\" &&\n \trm submodule/.gitmodules &&\n \tgit grep --recurse-submodules -e \"(.|.)[\\d]\" >actual &&\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373047","messageId":"20190403113457.20399-31-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 30/32] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:55Z","receivedAt":"2019-04-03T11:37:51Z","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 setup.c     | 7 ++++---\n sha1-name.c | 6 ++++--\n 3 files changed, 11 insertions(+), 6 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex f6e87194d0..3718b3db8a 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1387,7 +1387,9 @@ extern int get_oid_committish(const char *str, struct object_id *oid);\n extern int get_oid_tree(const char *str, struct object_id *oid);\n extern int get_oid_treeish(const char *str, struct object_id *oid);\n extern int get_oid_blob(const char *str, struct object_id *oid);\n-extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);\n+void maybe_die_on_misspelt_object_name(struct repository *repo,\n+\t\t\t\t       const char *name,\n+\t\t\t\t       const char *prefix);\n extern enum get_oid_result get_oid_with_context(struct repository *repo, const char *str,\n \t\t\t\tunsigned flags, struct object_id *oid,\n \t\t\t\tstruct object_context *oc);\ndiff --git a/setup.c b/setup.c\nindex d0c958c3b2..8dcb4631f7 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -164,7 +164,8 @@ int check_filename(const char *prefix, const char *arg)\n \tdie_errno(_(\"failed to stat '%s'\"), arg);\n }\n \n-static void NORETURN die_verify_filename(const char *prefix,\n+static void NORETURN die_verify_filename(struct repository *r,\n+\t\t\t\t\t const char *prefix,\n \t\t\t\t\t const char *arg,\n \t\t\t\t\t int diagnose_misspelt_rev)\n {\n@@ -179,7 +180,7 @@ static void NORETURN die_verify_filename(const char *prefix,\n \t * let maybe_die_on_misspelt_object_name() even trigger.\n \t */\n \tif (!(arg[0] == ':' && !isalnum(arg[1])))\n-\t\tmaybe_die_on_misspelt_object_name(arg, prefix);\n+\t\tmaybe_die_on_misspelt_object_name(r, arg, prefix);\n \n \t/* ... or fall back the most general message. */\n \tdie(_(\"ambiguous argument '%s': unknown revision or path not in the working tree.\\n\"\n@@ -234,7 +235,7 @@ void verify_filename(const char *prefix,\n \t\tdie(_(\"option '%s' must come before non-option arguments\"), arg);\n \tif (looks_like_pathspec(arg) || check_filename(prefix, arg))\n \t\treturn;\n-\tdie_verify_filename(prefix, arg, diagnose_misspelt_rev);\n+\tdie_verify_filename(the_repository, prefix, arg, diagnose_misspelt_rev);\n }\n \n /*\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 953df0d692..b94d381bef 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1885,11 +1885,13 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n  * exist in 'HEAD'\" when given \"HEAD:doc\", or it may return in which case\n  * you have a chance to diagnose the error further.\n  */\n-void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)\n+void maybe_die_on_misspelt_object_name(struct repository *r,\n+\t\t\t\t       const char *name,\n+\t\t\t\t       const char *prefix)\n {\n \tstruct object_context oc;\n \tstruct object_id oid;\n-\tget_oid_with_context_1(the_repository, name, GET_OID_ONLY_TO_DIE,\n+\tget_oid_with_context_1(r, name, GET_OID_ONLY_TO_DIE,\n \t\t\t       prefix, &oid, &oc);\n }\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373048","messageId":"20190403113457.20399-32-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 31/32] sha1-name.c: remove the_repo from other get_oid_*","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:56Z","receivedAt":"2019-04-03T11:37:57Z","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     | 18 ++++++++++++------\n sha1-name.c | 35 ++++++++++++++++++++---------------\n 2 files changed, 32 insertions(+), 21 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 3718b3db8a..871a167bf8 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1381,12 +1381,11 @@ enum get_oid_result {\n };\n \n int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);\n-#define get_oid(str, oid) repo_get_oid(the_repository, str, oid)\n-extern int get_oid_commit(const char *str, struct object_id *oid);\n-extern int get_oid_committish(const char *str, struct object_id *oid);\n-extern int get_oid_tree(const char *str, struct object_id *oid);\n-extern int get_oid_treeish(const char *str, struct object_id *oid);\n-extern int get_oid_blob(const char *str, struct object_id *oid);\n+int repo_get_oid_commit(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_committish(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid);\n void maybe_die_on_misspelt_object_name(struct repository *repo,\n \t\t\t\t       const char *name,\n \t\t\t\t       const char *prefix);\n@@ -1394,6 +1393,13 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c\n \t\t\t\tunsigned flags, struct object_id *oid,\n \t\t\t\tstruct object_context *oc);\n \n+#define get_oid(str, oid)\t\trepo_get_oid(the_repository, str, oid)\n+#define get_oid_commit(str, oid)\trepo_get_oid_commit(the_repository, str, oid)\n+#define get_oid_committish(str, oid)\trepo_get_oid_committish(the_repository, str, oid)\n+#define get_oid_tree(str, oid)\t\trepo_get_oid_tree(the_repository, str, oid)\n+#define get_oid_treeish(str, oid)\trepo_get_oid_treeish(the_repository, str, oid)\n+#define get_oid_blob(str, oid)\t\trepo_get_oid_blob(the_repository, str, oid)\n+\n typedef int each_abbrev_fn(const struct object_id *oid, void *);\n int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);\n #define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data)\ndiff --git a/sha1-name.c b/sha1-name.c\nindex b94d381bef..d49496397d 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1590,43 +1590,48 @@ int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)\n  * commit-ish. It is merely to give a hint to the disambiguation\n  * machinery.\n  */\n-int get_oid_committish(const char *name, struct object_id *oid)\n+int repo_get_oid_committish(struct repository *r,\n+\t\t\t    const char *name,\n+\t\t\t    struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_COMMITTISH,\n+\treturn get_oid_with_context(r, name, GET_OID_COMMITTISH,\n \t\t\t\t    oid, &unused);\n }\n \n-int get_oid_treeish(const char *name, struct object_id *oid)\n+int repo_get_oid_treeish(struct repository *r,\n+\t\t\t const char *name,\n+\t\t\t struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_TREEISH,\n+\treturn get_oid_with_context(r, name, GET_OID_TREEISH,\n \t\t\t\t    oid, &unused);\n }\n \n-int get_oid_commit(const char *name, struct object_id *oid)\n+int repo_get_oid_commit(struct repository *r,\n+\t\t\tconst char *name,\n+\t\t\tstruct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_COMMIT,\n+\treturn get_oid_with_context(r, name, GET_OID_COMMIT,\n \t\t\t\t    oid, &unused);\n }\n \n-int get_oid_tree(const char *name, struct object_id *oid)\n+int repo_get_oid_tree(struct repository *r,\n+\t\t      const char *name,\n+\t\t      struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_TREE,\n+\treturn get_oid_with_context(r, name, GET_OID_TREE,\n \t\t\t\t    oid, &unused);\n }\n \n-int get_oid_blob(const char *name, struct object_id *oid)\n+int repo_get_oid_blob(struct repository *r,\n+\t\t      const char *name,\n+\t\t      struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_BLOB,\n+\treturn get_oid_with_context(r, name, GET_OID_BLOB,\n \t\t\t\t    oid, &unused);\n }\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373049","messageId":"20190403113457.20399-33-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v2 32/32] sha1-name.c: remove the_repo from get_oid_mb()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-03T11:34:57Z","receivedAt":"2019-04-03T11:38: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 cache.h     |  3 ++-\n sha1-name.c | 18 +++++++++++-------\n 2 files changed, 13 insertions(+), 8 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 871a167bf8..9a600a8b50 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1386,6 +1386,7 @@ int repo_get_oid_committish(struct repository *r, const char *str, struct object\n int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid);\n int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid);\n int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_mb(struct repository *r, const char *str, struct object_id *oid);\n void maybe_die_on_misspelt_object_name(struct repository *repo,\n \t\t\t\t       const char *name,\n \t\t\t\t       const char *prefix);\n@@ -1399,6 +1400,7 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c\n #define get_oid_tree(str, oid)\t\trepo_get_oid_tree(the_repository, str, oid)\n #define get_oid_treeish(str, oid)\trepo_get_oid_treeish(the_repository, str, oid)\n #define get_oid_blob(str, oid)\t\trepo_get_oid_blob(the_repository, str, oid)\n+#define get_oid_mb(str, oid) \t\trepo_get_oid_mb(the_repository, str, oid)\n \n typedef int each_abbrev_fn(const struct object_id *oid, void *);\n int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);\n@@ -1486,7 +1488,6 @@ int repo_interpret_branch_name(struct repository *r,\n \t\t\t       unsigned allowed);\n #define interpret_branch_name(str, len, buf, allowed) \\\n \trepo_interpret_branch_name(the_repository, str, len, buf, allowed)\n-extern int get_oid_mb(const char *str, struct object_id *oid);\n \n extern int validate_headref(const char *ref);\n \ndiff --git a/sha1-name.c b/sha1-name.c\nindex d49496397d..cf314ebb29 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1338,7 +1338,9 @@ static int interpret_nth_prior_checkout(struct repository *r,\n \treturn retval;\n }\n \n-int get_oid_mb(const char *name, struct object_id *oid)\n+int repo_get_oid_mb(struct repository *r,\n+\t\t    const char *name,\n+\t\t    struct object_id *oid)\n {\n \tstruct commit *one, *two;\n \tstruct commit_list *mbs;\n@@ -1348,27 +1350,29 @@ int get_oid_mb(const char *name, struct object_id *oid)\n \n \tdots = strstr(name, \"...\");\n \tif (!dots)\n-\t\treturn get_oid(name, oid);\n+\t\treturn repo_get_oid(r, name, oid);\n \tif (dots == name)\n-\t\tst = get_oid(\"HEAD\", &oid_tmp);\n+\t\tst = repo_get_oid(r, \"HEAD\", &oid_tmp);\n \telse {\n \t\tstruct strbuf sb;\n \t\tstrbuf_init(&sb, dots - name);\n \t\tstrbuf_add(&sb, name, dots - name);\n-\t\tst = get_oid_committish(sb.buf, &oid_tmp);\n+\t\tst = repo_get_oid_committish(r, sb.buf, &oid_tmp);\n \t\tstrbuf_release(&sb);\n \t}\n \tif (st)\n \t\treturn st;\n-\tone = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);\n+\tone = lookup_commit_reference_gently(r, &oid_tmp, 0);\n \tif (!one)\n \t\treturn -1;\n \n-\tif (get_oid_committish(dots[3] ? (dots + 3) : \"HEAD\", &oid_tmp))\n+\tif (repo_get_oid_committish(r, dots[3] ? (dots + 3) : \"HEAD\", &oid_tmp))\n \t\treturn -1;\n-\ttwo = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);\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 \tif (!mbs || mbs->next)\n \t\tst = -1;\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373124","messageId":"20190404170427.GQ32732@szeder.dev","threadId":"50841","inReplyTo":"20190403113457.20399-11-pclouds@gmail.com","subject":"Re: [PATCH v2 10/32] commit.c: add repo_get_commit_tree()","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2019-04-04T17:04:27Z","receivedAt":"2019-04-04T17:04:34Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Wed, Apr 03, 2019 at 06:34:35PM +0700, Nguyễn Thái Ngọc Duy wrote:\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n\nOh, look, an empty commit message ;)\n\n> ---\n>  commit.c                        | 5 +++--\n>  commit.h                        | 3 ++-\n>  contrib/coccinelle/commit.cocci | 4 ++--\n>  3 files changed, 7 insertions(+), 5 deletions(-)\n> \n> diff --git a/commit.c b/commit.c\n> index a5333c7ac6..f0a5506f04 100644\n> --- a/commit.c\n> +++ b/commit.c\n> @@ -340,7 +340,8 @@ void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)\n>  \t}\n>  }\n>  \n> -struct tree *get_commit_tree(const struct commit *commit)\n> +struct tree *repo_get_commit_tree(struct repository *r,\n> +\t\t\t\t  const struct commit *commit)\n\nA rename to accomodate the additional 'struct repository*'\nparameter.  Ok.\n\n>  {\n>  \tif (commit->maybe_tree || !commit->object.parsed)\n>  \t\treturn commit->maybe_tree;\n> @@ -348,7 +349,7 @@ struct tree *get_commit_tree(const struct commit *commit)\n>  \tif (commit->graph_pos == COMMIT_NOT_FROM_GRAPH)\n>  \t\tBUG(\"commit has NULL tree, but was not loaded from commit-graph\");\n>  \n> -\treturn get_commit_tree_in_graph(the_repository, commit);\n> +\treturn get_commit_tree_in_graph(r, commit);\n>  }\n>  \n>  struct object_id *get_commit_tree_oid(const struct commit *commit)\n> diff --git a/commit.h b/commit.h\n> index 42728c2906..b576201be8 100644\n> --- a/commit.h\n> +++ b/commit.h\n> @@ -143,7 +143,8 @@ void repo_unuse_commit_buffer(struct repository *r,\n>   */\n>  void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);\n>  \n> -struct tree *get_commit_tree(const struct commit *);\n> +struct tree *repo_get_commit_tree(struct repository *, const struct commit *);\n> +#define get_commit_tree(c) repo_get_commit_tree(the_repository, c)\n\nBut we still keep 'get_commit_tree' around as a macro wrapper\ndefaulting to 'the_repository', leaving the 30+ callsites intact.\nGood.\n\nFurthermore, the comment describing the 'maybe_tree' field in 'struct\ncommit's declaration still suggest get_commit_tree():\n\n  * If the commit is loaded from the commit-graph file, then this\n  * member may be NULL. Only access it through get_commit_tree()\n  * or get_commit_tree_oid().\n\n\n>  struct object_id *get_commit_tree_oid(const struct commit *);\n>  \n>  /*\n> diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\n> index c49aa558f0..f5bc639981 100644\n> --- a/contrib/coccinelle/commit.cocci\n> +++ b/contrib/coccinelle/commit.cocci\n> @@ -12,12 +12,12 @@ expression c;\n>  \n>  // These excluded functions must access c->maybe_tree direcly.\n>  @@\n> -identifier f !~ \"^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n> +identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n>  expression c;\n>  @@\n>    f(...) {<...\n>  - c->maybe_tree\n> -+ get_commit_tree(c)\n> ++ repo_get_commit_tree(the_repository, c)\n\nSo, why this change?\n\nIt would also require furher changes to 'commit.cocci', in particular\nto the last semantic patch, which is supposed to ensure that\nget_commit_tree() doesn't end up on the LHS of an assignment, but with\nthis change Coccinelle does suggest transfomations with\nrepo_get_commit_tree() on the LHS.\n\n>    ...>}\n>  \n>  @@\n> -- \n> 2.21.0.479.g47ac719cd3\n> \n"},{"id":"373125","messageId":"20190404172515.GR32732@szeder.dev","threadId":"50841","inReplyTo":"20190403113457.20399-2-pclouds@gmail.com","subject":"Re: [PATCH v2 01/32] rebase: 'make coccicheck' cleanup","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2019-04-04T17:25:15Z","receivedAt":"2019-04-04T17:25:21Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Wed, Apr 03, 2019 at 06:34:26PM +0700, Nguyễn Thái Ngọc Duy wrote:\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  builtin/rebase.c | 5 ++---\n>  1 file changed, 2 insertions(+), 3 deletions(-)\n> \n> diff --git a/builtin/rebase.c b/builtin/rebase.c\n> index 77deebc65c..c064909329 100644\n> --- a/builtin/rebase.c\n> +++ b/builtin/rebase.c\n> @@ -1592,8 +1592,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n>  \t\t\t\tbranch_name = options.head_name;\n>  \n>  \t\t} else {\n> -\t\t\tfree(options.head_name);\n> -\t\t\toptions.head_name = NULL;\n> +\t\t\tFREE_AND_NULL(options.head_name);\n>  \t\t\tbranch_name = \"HEAD\";\n>  \t\t}\n>  \t\tif (get_oid(\"HEAD\", &options.orig_head))\n> @@ -1793,7 +1792,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n>  \t * we just fast-forwarded.\n>  \t */\n>  \tstrbuf_reset(&msg);\n> -\tif (!oidcmp(&merge_base, &options.orig_head)) {\n> +\tif (oideq(&merge_base, &options.orig_head)) {\n>  \t\tprintf(_(\"Fast-forwarded %s to %s.\\n\"),\n>  \t\t\tbranch_name, options.onto_name);\n>  \t\tstrbuf_addf(&msg, \"rebase finished: %s onto %s\",\n\nYou are already using Coccinelle v1.0.7, aren't you?\n\nFor some reason previous versions don't notice these two\ntransformations.  I have patches with these transformations lying\naround here for some time now, but haven't submitted them yet, because\nI don't really like the way I run Coccinelle v1.0.7 in our static\nanalysis CI build jobs [1]\n\nAnyway, here are my commit messages for these transformations, please\nfeel free to re-use them:\n\n  -- >8 --\n\nSubject: builtin rebase: use oideq()\n\nUse oideq() instead of !oidcmp(), as it is more idiomatic, and might\ngive the compiler more opportunities to optimize.\n\nPatch generated with 'contrib/coccinelle/free.cocci' and Coccinelle\nv1.0.7 (previous Coccinelle versions don't notice this).\n\n  -- 8< --\n\nSubject: builtin rebase: use FREE_AND_NULL\n    \nUse the macro FREE_AND_NULL to release memory allocated for\n'head_name' and clear its pointer.\n    \nPatch generated with 'contrib/coccinelle/free.cocci' and Coccinelle\nv1.0.7 (previous Coccinelle versions don't notice this).\n\n  -- >8 --\n\n\n[1] https://github.com/szeder/git/commits/travis-coccinelle\n\n"},{"id":"373188","messageId":"CACsJy8C5K15QOeAJmPBb-VkcJnAiha9BNuUwVAL_mH_y6YBjow@mail.gmail.com","threadId":"50841","inReplyTo":"20190404172515.GR32732@szeder.dev","subject":"Re: [PATCH v2 01/32] rebase: 'make coccicheck' cleanup","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-05T09:26:10Z","receivedAt":"2019-04-05T09:26:38Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Fri, Apr 5, 2019 at 12:25 AM SZEDER Gábor <szeder.dev@gmail.com> wrote:\n>\n> On Wed, Apr 03, 2019 at 06:34:26PM +0700, Nguyễn Thái Ngọc Duy wrote:\n> > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> > ---\n> >  builtin/rebase.c | 5 ++---\n> >  1 file changed, 2 insertions(+), 3 deletions(-)\n> >\n> > diff --git a/builtin/rebase.c b/builtin/rebase.c\n> > index 77deebc65c..c064909329 100644\n> > --- a/builtin/rebase.c\n> > +++ b/builtin/rebase.c\n> > @@ -1592,8 +1592,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n> >                               branch_name = options.head_name;\n> >\n> >               } else {\n> > -                     free(options.head_name);\n> > -                     options.head_name = NULL;\n> > +                     FREE_AND_NULL(options.head_name);\n> >                       branch_name = \"HEAD\";\n> >               }\n> >               if (get_oid(\"HEAD\", &options.orig_head))\n> > @@ -1793,7 +1792,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n> >        * we just fast-forwarded.\n> >        */\n> >       strbuf_reset(&msg);\n> > -     if (!oidcmp(&merge_base, &options.orig_head)) {\n> > +     if (oideq(&merge_base, &options.orig_head)) {\n> >               printf(_(\"Fast-forwarded %s to %s.\\n\"),\n> >                       branch_name, options.onto_name);\n> >               strbuf_addf(&msg, \"rebase finished: %s onto %s\",\n>\n> You are already using Coccinelle v1.0.7, aren't you?\n\nNo it's 1.0.5. I guess I should upgrade then.\n\n> For some reason previous versions don't notice these two\n> transformations.  I have patches with these transformations lying\n> around here for some time now, but haven't submitted them yet, because\n> I don't really like the way I run Coccinelle v1.0.7 in our static\n> analysis CI build jobs [1]\n>\n> Anyway, here are my commit messages for these transformations, please\n> feel free to re-use them:\n\nI'm not sure if even more elaboration is needed. It looks so trivial\n(and at least obvious to me). But if you or Junio (or anybody else)\ninsists, I'll resend with updated commit messages. Or I can drop this\npatch too if you have more cocci patches to send soon.\n\n>\n>   -- >8 --\n>\n> Subject: builtin rebase: use oideq()\n>\n> Use oideq() instead of !oidcmp(), as it is more idiomatic, and might\n> give the compiler more opportunities to optimize.\n>\n> Patch generated with 'contrib/coccinelle/free.cocci' and Coccinelle\n> v1.0.7 (previous Coccinelle versions don't notice this).\n>\n>   -- 8< --\n>\n> Subject: builtin rebase: use FREE_AND_NULL\n>\n> Use the macro FREE_AND_NULL to release memory allocated for\n> 'head_name' and clear its pointer.\n>\n> Patch generated with 'contrib/coccinelle/free.cocci' and Coccinelle\n> v1.0.7 (previous Coccinelle versions don't notice this).\n>\n>   -- >8 --\n>\n>\n> [1] https://github.com/szeder/git/commits/travis-coccinelle\n>\n\n\n-- \nDuy\n"},{"id":"373189","messageId":"CACsJy8Aa_Zcawoz07FBWjUjYE+RbMpxwrgim-tvQhMZW9+h2gQ@mail.gmail.com","threadId":"50841","inReplyTo":"20190404170427.GQ32732@szeder.dev","subject":"Re: [PATCH v2 10/32] commit.c: add repo_get_commit_tree()","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-05T09:32:22Z","receivedAt":"2019-04-05T09:32:50Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Fri, Apr 5, 2019 at 12:04 AM SZEDER Gábor <szeder.dev@gmail.com> wrote:\n> >  struct object_id *get_commit_tree_oid(const struct commit *);\n> >\n> >  /*\n> > diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\n> > index c49aa558f0..f5bc639981 100644\n> > --- a/contrib/coccinelle/commit.cocci\n> > +++ b/contrib/coccinelle/commit.cocci\n> > @@ -12,12 +12,12 @@ expression c;\n> >\n> >  // These excluded functions must access c->maybe_tree direcly.\n> >  @@\n> > -identifier f !~ \"^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n> > +identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n> >  expression c;\n> >  @@\n> >    f(...) {<...\n> >  - c->maybe_tree\n> > -+ get_commit_tree(c)\n> > ++ repo_get_commit_tree(the_repository, c)\n>\n> So, why this change?\n\nBecause get_commit_tree() now becomes a compat wrapper (yes I'll fill\nin the commit message ;) and should be avoided.\n\n> It would also require furher changes to 'commit.cocci', in particular\n> to the last semantic patch, which is supposed to ensure that\n> get_commit_tree() doesn't end up on the LHS of an assignment, but with\n> this change Coccinelle does suggest transfomations with\n> repo_get_commit_tree() on the LHS.\n\nOooh.. I see now. I actually updated that then dropped, thinking that\na function call cannot be on LHS and that conversion is for\nalready-long-gone code anyway. But yeah when you stack that conversion\non top of this, it makes sense that we need double conversion to avoid\nbuild error.\n\nSince I will have to update this patch anyway, I'll update the commit\nmessage on the first cocci patch too.\n\n>\n> >    ...>}\n> >\n> >  @@\n> > --\n> > 2.21.0.479.g47ac719cd3\n> >\n\n\n\n-- \nDuy\n"},{"id":"373234","messageId":"nycvar.QRO.7.76.6.1904052011180.41@tvgsbejvaqbjf.bet","threadId":"50841","inReplyTo":"CACsJy8Aa_Zcawoz07FBWjUjYE+RbMpxwrgim-tvQhMZW9+h2gQ@mail.gmail.com","subject":"Re: [PATCH v2 10/32] commit.c: add repo_get_commit_tree()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2019-04-05T18:13:05Z","receivedAt":"2019-04-05T18:13:10Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Duy,\n\nOn Fri, 5 Apr 2019, Duy Nguyen wrote:\n\n> On Fri, Apr 5, 2019 at 12:04 AM SZEDER Gábor <szeder.dev@gmail.com> wrote:\n> > >  struct object_id *get_commit_tree_oid(const struct commit *);\n> > >\n\n> > >  /*\n> > > diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\n> > > index c49aa558f0..f5bc639981 100644\n> > > --- a/contrib/coccinelle/commit.cocci\n> > > +++ b/contrib/coccinelle/commit.cocci\n> > > @@ -12,12 +12,12 @@ expression c;\n> > >\n> > >  // These excluded functions must access c->maybe_tree direcly.\n> > >  @@\n> > > -identifier f !~ \"^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n> > > +identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n> > >  expression c;\n> > >  @@\n> > >    f(...) {<...\n> > >  - c->maybe_tree\n> > > -+ get_commit_tree(c)\n> > > ++ repo_get_commit_tree(the_repository, c)\n> >\n> > So, why this change?\n>\n> Because get_commit_tree() now becomes a compat wrapper (yes I'll fill\n> in the commit message ;) and should be avoided.\n>\n> > It would also require furher changes to 'commit.cocci', in particular\n> > to the last semantic patch, which is supposed to ensure that\n> > get_commit_tree() doesn't end up on the LHS of an assignment, but with\n> > this change Coccinelle does suggest transfomations with\n> > repo_get_commit_tree() on the LHS.\n>\n> Oooh.. I see now. I actually updated that then dropped, thinking that\n> a function call cannot be on LHS and that conversion is for\n> already-long-gone code anyway. But yeah when you stack that conversion\n> on top of this, it makes sense that we need double conversion to avoid\n> build error.\n>\n> Since I will have to update this patch anyway, I'll update the commit\n> message on the first cocci patch too.\n\nThis actually broke the build. So here is what I have on top of `pu` to\nmake it work again:\n\n-- snip --\nSubject: [PATCH] fixup??? commit.c: add repo_get_commit_tree()\n\nThe search/replace of this patch was apparently not done fully.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n contrib/coccinelle/commit.cocci | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\nindex f5bc639981..7f53f361c7 100644\n--- a/contrib/coccinelle/commit.cocci\n+++ b/contrib/coccinelle/commit.cocci\n@@ -24,5 +24,5 @@ expression c;\n expression c;\n expression s;\n @@\n-- get_commit_tree(c) = s\n+- repo_get_commit_tree(the_repository, c) = s\n + c->maybe_tree = s\n-- snap --\n\nCiao,\nJohannes\n\n>\n> >\n> > >    ...>}\n> > >\n> > >  @@\n> > > --\n> > > 2.21.0.479.g47ac719cd3\n> > >\n>\n>\n>\n> --\n> Duy\n>\n"},{"id":"373284","messageId":"20190406113453.5149-1-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190403113457.20399-1-pclouds@gmail.com","subject":"[PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:20Z","receivedAt":"2019-04-06T11:35:17Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Hopefully the final fix for commit.cocci in 11/33. Instead of adding\nmore commit details on 01/33 I replaced it with the two commits from\nSzeder, he put more efforts into them anyway.\n\nRange-diff dựa trên v2:\n 1:  b992f6c799 !  1:  aa603ea09e rebase: 'make coccicheck' cleanup\n    @@ -1,6 +1,14 @@\n    -Author: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n    +Author: SZEDER Gábor <szeder.dev@gmail.com>\n     \n    -    rebase: 'make coccicheck' cleanup\n    +    builtin rebase: use FREE_AND_NULL\n    +\n    +    Use the macro FREE_AND_NULL to release memory allocated for\n    +    'head_name' and clear its pointer.\n    +\n    +    Patch generated with 'contrib/coccinelle/free.cocci' and Coccinelle\n    +    v1.0.7 (previous Coccinelle versions don't notice this).\n    +\n    +    Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n     \n      diff --git a/builtin/rebase.c b/builtin/rebase.c\n      --- a/builtin/rebase.c\n    @@ -15,12 +23,3 @@\n      \t\t\tbranch_name = \"HEAD\";\n      \t\t}\n      \t\tif (get_oid(\"HEAD\", &options.orig_head))\n    -@@\n    - \t * we just fast-forwarded.\n    - \t */\n    - \tstrbuf_reset(&msg);\n    --\tif (!oidcmp(&merge_base, &options.orig_head)) {\n    -+\tif (oideq(&merge_base, &options.orig_head)) {\n    - \t\tprintf(_(\"Fast-forwarded %s to %s.\\n\"),\n    - \t\t\tbranch_name, options.onto_name);\n    - \t\tstrbuf_addf(&msg, \"rebase finished: %s onto %s\",\n -:  ---------- >  2:  b03cd28a4e builtin rebase: use oideq()\n 2:  e76c73a75a =  3:  3a68454479 packfile.c: add repo_approximate_object_count()\n 3:  962a168516 =  4:  9738ab8797 refs.c: add refs_ref_exists()\n 4:  d06bea7909 =  5:  1a2cb46fe9 refs.c: add refs_shorten_unambiguous_ref()\n 5:  fb880154e6 =  6:  ffdf9ad9bf refs.c: remove the_repo from substitute_branch_name()\n 6:  6fd7960522 =  7:  697daf317f refs.c: remove the_repo from expand_ref()\n 7:  f5ad3133bc =  8:  fac41b3b1c refs.c: add repo_dwim_ref()\n 8:  7552a4085a =  9:  db528690fd refs.c: add repo_dwim_log()\n 9:  962fff4c9c = 10:  9318416f94 refs.c: remove the_repo from read_ref_at()\n10:  68876a150f ! 11:  848456f59c commit.c: add repo_get_commit_tree()\n    @@ -2,6 +2,11 @@\n     \n         commit.c: add repo_get_commit_tree()\n     \n    +    Remove the implicit dependency on the_repository in this function.\n    +    It will be used in sha1-name.c functions when they are updated to take\n    +    any 'struct repository'. get_commit_tree() remains as a compat wrapper,\n    +    to be slowly replaced later.\n    +\n      diff --git a/commit.c b/commit.c\n      --- a/commit.c\n      +++ b/commit.c\n    @@ -29,6 +34,15 @@\n      --- a/commit.h\n      +++ b/commit.h\n     @@\n    + \n    + \t/*\n    + \t * If the commit is loaded from the commit-graph file, then this\n    +-\t * member may be NULL. Only access it through get_commit_tree()\n    ++\t * member may be NULL. Only access it through repo_get_commit_tree()\n    + \t * or get_commit_tree_oid().\n    + \t */\n    + \tstruct tree *maybe_tree;\n    +@@\n       */\n      void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);\n      \n    @@ -57,3 +71,10 @@\n        ...>}\n      \n      @@\n    + expression c;\n    ++expression r;\n    + expression s;\n    + @@\n    +-- get_commit_tree(c) = s\n    ++- repo_get_commit_tree(r, c) = s\n    + + c->maybe_tree = s\n11:  9817d150b2 = 12:  a60c06b63a sha1-name.c: remove the_repo from sort_ambiguous()\n12:  7ce23aaeb5 = 13:  3cbbe5de4a sha1-name.c: remove the_repo from find_abbrev_len_packed()\n13:  2d99af106f = 14:  a79bf276bd sha1-name.c: add repo_find_unique_abbrev_r()\n14:  f63626e937 = 15:  aa0fa191d9 sha1-name.c: store and use repo in struct disambiguate_state\n15:  ce9f7ebab8 = 16:  ad00c19d30 sha1-name.c: add repo_for_each_abbrev()\n16:  8cb8278d6e = 17:  d9ff762461 sha1-name.c: remove the_repo from get_short_oid()\n17:  9210dd01b8 = 18:  46b8a05d8c sha1-name.c: remove the_repo from interpret_nth_prior_checkout()\n18:  a161ed33d2 = 19:  52ec37f2d7 sha1-name.c: remove the_repo from interpret_branch_mark()\n19:  6bf4df0131 = 20:  f50562b480 sha1-name.c: add repo_interpret_branch_name()\n20:  94f707cb7f = 21:  66619e37cb sha1-name.c: remove the_repo from get_oid_oneline()\n21:  2a1dd6368c = 22:  d960f47821 sha1-name.c: remove the_repo from get_describe_name()\n22:  f958b565db = 23:  f38960304d sha1-name.c: remove the_repo from get_oid_basic()\n23:  ec821007b2 = 24:  3b69cfcd8b sha1-name.c: remove the_repo from get_oid_1()\n24:  317a365f30 = 25:  e889ae729a sha1-name.c: remove the_repo from handle_one_ref()\n25:  3a46ea22b2 = 26:  386b6f4654 sha1-name.c: remove the_repo from diagnose_invalid_index_path()\n26:  59a8cb9749 = 27:  d3ff3ee163 sha1-name.c: remove the_repo from resolve_relative_path()\n27:  d1f4df1915 = 28:  226a30e6f6 sha1-name.c: remove the_repo from get_oid_with_context_1()\n28:  3034e9cf1e = 29:  5d0aed2f70 sha1-name.c: add repo_get_oid()\n29:  9c72941ec9 = 30:  72ab26a247 submodule-config.c: use repo_get_oid for reading .gitmodules\n30:  40acfb6b82 = 31:  53dc11463d sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name\n31:  3b8be75e77 = 32:  01b4deaa8a sha1-name.c: remove the_repo from other get_oid_*\n32:  59cadc5deb = 33:  03a7283ef3 sha1-name.c: remove the_repo from get_oid_mb()\n\nNguyễn Thái Ngọc Duy (31):\n  packfile.c: add repo_approximate_object_count()\n  refs.c: add refs_ref_exists()\n  refs.c: add refs_shorten_unambiguous_ref()\n  refs.c: remove the_repo from substitute_branch_name()\n  refs.c: remove the_repo from expand_ref()\n  refs.c: add repo_dwim_ref()\n  refs.c: add repo_dwim_log()\n  refs.c: remove the_repo from read_ref_at()\n  commit.c: add repo_get_commit_tree()\n  sha1-name.c: remove the_repo from sort_ambiguous()\n  sha1-name.c: remove the_repo from find_abbrev_len_packed()\n  sha1-name.c: add repo_find_unique_abbrev_r()\n  sha1-name.c: store and use repo in struct disambiguate_state\n  sha1-name.c: add repo_for_each_abbrev()\n  sha1-name.c: remove the_repo from get_short_oid()\n  sha1-name.c: remove the_repo from interpret_nth_prior_checkout()\n  sha1-name.c: remove the_repo from interpret_branch_mark()\n  sha1-name.c: add repo_interpret_branch_name()\n  sha1-name.c: remove the_repo from get_oid_oneline()\n  sha1-name.c: remove the_repo from get_describe_name()\n  sha1-name.c: remove the_repo from get_oid_basic()\n  sha1-name.c: remove the_repo from get_oid_1()\n  sha1-name.c: remove the_repo from handle_one_ref()\n  sha1-name.c: remove the_repo from diagnose_invalid_index_path()\n  sha1-name.c: remove the_repo from resolve_relative_path()\n  sha1-name.c: remove the_repo from get_oid_with_context_1()\n  sha1-name.c: add repo_get_oid()\n  submodule-config.c: use repo_get_oid for reading .gitmodules\n  sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name\n  sha1-name.c: remove the_repo from other get_oid_*\n  sha1-name.c: remove the_repo from get_oid_mb()\n\nSZEDER Gábor (2):\n  builtin rebase: use FREE_AND_NULL\n  builtin rebase: use oideq()\n\n builtin/rebase.c                   |   5 +-\n builtin/show-branch.c              |   6 +-\n cache.h                            |  50 ++--\n commit.c                           |   5 +-\n commit.h                           |   5 +-\n contrib/coccinelle/commit.cocci    |   7 +-\n dir.c                              |   8 +\n dir.h                              |   4 +-\n packfile.c                         |  14 +-\n packfile.h                         |   3 +-\n refs.c                             |  71 ++++--\n refs.h                             |   9 +-\n setup.c                            |   7 +-\n sha1-name.c                        | 388 ++++++++++++++++++-----------\n submodule-config.c                 |  20 +-\n t/t7814-grep-recurse-submodules.sh |   6 +-\n upload-pack.c                      |   2 +-\n 17 files changed, 378 insertions(+), 232 deletions(-)\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373285","messageId":"20190406113453.5149-2-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 01/33] builtin rebase: use FREE_AND_NULL","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:21Z","receivedAt":"2019-04-06T11:35:22Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"From: SZEDER Gábor <szeder.dev@gmail.com>\n\nUse the macro FREE_AND_NULL to release memory allocated for\n'head_name' and clear its pointer.\n\nPatch generated with 'contrib/coccinelle/free.cocci' and Coccinelle\nv1.0.7 (previous Coccinelle versions don't notice this).\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/rebase.c | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 77deebc65c..868bcd1446 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -1592,8 +1592,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\t\t\tbranch_name = options.head_name;\n \n \t\t} else {\n-\t\t\tfree(options.head_name);\n-\t\t\toptions.head_name = NULL;\n+\t\t\tFREE_AND_NULL(options.head_name);\n \t\t\tbranch_name = \"HEAD\";\n \t\t}\n \t\tif (get_oid(\"HEAD\", &options.orig_head))\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373286","messageId":"20190406113453.5149-3-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 02/33] builtin rebase: use oideq()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:22Z","receivedAt":"2019-04-06T11:35:27Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"From: SZEDER Gábor <szeder.dev@gmail.com>\n\nUse oideq() instead of !oidcmp(), as it is more idiomatic, and might\ngive the compiler more opportunities to optimize.\n\nPatch generated with 'contrib/coccinelle/free.cocci' and Coccinelle\nv1.0.7 (previous Coccinelle versions don't notice this).\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/rebase.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 868bcd1446..c064909329 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -1792,7 +1792,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t * we just fast-forwarded.\n \t */\n \tstrbuf_reset(&msg);\n-\tif (!oidcmp(&merge_base, &options.orig_head)) {\n+\tif (oideq(&merge_base, &options.orig_head)) {\n \t\tprintf(_(\"Fast-forwarded %s to %s.\\n\"),\n \t\t\tbranch_name, options.onto_name);\n \t\tstrbuf_addf(&msg, \"rebase finished: %s onto %s\",\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373287","messageId":"20190406113453.5149-4-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 03/33] packfile.c: add repo_approximate_object_count()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:23Z","receivedAt":"2019-04-06T11:35:33Z","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 packfile.c | 14 +++++++-------\n packfile.h |  3 ++-\n 2 files changed, 9 insertions(+), 8 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex 16bcb75262..2ad4fab2f8 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -893,25 +893,25 @@ static void prepare_packed_git(struct repository *r);\n  * all unreachable objects about to be pruned, in which case they're not really\n  * interesting as a measure of repo size in the first place.\n  */\n-unsigned long approximate_object_count(void)\n+unsigned long repo_approximate_object_count(struct repository *r)\n {\n-\tif (!the_repository->objects->approximate_object_count_valid) {\n+\tif (!r->objects->approximate_object_count_valid) {\n \t\tunsigned long count;\n \t\tstruct multi_pack_index *m;\n \t\tstruct packed_git *p;\n \n-\t\tprepare_packed_git(the_repository);\n+\t\tprepare_packed_git(r);\n \t\tcount = 0;\n-\t\tfor (m = get_multi_pack_index(the_repository); m; m = m->next)\n+\t\tfor (m = get_multi_pack_index(r); m; m = m->next)\n \t\t\tcount += m->num_objects;\n-\t\tfor (p = the_repository->objects->packed_git; p; p = p->next) {\n+\t\tfor (p = r->objects->packed_git; p; p = p->next) {\n \t\t\tif (open_pack_index(p))\n \t\t\t\tcontinue;\n \t\t\tcount += p->num_objects;\n \t\t}\n-\t\tthe_repository->objects->approximate_object_count = count;\n+\t\tr->objects->approximate_object_count = count;\n \t}\n-\treturn the_repository->objects->approximate_object_count;\n+\treturn r->objects->approximate_object_count;\n }\n \n static void *get_next_packed_git(const void *p)\ndiff --git a/packfile.h b/packfile.h\nindex d70c6d9afb..f04440f984 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -57,7 +57,8 @@ struct packed_git *get_all_packs(struct repository *r);\n  * Give a rough count of objects in the repository. This sacrifices accuracy\n  * for speed.\n  */\n-unsigned long approximate_object_count(void);\n+unsigned long repo_approximate_object_count(struct repository *r);\n+#define approximate_object_count() repo_approximate_object_count(the_repository)\n \n extern struct packed_git *find_sha1_pack(const unsigned char *sha1,\n \t\t\t\t\t struct packed_git *packs);\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373288","messageId":"20190406113453.5149-5-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 04/33] refs.c: add refs_ref_exists()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:24Z","receivedAt":"2019-04-06T11:35:38Z","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 refs.c | 7 ++++++-\n 1 file changed, 6 insertions(+), 1 deletion(-)\n\ndiff --git a/refs.c b/refs.c\nindex 142888a40a..b869f32d8b 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -241,9 +241,14 @@ int read_ref(const char *refname, struct object_id *oid)\n \treturn read_ref_full(refname, RESOLVE_REF_READING, oid, NULL);\n }\n \n+static int refs_ref_exists(struct ref_store *refs, const char *refname)\n+{\n+\treturn !!refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING, NULL, NULL);\n+}\n+\n int ref_exists(const char *refname)\n {\n-\treturn !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, NULL, NULL);\n+\treturn refs_ref_exists(get_main_ref_store(the_repository), refname);\n }\n \n static int match_ref_pattern(const char *refname,\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373289","messageId":"20190406113453.5149-6-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 05/33] refs.c: add refs_shorten_unambiguous_ref()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:25Z","receivedAt":"2019-04-06T11:35:44Z","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 refs.c | 11 +++++++++--\n refs.h |  2 ++\n 2 files changed, 11 insertions(+), 2 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex b869f32d8b..3dde824aab 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1169,7 +1169,8 @@ int update_ref(const char *msg, const char *refname,\n \t\t\t       old_oid, flags, onerr);\n }\n \n-char *shorten_unambiguous_ref(const char *refname, int strict)\n+char *refs_shorten_unambiguous_ref(struct ref_store *refs,\n+\t\t\t\t   const char *refname, int strict)\n {\n \tint i;\n \tstatic char **scanf_fmts;\n@@ -1247,7 +1248,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)\n \t\t\tstrbuf_reset(&resolved_buf);\n \t\t\tstrbuf_addf(&resolved_buf, rule,\n \t\t\t\t    short_name_len, short_name);\n-\t\t\tif (ref_exists(resolved_buf.buf))\n+\t\t\tif (refs_ref_exists(refs, resolved_buf.buf))\n \t\t\t\tbreak;\n \t\t}\n \n@@ -1266,6 +1267,12 @@ char *shorten_unambiguous_ref(const char *refname, int strict)\n \treturn xstrdup(refname);\n }\n \n+char *shorten_unambiguous_ref(const char *refname, int strict)\n+{\n+\treturn refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),\n+\t\t\t\t\t    refname, strict);\n+}\n+\n static struct string_list *hide_refs;\n \n int parse_hide_refs_config(const char *var, const char *value, const char *section)\ndiff --git a/refs.h b/refs.h\nindex 308fa1f03b..5627570241 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -462,6 +462,8 @@ int check_refname_format(const char *refname, int flags);\n \n const char *prettify_refname(const char *refname);\n \n+char *refs_shorten_unambiguous_ref(struct ref_store *refs,\n+\t\t\t\t   const char *refname, int strict);\n char *shorten_unambiguous_ref(const char *refname, int strict);\n \n /** rename ref, return 0 on success **/\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373290","messageId":"20190406113453.5149-7-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 06/33] refs.c: remove the_repo from substitute_branch_name()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:26Z","receivedAt":"2019-04-06T11:35: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 cache.h     | 8 ++++++--\n refs.c      | 9 +++++----\n sha1-name.c | 8 ++++++--\n 3 files changed, 17 insertions(+), 8 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex ac92421f3a..fcb24b5781 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1468,8 +1468,12 @@ extern int parse_oid_hex(const char *hex, struct object_id *oid, const char **en\n #define INTERPRET_BRANCH_LOCAL (1<<0)\n #define INTERPRET_BRANCH_REMOTE (1<<1)\n #define INTERPRET_BRANCH_HEAD (1<<2)\n-extern int interpret_branch_name(const char *str, int len, struct strbuf *,\n-\t\t\t\t unsigned allowed);\n+int repo_interpret_branch_name(struct repository *r,\n+\t\t\t       const char *str, int len,\n+\t\t\t       struct strbuf *buf,\n+\t\t\t       unsigned allowed);\n+#define interpret_branch_name(str, len, buf, allowed) \\\n+\trepo_interpret_branch_name(the_repository, str, len, buf, allowed)\n extern int get_oid_mb(const char *str, struct object_id *oid);\n \n extern int validate_headref(const char *ref);\ndiff --git a/refs.c b/refs.c\nindex 3dde824aab..44df049796 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -539,10 +539,11 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n  * later free()ing) if the string passed in is a magic short-hand form\n  * to name a branch.\n  */\n-static char *substitute_branch_name(const char **string, int *len)\n+static char *substitute_branch_name(struct repository *r,\n+\t\t\t\t    const char **string, int *len)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n-\tint ret = interpret_branch_name(*string, *len, &buf, 0);\n+\tint ret = repo_interpret_branch_name(r, *string, *len, &buf, 0);\n \n \tif (ret == *len) {\n \t\tsize_t size;\n@@ -556,7 +557,7 @@ static char *substitute_branch_name(const char **string, int *len)\n \n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)\n {\n-\tchar *last_branch = substitute_branch_name(&str, &len);\n+\tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n \tint   refs_found  = expand_ref(str, len, oid, ref);\n \tfree(last_branch);\n \treturn refs_found;\n@@ -596,7 +597,7 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)\n \n int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n {\n-\tchar *last_branch = substitute_branch_name(&str, &len);\n+\tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n \tconst char **p;\n \tint logs_found = 0;\n \tstruct strbuf path = STRBUF_INIT;\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 6dda2c16df..d535bb82f7 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1427,13 +1427,17 @@ static int interpret_branch_mark(const char *name, int namelen,\n \treturn len + at;\n }\n \n-int interpret_branch_name(const char *name, int namelen, struct strbuf *buf,\n-\t\t\t  unsigned allowed)\n+int repo_interpret_branch_name(struct repository *r,\n+\t\t\t       const char *name, int namelen,\n+\t\t\t       struct strbuf *buf,\n+\t\t\t       unsigned allowed)\n {\n \tchar *at;\n \tconst char *start;\n \tint len;\n \n+\tif (r != the_repository)\n+\t\tBUG(\"interpret_branch_name() does not really use 'r' yet\");\n \tif (!namelen)\n \t\tnamelen = strlen(name);\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373291","messageId":"20190406113453.5149-8-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 07/33] refs.c: remove the_repo from expand_ref()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:27Z","receivedAt":"2019-04-06T11:35:56Z","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 refs.c        | 10 ++++++----\n refs.h        |  2 +-\n upload-pack.c |  2 +-\n 3 files changed, 8 insertions(+), 6 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 44df049796..1f5864aa36 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -558,12 +558,13 @@ static char *substitute_branch_name(struct repository *r,\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)\n {\n \tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n-\tint   refs_found  = expand_ref(str, len, oid, ref);\n+\tint   refs_found  = expand_ref(the_repository, str, len, oid, ref);\n \tfree(last_branch);\n \treturn refs_found;\n }\n \n-int expand_ref(const char *str, int len, struct object_id *oid, char **ref)\n+int expand_ref(struct repository *repo, const char *str, int len,\n+\t       struct object_id *oid, char **ref)\n {\n \tconst char **p, *r;\n \tint refs_found = 0;\n@@ -578,8 +579,9 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)\n \t\tthis_result = refs_found ? &oid_from_ref : oid;\n \t\tstrbuf_reset(&fullref);\n \t\tstrbuf_addf(&fullref, *p, len, str);\n-\t\tr = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,\n-\t\t\t\t       this_result, &flag);\n+\t\tr = refs_resolve_ref_unsafe(get_main_ref_store(repo),\n+\t\t\t\t\t    fullref.buf, RESOLVE_REF_READING,\n+\t\t\t\t\t    this_result, &flag);\n \t\tif (r) {\n \t\t\tif (!refs_found++)\n \t\t\t\t*ref = xstrdup(r);\ndiff --git a/refs.h b/refs.h\nindex 5627570241..b630d5bde7 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -148,7 +148,7 @@ int refname_match(const char *abbrev_name, const char *full_name);\n struct argv_array;\n void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);\n \n-int expand_ref(const char *str, int len, struct object_id *oid, char **ref);\n+int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n \ndiff --git a/upload-pack.c b/upload-pack.c\nindex d098ef5982..56505d60c3 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -834,7 +834,7 @@ static int process_deepen_not(const char *line, struct string_list *deepen_not,\n \tif (skip_prefix(line, \"deepen-not \", &arg)) {\n \t\tchar *ref = NULL;\n \t\tstruct object_id oid;\n-\t\tif (expand_ref(arg, strlen(arg), &oid, &ref) != 1)\n+\t\tif (expand_ref(the_repository, arg, strlen(arg), &oid, &ref) != 1)\n \t\t\tdie(\"git upload-pack: ambiguous deepen-not: %s\", line);\n \t\tstring_list_append(deepen_not, ref);\n \t\tfree(ref);\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373292","messageId":"20190406113453.5149-9-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 08/33] refs.c: add repo_dwim_ref()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:28Z","receivedAt":"2019-04-06T11:36:00Z","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 refs.c | 12 +++++++++---\n refs.h |  1 +\n 2 files changed, 10 insertions(+), 3 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 1f5864aa36..bd0fec5776 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -555,14 +555,20 @@ static char *substitute_branch_name(struct repository *r,\n \treturn NULL;\n }\n \n-int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)\n+int repo_dwim_ref(struct repository *r, const char *str, int len,\n+\t\t  struct object_id *oid, char **ref)\n {\n-\tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n-\tint   refs_found  = expand_ref(the_repository, str, len, oid, ref);\n+\tchar *last_branch = substitute_branch_name(r, &str, &len);\n+\tint   refs_found  = expand_ref(r, str, len, oid, ref);\n \tfree(last_branch);\n \treturn refs_found;\n }\n \n+int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)\n+{\n+\treturn repo_dwim_ref(the_repository, str, len, oid, ref);\n+}\n+\n int expand_ref(struct repository *repo, const char *str, int len,\n \t       struct object_id *oid, char **ref)\n {\ndiff --git a/refs.h b/refs.h\nindex b630d5bde7..fd3dc1d0f4 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -149,6 +149,7 @@ struct argv_array;\n void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);\n \n int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n+int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373293","messageId":"20190406113453.5149-10-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 09/33] refs.c: add repo_dwim_log()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:29Z","receivedAt":"2019-04-06T11:36:05Z","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 refs.c | 21 +++++++++++++++------\n refs.h |  1 +\n 2 files changed, 16 insertions(+), 6 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex bd0fec5776..edea001446 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -603,9 +603,11 @@ int expand_ref(struct repository *repo, const char *str, int len,\n \treturn refs_found;\n }\n \n-int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n+int repo_dwim_log(struct repository *r, const char *str, int len,\n+\t\t  struct object_id *oid, char **log)\n {\n-\tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n+\tstruct ref_store *refs = get_main_ref_store(r);\n+\tchar *last_branch = substitute_branch_name(r, &str, &len);\n \tconst char **p;\n \tint logs_found = 0;\n \tstruct strbuf path = STRBUF_INIT;\n@@ -617,13 +619,15 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n \n \t\tstrbuf_reset(&path);\n \t\tstrbuf_addf(&path, *p, len, str);\n-\t\tref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,\n-\t\t\t\t\t &hash, NULL);\n+\t\tref = refs_resolve_ref_unsafe(refs, path.buf,\n+\t\t\t\t\t      RESOLVE_REF_READING,\n+\t\t\t\t\t      &hash, NULL);\n \t\tif (!ref)\n \t\t\tcontinue;\n-\t\tif (reflog_exists(path.buf))\n+\t\tif (refs_reflog_exists(refs, path.buf))\n \t\t\tit = path.buf;\n-\t\telse if (strcmp(ref, path.buf) && reflog_exists(ref))\n+\t\telse if (strcmp(ref, path.buf) &&\n+\t\t\t refs_reflog_exists(refs, ref))\n \t\t\tit = ref;\n \t\telse\n \t\t\tcontinue;\n@@ -639,6 +643,11 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n \treturn logs_found;\n }\n \n+int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n+{\n+\treturn repo_dwim_log(the_repository, str, len, oid, log);\n+}\n+\n static int is_per_worktree_ref(const char *refname)\n {\n \treturn !strcmp(refname, \"HEAD\") ||\ndiff --git a/refs.h b/refs.h\nindex fd3dc1d0f4..859dffe691 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -150,6 +150,7 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);\n \n int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n+int repo_dwim_log(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373294","messageId":"20190406113453.5149-11-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 10/33] refs.c: remove the_repo from read_ref_at()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:30Z","receivedAt":"2019-04-06T11:36:10Z","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/show-branch.c | 6 ++++--\n refs.c                | 7 ++++---\n refs.h                | 3 ++-\n sha1-name.c           | 3 ++-\n 4 files changed, 12 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/show-branch.c b/builtin/show-branch.c\nindex 934e514944..082daeac32 100644\n--- a/builtin/show-branch.c\n+++ b/builtin/show-branch.c\n@@ -753,7 +753,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\t\t/* Ah, that is a date spec... */\n \t\t\t\ttimestamp_t at;\n \t\t\t\tat = approxidate(reflog_base);\n-\t\t\t\tread_ref_at(ref, flags, at, -1, &oid, NULL,\n+\t\t\t\tread_ref_at(get_main_ref_store(the_repository),\n+\t\t\t\t\t    ref, flags, at, -1, &oid, NULL,\n \t\t\t\t\t    NULL, NULL, &base);\n \t\t\t}\n \t\t}\n@@ -765,7 +766,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\ttimestamp_t timestamp;\n \t\t\tint tz;\n \n-\t\t\tif (read_ref_at(ref, flags, 0, base + i, &oid, &logmsg,\n+\t\t\tif (read_ref_at(get_main_ref_store(the_repository),\n+\t\t\t\t\tref, flags, 0, base + i, &oid, &logmsg,\n \t\t\t\t\t&timestamp, &tz, NULL)) {\n \t\t\t\treflog = i;\n \t\t\t\tbreak;\ndiff --git a/refs.c b/refs.c\nindex edea001446..92d1f6dbdd 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -967,7 +967,8 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid\n \treturn 1;\n }\n \n-int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, int cnt,\n+int read_ref_at(struct ref_store *refs, const char *refname,\n+\t\tunsigned int flags, timestamp_t at_time, int cnt,\n \t\tstruct object_id *oid, char **msg,\n \t\ttimestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt)\n {\n@@ -983,7 +984,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in\n \tcb.cutoff_cnt = cutoff_cnt;\n \tcb.oid = oid;\n \n-\tfor_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);\n+\trefs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent, &cb);\n \n \tif (!cb.reccnt) {\n \t\tif (flags & GET_OID_QUIETLY)\n@@ -994,7 +995,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in\n \tif (cb.found_it)\n \t\treturn 0;\n \n-\tfor_each_reflog_ent(refname, read_ref_at_ent_oldest, &cb);\n+\trefs_for_each_reflog_ent(refs, refname, read_ref_at_ent_oldest, &cb);\n \n \treturn 1;\n }\ndiff --git a/refs.h b/refs.h\nindex 859dffe691..8f9cbf8a93 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -388,7 +388,8 @@ int refs_create_reflog(struct ref_store *refs, const char *refname,\n int safe_create_reflog(const char *refname, int force_create, struct strbuf *err);\n \n /** Reads log for the value of ref during at_time. **/\n-int read_ref_at(const char *refname, unsigned int flags,\n+int read_ref_at(struct ref_store *refs,\n+\t\tconst char *refname, unsigned int flags,\n \t\ttimestamp_t at_time, int cnt,\n \t\tstruct object_id *oid, char **msg,\n \t\ttimestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt);\ndiff --git a/sha1-name.c b/sha1-name.c\nindex d535bb82f7..15a1107998 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -849,7 +849,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\t\t\treturn -1;\n \t\t\t}\n \t\t}\n-\t\tif (read_ref_at(real_ref, flags, at_time, nth, oid, NULL,\n+\t\tif (read_ref_at(get_main_ref_store(the_repository),\n+\t\t\t\treal_ref, flags, at_time, nth, oid, NULL,\n \t\t\t\t&co_time, &co_tz, &co_cnt)) {\n \t\t\tif (!len) {\n \t\t\t\tif (starts_with(real_ref, \"refs/heads/\")) {\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373295","messageId":"20190406113453.5149-12-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 11/33] commit.c: add repo_get_commit_tree()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:31Z","receivedAt":"2019-04-06T11:36:15Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Remove the implicit dependency on the_repository in this function.\nIt will be used in sha1-name.c functions when they are updated to take\nany 'struct repository'. get_commit_tree() remains as a compat wrapper,\nto be slowly replaced later.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n commit.c                        | 5 +++--\n commit.h                        | 5 +++--\n contrib/coccinelle/commit.cocci | 7 ++++---\n 3 files changed, 10 insertions(+), 7 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex a5333c7ac6..f0a5506f04 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -340,7 +340,8 @@ void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)\n \t}\n }\n \n-struct tree *get_commit_tree(const struct commit *commit)\n+struct tree *repo_get_commit_tree(struct repository *r,\n+\t\t\t\t  const struct commit *commit)\n {\n \tif (commit->maybe_tree || !commit->object.parsed)\n \t\treturn commit->maybe_tree;\n@@ -348,7 +349,7 @@ struct tree *get_commit_tree(const struct commit *commit)\n \tif (commit->graph_pos == COMMIT_NOT_FROM_GRAPH)\n \t\tBUG(\"commit has NULL tree, but was not loaded from commit-graph\");\n \n-\treturn get_commit_tree_in_graph(the_repository, commit);\n+\treturn get_commit_tree_in_graph(r, commit);\n }\n \n struct object_id *get_commit_tree_oid(const struct commit *commit)\ndiff --git a/commit.h b/commit.h\nindex 42728c2906..f1aa4c0472 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -32,7 +32,7 @@ struct commit {\n \n \t/*\n \t * If the commit is loaded from the commit-graph file, then this\n-\t * member may be NULL. Only access it through get_commit_tree()\n+\t * member may be NULL. Only access it through repo_get_commit_tree()\n \t * or get_commit_tree_oid().\n \t */\n \tstruct tree *maybe_tree;\n@@ -143,7 +143,8 @@ void repo_unuse_commit_buffer(struct repository *r,\n  */\n void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);\n \n-struct tree *get_commit_tree(const struct commit *);\n+struct tree *repo_get_commit_tree(struct repository *, const struct commit *);\n+#define get_commit_tree(c) repo_get_commit_tree(the_repository, c)\n struct object_id *get_commit_tree_oid(const struct commit *);\n \n /*\ndiff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\nindex c49aa558f0..57c8f71479 100644\n--- a/contrib/coccinelle/commit.cocci\n+++ b/contrib/coccinelle/commit.cocci\n@@ -12,17 +12,18 @@ expression c;\n \n // These excluded functions must access c->maybe_tree direcly.\n @@\n-identifier f !~ \"^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n+identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n expression c;\n @@\n   f(...) {<...\n - c->maybe_tree\n-+ get_commit_tree(c)\n++ repo_get_commit_tree(the_repository, c)\n   ...>}\n \n @@\n expression c;\n+expression r;\n expression s;\n @@\n-- get_commit_tree(c) = s\n+- repo_get_commit_tree(r, c) = s\n + c->maybe_tree = s\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373296","messageId":"20190406113453.5149-13-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 12/33] sha1-name.c: remove the_repo from sort_ambiguous()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:32Z","receivedAt":"2019-04-06T11:36:21Z","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 | 15 ++++++++++++---\n 1 file changed, 12 insertions(+), 3 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 15a1107998..7558ce51a3 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -383,10 +383,11 @@ static int collect_ambiguous(const struct object_id *oid, void *data)\n \treturn 0;\n }\n \n+static struct repository *sort_ambiguous_repo;\n static int sort_ambiguous(const void *a, const void *b)\n {\n-\tint a_type = oid_object_info(the_repository, a, NULL);\n-\tint b_type = oid_object_info(the_repository, b, NULL);\n+\tint a_type = oid_object_info(sort_ambiguous_repo, a, NULL);\n+\tint b_type = oid_object_info(sort_ambiguous_repo, b, NULL);\n \tint a_type_sort;\n \tint b_type_sort;\n \n@@ -411,6 +412,14 @@ static int sort_ambiguous(const void *a, const void *b)\n \treturn a_type_sort > b_type_sort ? 1 : -1;\n }\n \n+static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)\n+{\n+\t/* mutex will be needed if this code is to be made thread safe */\n+\tsort_ambiguous_repo = r;\n+\tQSORT(a->oid, a->nr, sort_ambiguous);\n+\tsort_ambiguous_repo = NULL;\n+}\n+\n static enum get_oid_result get_short_oid(const char *name, int len,\n \t\t\t\t\t struct object_id *oid,\n \t\t\t\t\t unsigned flags)\n@@ -458,7 +467,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \n \t\tadvise(_(\"The candidates are:\"));\n \t\tfor_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect);\n-\t\tQSORT(collect.oid, collect.nr, sort_ambiguous);\n+\t\tsort_ambiguous_oid_array(the_repository, &collect);\n \n \t\tif (oid_array_for_each(&collect, show_ambiguous_object, &ds))\n \t\t\tBUG(\"show_ambiguous_object shouldn't return non-zero\");\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373297","messageId":"20190406113453.5149-14-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 13/33] sha1-name.c: remove the_repo from find_abbrev_len_packed()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:33Z","receivedAt":"2019-04-06T11:36:26Z","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 | 6 ++++--\n 1 file changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 7558ce51a3..b9381aaba6 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -514,6 +514,7 @@ struct min_abbrev_data {\n \tunsigned int init_len;\n \tunsigned int cur_len;\n \tchar *hex;\n+\tstruct repository *repo;\n \tconst struct object_id *oid;\n };\n \n@@ -619,9 +620,9 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)\n \tstruct multi_pack_index *m;\n \tstruct packed_git *p;\n \n-\tfor (m = get_multi_pack_index(the_repository); m; m = m->next)\n+\tfor (m = get_multi_pack_index(mad->repo); m; m = m->next)\n \t\tfind_abbrev_len_for_midx(m, mad);\n-\tfor (p = get_packed_git(the_repository); p; p = p->next)\n+\tfor (p = get_packed_git(mad->repo); p; p = p->next)\n \t\tfind_abbrev_len_for_pack(p, mad);\n }\n \n@@ -658,6 +659,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)\n \tif (len == hexsz || !len)\n \t\treturn hexsz;\n \n+\tmad.repo = the_repository;\n \tmad.init_len = len;\n \tmad.cur_len = len;\n \tmad.hex = hex;\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373298","messageId":"20190406113453.5149-15-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 14/33] sha1-name.c: add repo_find_unique_abbrev_r()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:34Z","receivedAt":"2019-04-06T11:36:32Z","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     |  6 ++++--\n sha1-name.c | 15 +++++++++------\n 2 files changed, 13 insertions(+), 8 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex fcb24b5781..4f8ebb0a67 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1045,8 +1045,10 @@ extern void check_repository_format(void);\n  * Note that while this version avoids the static buffer, it is not fully\n  * reentrant, as it calls into other non-reentrant git code.\n  */\n-extern const char *find_unique_abbrev(const struct object_id *oid, int len);\n-extern int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len);\n+const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len);\n+#define find_unique_abbrev(oid, len) repo_find_unique_abbrev(the_repository, oid, len)\n+int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);\n+#define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len)\n \n extern const unsigned char null_sha1[GIT_MAX_RAWSZ];\n extern const struct object_id null_oid;\ndiff --git a/sha1-name.c b/sha1-name.c\nindex b9381aaba6..9b57787b76 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -626,15 +626,16 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)\n \t\tfind_abbrev_len_for_pack(p, mad);\n }\n \n-int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)\n+int repo_find_unique_abbrev_r(struct repository *r, char *hex,\n+\t\t\t      const struct object_id *oid, int len)\n {\n \tstruct disambiguate_state ds;\n \tstruct min_abbrev_data mad;\n \tstruct object_id oid_ret;\n-\tconst unsigned hexsz = the_hash_algo->hexsz;\n+\tconst unsigned hexsz = r->hash_algo->hexsz;\n \n \tif (len < 0) {\n-\t\tunsigned long count = approximate_object_count();\n+\t\tunsigned long count = repo_approximate_object_count(r);\n \t\t/*\n \t\t * Add one because the MSB only tells us the highest bit set,\n \t\t * not including the value of all the _other_ bits (so \"15\"\n@@ -659,7 +660,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)\n \tif (len == hexsz || !len)\n \t\treturn hexsz;\n \n-\tmad.repo = the_repository;\n+\tmad.repo = r;\n \tmad.init_len = len;\n \tmad.cur_len = len;\n \tmad.hex = hex;\n@@ -681,13 +682,15 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)\n \treturn mad.cur_len;\n }\n \n-const char *find_unique_abbrev(const struct object_id *oid, int len)\n+const char *repo_find_unique_abbrev(struct repository *r,\n+\t\t\t\t    const struct object_id *oid,\n+\t\t\t\t    int len)\n {\n \tstatic int bufno;\n \tstatic char hexbuffer[4][GIT_MAX_HEXSZ + 1];\n \tchar *hex = hexbuffer[bufno];\n \tbufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);\n-\tfind_unique_abbrev_r(hex, oid, len);\n+\trepo_find_unique_abbrev_r(r, hex, oid, len);\n \treturn hex;\n }\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373299","messageId":"20190406113453.5149-16-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 15/33] sha1-name.c: store and use repo in struct disambiguate_state","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:35Z","receivedAt":"2019-04-06T11:36:37Z","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 | 95 +++++++++++++++++++++++++++++++++--------------------\n 1 file changed, 59 insertions(+), 36 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 9b57787b76..a75992eb54 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -17,13 +17,14 @@\n \n static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);\n \n-typedef int (*disambiguate_hint_fn)(const struct object_id *, void *);\n+typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);\n \n struct disambiguate_state {\n \tint len; /* length of prefix in hex chars */\n \tchar hex_pfx[GIT_MAX_HEXSZ + 1];\n \tstruct object_id bin_pfx;\n \n+\tstruct repository *repo;\n \tdisambiguate_hint_fn fn;\n \tvoid *cb_data;\n \tstruct object_id candidate;\n@@ -38,7 +39,7 @@ struct disambiguate_state {\n static void update_candidates(struct disambiguate_state *ds, const struct object_id *current)\n {\n \tif (ds->always_call_fn) {\n-\t\tds->ambiguous = ds->fn(current, ds->cb_data) ? 1 : 0;\n+\t\tds->ambiguous = ds->fn(ds->repo, current, ds->cb_data) ? 1 : 0;\n \t\treturn;\n \t}\n \tif (!ds->candidate_exists) {\n@@ -58,7 +59,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object\n \t}\n \n \tif (!ds->candidate_checked) {\n-\t\tds->candidate_ok = ds->fn(&ds->candidate, ds->cb_data);\n+\t\tds->candidate_ok = ds->fn(ds->repo, &ds->candidate, ds->cb_data);\n \t\tds->disambiguate_fn_used = 1;\n \t\tds->candidate_checked = 1;\n \t}\n@@ -71,7 +72,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object\n \t}\n \n \t/* if we reach this point, we know ds->candidate satisfies fn */\n-\tif (ds->fn(current, ds->cb_data)) {\n+\tif (ds->fn(ds->repo, current, ds->cb_data)) {\n \t\t/*\n \t\t * if both current and candidate satisfy fn, we cannot\n \t\t * disambiguate.\n@@ -89,9 +90,7 @@ static void find_short_object_filename(struct disambiguate_state *ds)\n {\n \tstruct object_directory *odb;\n \n-\tfor (odb = the_repository->objects->odb;\n-\t     odb && !ds->ambiguous;\n-\t     odb = odb->next) {\n+\tfor (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next) {\n \t\tint pos;\n \t\tstruct oid_array *loose_objects;\n \n@@ -182,10 +181,10 @@ static void find_short_packed_object(struct disambiguate_state *ds)\n \tstruct multi_pack_index *m;\n \tstruct packed_git *p;\n \n-\tfor (m = get_multi_pack_index(the_repository); m && !ds->ambiguous;\n+\tfor (m = get_multi_pack_index(ds->repo); m && !ds->ambiguous;\n \t     m = m->next)\n \t\tunique_in_midx(m, ds);\n-\tfor (p = get_packed_git(the_repository); p && !ds->ambiguous;\n+\tfor (p = get_packed_git(ds->repo); p && !ds->ambiguous;\n \t     p = p->next)\n \t\tunique_in_pack(p, ds);\n }\n@@ -215,7 +214,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,\n \t\t * same repository!\n \t\t */\n \t\tds->candidate_ok = (!ds->disambiguate_fn_used ||\n-\t\t\t\t    ds->fn(&ds->candidate, ds->cb_data));\n+\t\t\t\t    ds->fn(ds->repo, &ds->candidate, ds->cb_data));\n \n \tif (!ds->candidate_ok)\n \t\treturn SHORT_NAME_AMBIGUOUS;\n@@ -224,59 +223,67 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,\n \treturn 0;\n }\n \n-static int disambiguate_commit_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_commit_only(struct repository *r,\n+\t\t\t\t    const struct object_id *oid,\n+\t\t\t\t    void *cb_data_unused)\n {\n-\tint kind = oid_object_info(the_repository, oid, NULL);\n+\tint kind = oid_object_info(r, oid, NULL);\n \treturn kind == OBJ_COMMIT;\n }\n \n-static int disambiguate_committish_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_committish_only(struct repository *r,\n+\t\t\t\t\tconst struct object_id *oid,\n+\t\t\t\t\tvoid *cb_data_unused)\n {\n \tstruct object *obj;\n \tint kind;\n \n-\tkind = oid_object_info(the_repository, oid, NULL);\n+\tkind = oid_object_info(r, oid, NULL);\n \tif (kind == OBJ_COMMIT)\n \t\treturn 1;\n \tif (kind != OBJ_TAG)\n \t\treturn 0;\n \n \t/* We need to do this the hard way... */\n-\tobj = deref_tag(the_repository, parse_object(the_repository, oid),\n-\t\t\tNULL, 0);\n+\tobj = deref_tag(r, parse_object(r, oid), NULL, 0);\n \tif (obj && obj->type == OBJ_COMMIT)\n \t\treturn 1;\n \treturn 0;\n }\n \n-static int disambiguate_tree_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_tree_only(struct repository *r,\n+\t\t\t\t  const struct object_id *oid,\n+\t\t\t\t  void *cb_data_unused)\n {\n-\tint kind = oid_object_info(the_repository, oid, NULL);\n+\tint kind = oid_object_info(r, oid, NULL);\n \treturn kind == OBJ_TREE;\n }\n \n-static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_treeish_only(struct repository *r,\n+\t\t\t\t     const struct object_id *oid,\n+\t\t\t\t     void *cb_data_unused)\n {\n \tstruct object *obj;\n \tint kind;\n \n-\tkind = oid_object_info(the_repository, oid, NULL);\n+\tkind = oid_object_info(r, oid, NULL);\n \tif (kind == OBJ_TREE || kind == OBJ_COMMIT)\n \t\treturn 1;\n \tif (kind != OBJ_TAG)\n \t\treturn 0;\n \n \t/* We need to do this the hard way... */\n-\tobj = deref_tag(the_repository, parse_object(the_repository, oid),\n-\t\t\tNULL, 0);\n+\tobj = deref_tag(r, parse_object(r, oid), NULL, 0);\n \tif (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))\n \t\treturn 1;\n \treturn 0;\n }\n \n-static int disambiguate_blob_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_blob_only(struct repository *r,\n+\t\t\t\t  const struct object_id *oid,\n+\t\t\t\t  void *cb_data_unused)\n {\n-\tint kind = oid_object_info(the_repository, oid, NULL);\n+\tint kind = oid_object_info(r, oid, NULL);\n \treturn kind == OBJ_BLOB;\n }\n \n@@ -310,7 +317,8 @@ int set_disambiguate_hint_config(const char *var, const char *value)\n \treturn error(\"unknown hint type for '%s': %s\", var, value);\n }\n \n-static int init_object_disambiguation(const char *name, int len,\n+static int init_object_disambiguation(struct repository *r,\n+\t\t\t\t      const char *name, int len,\n \t\t\t\t      struct disambiguate_state *ds)\n {\n \tint i;\n@@ -341,7 +349,8 @@ static int init_object_disambiguation(const char *name, int len,\n \n \tds->len = len;\n \tds->hex_pfx[len] = '\\0';\n-\tprepare_alt_odb(the_repository);\n+\tds->repo = r;\n+\tprepare_alt_odb(r);\n \treturn 0;\n }\n \n@@ -351,25 +360,25 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)\n \tstruct strbuf desc = STRBUF_INIT;\n \tint type;\n \n-\tif (ds->fn && !ds->fn(oid, ds->cb_data))\n+\tif (ds->fn && !ds->fn(ds->repo, oid, ds->cb_data))\n \t\treturn 0;\n \n-\ttype = oid_object_info(the_repository, oid, NULL);\n+\ttype = oid_object_info(ds->repo, oid, NULL);\n \tif (type == OBJ_COMMIT) {\n-\t\tstruct commit *commit = lookup_commit(the_repository, oid);\n+\t\tstruct commit *commit = lookup_commit(ds->repo, oid);\n \t\tif (commit) {\n \t\t\tstruct pretty_print_context pp = {0};\n \t\t\tpp.date_mode.type = DATE_SHORT;\n \t\t\tformat_commit_message(commit, \" %ad - %s\", &desc, &pp);\n \t\t}\n \t} else if (type == OBJ_TAG) {\n-\t\tstruct tag *tag = lookup_tag(the_repository, oid);\n+\t\tstruct tag *tag = lookup_tag(ds->repo, oid);\n \t\tif (!parse_tag(tag) && tag->tag)\n \t\t\tstrbuf_addf(&desc, \" %s\", tag->tag);\n \t}\n \n \tadvise(\"  %s %s%s\",\n-\t       find_unique_abbrev(oid, DEFAULT_ABBREV),\n+\t       repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV),\n \t       type_name(type) ? type_name(type) : \"unknown type\",\n \t       desc.buf);\n \n@@ -383,6 +392,13 @@ static int collect_ambiguous(const struct object_id *oid, void *data)\n \treturn 0;\n }\n \n+static int repo_collect_ambiguous(struct repository *r,\n+\t\t\t\t  const struct object_id *oid,\n+\t\t\t\t  void *data)\n+{\n+\treturn collect_ambiguous(oid, data);\n+}\n+\n static struct repository *sort_ambiguous_repo;\n static int sort_ambiguous(const void *a, const void *b)\n {\n@@ -428,7 +444,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \tstruct disambiguate_state ds;\n \tint quietly = !!(flags & GET_OID_QUIETLY);\n \n-\tif (init_object_disambiguation(name, len, &ds) < 0)\n+\tif (init_object_disambiguation(the_repository, name, len, &ds) < 0)\n \t\treturn -1;\n \n \tif (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))\n@@ -483,11 +499,11 @@ int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)\n \tstruct disambiguate_state ds;\n \tint ret;\n \n-\tif (init_object_disambiguation(prefix, strlen(prefix), &ds) < 0)\n+\tif (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0)\n \t\treturn -1;\n \n \tds.always_call_fn = 1;\n-\tds.fn = collect_ambiguous;\n+\tds.fn = repo_collect_ambiguous;\n \tds.cb_data = &collect;\n \tfind_short_object_filename(&ds);\n \tfind_short_packed_object(&ds);\n@@ -543,6 +559,13 @@ static int extend_abbrev_len(const struct object_id *oid, void *cb_data)\n \treturn 0;\n }\n \n+static int repo_extend_abbrev_len(struct repository *r,\n+\t\t\t\t  const struct object_id *oid,\n+\t\t\t\t  void *cb_data)\n+{\n+\treturn extend_abbrev_len(oid, cb_data);\n+}\n+\n static void find_abbrev_len_for_midx(struct multi_pack_index *m,\n \t\t\t\t     struct min_abbrev_data *mad)\n {\n@@ -668,10 +691,10 @@ int repo_find_unique_abbrev_r(struct repository *r, char *hex,\n \n \tfind_abbrev_len_packed(&mad);\n \n-\tif (init_object_disambiguation(hex, mad.cur_len, &ds) < 0)\n+\tif (init_object_disambiguation(r, hex, mad.cur_len, &ds) < 0)\n \t\treturn -1;\n \n-\tds.fn = extend_abbrev_len;\n+\tds.fn = repo_extend_abbrev_len;\n \tds.always_call_fn = 1;\n \tds.cb_data = (void *)&mad;\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373300","messageId":"20190406113453.5149-17-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 16/33] sha1-name.c: add repo_for_each_abbrev()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:36Z","receivedAt":"2019-04-06T11:36: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>\n---\n cache.h     | 3 ++-\n sha1-name.c | 5 +++--\n 2 files changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 4f8ebb0a67..0cb95c0d4f 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1392,7 +1392,8 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c\n \t\t\t\tstruct object_context *oc);\n \n typedef int each_abbrev_fn(const struct object_id *oid, void *);\n-extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);\n+int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);\n+#define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data)\n \n extern int set_disambiguate_hint_config(const char *var, const char *value);\n \ndiff --git a/sha1-name.c b/sha1-name.c\nindex a75992eb54..cdcf84b826 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -493,13 +493,14 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \treturn status;\n }\n \n-int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)\n+int repo_for_each_abbrev(struct repository *r, const char *prefix,\n+\t\t\t each_abbrev_fn fn, void *cb_data)\n {\n \tstruct oid_array collect = OID_ARRAY_INIT;\n \tstruct disambiguate_state ds;\n \tint ret;\n \n-\tif (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0)\n+\tif (init_object_disambiguation(r, prefix, strlen(prefix), &ds) < 0)\n \t\treturn -1;\n \n \tds.always_call_fn = 1;\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373301","messageId":"20190406113453.5149-18-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 17/33] sha1-name.c: remove the_repo from get_short_oid()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:37Z","receivedAt":"2019-04-06T11:36:48Z","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 | 17 ++++++++++-------\n 1 file changed, 10 insertions(+), 7 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex cdcf84b826..2643b75b54 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -436,7 +436,8 @@ static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)\n \tsort_ambiguous_repo = NULL;\n }\n \n-static enum get_oid_result get_short_oid(const char *name, int len,\n+static enum get_oid_result get_short_oid(struct repository *r,\n+\t\t\t\t\t const char *name, int len,\n \t\t\t\t\t struct object_id *oid,\n \t\t\t\t\t unsigned flags)\n {\n@@ -444,7 +445,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \tstruct disambiguate_state ds;\n \tint quietly = !!(flags & GET_OID_QUIETLY);\n \n-\tif (init_object_disambiguation(the_repository, name, len, &ds) < 0)\n+\tif (init_object_disambiguation(r, name, len, &ds) < 0)\n \t\treturn -1;\n \n \tif (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))\n@@ -482,8 +483,8 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \t\t\tds.fn = NULL;\n \n \t\tadvise(_(\"The candidates are:\"));\n-\t\tfor_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect);\n-\t\tsort_ambiguous_oid_array(the_repository, &collect);\n+\t\trepo_for_each_abbrev(r, ds.hex_pfx, collect_ambiguous, &collect);\n+\t\tsort_ambiguous_oid_array(r, &collect);\n \n \t\tif (oid_array_for_each(&collect, show_ambiguous_object, &ds))\n \t\t\tBUG(\"show_ambiguous_object shouldn't return non-zero\");\n@@ -855,7 +856,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \n \tif (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&\n \t    (refs_found > 1 ||\n-\t     !get_short_oid(str, len, &tmp_oid, GET_OID_QUIETLY)))\n+\t     !get_short_oid(the_repository,\n+\t\t\t    str, len, &tmp_oid, GET_OID_QUIETLY)))\n \t\twarning(warn_msg, len, str);\n \n \tif (reflog_len) {\n@@ -1109,7 +1111,8 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)\n \t\t\tif (ch == 'g' && cp[-1] == '-') {\n \t\t\t\tcp++;\n \t\t\t\tlen -= cp - name;\n-\t\t\t\treturn get_short_oid(cp, len, oid, flags);\n+\t\t\t\treturn get_short_oid(the_repository,\n+\t\t\t\t\t\t     cp, len, oid, flags);\n \t\t\t}\n \t\t}\n \t}\n@@ -1163,7 +1166,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,\n \tif (!ret)\n \t\treturn FOUND;\n \n-\treturn get_short_oid(name, len, oid, lookup_flags);\n+\treturn get_short_oid(the_repository, name, len, oid, lookup_flags);\n }\n \n /*\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373302","messageId":"20190406113453.5149-19-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 18/33] sha1-name.c: remove the_repo from interpret_nth_prior_checkout()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:38Z","receivedAt":"2019-04-06T11:36:53Z","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 | 17 ++++++++++-------\n 1 file changed, 10 insertions(+), 7 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 2643b75b54..af8bf5b351 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -771,7 +771,7 @@ static inline int push_mark(const char *string, int len)\n }\n \n static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);\n-static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);\n+static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);\n \n static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\t\t  unsigned int flags)\n@@ -835,7 +835,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tint detached;\n \n-\t\tif (interpret_nth_prior_checkout(str, len, &buf) > 0) {\n+\t\tif (interpret_nth_prior_checkout(the_repository, str, len, &buf) > 0) {\n \t\t\tdetached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));\n \t\t\tstrbuf_release(&buf);\n \t\t\tif (detached)\n@@ -1288,7 +1288,8 @@ static int grab_nth_branch_switch(struct object_id *ooid, struct object_id *noid\n  * Parse @{-N} syntax, return the number of characters parsed\n  * if successful; otherwise signal an error with negative value.\n  */\n-static int interpret_nth_prior_checkout(const char *name, int namelen,\n+static int interpret_nth_prior_checkout(struct repository *r,\n+\t\t\t\t\tconst char *name, int namelen,\n \t\t\t\t\tstruct strbuf *buf)\n {\n \tlong nth;\n@@ -1312,12 +1313,14 @@ static int interpret_nth_prior_checkout(const char *name, int namelen,\n \tcb.remaining = nth;\n \tstrbuf_init(&cb.buf, 20);\n \n-\tretval = 0;\n-\tif (0 < for_each_reflog_ent_reverse(\"HEAD\", grab_nth_branch_switch, &cb)) {\n+\tretval = refs_for_each_reflog_ent_reverse(get_main_ref_store(r),\n+\t\t\t\"HEAD\", grab_nth_branch_switch, &cb);\n+\tif (0 < retval) {\n \t\tstrbuf_reset(buf);\n \t\tstrbuf_addbuf(buf, &cb.buf);\n \t\tretval = brace - name + 1;\n-\t}\n+\t} else\n+\t\tretval = 0;\n \n \tstrbuf_release(&cb.buf);\n \treturn retval;\n@@ -1484,7 +1487,7 @@ int repo_interpret_branch_name(struct repository *r,\n \t\tnamelen = strlen(name);\n \n \tif (!allowed || (allowed & INTERPRET_BRANCH_LOCAL)) {\n-\t\tlen = interpret_nth_prior_checkout(name, namelen, buf);\n+\t\tlen = interpret_nth_prior_checkout(the_repository, name, namelen, buf);\n \t\tif (!len) {\n \t\t\treturn len; /* syntax Ok, not enough switches */\n \t\t} else if (len > 0) {\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373303","messageId":"20190406113453.5149-20-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 19/33] sha1-name.c: remove the_repo from interpret_branch_mark()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:39Z","receivedAt":"2019-04-06T11:36:59Z","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 | 13 +++++++------\n 1 file changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex af8bf5b351..7d9512ac44 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1412,9 +1412,9 @@ static int reinterpret(const char *name, int namelen, int len,\n \treturn ret - used + len;\n }\n \n-static void set_shortened_ref(struct strbuf *buf, const char *ref)\n+static void set_shortened_ref(struct repository *r, struct strbuf *buf, const char *ref)\n {\n-\tchar *s = shorten_unambiguous_ref(ref, 0);\n+\tchar *s = refs_shorten_unambiguous_ref(get_main_ref_store(r), ref, 0);\n \tstrbuf_reset(buf);\n \tstrbuf_addstr(buf, s);\n \tfree(s);\n@@ -1435,7 +1435,8 @@ static int branch_interpret_allowed(const char *refname, unsigned allowed)\n \treturn 0;\n }\n \n-static int interpret_branch_mark(const char *name, int namelen,\n+static int interpret_branch_mark(struct repository *r,\n+\t\t\t\t const char *name, int namelen,\n \t\t\t\t int at, struct strbuf *buf,\n \t\t\t\t int (*get_mark)(const char *, int),\n \t\t\t\t const char *(*get_data)(struct branch *,\n@@ -1468,7 +1469,7 @@ static int interpret_branch_mark(const char *name, int namelen,\n \tif (!branch_interpret_allowed(value, allowed))\n \t\treturn -1;\n \n-\tset_shortened_ref(buf, value);\n+\tset_shortened_ref(r, buf, value);\n \treturn len + at;\n }\n \n@@ -1509,13 +1510,13 @@ int repo_interpret_branch_name(struct repository *r,\n \t\t\t\t\t\t   allowed);\n \t\t}\n \n-\t\tlen = interpret_branch_mark(name, namelen, at - name, buf,\n+\t\tlen = interpret_branch_mark(the_repository, name, namelen, at - name, buf,\n \t\t\t\t\t    upstream_mark, branch_get_upstream,\n \t\t\t\t\t    allowed);\n \t\tif (len > 0)\n \t\t\treturn len;\n \n-\t\tlen = interpret_branch_mark(name, namelen, at - name, buf,\n+\t\tlen = interpret_branch_mark(the_repository, name, namelen, at - name, buf,\n \t\t\t\t\t    push_mark, branch_get_push,\n \t\t\t\t\t    allowed);\n \t\tif (len > 0)\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373304","messageId":"20190406113453.5149-21-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 20/33] sha1-name.c: add repo_interpret_branch_name()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:40Z","receivedAt":"2019-04-06T11:37:06Z","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 | 17 ++++++++---------\n 1 file changed, 8 insertions(+), 9 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 7d9512ac44..49c62d5254 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1390,7 +1390,8 @@ static int interpret_empty_at(const char *name, int namelen, int len, struct str\n \treturn 1;\n }\n \n-static int reinterpret(const char *name, int namelen, int len,\n+static int reinterpret(struct repository *r,\n+\t\t       const char *name, int namelen, int len,\n \t\t       struct strbuf *buf, unsigned allowed)\n {\n \t/* we have extra data, which might need further processing */\n@@ -1399,7 +1400,7 @@ static int reinterpret(const char *name, int namelen, int len,\n \tint ret;\n \n \tstrbuf_add(buf, name + len, namelen - len);\n-\tret = interpret_branch_name(buf->buf, buf->len, &tmp, allowed);\n+\tret = repo_interpret_branch_name(r, buf->buf, buf->len, &tmp, allowed);\n \t/* that data was not interpreted, remove our cruft */\n \tif (ret < 0) {\n \t\tstrbuf_setlen(buf, used);\n@@ -1482,20 +1483,18 @@ int repo_interpret_branch_name(struct repository *r,\n \tconst char *start;\n \tint len;\n \n-\tif (r != the_repository)\n-\t\tBUG(\"interpret_branch_name() does not really use 'r' yet\");\n \tif (!namelen)\n \t\tnamelen = strlen(name);\n \n \tif (!allowed || (allowed & INTERPRET_BRANCH_LOCAL)) {\n-\t\tlen = interpret_nth_prior_checkout(the_repository, name, namelen, buf);\n+\t\tlen = interpret_nth_prior_checkout(r, name, namelen, buf);\n \t\tif (!len) {\n \t\t\treturn len; /* syntax Ok, not enough switches */\n \t\t} else if (len > 0) {\n \t\t\tif (len == namelen)\n \t\t\t\treturn len; /* consumed all */\n \t\t\telse\n-\t\t\t\treturn reinterpret(name, namelen, len, buf, allowed);\n+\t\t\t\treturn reinterpret(r, name, namelen, len, buf, allowed);\n \t\t}\n \t}\n \n@@ -1506,17 +1505,17 @@ int repo_interpret_branch_name(struct repository *r,\n \t\tif (!allowed || (allowed & INTERPRET_BRANCH_HEAD)) {\n \t\t\tlen = interpret_empty_at(name, namelen, at - name, buf);\n \t\t\tif (len > 0)\n-\t\t\t\treturn reinterpret(name, namelen, len, buf,\n+\t\t\t\treturn reinterpret(r, name, namelen, len, buf,\n \t\t\t\t\t\t   allowed);\n \t\t}\n \n-\t\tlen = interpret_branch_mark(the_repository, name, namelen, at - name, buf,\n+\t\tlen = interpret_branch_mark(r, name, namelen, at - name, buf,\n \t\t\t\t\t    upstream_mark, branch_get_upstream,\n \t\t\t\t\t    allowed);\n \t\tif (len > 0)\n \t\t\treturn len;\n \n-\t\tlen = interpret_branch_mark(the_repository, name, namelen, at - name, buf,\n+\t\tlen = interpret_branch_mark(r, name, namelen, at - name, buf,\n \t\t\t\t\t    push_mark, branch_get_push,\n \t\t\t\t\t    allowed);\n \t\tif (len > 0)\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373305","messageId":"20190406113453.5149-22-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 21/33] sha1-name.c: remove the_repo from get_oid_oneline()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:41Z","receivedAt":"2019-04-06T11:37:11Z","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 | 13 +++++++------\n 1 file changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 49c62d5254..fb80306f1a 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -15,7 +15,7 @@\n #include \"midx.h\"\n #include \"commit-reach.h\"\n \n-static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);\n+static int get_oid_oneline(struct repository *r, const char *, struct object_id *, struct commit_list *);\n \n typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);\n \n@@ -1090,7 +1090,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \n \t\tprefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));\n \t\tcommit_list_insert((struct commit *)o, &list);\n-\t\tret = get_oid_oneline(prefix, oid, list);\n+\t\tret = get_oid_oneline(the_repository, prefix, oid, list);\n \t\tfree(prefix);\n \t\treturn ret;\n \t}\n@@ -1204,8 +1204,9 @@ static int handle_one_ref(const char *path, const struct object_id *oid,\n \treturn 0;\n }\n \n-static int get_oid_oneline(const char *prefix, struct object_id *oid,\n-\t\t\t    struct commit_list *list)\n+static int get_oid_oneline(struct repository *r,\n+\t\t\t   const char *prefix, struct object_id *oid,\n+\t\t\t   struct commit_list *list)\n {\n \tstruct commit_list *backup = NULL, *l;\n \tint found = 0;\n@@ -1236,7 +1237,7 @@ static int get_oid_oneline(const char *prefix, struct object_id *oid,\n \t\tint matches;\n \n \t\tcommit = pop_most_recent_commit(&list, ONELINE_SEEN);\n-\t\tif (!parse_object(the_repository, &commit->object.oid))\n+\t\tif (!parse_object(r, &commit->object.oid))\n \t\t\tcontinue;\n \t\tbuf = get_commit_buffer(commit, NULL);\n \t\tp = strstr(buf, \"\\n\\n\");\n@@ -1760,7 +1761,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\tfor_each_ref(handle_one_ref, &list);\n \t\t\thead_ref(handle_one_ref, &list);\n \t\t\tcommit_list_sort_by_date(&list);\n-\t\t\treturn get_oid_oneline(name + 2, oid, list);\n+\t\t\treturn get_oid_oneline(repo, name + 2, oid, list);\n \t\t}\n \t\tif (namelen < 3 ||\n \t\t    name[2] != ':' ||\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373306","messageId":"20190406113453.5149-23-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 22/33] sha1-name.c: remove the_repo from get_describe_name()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:42Z","receivedAt":"2019-04-06T11:37:17Z","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 | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex fb80306f1a..1cda854f02 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1097,7 +1097,9 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \treturn 0;\n }\n \n-static int get_describe_name(const char *name, int len, struct object_id *oid)\n+static int get_describe_name(struct repository *r,\n+\t\t\t     const char *name, int len,\n+\t\t\t     struct object_id *oid)\n {\n \tconst char *cp;\n \tunsigned flags = GET_OID_QUIETLY | GET_OID_COMMIT;\n@@ -1111,7 +1113,7 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)\n \t\t\tif (ch == 'g' && cp[-1] == '-') {\n \t\t\t\tcp++;\n \t\t\t\tlen -= cp - name;\n-\t\t\t\treturn get_short_oid(the_repository,\n+\t\t\t\treturn get_short_oid(r,\n \t\t\t\t\t\t     cp, len, oid, flags);\n \t\t\t}\n \t\t}\n@@ -1162,7 +1164,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,\n \t\treturn FOUND;\n \n \t/* It could be describe output that is \"SOMETHING-gXXXX\" */\n-\tret = get_describe_name(name, len, oid);\n+\tret = get_describe_name(the_repository, name, len, oid);\n \tif (!ret)\n \t\treturn FOUND;\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373307","messageId":"20190406113453.5149-24-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 23/33] sha1-name.c: remove the_repo from get_oid_basic()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:43Z","receivedAt":"2019-04-06T11:37:22Z","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 | 25 ++++++++++++-------------\n 1 file changed, 12 insertions(+), 13 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 1cda854f02..d4c135aea8 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -773,8 +773,8 @@ static inline int push_mark(const char *string, int len)\n static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);\n static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);\n \n-static int get_oid_basic(const char *str, int len, struct object_id *oid,\n-\t\t\t  unsigned int flags)\n+static int get_oid_basic(struct repository *r, const char *str, int len,\n+\t\t\t struct object_id *oid, unsigned int flags)\n {\n \tstatic const char *warn_msg = \"refname '%.*s' is ambiguous.\";\n \tstatic const char *object_name_msg = N_(\n@@ -792,9 +792,9 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \tint refs_found = 0;\n \tint at, reflog_len, nth_prior = 0;\n \n-\tif (len == the_hash_algo->hexsz && !get_oid_hex(str, oid)) {\n+\tif (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {\n \t\tif (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {\n-\t\t\trefs_found = dwim_ref(str, len, &tmp_oid, &real_ref);\n+\t\t\trefs_found = repo_dwim_ref(r, str, len, &tmp_oid, &real_ref);\n \t\t\tif (refs_found > 0) {\n \t\t\t\twarning(warn_msg, len, str);\n \t\t\t\tif (advice_object_name_warning)\n@@ -835,8 +835,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tint detached;\n \n-\t\tif (interpret_nth_prior_checkout(the_repository, str, len, &buf) > 0) {\n-\t\t\tdetached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));\n+\t\tif (interpret_nth_prior_checkout(r, str, len, &buf) > 0) {\n+\t\t\tdetached = (buf.len == r->hash_algo->hexsz && !get_oid_hex(buf.buf, oid));\n \t\t\tstrbuf_release(&buf);\n \t\t\tif (detached)\n \t\t\t\treturn 0;\n@@ -845,19 +845,18 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \n \tif (!len && reflog_len)\n \t\t/* allow \"@{...}\" to mean the current branch reflog */\n-\t\trefs_found = dwim_ref(\"HEAD\", 4, oid, &real_ref);\n+\t\trefs_found = repo_dwim_ref(r, \"HEAD\", 4, oid, &real_ref);\n \telse if (reflog_len)\n-\t\trefs_found = dwim_log(str, len, oid, &real_ref);\n+\t\trefs_found = repo_dwim_log(r, str, len, oid, &real_ref);\n \telse\n-\t\trefs_found = dwim_ref(str, len, oid, &real_ref);\n+\t\trefs_found = repo_dwim_ref(r, str, len, oid, &real_ref);\n \n \tif (!refs_found)\n \t\treturn -1;\n \n \tif (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&\n \t    (refs_found > 1 ||\n-\t     !get_short_oid(the_repository,\n-\t\t\t    str, len, &tmp_oid, GET_OID_QUIETLY)))\n+\t     !get_short_oid(r, str, len, &tmp_oid, GET_OID_QUIETLY)))\n \t\twarning(warn_msg, len, str);\n \n \tif (reflog_len) {\n@@ -889,7 +888,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\t\t\treturn -1;\n \t\t\t}\n \t\t}\n-\t\tif (read_ref_at(get_main_ref_store(the_repository),\n+\t\tif (read_ref_at(get_main_ref_store(r),\n \t\t\t\treal_ref, flags, at_time, nth, oid, NULL,\n \t\t\t\t&co_time, &co_tz, &co_cnt)) {\n \t\t\tif (!len) {\n@@ -1159,7 +1158,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,\n \tif (!ret)\n \t\treturn FOUND;\n \n-\tret = get_oid_basic(name, len, oid, lookup_flags);\n+\tret = get_oid_basic(the_repository, name, len, oid, lookup_flags);\n \tif (!ret)\n \t\treturn FOUND;\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373308","messageId":"20190406113453.5149-25-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 24/33] sha1-name.c: remove the_repo from get_oid_1()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:44Z","receivedAt":"2019-04-06T11:37:28Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"There is a cyclic dependency between one of these functions so they\ncannot be converted one by one, so all related functions are converted\nat once.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n cache.h     |  7 +++++--\n sha1-name.c | 59 ++++++++++++++++++++++++++++-------------------------\n 2 files changed, 36 insertions(+), 30 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 0cb95c0d4f..2149dc4f56 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1491,8 +1491,11 @@ extern void *read_object_with_reference(const struct object_id *oid,\n \t\t\t\t\tunsigned long *size,\n \t\t\t\t\tstruct object_id *oid_ret);\n \n-extern struct object *peel_to_type(const char *name, int namelen,\n-\t\t\t\t   struct object *o, enum object_type);\n+struct object *repo_peel_to_type(struct repository *r,\n+\t\t\t\t const char *name, int namelen,\n+\t\t\t\t struct object *o, enum object_type);\n+#define peel_to_type(name, namelen, obj, type) \\\n+\trepo_peel_to_type(the_repository, name, namelen, obj, type)\n \n enum date_mode_type {\n \tDATE_NORMAL = 0,\ndiff --git a/sha1-name.c b/sha1-name.c\nindex d4c135aea8..5741a9f821 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -770,7 +770,7 @@ static inline int push_mark(const char *string, int len)\n \treturn at_mark(string, len, suffix, ARRAY_SIZE(suffix));\n }\n \n-static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);\n+static enum get_oid_result get_oid_1(struct repository *r, const char *name, int len, struct object_id *oid, unsigned lookup_flags);\n static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);\n \n static int get_oid_basic(struct repository *r, const char *str, int len,\n@@ -921,18 +921,19 @@ static int get_oid_basic(struct repository *r, const char *str, int len,\n \treturn 0;\n }\n \n-static enum get_oid_result get_parent(const char *name, int len,\n+static enum get_oid_result get_parent(struct repository *r,\n+\t\t\t\t      const char *name, int len,\n \t\t\t\t      struct object_id *result, int idx)\n {\n \tstruct object_id oid;\n-\tenum get_oid_result ret = get_oid_1(name, len, &oid,\n+\tenum get_oid_result ret = get_oid_1(r, name, len, &oid,\n \t\t\t\t\t    GET_OID_COMMITTISH);\n \tstruct commit *commit;\n \tstruct commit_list *p;\n \n \tif (ret)\n \t\treturn ret;\n-\tcommit = lookup_commit_reference(the_repository, &oid);\n+\tcommit = lookup_commit_reference(r, &oid);\n \tif (parse_commit(commit))\n \t\treturn MISSING_OBJECT;\n \tif (!idx) {\n@@ -950,7 +951,8 @@ static enum get_oid_result get_parent(const char *name, int len,\n \treturn MISSING_OBJECT;\n }\n \n-static enum get_oid_result get_nth_ancestor(const char *name, int len,\n+static enum get_oid_result get_nth_ancestor(struct repository *r,\n+\t\t\t\t\t    const char *name, int len,\n \t\t\t\t\t    struct object_id *result,\n \t\t\t\t\t    int generation)\n {\n@@ -958,10 +960,10 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,\n \tstruct commit *commit;\n \tint ret;\n \n-\tret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);\n+\tret = get_oid_1(r, name, len, &oid, GET_OID_COMMITTISH);\n \tif (ret)\n \t\treturn ret;\n-\tcommit = lookup_commit_reference(the_repository, &oid);\n+\tcommit = lookup_commit_reference(r, &oid);\n \tif (!commit)\n \t\treturn MISSING_OBJECT;\n \n@@ -974,20 +976,20 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,\n \treturn FOUND;\n }\n \n-struct object *peel_to_type(const char *name, int namelen,\n-\t\t\t    struct object *o, enum object_type expected_type)\n+struct object *repo_peel_to_type(struct repository *r, const char *name, int namelen,\n+\t\t\t\t struct object *o, enum object_type expected_type)\n {\n \tif (name && !namelen)\n \t\tnamelen = strlen(name);\n \twhile (1) {\n-\t\tif (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))\n+\t\tif (!o || (!o->parsed && !parse_object(r, &o->oid)))\n \t\t\treturn NULL;\n \t\tif (expected_type == OBJ_ANY || o->type == expected_type)\n \t\t\treturn o;\n \t\tif (o->type == OBJ_TAG)\n \t\t\to = ((struct tag*) o)->tagged;\n \t\telse if (o->type == OBJ_COMMIT)\n-\t\t\to = &(get_commit_tree(((struct commit *)o))->object);\n+\t\t\to = &(repo_get_commit_tree(r, ((struct commit *)o))->object);\n \t\telse {\n \t\t\tif (name)\n \t\t\t\terror(\"%.*s: expected %s type, but the object \"\n@@ -999,8 +1001,8 @@ struct object *peel_to_type(const char *name, int namelen,\n \t}\n }\n \n-static int peel_onion(const char *name, int len, struct object_id *oid,\n-\t\t      unsigned lookup_flags)\n+static int peel_onion(struct repository *r, const char *name, int len,\n+\t\t      struct object_id *oid, unsigned lookup_flags)\n {\n \tstruct object_id outer;\n \tconst char *sp;\n@@ -1050,15 +1052,15 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \telse if (expected_type == OBJ_TREE)\n \t\tlookup_flags |= GET_OID_TREEISH;\n \n-\tif (get_oid_1(name, sp - name - 2, &outer, lookup_flags))\n+\tif (get_oid_1(r, name, sp - name - 2, &outer, lookup_flags))\n \t\treturn -1;\n \n-\to = parse_object(the_repository, &outer);\n+\to = parse_object(r, &outer);\n \tif (!o)\n \t\treturn -1;\n \tif (!expected_type) {\n-\t\to = deref_tag(the_repository, o, name, sp - name - 2);\n-\t\tif (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))\n+\t\to = deref_tag(r, o, name, sp - name - 2);\n+\t\tif (!o || (!o->parsed && !parse_object(r, &o->oid)))\n \t\t\treturn -1;\n \t\toidcpy(oid, &o->oid);\n \t\treturn 0;\n@@ -1069,7 +1071,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \t * if we do not get the needed object, we should\n \t * barf.\n \t */\n-\to = peel_to_type(name, len, o, expected_type);\n+\to = repo_peel_to_type(r, name, len, o, expected_type);\n \tif (!o)\n \t\treturn -1;\n \n@@ -1089,7 +1091,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \n \t\tprefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));\n \t\tcommit_list_insert((struct commit *)o, &list);\n-\t\tret = get_oid_oneline(the_repository, prefix, oid, list);\n+\t\tret = get_oid_oneline(r, prefix, oid, list);\n \t\tfree(prefix);\n \t\treturn ret;\n \t}\n@@ -1120,7 +1122,8 @@ static int get_describe_name(struct repository *r,\n \treturn -1;\n }\n \n-static enum get_oid_result get_oid_1(const char *name, int len,\n+static enum get_oid_result get_oid_1(struct repository *r,\n+\t\t\t\t     const char *name, int len,\n \t\t\t\t     struct object_id *oid,\n \t\t\t\t     unsigned lookup_flags)\n {\n@@ -1149,25 +1152,25 @@ static enum get_oid_result get_oid_1(const char *name, int len,\n \t\tif (!num && len1 == len - 1)\n \t\t\tnum = 1;\n \t\tif (has_suffix == '^')\n-\t\t\treturn get_parent(name, len1, oid, num);\n+\t\t\treturn get_parent(r, name, len1, oid, num);\n \t\t/* else if (has_suffix == '~') -- goes without saying */\n-\t\treturn get_nth_ancestor(name, len1, oid, num);\n+\t\treturn get_nth_ancestor(r, name, len1, oid, num);\n \t}\n \n-\tret = peel_onion(name, len, oid, lookup_flags);\n+\tret = peel_onion(r, name, len, oid, lookup_flags);\n \tif (!ret)\n \t\treturn FOUND;\n \n-\tret = get_oid_basic(the_repository, name, len, oid, lookup_flags);\n+\tret = get_oid_basic(r, name, len, oid, lookup_flags);\n \tif (!ret)\n \t\treturn FOUND;\n \n \t/* It could be describe output that is \"SOMETHING-gXXXX\" */\n-\tret = get_describe_name(the_repository, name, len, oid);\n+\tret = get_describe_name(r, name, len, oid);\n \tif (!ret)\n \t\treturn FOUND;\n \n-\treturn get_short_oid(the_repository, name, len, oid, lookup_flags);\n+\treturn get_short_oid(r, name, len, oid, lookup_flags);\n }\n \n /*\n@@ -1741,7 +1744,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \tmemset(oc, 0, sizeof(*oc));\n \toc->mode = S_IFINVALID;\n \tstrbuf_init(&oc->symlink_path, 0);\n-\tret = get_oid_1(name, namelen, oid, flags);\n+\tret = get_oid_1(repo, name, namelen, oid, flags);\n \tif (!ret)\n \t\treturn ret;\n \t/*\n@@ -1822,7 +1825,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\tsub_flags &= ~GET_OID_DISAMBIGUATORS;\n \t\tsub_flags |= GET_OID_TREEISH;\n \n-\t\tif (!get_oid_1(name, len, &tree_oid, sub_flags)) {\n+\t\tif (!get_oid_1(repo, name, len, &tree_oid, sub_flags)) {\n \t\t\tconst char *filename = cp+1;\n \t\t\tchar *new_filename = NULL;\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373309","messageId":"20190406113453.5149-26-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 25/33] sha1-name.c: remove the_repo from handle_one_ref()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:45Z","receivedAt":"2019-04-06T11:37:33Z","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 | 19 ++++++++++++++-----\n 1 file changed, 14 insertions(+), 5 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 5741a9f821..d9050776dd 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1189,15 +1189,21 @@ static enum get_oid_result get_oid_1(struct repository *r,\n /* Remember to update object flag allocation in object.h */\n #define ONELINE_SEEN (1u<<20)\n \n+struct handle_one_ref_cb {\n+\tstruct repository *repo;\n+\tstruct commit_list **list;\n+};\n+\n static int handle_one_ref(const char *path, const struct object_id *oid,\n \t\t\t  int flag, void *cb_data)\n {\n-\tstruct commit_list **list = cb_data;\n-\tstruct object *object = parse_object(the_repository, oid);\n+\tstruct handle_one_ref_cb *cb = cb_data;\n+\tstruct commit_list **list = cb->list;\n+\tstruct object *object = parse_object(cb->repo, oid);\n \tif (!object)\n \t\treturn 0;\n \tif (object->type == OBJ_TAG) {\n-\t\tobject = deref_tag(the_repository, object, path,\n+\t\tobject = deref_tag(cb->repo, object, path,\n \t\t\t\t   strlen(path));\n \t\tif (!object)\n \t\t\treturn 0;\n@@ -1760,10 +1766,13 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\tchar *new_path = NULL;\n \t\tint pos;\n \t\tif (!only_to_die && namelen > 2 && name[1] == '/') {\n+\t\t\tstruct handle_one_ref_cb cb;\n \t\t\tstruct commit_list *list = NULL;\n \n-\t\t\tfor_each_ref(handle_one_ref, &list);\n-\t\t\thead_ref(handle_one_ref, &list);\n+\t\t\tcb.repo = repo;\n+\t\t\tcb.list = &list;\n+\t\t\trefs_for_each_ref(repo->refs, handle_one_ref, &cb);\n+\t\t\trefs_head_ref(repo->refs, handle_one_ref, &cb);\n \t\t\tcommit_list_sort_by_date(&list);\n \t\t\treturn get_oid_oneline(repo, name + 2, oid, list);\n \t\t}\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373310","messageId":"20190406113453.5149-27-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 26/33] sha1-name.c: remove the_repo from diagnose_invalid_index_path()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:46Z","receivedAt":"2019-04-06T11:37:38Z","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 dir.c       | 8 ++++++++\n dir.h       | 4 +++-\n sha1-name.c | 7 ++++---\n 3 files changed, 15 insertions(+), 4 deletions(-)\n\ndiff --git a/dir.c b/dir.c\nindex b2cabadf25..e6d97343f4 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -2315,6 +2315,14 @@ int file_exists(const char *f)\n \treturn lstat(f, &sb) == 0;\n }\n \n+int repo_file_exists(struct repository *repo, const char *path)\n+{\n+\tif (repo != the_repository)\n+\t\tBUG(\"do not know how to check file existence in arbitrary repo\");\n+\n+\treturn file_exists(path);\n+}\n+\n static int cmp_icase(char a, char b)\n {\n \tif (a == b)\ndiff --git a/dir.h b/dir.h\nindex e3ec26143d..47c5409ced 100644\n--- a/dir.h\n+++ b/dir.h\n@@ -269,7 +269,9 @@ extern void add_exclude(const char *string, const char *base,\n \t\t\tint baselen, struct exclude_list *el, int srcpos);\n extern void clear_exclude_list(struct exclude_list *el);\n extern void clear_directory(struct dir_struct *dir);\n-extern int file_exists(const char *);\n+\n+int repo_file_exists(struct repository *repo, const char *path);\n+int file_exists(const char *);\n \n extern int is_inside_dir(const char *dir);\n extern int dir_inside_of(const char *subdir, const char *dir);\ndiff --git a/sha1-name.c b/sha1-name.c\nindex d9050776dd..6caf3f4e3a 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1664,11 +1664,12 @@ static void diagnose_invalid_oid_path(const char *prefix,\n }\n \n /* Must be called only when :stage:filename doesn't exist. */\n-static void diagnose_invalid_index_path(struct index_state *istate,\n+static void diagnose_invalid_index_path(struct repository *r,\n \t\t\t\t\tint stage,\n \t\t\t\t\tconst char *prefix,\n \t\t\t\t\tconst char *filename)\n {\n+\tstruct index_state *istate = r->index;\n \tconst struct cache_entry *ce;\n \tint pos;\n \tunsigned namelen = strlen(filename);\n@@ -1708,7 +1709,7 @@ static void diagnose_invalid_index_path(struct index_state *istate,\n \t\t\t    ce_stage(ce), filename);\n \t}\n \n-\tif (file_exists(filename))\n+\tif (repo_file_exists(r, filename))\n \t\tdie(\"Path '%s' exists on disk, but not in the index.\", filename);\n \tif (is_missing_file_error(errno))\n \t\tdie(\"Path '%s' does not exist (neither on disk nor in the index).\",\n@@ -1814,7 +1815,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\tpos++;\n \t\t}\n \t\tif (only_to_die && name[1] && name[1] != '/')\n-\t\t\tdiagnose_invalid_index_path(repo->index, stage, prefix, cp);\n+\t\t\tdiagnose_invalid_index_path(repo, stage, prefix, cp);\n \t\tfree(new_path);\n \t\treturn -1;\n \t}\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373311","messageId":"20190406113453.5149-28-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 27/33] sha1-name.c: remove the_repo from resolve_relative_path()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:47Z","receivedAt":"2019-04-06T11:37:43Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\"remove\" is not entirely correct. But at least the function is aware\nthat if the given repo is not the_repository, then $CWD and\nis_inside_work_tree() means nothing.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n sha1-name.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 6caf3f4e3a..6b53ea2eeb 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1719,12 +1719,12 @@ static void diagnose_invalid_index_path(struct repository *r,\n }\n \n \n-static char *resolve_relative_path(const char *rel)\n+static char *resolve_relative_path(struct repository *r, const char *rel)\n {\n \tif (!starts_with(rel, \"./\") && !starts_with(rel, \"../\"))\n \t\treturn NULL;\n \n-\tif (!is_inside_work_tree())\n+\tif (r != the_repository || !is_inside_work_tree())\n \t\tdie(\"relative path syntax can't be used outside working tree.\");\n \n \t/* die() inside prefix_path() if resolved path is outside worktree */\n@@ -1785,7 +1785,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\tstage = name[1] - '0';\n \t\t\tcp = name + 3;\n \t\t}\n-\t\tnew_path = resolve_relative_path(cp);\n+\t\tnew_path = resolve_relative_path(repo, cp);\n \t\tif (!new_path) {\n \t\t\tnamelen = namelen - (cp - name);\n \t\t} else {\n@@ -1839,7 +1839,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\tconst char *filename = cp+1;\n \t\t\tchar *new_filename = NULL;\n \n-\t\t\tnew_filename = resolve_relative_path(filename);\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\tif (flags & GET_OID_FOLLOW_SYMLINKS) {\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373312","messageId":"20190406113453.5149-29-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 28/33] sha1-name.c: remove the_repo from get_oid_with_context_1()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:48Z","receivedAt":"2019-04-06T11:37: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 sha1-name.c | 11 ++++++++++-\n 1 file changed, 10 insertions(+), 1 deletion(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 6b53ea2eeb..64a50d1291 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -12,6 +12,7 @@\n #include \"packfile.h\"\n #include \"object-store.h\"\n #include \"repository.h\"\n+#include \"submodule.h\"\n #include \"midx.h\"\n #include \"commit-reach.h\"\n \n@@ -1797,7 +1798,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\toc->path = xstrdup(cp);\n \n \t\tif (!repo->index->cache)\n-\t\t\trepo_read_index(the_repository);\n+\t\t\trepo_read_index(repo);\n \t\tpos = index_name_pos(repo->index, cp, namelen);\n \t\tif (pos < 0)\n \t\t\tpos = -pos - 1;\n@@ -1842,6 +1843,14 @@ 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\t\tfilename, oid, &oc->symlink_path,\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373313","messageId":"20190406113453.5149-30-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 29/33] sha1-name.c: add repo_get_oid()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:49Z","receivedAt":"2019-04-06T11:37:54Z","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     | 3 ++-\n sha1-name.c | 4 ++--\n 2 files changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 2149dc4f56..f6e87194d0 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1380,7 +1380,8 @@ enum get_oid_result {\n \t\t       */\n };\n \n-extern int get_oid(const char *str, struct object_id *oid);\n+int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);\n+#define get_oid(str, oid) repo_get_oid(the_repository, str, oid)\n extern int get_oid_commit(const char *str, struct object_id *oid);\n extern int get_oid_committish(const char *str, struct object_id *oid);\n extern int get_oid_tree(const char *str, struct object_id *oid);\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 64a50d1291..953df0d692 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1573,10 +1573,10 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)\n  * This is like \"get_oid_basic()\", except it allows \"object ID expressions\",\n  * notably \"xyz^\" for \"parent of xyz\"\n  */\n-int get_oid(const char *name, struct object_id *oid)\n+int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository, name, 0, oid, &unused);\n+\treturn get_oid_with_context(r, name, 0, oid, &unused);\n }\n \n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373314","messageId":"20190406113453.5149-31-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 30/33] submodule-config.c: use repo_get_oid for reading .gitmodules","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:50Z","receivedAt":"2019-04-06T11:38:00Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Since 76e9bdc437 (submodule: support reading .gitmodules when it's not\nin the working tree - 2018-10-25), every time you do\n\n    git grep --recurse-submodules\n\nyou are likely to see one warning line per submodule (unless all those\nsubmodules also have submodules). On a superproject with plenty of\nsubmodules (I've seen one with 67) this is really annoying.\n\nThe warning was there because we could not resolve extended SHA-1\nsyntax on a submodule. We can now. Make use of the new API and get rid\nof the warning.\n\nIt would be even better if config_with_options() supports multiple\nrepositories too. But one step at a time.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n submodule-config.c                 | 20 +++++++-------------\n t/t7814-grep-recurse-submodules.sh |  6 +-----\n 2 files changed, 8 insertions(+), 18 deletions(-)\n\ndiff --git a/submodule-config.c b/submodule-config.c\nindex 66653e86b9..4264ee216f 100644\n--- a/submodule-config.c\n+++ b/submodule-config.c\n@@ -625,23 +625,16 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void\n \t\tconst struct config_options opts = { 0 };\n \t\tstruct object_id oid;\n \t\tchar *file;\n+\t\tchar *oidstr = NULL;\n \n \t\tfile = repo_worktree_path(repo, GITMODULES_FILE);\n \t\tif (file_exists(file)) {\n \t\t\tconfig_source.file = file;\n-\t\t} else if (repo->submodule_prefix) {\n-\t\t\t/*\n-\t\t\t * When get_oid and config_with_options, used below,\n-\t\t\t * become able to work on a specific repository, this\n-\t\t\t * warning branch can be removed.\n-\t\t\t */\n-\t\t\twarning(\"nested submodules without %s in the working tree are not supported yet\",\n-\t\t\t\tGITMODULES_FILE);\n-\t\t\tgoto out;\n-\t\t} else if (get_oid(GITMODULES_INDEX, &oid) >= 0) {\n-\t\t\tconfig_source.blob = GITMODULES_INDEX;\n-\t\t} else if (get_oid(GITMODULES_HEAD, &oid) >= 0) {\n-\t\t\tconfig_source.blob = GITMODULES_HEAD;\n+\t\t} else if (repo_get_oid(repo, GITMODULES_INDEX, &oid) >= 0 ||\n+\t\t\t   repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {\n+\t\t\tconfig_source.blob = oidstr = xstrdup(oid_to_hex(&oid));\n+\t\t\tif (repo != the_repository)\n+\t\t\t\tadd_to_alternates_memory(repo->objects->odb->path);\n \t\t} else {\n \t\t\tgoto out;\n \t\t}\n@@ -649,6 +642,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void\n \t\tconfig_with_options(fn, data, &config_source, &opts);\n \n out:\n+\t\tfree(oidstr);\n \t\tfree(file);\n \t}\n }\ndiff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh\nindex fa475d52fa..134a694516 100755\n--- a/t/t7814-grep-recurse-submodules.sh\n+++ b/t/t7814-grep-recurse-submodules.sh\n@@ -380,11 +380,7 @@ test_expect_success 'grep --recurse-submodules should pass the pattern type alon\n \tfi\n '\n \n-# Recursing down into nested submodules which do not have .gitmodules in their\n-# working tree does not work yet. This is because config_from_gitmodules()\n-# uses get_oid() and the latter is still not able to get objects from an\n-# arbitrary repository (the nested submodule, in this case).\n-test_expect_failure 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '\n+test_expect_success 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '\n \ttest_when_finished \"git -C submodule checkout .gitmodules\" &&\n \trm submodule/.gitmodules &&\n \tgit grep --recurse-submodules -e \"(.|.)[\\d]\" >actual &&\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373315","messageId":"20190406113453.5149-32-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 31/33] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:51Z","receivedAt":"2019-04-06T11:38:05Z","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 setup.c     | 7 ++++---\n sha1-name.c | 6 ++++--\n 3 files changed, 11 insertions(+), 6 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex f6e87194d0..3718b3db8a 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1387,7 +1387,9 @@ extern int get_oid_committish(const char *str, struct object_id *oid);\n extern int get_oid_tree(const char *str, struct object_id *oid);\n extern int get_oid_treeish(const char *str, struct object_id *oid);\n extern int get_oid_blob(const char *str, struct object_id *oid);\n-extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);\n+void maybe_die_on_misspelt_object_name(struct repository *repo,\n+\t\t\t\t       const char *name,\n+\t\t\t\t       const char *prefix);\n extern enum get_oid_result get_oid_with_context(struct repository *repo, const char *str,\n \t\t\t\tunsigned flags, struct object_id *oid,\n \t\t\t\tstruct object_context *oc);\ndiff --git a/setup.c b/setup.c\nindex d0c958c3b2..8dcb4631f7 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -164,7 +164,8 @@ int check_filename(const char *prefix, const char *arg)\n \tdie_errno(_(\"failed to stat '%s'\"), arg);\n }\n \n-static void NORETURN die_verify_filename(const char *prefix,\n+static void NORETURN die_verify_filename(struct repository *r,\n+\t\t\t\t\t const char *prefix,\n \t\t\t\t\t const char *arg,\n \t\t\t\t\t int diagnose_misspelt_rev)\n {\n@@ -179,7 +180,7 @@ static void NORETURN die_verify_filename(const char *prefix,\n \t * let maybe_die_on_misspelt_object_name() even trigger.\n \t */\n \tif (!(arg[0] == ':' && !isalnum(arg[1])))\n-\t\tmaybe_die_on_misspelt_object_name(arg, prefix);\n+\t\tmaybe_die_on_misspelt_object_name(r, arg, prefix);\n \n \t/* ... or fall back the most general message. */\n \tdie(_(\"ambiguous argument '%s': unknown revision or path not in the working tree.\\n\"\n@@ -234,7 +235,7 @@ void verify_filename(const char *prefix,\n \t\tdie(_(\"option '%s' must come before non-option arguments\"), arg);\n \tif (looks_like_pathspec(arg) || check_filename(prefix, arg))\n \t\treturn;\n-\tdie_verify_filename(prefix, arg, diagnose_misspelt_rev);\n+\tdie_verify_filename(the_repository, prefix, arg, diagnose_misspelt_rev);\n }\n \n /*\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 953df0d692..b94d381bef 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1885,11 +1885,13 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n  * exist in 'HEAD'\" when given \"HEAD:doc\", or it may return in which case\n  * you have a chance to diagnose the error further.\n  */\n-void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)\n+void maybe_die_on_misspelt_object_name(struct repository *r,\n+\t\t\t\t       const char *name,\n+\t\t\t\t       const char *prefix)\n {\n \tstruct object_context oc;\n \tstruct object_id oid;\n-\tget_oid_with_context_1(the_repository, name, GET_OID_ONLY_TO_DIE,\n+\tget_oid_with_context_1(r, name, GET_OID_ONLY_TO_DIE,\n \t\t\t       prefix, &oid, &oc);\n }\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373316","messageId":"20190406113453.5149-33-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 32/33] sha1-name.c: remove the_repo from other get_oid_*","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:52Z","receivedAt":"2019-04-06T11:38:10Z","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     | 18 ++++++++++++------\n sha1-name.c | 35 ++++++++++++++++++++---------------\n 2 files changed, 32 insertions(+), 21 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 3718b3db8a..871a167bf8 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1381,12 +1381,11 @@ enum get_oid_result {\n };\n \n int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);\n-#define get_oid(str, oid) repo_get_oid(the_repository, str, oid)\n-extern int get_oid_commit(const char *str, struct object_id *oid);\n-extern int get_oid_committish(const char *str, struct object_id *oid);\n-extern int get_oid_tree(const char *str, struct object_id *oid);\n-extern int get_oid_treeish(const char *str, struct object_id *oid);\n-extern int get_oid_blob(const char *str, struct object_id *oid);\n+int repo_get_oid_commit(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_committish(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid);\n void maybe_die_on_misspelt_object_name(struct repository *repo,\n \t\t\t\t       const char *name,\n \t\t\t\t       const char *prefix);\n@@ -1394,6 +1393,13 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c\n \t\t\t\tunsigned flags, struct object_id *oid,\n \t\t\t\tstruct object_context *oc);\n \n+#define get_oid(str, oid)\t\trepo_get_oid(the_repository, str, oid)\n+#define get_oid_commit(str, oid)\trepo_get_oid_commit(the_repository, str, oid)\n+#define get_oid_committish(str, oid)\trepo_get_oid_committish(the_repository, str, oid)\n+#define get_oid_tree(str, oid)\t\trepo_get_oid_tree(the_repository, str, oid)\n+#define get_oid_treeish(str, oid)\trepo_get_oid_treeish(the_repository, str, oid)\n+#define get_oid_blob(str, oid)\t\trepo_get_oid_blob(the_repository, str, oid)\n+\n typedef int each_abbrev_fn(const struct object_id *oid, void *);\n int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);\n #define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data)\ndiff --git a/sha1-name.c b/sha1-name.c\nindex b94d381bef..d49496397d 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1590,43 +1590,48 @@ int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)\n  * commit-ish. It is merely to give a hint to the disambiguation\n  * machinery.\n  */\n-int get_oid_committish(const char *name, struct object_id *oid)\n+int repo_get_oid_committish(struct repository *r,\n+\t\t\t    const char *name,\n+\t\t\t    struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_COMMITTISH,\n+\treturn get_oid_with_context(r, name, GET_OID_COMMITTISH,\n \t\t\t\t    oid, &unused);\n }\n \n-int get_oid_treeish(const char *name, struct object_id *oid)\n+int repo_get_oid_treeish(struct repository *r,\n+\t\t\t const char *name,\n+\t\t\t struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_TREEISH,\n+\treturn get_oid_with_context(r, name, GET_OID_TREEISH,\n \t\t\t\t    oid, &unused);\n }\n \n-int get_oid_commit(const char *name, struct object_id *oid)\n+int repo_get_oid_commit(struct repository *r,\n+\t\t\tconst char *name,\n+\t\t\tstruct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_COMMIT,\n+\treturn get_oid_with_context(r, name, GET_OID_COMMIT,\n \t\t\t\t    oid, &unused);\n }\n \n-int get_oid_tree(const char *name, struct object_id *oid)\n+int repo_get_oid_tree(struct repository *r,\n+\t\t      const char *name,\n+\t\t      struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_TREE,\n+\treturn get_oid_with_context(r, name, GET_OID_TREE,\n \t\t\t\t    oid, &unused);\n }\n \n-int get_oid_blob(const char *name, struct object_id *oid)\n+int repo_get_oid_blob(struct repository *r,\n+\t\t      const char *name,\n+\t\t      struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_BLOB,\n+\treturn get_oid_with_context(r, name, GET_OID_BLOB,\n \t\t\t\t    oid, &unused);\n }\n \n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373317","messageId":"20190406113453.5149-34-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v3 33/33] sha1-name.c: remove the_repo from get_oid_mb()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-06T11:34:53Z","receivedAt":"2019-04-06T11:38:16Z","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     |  3 ++-\n sha1-name.c | 18 +++++++++++-------\n 2 files changed, 13 insertions(+), 8 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 871a167bf8..9a600a8b50 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1386,6 +1386,7 @@ int repo_get_oid_committish(struct repository *r, const char *str, struct object\n int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid);\n int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid);\n int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_mb(struct repository *r, const char *str, struct object_id *oid);\n void maybe_die_on_misspelt_object_name(struct repository *repo,\n \t\t\t\t       const char *name,\n \t\t\t\t       const char *prefix);\n@@ -1399,6 +1400,7 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c\n #define get_oid_tree(str, oid)\t\trepo_get_oid_tree(the_repository, str, oid)\n #define get_oid_treeish(str, oid)\trepo_get_oid_treeish(the_repository, str, oid)\n #define get_oid_blob(str, oid)\t\trepo_get_oid_blob(the_repository, str, oid)\n+#define get_oid_mb(str, oid) \t\trepo_get_oid_mb(the_repository, str, oid)\n \n typedef int each_abbrev_fn(const struct object_id *oid, void *);\n int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);\n@@ -1486,7 +1488,6 @@ int repo_interpret_branch_name(struct repository *r,\n \t\t\t       unsigned allowed);\n #define interpret_branch_name(str, len, buf, allowed) \\\n \trepo_interpret_branch_name(the_repository, str, len, buf, allowed)\n-extern int get_oid_mb(const char *str, struct object_id *oid);\n \n extern int validate_headref(const char *ref);\n \ndiff --git a/sha1-name.c b/sha1-name.c\nindex d49496397d..cf314ebb29 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1338,7 +1338,9 @@ static int interpret_nth_prior_checkout(struct repository *r,\n \treturn retval;\n }\n \n-int get_oid_mb(const char *name, struct object_id *oid)\n+int repo_get_oid_mb(struct repository *r,\n+\t\t    const char *name,\n+\t\t    struct object_id *oid)\n {\n \tstruct commit *one, *two;\n \tstruct commit_list *mbs;\n@@ -1348,27 +1350,29 @@ int get_oid_mb(const char *name, struct object_id *oid)\n \n \tdots = strstr(name, \"...\");\n \tif (!dots)\n-\t\treturn get_oid(name, oid);\n+\t\treturn repo_get_oid(r, name, oid);\n \tif (dots == name)\n-\t\tst = get_oid(\"HEAD\", &oid_tmp);\n+\t\tst = repo_get_oid(r, \"HEAD\", &oid_tmp);\n \telse {\n \t\tstruct strbuf sb;\n \t\tstrbuf_init(&sb, dots - name);\n \t\tstrbuf_add(&sb, name, dots - name);\n-\t\tst = get_oid_committish(sb.buf, &oid_tmp);\n+\t\tst = repo_get_oid_committish(r, sb.buf, &oid_tmp);\n \t\tstrbuf_release(&sb);\n \t}\n \tif (st)\n \t\treturn st;\n-\tone = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);\n+\tone = lookup_commit_reference_gently(r, &oid_tmp, 0);\n \tif (!one)\n \t\treturn -1;\n \n-\tif (get_oid_committish(dots[3] ? (dots + 3) : \"HEAD\", &oid_tmp))\n+\tif (repo_get_oid_committish(r, dots[3] ? (dots + 3) : \"HEAD\", &oid_tmp))\n \t\treturn -1;\n-\ttwo = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);\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 \tif (!mbs || mbs->next)\n \t\tst = -1;\n-- \n2.21.0.479.g47ac719cd3\n\n"},{"id":"373479","messageId":"20190409105834.GG8796@szeder.dev","threadId":"50841","inReplyTo":"CACsJy8C5K15QOeAJmPBb-VkcJnAiha9BNuUwVAL_mH_y6YBjow@mail.gmail.com","subject":"Re: [PATCH v2 01/32] rebase: 'make coccicheck' cleanup","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2019-04-09T10:58:34Z","receivedAt":"2019-04-09T10:58:41Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Fri, Apr 05, 2019 at 04:26:10PM +0700, Duy Nguyen wrote:\n> On Fri, Apr 5, 2019 at 12:25 AM SZEDER Gábor <szeder.dev@gmail.com> wrote:\n> >\n> > On Wed, Apr 03, 2019 at 06:34:26PM +0700, Nguyễn Thái Ngọc Duy wrote:\n> > > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> > > ---\n> > >  builtin/rebase.c | 5 ++---\n> > >  1 file changed, 2 insertions(+), 3 deletions(-)\n> > >\n> > > diff --git a/builtin/rebase.c b/builtin/rebase.c\n> > > index 77deebc65c..c064909329 100644\n> > > --- a/builtin/rebase.c\n> > > +++ b/builtin/rebase.c\n> > > @@ -1592,8 +1592,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n> > >                               branch_name = options.head_name;\n> > >\n> > >               } else {\n> > > -                     free(options.head_name);\n> > > -                     options.head_name = NULL;\n> > > +                     FREE_AND_NULL(options.head_name);\n> > >                       branch_name = \"HEAD\";\n> > >               }\n> > >               if (get_oid(\"HEAD\", &options.orig_head))\n> > > @@ -1793,7 +1792,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n> > >        * we just fast-forwarded.\n> > >        */\n> > >       strbuf_reset(&msg);\n> > > -     if (!oidcmp(&merge_base, &options.orig_head)) {\n> > > +     if (oideq(&merge_base, &options.orig_head)) {\n> > >               printf(_(\"Fast-forwarded %s to %s.\\n\"),\n> > >                       branch_name, options.onto_name);\n> > >               strbuf_addf(&msg, \"rebase finished: %s onto %s\",\n> >\n> > You are already using Coccinelle v1.0.7, aren't you?\n> \n> No it's 1.0.5.\n\nOh, you are right, Coccinelle 1.0.5 does indeed find these.\n\nWhen I saw that the self-built 1.0.7 found something that the\ndistro-shipped 1.0.4 didn't, I checked it with a self-built 1.0.6, and\nas it didn't find these, either, I didn't bother with 1.0.5.  It seems\nthat it got fixed 1.0.5, then regressed in 1.0.6, to be fixed again in\n1.0.7.\n\n> I guess I should upgrade then.\n\nI found 'make coccicheck' with 1.0.7 to be about 10-15% faster than\nprevious versions.\n\n"},{"id":"373613","messageId":"nycvar.QRO.7.76.6.1904102254500.41@tvgsbejvaqbjf.bet","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"Re: [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2019-04-10T20:56:52Z","receivedAt":"2019-04-10T20:57:00Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Duy,\n\nOn Sat, 6 Apr 2019, Nguyễn Thái Ngọc Duy wrote:\n\n> 10:  68876a150f ! 11:  848456f59c commit.c: add repo_get_commit_tree()\n>     @@ -2,6 +2,11 @@\n>\n>          commit.c: add repo_get_commit_tree()\n>\n>     +    Remove the implicit dependency on the_repository in this function.\n>     +    It will be used in sha1-name.c functions when they are updated to take\n>     +    any 'struct repository'. get_commit_tree() remains as a compat wrapper,\n>     +    to be slowly replaced later.\n>     +\n>       diff --git a/commit.c b/commit.c\n>       --- a/commit.c\n>       +++ b/commit.c\n>     @@ -29,6 +34,15 @@\n>       --- a/commit.h\n>       +++ b/commit.h\n>      @@\n>     +\n>     + \t/*\n>     + \t * If the commit is loaded from the commit-graph file, then this\n>     +-\t * member may be NULL. Only access it through get_commit_tree()\n>     ++\t * member may be NULL. Only access it through repo_get_commit_tree()\n>     + \t * or get_commit_tree_oid().\n>     + \t */\n>     + \tstruct tree *maybe_tree;\n>     +@@\n>        */\n>       void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);\n>\n>     @@ -57,3 +71,10 @@\n>         ...>}\n>\n>       @@\n>     + expression c;\n>     ++expression r;\n>     + expression s;\n>     + @@\n>     +-- get_commit_tree(c) = s\n>     ++- repo_get_commit_tree(r, c) = s\n>     + + c->maybe_tree = s\n\nI think this is wrong, and admittedly I had the very same version\noriginally.\n\nWhen you have an arbitrary `r` in any `repo_get_commit_tree(r, c)` (as\nopposed to `the_repository`), the conversion to `c->maybe_tree` is most\nlikely incorrect.\n\nTherefore, I don't think that we can do that.\n\nCiao,\nJohannes\n"},{"id":"373622","messageId":"CACsJy8AE1cOYCNDu7suQDJ0NYxeoG3w6e-+mZ-J1D5j_WNLWeg@mail.gmail.com","threadId":"50841","inReplyTo":"nycvar.QRO.7.76.6.1904102254500.41@tvgsbejvaqbjf.bet","subject":"Re: [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-11T00:26:10Z","receivedAt":"2019-04-11T00:26:38Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, Apr 11, 2019 at 3:56 AM Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> >       @@\n> >     + expression c;\n> >     ++expression r;\n> >     + expression s;\n> >     + @@\n> >     +-- get_commit_tree(c) = s\n> >     ++- repo_get_commit_tree(r, c) = s\n> >     + + c->maybe_tree = s\n>\n> I think this is wrong, and admittedly I had the very same version\n> originally.\n>\n> When you have an arbitrary `r` in any `repo_get_commit_tree(r, c)` (as\n> opposed to `the_repository`), the conversion to `c->maybe_tree` is most\n> likely incorrect.\n\nI did read the get_commit_tree() source code before doing this. struct\nrepository is only used to get commit graph to speed things up and we\ncan't change a thing there when maybe_tree is reassigned. To reassign\nmaybe_tree, commit-graph does not matter. Neither does the_repository\n(vs arbitrary struct repo)\n\n>\n> Therefore, I don't think that we can do that.\n>\n> Ciao,\n> Johannes\n\n\n\n-- \nDuy\n"},{"id":"373686","messageId":"nycvar.QRO.7.76.6.1904112233490.41@tvgsbejvaqbjf.bet","threadId":"50841","inReplyTo":"CACsJy8AE1cOYCNDu7suQDJ0NYxeoG3w6e-+mZ-J1D5j_WNLWeg@mail.gmail.com","subject":"Re: [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2019-04-11T20:36:46Z","receivedAt":"2019-04-11T20:37:09Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 11 Apr 2019, Duy Nguyen wrote:\n\n> On Thu, Apr 11, 2019 at 3:56 AM Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n> > >       @@\n> > >     + expression c;\n> > >     ++expression r;\n> > >     + expression s;\n> > >     + @@\n> > >     +-- get_commit_tree(c) = s\n> > >     ++- repo_get_commit_tree(r, c) = s\n> > >     + + c->maybe_tree = s\n> >\n> > I think this is wrong, and admittedly I had the very same version\n> > originally.\n> >\n> > When you have an arbitrary `r` in any `repo_get_commit_tree(r, c)` (as\n> > opposed to `the_repository`), the conversion to `c->maybe_tree` is most\n> > likely incorrect.\n>\n> I did read the get_commit_tree() source code before doing this. struct\n> repository is only used to get commit graph to speed things up and we\n> can't change a thing there when maybe_tree is reassigned. To reassign\n> maybe_tree, commit-graph does not matter. Neither does the_repository\n> (vs arbitrary struct repo)\n\nYou read the current code. Obviously, you had no future code to read.\n\nThe cocci patch you are changing will affect future code, too.\n\nThe safe, and correct, thing to do, then, is to not pretend to know what\nfuture `get_commit_tree()` functions will do, and instead go with the\nstricter  version of the cocci patch, as I had suggested.\n\nCiao,\nJohannes\n\n> >\n> > Therefore, I don't think that we can do that.\n> >\n> > Ciao,\n> > Johannes\n>\n>\n>\n> --\n> Duy\n>\n"},{"id":"373687","messageId":"20190411205146.GK8796@szeder.dev","threadId":"50841","inReplyTo":"nycvar.QRO.7.76.6.1904102254500.41@tvgsbejvaqbjf.bet","subject":"Re: [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2019-04-11T20:51:46Z","receivedAt":"2019-04-11T20:51:54Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Wed, Apr 10, 2019 at 10:56:52PM +0200, Johannes Schindelin wrote:\n> Hi Duy,\n> \n> On Sat, 6 Apr 2019, Nguyễn Thái Ngọc Duy wrote:\n> \n> > 10:  68876a150f ! 11:  848456f59c commit.c: add repo_get_commit_tree()\n> >     @@ -2,6 +2,11 @@\n> >\n> >          commit.c: add repo_get_commit_tree()\n> >\n> >     +    Remove the implicit dependency on the_repository in this function.\n> >     +    It will be used in sha1-name.c functions when they are updated to take\n> >     +    any 'struct repository'. get_commit_tree() remains as a compat wrapper,\n> >     +    to be slowly replaced later.\n> >     +\n> >       diff --git a/commit.c b/commit.c\n> >       --- a/commit.c\n> >       +++ b/commit.c\n> >     @@ -29,6 +34,15 @@\n> >       --- a/commit.h\n> >       +++ b/commit.h\n> >      @@\n> >     +\n> >     + \t/*\n> >     + \t * If the commit is loaded from the commit-graph file, then this\n> >     +-\t * member may be NULL. Only access it through get_commit_tree()\n> >     ++\t * member may be NULL. Only access it through repo_get_commit_tree()\n> >     + \t * or get_commit_tree_oid().\n> >     + \t */\n> >     + \tstruct tree *maybe_tree;\n> >     +@@\n> >        */\n> >       void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);\n> >\n> >     @@ -57,3 +71,10 @@\n> >         ...>}\n> >\n> >       @@\n> >     + expression c;\n> >     ++expression r;\n> >     + expression s;\n> >     + @@\n> >     +-- get_commit_tree(c) = s\n> >     ++- repo_get_commit_tree(r, c) = s\n> >     + + c->maybe_tree = s\n> \n> I think this is wrong, and admittedly I had the very same version\n> originally.\n> \n> When you have an arbitrary `r` in any `repo_get_commit_tree(r, c)` (as\n> opposed to `the_repository`), the conversion to `c->maybe_tree` is most\n> likely incorrect.\n> \n> Therefore, I don't think that we can do that.\n\nSo, as far as I understand, the goal of these 'c->maybe_tree'-related\nsemantic patches is to prevent \"generic\" parts of Git from accessing\nthis field directly, as it might not be initialized in a\ncommit-graph-enabled repository.\n\nOnly three functions are explicitly exempt, while this last semantic\npatch in question implicitly allows a few more that assign a value to\n'c->maybe_tree'.  These functions are release_commit_memory() and\nparse_commit_buffer() in 'commit.c' and fill_commit_in_graph() in\n'commit-graph.c', and after a quick look these functions seem to be\nrather fundamenal in the life-cycle of a commit object.\n\nI think they deserve to be explicitly exempted, too, and then we could\nremove this last semantic patch altogether.\n\n\n"},{"id":"373688","messageId":"20190411205857.GL8796@szeder.dev","threadId":"50841","inReplyTo":"20190411205146.GK8796@szeder.dev","subject":"Re: [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2019-04-11T20:58:57Z","receivedAt":"2019-04-11T20:59:03Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Thu, Apr 11, 2019 at 10:51:46PM +0200, SZEDER Gábor wrote:\n> On Wed, Apr 10, 2019 at 10:56:52PM +0200, Johannes Schindelin wrote:\n> > >         ...>}\n> > >\n> > >       @@\n> > >     + expression c;\n> > >     ++expression r;\n> > >     + expression s;\n> > >     + @@\n> > >     +-- get_commit_tree(c) = s\n> > >     ++- repo_get_commit_tree(r, c) = s\n> > >     + + c->maybe_tree = s\n> > \n> > I think this is wrong, and admittedly I had the very same version\n> > originally.\n> > \n> > When you have an arbitrary `r` in any `repo_get_commit_tree(r, c)` (as\n> > opposed to `the_repository`), the conversion to `c->maybe_tree` is most\n> > likely incorrect.\n> > \n> > Therefore, I don't think that we can do that.\n> \n> So, as far as I understand, the goal of these 'c->maybe_tree'-related\n> semantic patches is to prevent \"generic\" parts of Git from accessing\n> this field directly, as it might not be initialized in a\n> commit-graph-enabled repository.\n> \n> Only three functions are explicitly exempt, while this last semantic\n> patch in question implicitly allows a few more that assign a value to\n> 'c->maybe_tree'.  These functions are release_commit_memory() and\n> parse_commit_buffer() in 'commit.c' and fill_commit_in_graph() in\n> 'commit-graph.c', and after a quick look these functions seem to be\n> rather fundamenal in the life-cycle of a commit object.\n\nErm, not \"commit object\"; I meant the life-cycle of a 'struct commit'\ninstance.\n\n> I think they deserve to be explicitly exempted, too, and then we could\n> remove this last semantic patch altogether.\n> \n> \n"},{"id":"373697","messageId":"20190412001730.GM8796@szeder.dev","threadId":"50841","inReplyTo":"20190411205857.GL8796@szeder.dev","subject":"Re: [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2019-04-12T00:17:30Z","receivedAt":"2019-04-12T00:17:38Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Thu, Apr 11, 2019 at 10:58:57PM +0200, SZEDER Gábor wrote:\n> On Thu, Apr 11, 2019 at 10:51:46PM +0200, SZEDER Gábor wrote:\n> > On Wed, Apr 10, 2019 at 10:56:52PM +0200, Johannes Schindelin wrote:\n> > > >         ...>}\n> > > >\n> > > >       @@\n> > > >     + expression c;\n> > > >     ++expression r;\n> > > >     + expression s;\n> > > >     + @@\n> > > >     +-- get_commit_tree(c) = s\n> > > >     ++- repo_get_commit_tree(r, c) = s\n> > > >     + + c->maybe_tree = s\n> > > \n> > > I think this is wrong, and admittedly I had the very same version\n> > > originally.\n> > > \n> > > When you have an arbitrary `r` in any `repo_get_commit_tree(r, c)` (as\n> > > opposed to `the_repository`), the conversion to `c->maybe_tree` is most\n> > > likely incorrect.\n> > > \n> > > Therefore, I don't think that we can do that.\n> > \n> > So, as far as I understand, the goal of these 'c->maybe_tree'-related\n> > semantic patches is to prevent \"generic\" parts of Git from accessing\n> > this field directly, as it might not be initialized in a\n> > commit-graph-enabled repository.\n> > \n> > Only three functions are explicitly exempt, while this last semantic\n> > patch in question implicitly allows a few more that assign a value to\n> > 'c->maybe_tree'.  These functions are release_commit_memory() and\n> > parse_commit_buffer() in 'commit.c' and fill_commit_in_graph() in\n> > 'commit-graph.c', \n\n... and make_virtual_commit() in 'merge-recursive.c'.\n\n> and after a quick look these functions seem to be\n> > rather fundamenal in the life-cycle of a commit object.\n> \n> Erm, not \"commit object\"; I meant the life-cycle of a 'struct commit'\n> instance.\n> \n> > I think they deserve to be explicitly exempted, too, and then we could\n> > remove this last semantic patch altogether.\n\nAnd it would look like this.  Yeah, that's a very long line there, but\nI don't think we can break it up.\n\n  -- >8 --\n\ndiff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\nindex 57c8f71479..fe814f313e 100644\n--- a/contrib/coccinelle/commit.cocci\n+++ b/contrib/coccinelle/commit.cocci\n@@ -10,20 +10,15 @@ expression c;\n - c->maybe_tree->object.oid.hash\n + get_commit_tree_oid(c)->hash\n \n-// These excluded functions must access c->maybe_tree direcly.\n+// These excluded functions must access/modify c->maybe_tree direcly.\n+// Note that if c->maybe_tree is written somewhere outside of these\n+// functions, then the recommended transformation will be bogus with\n+// repo_get_commit_tree() on the LHS.\n @@\n-identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n-expression c;\n+identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|fill_commit_in_graph|parse_commit_buffer|release_commit_memory|make_virtual_commit)$\";\n+struct commit *c;\n @@\n   f(...) {<...\n - c->maybe_tree\n + repo_get_commit_tree(the_repository, c)\n   ...>}\n-\n-@@\n-expression c;\n-expression r;\n-expression s;\n-@@\n-- repo_get_commit_tree(r, c) = s\n-+ c->maybe_tree = s\n"},{"id":"373748","messageId":"nycvar.QRO.7.76.6.1904121624160.41@tvgsbejvaqbjf.bet","threadId":"50841","inReplyTo":"20190412001730.GM8796@szeder.dev","subject":"Re: [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2019-04-12T14:25:08Z","receivedAt":"2019-04-12T14:25:38Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 12 Apr 2019, SZEDER Gábor wrote:\n\n> On Thu, Apr 11, 2019 at 10:58:57PM +0200, SZEDER Gábor wrote:\n> > On Thu, Apr 11, 2019 at 10:51:46PM +0200, SZEDER Gábor wrote:\n> > > On Wed, Apr 10, 2019 at 10:56:52PM +0200, Johannes Schindelin wrote:\n> > > > >         ...>}\n> > > > >\n> > > > >       @@\n> > > > >     + expression c;\n> > > > >     ++expression r;\n> > > > >     + expression s;\n> > > > >     + @@\n> > > > >     +-- get_commit_tree(c) = s\n> > > > >     ++- repo_get_commit_tree(r, c) = s\n> > > > >     + + c->maybe_tree = s\n> > > >\n> > > > I think this is wrong, and admittedly I had the very same version\n> > > > originally.\n> > > >\n> > > > When you have an arbitrary `r` in any `repo_get_commit_tree(r, c)` (as\n> > > > opposed to `the_repository`), the conversion to `c->maybe_tree` is most\n> > > > likely incorrect.\n> > > >\n> > > > Therefore, I don't think that we can do that.\n> > >\n> > > So, as far as I understand, the goal of these 'c->maybe_tree'-related\n> > > semantic patches is to prevent \"generic\" parts of Git from accessing\n> > > this field directly, as it might not be initialized in a\n> > > commit-graph-enabled repository.\n> > >\n> > > Only three functions are explicitly exempt, while this last semantic\n> > > patch in question implicitly allows a few more that assign a value to\n> > > 'c->maybe_tree'.  These functions are release_commit_memory() and\n> > > parse_commit_buffer() in 'commit.c' and fill_commit_in_graph() in\n> > > 'commit-graph.c',\n>\n> ... and make_virtual_commit() in 'merge-recursive.c'.\n>\n> > and after a quick look these functions seem to be\n> > > rather fundamenal in the life-cycle of a commit object.\n> >\n> > Erm, not \"commit object\"; I meant the life-cycle of a 'struct commit'\n> > instance.\n> >\n> > > I think they deserve to be explicitly exempted, too, and then we could\n> > > remove this last semantic patch altogether.\n>\n> And it would look like this.  Yeah, that's a very long line there, but\n> I don't think we can break it up.\n>\n>   -- >8 --\n>\n> diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\n> index 57c8f71479..fe814f313e 100644\n> --- a/contrib/coccinelle/commit.cocci\n> +++ b/contrib/coccinelle/commit.cocci\n> @@ -10,20 +10,15 @@ expression c;\n>  - c->maybe_tree->object.oid.hash\n>  + get_commit_tree_oid(c)->hash\n>\n> -// These excluded functions must access c->maybe_tree direcly.\n> +// These excluded functions must access/modify c->maybe_tree direcly.\n> +// Note that if c->maybe_tree is written somewhere outside of these\n> +// functions, then the recommended transformation will be bogus with\n> +// repo_get_commit_tree() on the LHS.\n>  @@\n> -identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n> -expression c;\n> +identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|fill_commit_in_graph|parse_commit_buffer|release_commit_memory|make_virtual_commit)$\";\n\nHahahaha! That's *really* long.\n\nAnd a good indicator that this should be hidden in a single helper\nfunction (`set_commit_tree()`, file-local of course) that is exempted in\nthe cocci patch.\n\nCiao,\nDscho\n\n> +struct commit *c;\n>  @@\n>    f(...) {<...\n>  - c->maybe_tree\n>  + repo_get_commit_tree(the_repository, c)\n>    ...>}\n> -\n> -@@\n> -expression c;\n> -expression r;\n> -expression s;\n> -@@\n> -- repo_get_commit_tree(r, c) = s\n> -+ c->maybe_tree = s\n>\n"},{"id":"373791","messageId":"20190413101600.713-1-pclouds@gmail.com","threadId":"50841","inReplyTo":"nycvar.QRO.7.76.6.1904121624160.41@tvgsbejvaqbjf.bet","subject":"[PATCH v3* 11/33] commit.c: add repo_get_commit_tree()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-13T10:16:00Z","receivedAt":"2019-04-13T10:16:19Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Remove the implicit dependency on the_repository in this function.\nIt will be used in sha1-name.c functions when they are updated to take\nany 'struct repository'. get_commit_tree() remains as a compat wrapper,\nto be slowly replaced later.\n\nset_commit_tree() is added just to simplify the filtering in\ncommit.cocci.\n\nAny access to \"maybe_tree\" field directly will result in _broken_ code\nafter running through commit.cocci because we can't know what is the\nright repository to use.\n\nthe_repository would be correct most of the time. But we're relying less\nand less on the_repository and that assumption may no longer be\ntrue. The transformation now is more of a poor man replacement for a C++\ncompiler catching access to private fields.\n\nHelped-by: SZEDER Gábor <szeder.dev@gmail.com>\nHelped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n OK how about this? set_commit_tree() is added to keeps that long line\n in commit.cocci down. I also make commit.cocci generate invalid\n repo_get_commit_tree() code this time.\n\n commit-graph.c                  |  2 +-\n commit.c                        |  9 +++++----\n commit.h                        | 10 ++++++++--\n contrib/coccinelle/commit.cocci | 14 +++++---------\n merge-recursive.c               |  2 +-\n 5 files changed, 20 insertions(+), 17 deletions(-)\n\ndiff --git a/commit-graph.c b/commit-graph.c\nindex 47e9be0a3a..dcab53cda5 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -356,7 +356,7 @@ static int fill_commit_in_graph(struct repository *r,\n \titem->object.parsed = 1;\n \titem->graph_pos = pos;\n \n-\titem->maybe_tree = NULL;\n+\tset_commit_tree(item, NULL);\n \n \tdate_high = get_be32(commit_data + g->hash_len + 8) & 0x3;\n \tdate_low = get_be32(commit_data + g->hash_len + 12);\ndiff --git a/commit.c b/commit.c\nindex a5333c7ac6..d852bf60c1 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -340,7 +340,8 @@ void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)\n \t}\n }\n \n-struct tree *get_commit_tree(const struct commit *commit)\n+struct tree *repo_get_commit_tree(struct repository *r,\n+\t\t\t\t  const struct commit *commit)\n {\n \tif (commit->maybe_tree || !commit->object.parsed)\n \t\treturn commit->maybe_tree;\n@@ -348,7 +349,7 @@ struct tree *get_commit_tree(const struct commit *commit)\n \tif (commit->graph_pos == COMMIT_NOT_FROM_GRAPH)\n \t\tBUG(\"commit has NULL tree, but was not loaded from commit-graph\");\n \n-\treturn get_commit_tree_in_graph(the_repository, commit);\n+\treturn get_commit_tree_in_graph(r, commit);\n }\n \n struct object_id *get_commit_tree_oid(const struct commit *commit)\n@@ -358,7 +359,7 @@ struct object_id *get_commit_tree_oid(const struct commit *commit)\n \n void release_commit_memory(struct parsed_object_pool *pool, struct commit *c)\n {\n-\tc->maybe_tree = NULL;\n+\tset_commit_tree(c, NULL);\n \tc->index = 0;\n \tfree_commit_buffer(pool, c);\n \tfree_commit_list(c->parents);\n@@ -406,7 +407,7 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b\n \tif (get_oid_hex(bufptr + 5, &parent) < 0)\n \t\treturn error(\"bad tree pointer in commit %s\",\n \t\t\t     oid_to_hex(&item->object.oid));\n-\titem->maybe_tree = lookup_tree(r, &parent);\n+\tset_commit_tree(item, lookup_tree(r, &parent));\n \tbufptr += tree_entry_len + 1; /* \"tree \" + \"hex sha1\" + \"\\n\" */\n \tpptr = &item->parents;\n \ndiff --git a/commit.h b/commit.h\nindex 42728c2906..7342727e46 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -32,7 +32,7 @@ struct commit {\n \n \t/*\n \t * If the commit is loaded from the commit-graph file, then this\n-\t * member may be NULL. Only access it through get_commit_tree()\n+\t * member may be NULL. Only access it through repo_get_commit_tree()\n \t * or get_commit_tree_oid().\n \t */\n \tstruct tree *maybe_tree;\n@@ -143,9 +143,15 @@ void repo_unuse_commit_buffer(struct repository *r,\n  */\n void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);\n \n-struct tree *get_commit_tree(const struct commit *);\n+struct tree *repo_get_commit_tree(struct repository *, const struct commit *);\n+#define get_commit_tree(c) repo_get_commit_tree(the_repository, c)\n struct object_id *get_commit_tree_oid(const struct commit *);\n \n+static inline void set_commit_tree(struct commit *c, struct tree *t)\n+{\n+\tc->maybe_tree = t;\n+}\n+\n /*\n  * Release memory related to a commit, including the parent list and\n  * any cached object buffer.\ndiff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\nindex c49aa558f0..ee1dc29234 100644\n--- a/contrib/coccinelle/commit.cocci\n+++ b/contrib/coccinelle/commit.cocci\n@@ -11,18 +11,14 @@ expression c;\n + get_commit_tree_oid(c)->hash\n \n // These excluded functions must access c->maybe_tree direcly.\n+// Note that if c->maybe_tree is written somewhere outside of these\n+// functions, then the recommended transformation will be bogus with\n+// repo_get_commit_tree() on the LHS.\n @@\n-identifier f !~ \"^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n+identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|set_commit_tree)$\";\n expression c;\n @@\n   f(...) {<...\n - c->maybe_tree\n-+ get_commit_tree(c)\n++ repo_get_commit_tree(specify_the_right_repo_here, c)\n   ...>}\n-\n-@@\n-expression c;\n-expression s;\n-@@\n-- get_commit_tree(c) = s\n-+ c->maybe_tree = s\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 6c40c61c47..048fea71a0 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -170,7 +170,7 @@ static struct commit *make_virtual_commit(struct repository *repo,\n \tstruct commit *commit = alloc_commit_node(repo);\n \n \tset_merge_remote_desc(commit, comment, (struct object *)commit);\n-\tcommit->maybe_tree = tree;\n+\tset_commit_tree(commit, tree);\n \tcommit->object.parsed = 1;\n \treturn commit;\n }\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373794","messageId":"20190413121432.GB15936@szeder.dev","threadId":"50841","inReplyTo":"nycvar.QRO.7.76.6.1904121624160.41@tvgsbejvaqbjf.bet","subject":"Re: [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2019-04-13T12:14:32Z","receivedAt":"2019-04-13T12:14:39Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Fri, Apr 12, 2019 at 04:25:08PM +0200, Johannes Schindelin wrote:\n> Hi,\n> \n> On Fri, 12 Apr 2019, SZEDER Gábor wrote:\n> \n> > On Thu, Apr 11, 2019 at 10:58:57PM +0200, SZEDER Gábor wrote:\n> > > On Thu, Apr 11, 2019 at 10:51:46PM +0200, SZEDER Gábor wrote:\n> > > > On Wed, Apr 10, 2019 at 10:56:52PM +0200, Johannes Schindelin wrote:\n> > > > > >         ...>}\n> > > > > >\n> > > > > >       @@\n> > > > > >     + expression c;\n> > > > > >     ++expression r;\n> > > > > >     + expression s;\n> > > > > >     + @@\n> > > > > >     +-- get_commit_tree(c) = s\n> > > > > >     ++- repo_get_commit_tree(r, c) = s\n> > > > > >     + + c->maybe_tree = s\n> > > > >\n> > > > > I think this is wrong, and admittedly I had the very same version\n> > > > > originally.\n> > > > >\n> > > > > When you have an arbitrary `r` in any `repo_get_commit_tree(r, c)` (as\n> > > > > opposed to `the_repository`), the conversion to `c->maybe_tree` is most\n> > > > > likely incorrect.\n> > > > >\n> > > > > Therefore, I don't think that we can do that.\n> > > >\n> > > > So, as far as I understand, the goal of these 'c->maybe_tree'-related\n> > > > semantic patches is to prevent \"generic\" parts of Git from accessing\n> > > > this field directly, as it might not be initialized in a\n> > > > commit-graph-enabled repository.\n> > > >\n> > > > Only three functions are explicitly exempt, while this last semantic\n> > > > patch in question implicitly allows a few more that assign a value to\n> > > > 'c->maybe_tree'.  These functions are release_commit_memory() and\n> > > > parse_commit_buffer() in 'commit.c' and fill_commit_in_graph() in\n> > > > 'commit-graph.c',\n> >\n> > ... and make_virtual_commit() in 'merge-recursive.c'.\n> >\n> > > and after a quick look these functions seem to be\n> > > > rather fundamenal in the life-cycle of a commit object.\n> > >\n> > > Erm, not \"commit object\"; I meant the life-cycle of a 'struct commit'\n> > > instance.\n> > >\n> > > > I think they deserve to be explicitly exempted, too, and then we could\n> > > > remove this last semantic patch altogether.\n> >\n> > And it would look like this.  Yeah, that's a very long line there, but\n> > I don't think we can break it up.\n> >\n> >   -- >8 --\n> >\n> > diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\n> > index 57c8f71479..fe814f313e 100644\n> > --- a/contrib/coccinelle/commit.cocci\n> > +++ b/contrib/coccinelle/commit.cocci\n> > @@ -10,20 +10,15 @@ expression c;\n> >  - c->maybe_tree->object.oid.hash\n> >  + get_commit_tree_oid(c)->hash\n> >\n> > -// These excluded functions must access c->maybe_tree direcly.\n> > +// These excluded functions must access/modify c->maybe_tree direcly.\n> > +// Note that if c->maybe_tree is written somewhere outside of these\n> > +// functions, then the recommended transformation will be bogus with\n> > +// repo_get_commit_tree() on the LHS.\n> >  @@\n> > -identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n> > -expression c;\n> > +identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|fill_commit_in_graph|parse_commit_buffer|release_commit_memory|make_virtual_commit)$\";\n> \n> Hahahaha! That's *really* long.\n> \n> And a good indicator that this should be hidden in a single helper\n> function (`set_commit_tree()`, file-local of course) that is exempted in\n> the cocci patch.\n\nNote that this is not only about line length, and consider the slight\ndifferences between the three approaches:\n\n  - Currently only direct read accesses to 'c->maybe_tree' outside of\n    the listed functions are forbidden and transformed, but still any\n    function can set this field directly (thanks to the last semantic\n    patch in 'commit.cocci').\n\n  - Encapsulating writes in set_commit_tree() and adding this function\n    to that list would prevent other functions from setting\n    'c->maybe_tree' directly, but still any function could set it\n    indirectly by calling set_commit_tree().\n\n  - With that loooong line only those few listed special functions\n    would be able read or write 'c->maybe_tree'.\n\nDoes the additional restriction of the long line variant bring us\nbenefits?  Well, not sure.\n\nThe root tree of a commit is needed in many places, and in the past we\ngot used to it being always initialized in any 'struct commit'\ninstance.  However, with the commit graph that's not the case anymore,\nand any read accesses to the uninitialized root tree object would have\nbad consequences.  That's why there is get_commit_tree() helper\nperforming lazy-initialization, and the protection from direct reads\nin the form of the semantic patch.\n\nOTOH, apart from five functions, most parts of Git simply don't want\nto create new 'struct commit' instances themselves, or, more\ngenerally, set anything in a 'struct commit', so arguably there is not\nthat much danger to protect ourselves from.\n\nAnyway, I just wanted to make sure that we fully understand the\nimplications, and I think any solution is an improvement that\neliminates the current \"let's transform this code pattern, but then\nquickly transform it back in some cases\" back-and-forth.\n\n\n> > +struct commit *c;\n> >  @@\n> >    f(...) {<...\n> >  - c->maybe_tree\n> >  + repo_get_commit_tree(the_repository, c)\n> >    ...>}\n> > -\n> > -@@\n> > -expression c;\n> > -expression r;\n> > -expression s;\n> > -@@\n> > -- repo_get_commit_tree(r, c) = s\n> > -+ c->maybe_tree = s\n> >\n\n"},{"id":"373795","messageId":"20190413122256.GC15936@szeder.dev","threadId":"50841","inReplyTo":"20190413101600.713-1-pclouds@gmail.com","subject":"Re: [PATCH v3* 11/33] commit.c: add repo_get_commit_tree()","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2019-04-13T12:22:56Z","receivedAt":"2019-04-13T12:29:55Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Sat, Apr 13, 2019 at 05:16:00PM +0700, Nguyễn Thái Ngọc Duy wrote:\n>  OK how about this? set_commit_tree() is added to keeps that long line\n>  in commit.cocci down. I also make commit.cocci generate invalid\n>  repo_get_commit_tree() code this time.\n\n> diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\n> index c49aa558f0..ee1dc29234 100644\n> --- a/contrib/coccinelle/commit.cocci\n> +++ b/contrib/coccinelle/commit.cocci\n> @@ -11,18 +11,14 @@ expression c;\n>  + get_commit_tree_oid(c)->hash\n>  \n>  // These excluded functions must access c->maybe_tree direcly.\n> +// Note that if c->maybe_tree is written somewhere outside of these\n> +// functions, then the recommended transformation will be bogus with\n> +// repo_get_commit_tree() on the LHS.\n\nWe could prevent transformations putting repo_get_commit_tree() on the\nLHS by inserting the semantic patch:\n\n  @@\n  identifier f !~ \"^set_commit_tree$\";\n  expression c;\n  expression s;\n  @@\n    f(...) {<...\n  - c->maybe_tree = s\n  + set_commit_tree(c, s)\n    ...>}\n\nbefore this one.\n\n\n>  @@\n> -identifier f !~ \"^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n> +identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|set_commit_tree)$\";\n>  expression c;\n>  @@\n>    f(...) {<...\n>  - c->maybe_tree\n> -+ get_commit_tree(c)\n> ++ repo_get_commit_tree(specify_the_right_repo_here, c)\n>    ...>}\n> -\n> -@@\n> -expression c;\n> -expression s;\n> -@@\n> -- get_commit_tree(c) = s\n> -+ c->maybe_tree = s\n"},{"id":"373796","messageId":"CACsJy8DxOV6qSFPNZd_zvbnOiTETqnnK3NS+u0fhNLnuesEQhg@mail.gmail.com","threadId":"50841","inReplyTo":"20190413121432.GB15936@szeder.dev","subject":"Re: [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-13T14:00:02Z","receivedAt":"2019-04-13T14:01:43Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sat, Apr 13, 2019 at 7:14 PM SZEDER Gábor <szeder.dev@gmail.com> wrote:\n>\n> On Fri, Apr 12, 2019 at 04:25:08PM +0200, Johannes Schindelin wrote:\n> > Hi,\n> >\n> > On Fri, 12 Apr 2019, SZEDER Gábor wrote:\n> >\n> > > On Thu, Apr 11, 2019 at 10:58:57PM +0200, SZEDER Gábor wrote:\n> > > > On Thu, Apr 11, 2019 at 10:51:46PM +0200, SZEDER Gábor wrote:\n> > > > > On Wed, Apr 10, 2019 at 10:56:52PM +0200, Johannes Schindelin wrote:\n> > > > > > >         ...>}\n> > > > > > >\n> > > > > > >       @@\n> > > > > > >     + expression c;\n> > > > > > >     ++expression r;\n> > > > > > >     + expression s;\n> > > > > > >     + @@\n> > > > > > >     +-- get_commit_tree(c) = s\n> > > > > > >     ++- repo_get_commit_tree(r, c) = s\n> > > > > > >     + + c->maybe_tree = s\n> > > > > >\n> > > > > > I think this is wrong, and admittedly I had the very same version\n> > > > > > originally.\n> > > > > >\n> > > > > > When you have an arbitrary `r` in any `repo_get_commit_tree(r, c)` (as\n> > > > > > opposed to `the_repository`), the conversion to `c->maybe_tree` is most\n> > > > > > likely incorrect.\n> > > > > >\n> > > > > > Therefore, I don't think that we can do that.\n> > > > >\n> > > > > So, as far as I understand, the goal of these 'c->maybe_tree'-related\n> > > > > semantic patches is to prevent \"generic\" parts of Git from accessing\n> > > > > this field directly, as it might not be initialized in a\n> > > > > commit-graph-enabled repository.\n> > > > >\n> > > > > Only three functions are explicitly exempt, while this last semantic\n> > > > > patch in question implicitly allows a few more that assign a value to\n> > > > > 'c->maybe_tree'.  These functions are release_commit_memory() and\n> > > > > parse_commit_buffer() in 'commit.c' and fill_commit_in_graph() in\n> > > > > 'commit-graph.c',\n> > >\n> > > ... and make_virtual_commit() in 'merge-recursive.c'.\n> > >\n> > > > and after a quick look these functions seem to be\n> > > > > rather fundamenal in the life-cycle of a commit object.\n> > > >\n> > > > Erm, not \"commit object\"; I meant the life-cycle of a 'struct commit'\n> > > > instance.\n> > > >\n> > > > > I think they deserve to be explicitly exempted, too, and then we could\n> > > > > remove this last semantic patch altogether.\n> > >\n> > > And it would look like this.  Yeah, that's a very long line there, but\n> > > I don't think we can break it up.\n> > >\n> > >   -- >8 --\n> > >\n> > > diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\n> > > index 57c8f71479..fe814f313e 100644\n> > > --- a/contrib/coccinelle/commit.cocci\n> > > +++ b/contrib/coccinelle/commit.cocci\n> > > @@ -10,20 +10,15 @@ expression c;\n> > >  - c->maybe_tree->object.oid.hash\n> > >  + get_commit_tree_oid(c)->hash\n> > >\n> > > -// These excluded functions must access c->maybe_tree direcly.\n> > > +// These excluded functions must access/modify c->maybe_tree direcly.\n> > > +// Note that if c->maybe_tree is written somewhere outside of these\n> > > +// functions, then the recommended transformation will be bogus with\n> > > +// repo_get_commit_tree() on the LHS.\n> > >  @@\n> > > -identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n> > > -expression c;\n> > > +identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|fill_commit_in_graph|parse_commit_buffer|release_commit_memory|make_virtual_commit)$\";\n> >\n> > Hahahaha! That's *really* long.\n> >\n> > And a good indicator that this should be hidden in a single helper\n> > function (`set_commit_tree()`, file-local of course) that is exempted in\n> > the cocci patch.\n>\n> Note that this is not only about line length, and consider the slight\n> differences between the three approaches:\n>\n>   - Currently only direct read accesses to 'c->maybe_tree' outside of\n>     the listed functions are forbidden and transformed, but still any\n>     function can set this field directly (thanks to the last semantic\n>     patch in 'commit.cocci').\n>\n>   - Encapsulating writes in set_commit_tree() and adding this function\n>     to that list would prevent other functions from setting\n>     'c->maybe_tree' directly, but still any function could set it\n>     indirectly by calling set_commit_tree().\n>\n>   - With that loooong line only those few listed special functions\n>     would be able read or write 'c->maybe_tree'.\n>\n> Does the additional restriction of the long line variant bring us\n> benefits?  Well, not sure.\n>\n> The root tree of a commit is needed in many places, and in the past we\n> got used to it being always initialized in any 'struct commit'\n> instance.  However, with the commit graph that's not the case anymore,\n> and any read accesses to the uninitialized root tree object would have\n> bad consequences.  That's why there is get_commit_tree() helper\n> performing lazy-initialization, and the protection from direct reads\n> in the form of the semantic patch.\n\nAnd I think set_commit_tree() is a good way to go. Basically\n\"maybe_tree\" is not safe to be manipulated directly because of traps\nand pitfalls. If we have one entry point to update maybe_tree, we can\nhandle all that in one place (even though I don't foresee any special\nhandling when updating it). Keeping commit.cocci shorter is just a\nside bonus.\n-- \nDuy\n"},{"id":"373866","messageId":"nycvar.QRO.7.76.6.1904151518530.44@tvgsbejvaqbjf.bet","threadId":"50841","inReplyTo":"20190413101600.713-1-pclouds@gmail.com","subject":"Re: [PATCH v3* 11/33] commit.c: add repo_get_commit_tree()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2019-04-15T13:20:32Z","receivedAt":"2019-04-15T13:20:40Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Duy,\n\nOn Sat, 13 Apr 2019, Nguyễn Thái Ngọc Duy wrote:\n\n> diff --git a/commit.h b/commit.h\n> index 42728c2906..7342727e46 100644\n> --- a/commit.h\n> +++ b/commit.h\n> @@ -143,9 +143,15 @@ void repo_unuse_commit_buffer(struct repository *r,\n>  struct object_id *get_commit_tree_oid(const struct commit *);\n>\n> +static inline void set_commit_tree(struct commit *c, struct tree *t)\n> +{\n> +\tc->maybe_tree = t;\n> +}\n> +\n>  /*\n\nI head *really* hoped that we could keep this function file-local, i.e.\n`static` *inside* the relevant file(s). Kind of making this a \"private\" or\n\"protected\" function, if you know what I mean.\n\nCiao,\nJohannes\n"},{"id":"373932","messageId":"20190416093341.17079-1-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190406113453.5149-1-pclouds@gmail.com","subject":"[PATCH v4 00/34] nd/sha1-name-c-wo-the-repository updates","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:07Z","receivedAt":"2019-04-16T09:34:32Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"v4 is all about updating commit.c and commit.cocci 11/33. I think I have\nincorporated all changes from v3 discussion. The changes are separated\nto a new patch 11/34 though, the old 11/33 is now 12/34.\n\nDiff\n\ndiff --git a/commit-graph.c b/commit-graph.c\nindex 47e9be0a3a..155a270457 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -343,6 +343,11 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,\n \titem->generation = get_be32(commit_data + g->hash_len + 8) >> 2;\n }\n \n+static inline void set_commit_tree(struct commit *c, struct tree *t)\n+{\n+\tc->maybe_tree = t;\n+}\n+\n static int fill_commit_in_graph(struct repository *r,\n \t\t\t\tstruct commit *item,\n \t\t\t\tstruct commit_graph *g, uint32_t pos)\n@@ -356,7 +361,7 @@ static int fill_commit_in_graph(struct repository *r,\n \titem->object.parsed = 1;\n \titem->graph_pos = pos;\n \n-\titem->maybe_tree = NULL;\n+\tset_commit_tree(item, NULL);\n \n \tdate_high = get_be32(commit_data + g->hash_len + 8) & 0x3;\n \tdate_low = get_be32(commit_data + g->hash_len + 12);\n@@ -442,7 +447,7 @@ static struct tree *load_tree_for_commit(struct repository *r,\n \t\t\t\t\t   GRAPH_DATA_WIDTH * (c->graph_pos);\n \n \thashcpy(oid.hash, commit_data);\n-\tc->maybe_tree = lookup_tree(r, &oid);\n+\tset_commit_tree(c, lookup_tree(r, &oid));\n \n \treturn c->maybe_tree;\n }\ndiff --git a/commit.c b/commit.c\nindex f0a5506f04..a9e74647dc 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -340,6 +340,11 @@ void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)\n \t}\n }\n \n+static inline void set_commit_tree(struct commit *c, struct tree *t)\n+{\n+\tc->maybe_tree = t;\n+}\n+\n struct tree *repo_get_commit_tree(struct repository *r,\n \t\t\t\t  const struct commit *commit)\n {\n@@ -359,7 +364,7 @@ struct object_id *get_commit_tree_oid(const struct commit *commit)\n \n void release_commit_memory(struct parsed_object_pool *pool, struct commit *c)\n {\n-\tc->maybe_tree = NULL;\n+\tset_commit_tree(c, NULL);\n \tc->index = 0;\n \tfree_commit_buffer(pool, c);\n \tfree_commit_list(c->parents);\n@@ -407,7 +412,7 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b\n \tif (get_oid_hex(bufptr + 5, &parent) < 0)\n \t\treturn error(\"bad tree pointer in commit %s\",\n \t\t\t     oid_to_hex(&item->object.oid));\n-\titem->maybe_tree = lookup_tree(r, &parent);\n+\tset_commit_tree(item, lookup_tree(r, &parent));\n \tbufptr += tree_entry_len + 1; /* \"tree \" + \"hex sha1\" + \"\\n\" */\n \tpptr = &item->parents;\n \ndiff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\nindex 57c8f71479..d03453341e 100644\n--- a/contrib/coccinelle/commit.cocci\n+++ b/contrib/coccinelle/commit.cocci\n@@ -10,20 +10,25 @@ expression c;\n - c->maybe_tree->object.oid.hash\n + get_commit_tree_oid(c)->hash\n \n+@@\n+identifier f !~ \"^set_commit_tree$\";\n+expression c;\n+expression s;\n+@@\n+  f(...) {<...\n+- c->maybe_tree = s\n++ set_commit_tree(c, s)\n+  ...>}\n+\n // These excluded functions must access c->maybe_tree direcly.\n+// Note that if c->maybe_tree is written somewhere outside of these\n+// functions, then the recommended transformation will be bogus with\n+// repo_get_commit_tree() on the LHS.\n @@\n-identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n+identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|set_commit_tree)$\";\n expression c;\n @@\n   f(...) {<...\n - c->maybe_tree\n-+ repo_get_commit_tree(the_repository, c)\n++ repo_get_commit_tree(specify_the_right_repo_here, c)\n   ...>}\n-\n-@@\n-expression c;\n-expression r;\n-expression s;\n-@@\n-- repo_get_commit_tree(r, c) = s\n-+ c->maybe_tree = s\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 6c40c61c47..ca4731a719 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -163,6 +163,11 @@ static struct tree *shift_tree_object(struct repository *repo,\n \treturn lookup_tree(repo, &shifted);\n }\n \n+static inline void set_commit_tree(struct commit *c, struct tree *t)\n+{\n+\tc->maybe_tree = t;\n+}\n+\n static struct commit *make_virtual_commit(struct repository *repo,\n \t\t\t\t\t  struct tree *tree,\n \t\t\t\t\t  const char *comment)\n@@ -170,7 +175,7 @@ static struct commit *make_virtual_commit(struct repository *repo,\n \tstruct commit *commit = alloc_commit_node(repo);\n \n \tset_merge_remote_desc(commit, comment, (struct object *)commit);\n-\tcommit->maybe_tree = tree;\n+\tset_commit_tree(commit, tree);\n \tcommit->object.parsed = 1;\n \treturn commit;\n }\n \n\nNguyễn Thái Ngọc Duy (32):\n  packfile.c: add repo_approximate_object_count()\n  refs.c: add refs_ref_exists()\n  refs.c: add refs_shorten_unambiguous_ref()\n  refs.c: remove the_repo from substitute_branch_name()\n  refs.c: remove the_repo from expand_ref()\n  refs.c: add repo_dwim_ref()\n  refs.c: add repo_dwim_log()\n  refs.c: remove the_repo from read_ref_at()\n  commit.cocci: refactor code, avoid double rewrite\n  commit.c: add repo_get_commit_tree()\n  sha1-name.c: remove the_repo from sort_ambiguous()\n  sha1-name.c: remove the_repo from find_abbrev_len_packed()\n  sha1-name.c: add repo_find_unique_abbrev_r()\n  sha1-name.c: store and use repo in struct disambiguate_state\n  sha1-name.c: add repo_for_each_abbrev()\n  sha1-name.c: remove the_repo from get_short_oid()\n  sha1-name.c: remove the_repo from interpret_nth_prior_checkout()\n  sha1-name.c: remove the_repo from interpret_branch_mark()\n  sha1-name.c: add repo_interpret_branch_name()\n  sha1-name.c: remove the_repo from get_oid_oneline()\n  sha1-name.c: remove the_repo from get_describe_name()\n  sha1-name.c: remove the_repo from get_oid_basic()\n  sha1-name.c: remove the_repo from get_oid_1()\n  sha1-name.c: remove the_repo from handle_one_ref()\n  sha1-name.c: remove the_repo from diagnose_invalid_index_path()\n  sha1-name.c: remove the_repo from resolve_relative_path()\n  sha1-name.c: remove the_repo from get_oid_with_context_1()\n  sha1-name.c: add repo_get_oid()\n  submodule-config.c: use repo_get_oid for reading .gitmodules\n  sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name\n  sha1-name.c: remove the_repo from other get_oid_*\n  sha1-name.c: remove the_repo from get_oid_mb()\n\nSZEDER Gábor (2):\n  builtin rebase: use FREE_AND_NULL\n  builtin rebase: use oideq()\n\n builtin/rebase.c                   |   5 +-\n builtin/show-branch.c              |   6 +-\n cache.h                            |  50 ++--\n commit-graph.c                     |   9 +-\n commit.c                           |  14 +-\n commit.h                           |   5 +-\n contrib/coccinelle/commit.cocci    |  20 +-\n dir.c                              |   8 +\n dir.h                              |   4 +-\n merge-recursive.c                  |   7 +-\n packfile.c                         |  14 +-\n packfile.h                         |   3 +-\n refs.c                             |  71 ++++--\n refs.h                             |   9 +-\n setup.c                            |   7 +-\n sha1-name.c                        | 388 ++++++++++++++++++-----------\n submodule-config.c                 |  20 +-\n t/t7814-grep-recurse-submodules.sh |   6 +-\n upload-pack.c                      |   2 +-\n 19 files changed, 407 insertions(+), 241 deletions(-)\n\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373933","messageId":"20190416093341.17079-2-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 01/34] builtin rebase: use FREE_AND_NULL","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:08Z","receivedAt":"2019-04-16T09:34:38Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"From: SZEDER Gábor <szeder.dev@gmail.com>\n\nUse the macro FREE_AND_NULL to release memory allocated for\n'head_name' and clear its pointer.\n\nPatch generated with 'contrib/coccinelle/free.cocci' and Coccinelle\nv1.0.7 (previous Coccinelle versions don't notice this).\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/rebase.c | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 77deebc65c..868bcd1446 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -1592,8 +1592,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\t\t\tbranch_name = options.head_name;\n \n \t\t} else {\n-\t\t\tfree(options.head_name);\n-\t\t\toptions.head_name = NULL;\n+\t\t\tFREE_AND_NULL(options.head_name);\n \t\t\tbranch_name = \"HEAD\";\n \t\t}\n \t\tif (get_oid(\"HEAD\", &options.orig_head))\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373934","messageId":"20190416093341.17079-3-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 02/34] builtin rebase: use oideq()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:09Z","receivedAt":"2019-04-16T09:34:45Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"From: SZEDER Gábor <szeder.dev@gmail.com>\n\nUse oideq() instead of !oidcmp(), as it is more idiomatic, and might\ngive the compiler more opportunities to optimize.\n\nPatch generated with 'contrib/coccinelle/free.cocci' and Coccinelle\nv1.0.7 (previous Coccinelle versions don't notice this).\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/rebase.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 868bcd1446..c064909329 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -1792,7 +1792,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t * we just fast-forwarded.\n \t */\n \tstrbuf_reset(&msg);\n-\tif (!oidcmp(&merge_base, &options.orig_head)) {\n+\tif (oideq(&merge_base, &options.orig_head)) {\n \t\tprintf(_(\"Fast-forwarded %s to %s.\\n\"),\n \t\t\tbranch_name, options.onto_name);\n \t\tstrbuf_addf(&msg, \"rebase finished: %s onto %s\",\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373935","messageId":"20190416093341.17079-4-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 03/34] packfile.c: add repo_approximate_object_count()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:10Z","receivedAt":"2019-04-16T09:34:50Z","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 packfile.c | 14 +++++++-------\n packfile.h |  3 ++-\n 2 files changed, 9 insertions(+), 8 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex 16bcb75262..2ad4fab2f8 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -893,25 +893,25 @@ static void prepare_packed_git(struct repository *r);\n  * all unreachable objects about to be pruned, in which case they're not really\n  * interesting as a measure of repo size in the first place.\n  */\n-unsigned long approximate_object_count(void)\n+unsigned long repo_approximate_object_count(struct repository *r)\n {\n-\tif (!the_repository->objects->approximate_object_count_valid) {\n+\tif (!r->objects->approximate_object_count_valid) {\n \t\tunsigned long count;\n \t\tstruct multi_pack_index *m;\n \t\tstruct packed_git *p;\n \n-\t\tprepare_packed_git(the_repository);\n+\t\tprepare_packed_git(r);\n \t\tcount = 0;\n-\t\tfor (m = get_multi_pack_index(the_repository); m; m = m->next)\n+\t\tfor (m = get_multi_pack_index(r); m; m = m->next)\n \t\t\tcount += m->num_objects;\n-\t\tfor (p = the_repository->objects->packed_git; p; p = p->next) {\n+\t\tfor (p = r->objects->packed_git; p; p = p->next) {\n \t\t\tif (open_pack_index(p))\n \t\t\t\tcontinue;\n \t\t\tcount += p->num_objects;\n \t\t}\n-\t\tthe_repository->objects->approximate_object_count = count;\n+\t\tr->objects->approximate_object_count = count;\n \t}\n-\treturn the_repository->objects->approximate_object_count;\n+\treturn r->objects->approximate_object_count;\n }\n \n static void *get_next_packed_git(const void *p)\ndiff --git a/packfile.h b/packfile.h\nindex d70c6d9afb..f04440f984 100644\n--- a/packfile.h\n+++ b/packfile.h\n@@ -57,7 +57,8 @@ struct packed_git *get_all_packs(struct repository *r);\n  * Give a rough count of objects in the repository. This sacrifices accuracy\n  * for speed.\n  */\n-unsigned long approximate_object_count(void);\n+unsigned long repo_approximate_object_count(struct repository *r);\n+#define approximate_object_count() repo_approximate_object_count(the_repository)\n \n extern struct packed_git *find_sha1_pack(const unsigned char *sha1,\n \t\t\t\t\t struct packed_git *packs);\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373936","messageId":"20190416093341.17079-5-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 04/34] refs.c: add refs_ref_exists()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:11Z","receivedAt":"2019-04-16T09:34:56Z","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 refs.c | 7 ++++++-\n 1 file changed, 6 insertions(+), 1 deletion(-)\n\ndiff --git a/refs.c b/refs.c\nindex 142888a40a..b869f32d8b 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -241,9 +241,14 @@ int read_ref(const char *refname, struct object_id *oid)\n \treturn read_ref_full(refname, RESOLVE_REF_READING, oid, NULL);\n }\n \n+static int refs_ref_exists(struct ref_store *refs, const char *refname)\n+{\n+\treturn !!refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING, NULL, NULL);\n+}\n+\n int ref_exists(const char *refname)\n {\n-\treturn !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, NULL, NULL);\n+\treturn refs_ref_exists(get_main_ref_store(the_repository), refname);\n }\n \n static int match_ref_pattern(const char *refname,\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373937","messageId":"20190416093341.17079-6-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 05/34] refs.c: add refs_shorten_unambiguous_ref()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:12Z","receivedAt":"2019-04-16T09:35:03Z","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 refs.c | 11 +++++++++--\n refs.h |  2 ++\n 2 files changed, 11 insertions(+), 2 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex b869f32d8b..3dde824aab 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1169,7 +1169,8 @@ int update_ref(const char *msg, const char *refname,\n \t\t\t       old_oid, flags, onerr);\n }\n \n-char *shorten_unambiguous_ref(const char *refname, int strict)\n+char *refs_shorten_unambiguous_ref(struct ref_store *refs,\n+\t\t\t\t   const char *refname, int strict)\n {\n \tint i;\n \tstatic char **scanf_fmts;\n@@ -1247,7 +1248,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)\n \t\t\tstrbuf_reset(&resolved_buf);\n \t\t\tstrbuf_addf(&resolved_buf, rule,\n \t\t\t\t    short_name_len, short_name);\n-\t\t\tif (ref_exists(resolved_buf.buf))\n+\t\t\tif (refs_ref_exists(refs, resolved_buf.buf))\n \t\t\t\tbreak;\n \t\t}\n \n@@ -1266,6 +1267,12 @@ char *shorten_unambiguous_ref(const char *refname, int strict)\n \treturn xstrdup(refname);\n }\n \n+char *shorten_unambiguous_ref(const char *refname, int strict)\n+{\n+\treturn refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),\n+\t\t\t\t\t    refname, strict);\n+}\n+\n static struct string_list *hide_refs;\n \n int parse_hide_refs_config(const char *var, const char *value, const char *section)\ndiff --git a/refs.h b/refs.h\nindex 308fa1f03b..5627570241 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -462,6 +462,8 @@ int check_refname_format(const char *refname, int flags);\n \n const char *prettify_refname(const char *refname);\n \n+char *refs_shorten_unambiguous_ref(struct ref_store *refs,\n+\t\t\t\t   const char *refname, int strict);\n char *shorten_unambiguous_ref(const char *refname, int strict);\n \n /** rename ref, return 0 on success **/\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373938","messageId":"20190416093341.17079-7-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 06/34] refs.c: remove the_repo from substitute_branch_name()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:13Z","receivedAt":"2019-04-16T09:35: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     | 8 ++++++--\n refs.c      | 9 +++++----\n sha1-name.c | 8 ++++++--\n 3 files changed, 17 insertions(+), 8 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex ac92421f3a..fcb24b5781 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1468,8 +1468,12 @@ extern int parse_oid_hex(const char *hex, struct object_id *oid, const char **en\n #define INTERPRET_BRANCH_LOCAL (1<<0)\n #define INTERPRET_BRANCH_REMOTE (1<<1)\n #define INTERPRET_BRANCH_HEAD (1<<2)\n-extern int interpret_branch_name(const char *str, int len, struct strbuf *,\n-\t\t\t\t unsigned allowed);\n+int repo_interpret_branch_name(struct repository *r,\n+\t\t\t       const char *str, int len,\n+\t\t\t       struct strbuf *buf,\n+\t\t\t       unsigned allowed);\n+#define interpret_branch_name(str, len, buf, allowed) \\\n+\trepo_interpret_branch_name(the_repository, str, len, buf, allowed)\n extern int get_oid_mb(const char *str, struct object_id *oid);\n \n extern int validate_headref(const char *ref);\ndiff --git a/refs.c b/refs.c\nindex 3dde824aab..44df049796 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -539,10 +539,11 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)\n  * later free()ing) if the string passed in is a magic short-hand form\n  * to name a branch.\n  */\n-static char *substitute_branch_name(const char **string, int *len)\n+static char *substitute_branch_name(struct repository *r,\n+\t\t\t\t    const char **string, int *len)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n-\tint ret = interpret_branch_name(*string, *len, &buf, 0);\n+\tint ret = repo_interpret_branch_name(r, *string, *len, &buf, 0);\n \n \tif (ret == *len) {\n \t\tsize_t size;\n@@ -556,7 +557,7 @@ static char *substitute_branch_name(const char **string, int *len)\n \n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)\n {\n-\tchar *last_branch = substitute_branch_name(&str, &len);\n+\tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n \tint   refs_found  = expand_ref(str, len, oid, ref);\n \tfree(last_branch);\n \treturn refs_found;\n@@ -596,7 +597,7 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)\n \n int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n {\n-\tchar *last_branch = substitute_branch_name(&str, &len);\n+\tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n \tconst char **p;\n \tint logs_found = 0;\n \tstruct strbuf path = STRBUF_INIT;\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 6dda2c16df..d535bb82f7 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1427,13 +1427,17 @@ static int interpret_branch_mark(const char *name, int namelen,\n \treturn len + at;\n }\n \n-int interpret_branch_name(const char *name, int namelen, struct strbuf *buf,\n-\t\t\t  unsigned allowed)\n+int repo_interpret_branch_name(struct repository *r,\n+\t\t\t       const char *name, int namelen,\n+\t\t\t       struct strbuf *buf,\n+\t\t\t       unsigned allowed)\n {\n \tchar *at;\n \tconst char *start;\n \tint len;\n \n+\tif (r != the_repository)\n+\t\tBUG(\"interpret_branch_name() does not really use 'r' yet\");\n \tif (!namelen)\n \t\tnamelen = strlen(name);\n \n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373939","messageId":"20190416093341.17079-8-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 07/34] refs.c: remove the_repo from expand_ref()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:14Z","receivedAt":"2019-04-16T09:35:11Z","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 refs.c        | 10 ++++++----\n refs.h        |  2 +-\n upload-pack.c |  2 +-\n 3 files changed, 8 insertions(+), 6 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 44df049796..1f5864aa36 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -558,12 +558,13 @@ static char *substitute_branch_name(struct repository *r,\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)\n {\n \tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n-\tint   refs_found  = expand_ref(str, len, oid, ref);\n+\tint   refs_found  = expand_ref(the_repository, str, len, oid, ref);\n \tfree(last_branch);\n \treturn refs_found;\n }\n \n-int expand_ref(const char *str, int len, struct object_id *oid, char **ref)\n+int expand_ref(struct repository *repo, const char *str, int len,\n+\t       struct object_id *oid, char **ref)\n {\n \tconst char **p, *r;\n \tint refs_found = 0;\n@@ -578,8 +579,9 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)\n \t\tthis_result = refs_found ? &oid_from_ref : oid;\n \t\tstrbuf_reset(&fullref);\n \t\tstrbuf_addf(&fullref, *p, len, str);\n-\t\tr = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,\n-\t\t\t\t       this_result, &flag);\n+\t\tr = refs_resolve_ref_unsafe(get_main_ref_store(repo),\n+\t\t\t\t\t    fullref.buf, RESOLVE_REF_READING,\n+\t\t\t\t\t    this_result, &flag);\n \t\tif (r) {\n \t\t\tif (!refs_found++)\n \t\t\t\t*ref = xstrdup(r);\ndiff --git a/refs.h b/refs.h\nindex 5627570241..b630d5bde7 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -148,7 +148,7 @@ int refname_match(const char *abbrev_name, const char *full_name);\n struct argv_array;\n void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);\n \n-int expand_ref(const char *str, int len, struct object_id *oid, char **ref);\n+int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n \ndiff --git a/upload-pack.c b/upload-pack.c\nindex d098ef5982..56505d60c3 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -834,7 +834,7 @@ static int process_deepen_not(const char *line, struct string_list *deepen_not,\n \tif (skip_prefix(line, \"deepen-not \", &arg)) {\n \t\tchar *ref = NULL;\n \t\tstruct object_id oid;\n-\t\tif (expand_ref(arg, strlen(arg), &oid, &ref) != 1)\n+\t\tif (expand_ref(the_repository, arg, strlen(arg), &oid, &ref) != 1)\n \t\t\tdie(\"git upload-pack: ambiguous deepen-not: %s\", line);\n \t\tstring_list_append(deepen_not, ref);\n \t\tfree(ref);\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373940","messageId":"20190416093341.17079-9-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 08/34] refs.c: add repo_dwim_ref()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:15Z","receivedAt":"2019-04-16T09:35:16Z","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 refs.c | 12 +++++++++---\n refs.h |  1 +\n 2 files changed, 10 insertions(+), 3 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 1f5864aa36..bd0fec5776 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -555,14 +555,20 @@ static char *substitute_branch_name(struct repository *r,\n \treturn NULL;\n }\n \n-int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)\n+int repo_dwim_ref(struct repository *r, const char *str, int len,\n+\t\t  struct object_id *oid, char **ref)\n {\n-\tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n-\tint   refs_found  = expand_ref(the_repository, str, len, oid, ref);\n+\tchar *last_branch = substitute_branch_name(r, &str, &len);\n+\tint   refs_found  = expand_ref(r, str, len, oid, ref);\n \tfree(last_branch);\n \treturn refs_found;\n }\n \n+int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)\n+{\n+\treturn repo_dwim_ref(the_repository, str, len, oid, ref);\n+}\n+\n int expand_ref(struct repository *repo, const char *str, int len,\n \t       struct object_id *oid, char **ref)\n {\ndiff --git a/refs.h b/refs.h\nindex b630d5bde7..fd3dc1d0f4 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -149,6 +149,7 @@ struct argv_array;\n void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);\n \n int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n+int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n \n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373941","messageId":"20190416093341.17079-10-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 09/34] refs.c: add repo_dwim_log()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:16Z","receivedAt":"2019-04-16T09:35:22Z","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 refs.c | 21 +++++++++++++++------\n refs.h |  1 +\n 2 files changed, 16 insertions(+), 6 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex bd0fec5776..edea001446 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -603,9 +603,11 @@ int expand_ref(struct repository *repo, const char *str, int len,\n \treturn refs_found;\n }\n \n-int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n+int repo_dwim_log(struct repository *r, const char *str, int len,\n+\t\t  struct object_id *oid, char **log)\n {\n-\tchar *last_branch = substitute_branch_name(the_repository, &str, &len);\n+\tstruct ref_store *refs = get_main_ref_store(r);\n+\tchar *last_branch = substitute_branch_name(r, &str, &len);\n \tconst char **p;\n \tint logs_found = 0;\n \tstruct strbuf path = STRBUF_INIT;\n@@ -617,13 +619,15 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n \n \t\tstrbuf_reset(&path);\n \t\tstrbuf_addf(&path, *p, len, str);\n-\t\tref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,\n-\t\t\t\t\t &hash, NULL);\n+\t\tref = refs_resolve_ref_unsafe(refs, path.buf,\n+\t\t\t\t\t      RESOLVE_REF_READING,\n+\t\t\t\t\t      &hash, NULL);\n \t\tif (!ref)\n \t\t\tcontinue;\n-\t\tif (reflog_exists(path.buf))\n+\t\tif (refs_reflog_exists(refs, path.buf))\n \t\t\tit = path.buf;\n-\t\telse if (strcmp(ref, path.buf) && reflog_exists(ref))\n+\t\telse if (strcmp(ref, path.buf) &&\n+\t\t\t refs_reflog_exists(refs, ref))\n \t\t\tit = ref;\n \t\telse\n \t\t\tcontinue;\n@@ -639,6 +643,11 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n \treturn logs_found;\n }\n \n+int dwim_log(const char *str, int len, struct object_id *oid, char **log)\n+{\n+\treturn repo_dwim_log(the_repository, str, len, oid, log);\n+}\n+\n static int is_per_worktree_ref(const char *refname)\n {\n \treturn !strcmp(refname, \"HEAD\") ||\ndiff --git a/refs.h b/refs.h\nindex fd3dc1d0f4..859dffe691 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -150,6 +150,7 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);\n \n int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n+int repo_dwim_log(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);\n int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);\n int dwim_log(const char *str, int len, struct object_id *oid, char **ref);\n \n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373942","messageId":"20190416093341.17079-11-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 10/34] refs.c: remove the_repo from read_ref_at()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:17Z","receivedAt":"2019-04-16T09:35:27Z","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/show-branch.c | 6 ++++--\n refs.c                | 7 ++++---\n refs.h                | 3 ++-\n sha1-name.c           | 3 ++-\n 4 files changed, 12 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/show-branch.c b/builtin/show-branch.c\nindex 934e514944..082daeac32 100644\n--- a/builtin/show-branch.c\n+++ b/builtin/show-branch.c\n@@ -753,7 +753,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\t\t/* Ah, that is a date spec... */\n \t\t\t\ttimestamp_t at;\n \t\t\t\tat = approxidate(reflog_base);\n-\t\t\t\tread_ref_at(ref, flags, at, -1, &oid, NULL,\n+\t\t\t\tread_ref_at(get_main_ref_store(the_repository),\n+\t\t\t\t\t    ref, flags, at, -1, &oid, NULL,\n \t\t\t\t\t    NULL, NULL, &base);\n \t\t\t}\n \t\t}\n@@ -765,7 +766,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\ttimestamp_t timestamp;\n \t\t\tint tz;\n \n-\t\t\tif (read_ref_at(ref, flags, 0, base + i, &oid, &logmsg,\n+\t\t\tif (read_ref_at(get_main_ref_store(the_repository),\n+\t\t\t\t\tref, flags, 0, base + i, &oid, &logmsg,\n \t\t\t\t\t&timestamp, &tz, NULL)) {\n \t\t\t\treflog = i;\n \t\t\t\tbreak;\ndiff --git a/refs.c b/refs.c\nindex edea001446..92d1f6dbdd 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -967,7 +967,8 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid\n \treturn 1;\n }\n \n-int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, int cnt,\n+int read_ref_at(struct ref_store *refs, const char *refname,\n+\t\tunsigned int flags, timestamp_t at_time, int cnt,\n \t\tstruct object_id *oid, char **msg,\n \t\ttimestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt)\n {\n@@ -983,7 +984,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in\n \tcb.cutoff_cnt = cutoff_cnt;\n \tcb.oid = oid;\n \n-\tfor_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);\n+\trefs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent, &cb);\n \n \tif (!cb.reccnt) {\n \t\tif (flags & GET_OID_QUIETLY)\n@@ -994,7 +995,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in\n \tif (cb.found_it)\n \t\treturn 0;\n \n-\tfor_each_reflog_ent(refname, read_ref_at_ent_oldest, &cb);\n+\trefs_for_each_reflog_ent(refs, refname, read_ref_at_ent_oldest, &cb);\n \n \treturn 1;\n }\ndiff --git a/refs.h b/refs.h\nindex 859dffe691..8f9cbf8a93 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -388,7 +388,8 @@ int refs_create_reflog(struct ref_store *refs, const char *refname,\n int safe_create_reflog(const char *refname, int force_create, struct strbuf *err);\n \n /** Reads log for the value of ref during at_time. **/\n-int read_ref_at(const char *refname, unsigned int flags,\n+int read_ref_at(struct ref_store *refs,\n+\t\tconst char *refname, unsigned int flags,\n \t\ttimestamp_t at_time, int cnt,\n \t\tstruct object_id *oid, char **msg,\n \t\ttimestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt);\ndiff --git a/sha1-name.c b/sha1-name.c\nindex d535bb82f7..15a1107998 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -849,7 +849,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\t\t\treturn -1;\n \t\t\t}\n \t\t}\n-\t\tif (read_ref_at(real_ref, flags, at_time, nth, oid, NULL,\n+\t\tif (read_ref_at(get_main_ref_store(the_repository),\n+\t\t\t\treal_ref, flags, at_time, nth, oid, NULL,\n \t\t\t\t&co_time, &co_tz, &co_cnt)) {\n \t\t\tif (!len) {\n \t\t\t\tif (starts_with(real_ref, \"refs/heads/\")) {\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373943","messageId":"20190416093341.17079-12-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 11/34] commit.cocci: refactor code, avoid double rewrite","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:18Z","receivedAt":"2019-04-16T09:35:32Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\"maybe\" pointer in 'struct commit' is tricky because it can be lazily\ninitialized to take advantage of commit-graph if available. This makes\nit not safe to access directly.\n\nThis leads to a rule in commit.cocci to rewrite 'x->maybe_tree' to\n'get_commit_tree(x)'. But that rule alone could lead to incorrectly\nrewrite assignments, e.g. from\n\n    x->maybe_tree = yes\n\nto\n\n    get_commit_tree(x) = yes\n\nBecause of this we have a second rule to revert this effect. Szeder\nfound out that we could do better by performing the assignment rewrite\nrule first, then the remaining is read-only access and handled by the\ncurrent first rule.\n\nFor this to work, we need to transform \"x->maybe_tree = y\" to something\nthat does NOT contain \"x->maybe_tree\" to avoid the original first\nrule. This is where set_commit_tree() comes in.\n\nHelped-by: SZEDER Gábor <szeder.dev@gmail.com>\nHelped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n commit-graph.c                  |  9 +++++++--\n commit.c                        |  9 +++++++--\n contrib/coccinelle/commit.cocci | 20 +++++++++++++-------\n merge-recursive.c               |  7 ++++++-\n 4 files changed, 33 insertions(+), 12 deletions(-)\n\ndiff --git a/commit-graph.c b/commit-graph.c\nindex 47e9be0a3a..155a270457 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -343,6 +343,11 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,\n \titem->generation = get_be32(commit_data + g->hash_len + 8) >> 2;\n }\n \n+static inline void set_commit_tree(struct commit *c, struct tree *t)\n+{\n+\tc->maybe_tree = t;\n+}\n+\n static int fill_commit_in_graph(struct repository *r,\n \t\t\t\tstruct commit *item,\n \t\t\t\tstruct commit_graph *g, uint32_t pos)\n@@ -356,7 +361,7 @@ static int fill_commit_in_graph(struct repository *r,\n \titem->object.parsed = 1;\n \titem->graph_pos = pos;\n \n-\titem->maybe_tree = NULL;\n+\tset_commit_tree(item, NULL);\n \n \tdate_high = get_be32(commit_data + g->hash_len + 8) & 0x3;\n \tdate_low = get_be32(commit_data + g->hash_len + 12);\n@@ -442,7 +447,7 @@ static struct tree *load_tree_for_commit(struct repository *r,\n \t\t\t\t\t   GRAPH_DATA_WIDTH * (c->graph_pos);\n \n \thashcpy(oid.hash, commit_data);\n-\tc->maybe_tree = lookup_tree(r, &oid);\n+\tset_commit_tree(c, lookup_tree(r, &oid));\n \n \treturn c->maybe_tree;\n }\ndiff --git a/commit.c b/commit.c\nindex a5333c7ac6..043ba64f17 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -340,6 +340,11 @@ void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)\n \t}\n }\n \n+static inline void set_commit_tree(struct commit *c, struct tree *t)\n+{\n+\tc->maybe_tree = t;\n+}\n+\n struct tree *get_commit_tree(const struct commit *commit)\n {\n \tif (commit->maybe_tree || !commit->object.parsed)\n@@ -358,7 +363,7 @@ struct object_id *get_commit_tree_oid(const struct commit *commit)\n \n void release_commit_memory(struct parsed_object_pool *pool, struct commit *c)\n {\n-\tc->maybe_tree = NULL;\n+\tset_commit_tree(c, NULL);\n \tc->index = 0;\n \tfree_commit_buffer(pool, c);\n \tfree_commit_list(c->parents);\n@@ -406,7 +411,7 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b\n \tif (get_oid_hex(bufptr + 5, &parent) < 0)\n \t\treturn error(\"bad tree pointer in commit %s\",\n \t\t\t     oid_to_hex(&item->object.oid));\n-\titem->maybe_tree = lookup_tree(r, &parent);\n+\tset_commit_tree(item, lookup_tree(r, &parent));\n \tbufptr += tree_entry_len + 1; /* \"tree \" + \"hex sha1\" + \"\\n\" */\n \tpptr = &item->parents;\n \ndiff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\nindex c49aa558f0..663658a127 100644\n--- a/contrib/coccinelle/commit.cocci\n+++ b/contrib/coccinelle/commit.cocci\n@@ -10,19 +10,25 @@ expression c;\n - c->maybe_tree->object.oid.hash\n + get_commit_tree_oid(c)->hash\n \n-// These excluded functions must access c->maybe_tree direcly.\n @@\n-identifier f !~ \"^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$\";\n+identifier f !~ \"^set_commit_tree$\";\n expression c;\n+expression s;\n @@\n   f(...) {<...\n-- c->maybe_tree\n-+ get_commit_tree(c)\n+- c->maybe_tree = s\n++ set_commit_tree(c, s)\n   ...>}\n \n+// These excluded functions must access c->maybe_tree direcly.\n+// Note that if c->maybe_tree is written somewhere outside of these\n+// functions, then the recommended transformation will be bogus with\n+// get_commit_tree() on the LHS.\n @@\n+identifier f !~ \"^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|set_commit_tree)$\";\n expression c;\n-expression s;\n @@\n-- get_commit_tree(c) = s\n-+ c->maybe_tree = s\n+  f(...) {<...\n+- c->maybe_tree\n++ get_commit_tree(c)\n+  ...>}\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 6c40c61c47..ca4731a719 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -163,6 +163,11 @@ static struct tree *shift_tree_object(struct repository *repo,\n \treturn lookup_tree(repo, &shifted);\n }\n \n+static inline void set_commit_tree(struct commit *c, struct tree *t)\n+{\n+\tc->maybe_tree = t;\n+}\n+\n static struct commit *make_virtual_commit(struct repository *repo,\n \t\t\t\t\t  struct tree *tree,\n \t\t\t\t\t  const char *comment)\n@@ -170,7 +175,7 @@ static struct commit *make_virtual_commit(struct repository *repo,\n \tstruct commit *commit = alloc_commit_node(repo);\n \n \tset_merge_remote_desc(commit, comment, (struct object *)commit);\n-\tcommit->maybe_tree = tree;\n+\tset_commit_tree(commit, tree);\n \tcommit->object.parsed = 1;\n \treturn commit;\n }\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373944","messageId":"20190416093341.17079-13-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 12/34] commit.c: add repo_get_commit_tree()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:19Z","receivedAt":"2019-04-16T09:35:40Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Remove the implicit dependency on the_repository in this function.\nIt will be used in sha1-name.c functions when they are updated to take\nany 'struct repository'. get_commit_tree() remains as a compat wrapper,\nto be slowly replaced later.\n\nAny access to \"maybe_tree\" field directly will result in _broken_ code\nafter running through commit.cocci because we can't know what is the\nright repository to use.\n\nthe_repository would be correct most of the time. But we're relying less\nand less on the_repository and that assumption may no longer be\ntrue. The transformation now is more of a poor man replacement for a C++\ncompiler catching access to private fields.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n commit.c                        | 5 +++--\n commit.h                        | 5 +++--\n contrib/coccinelle/commit.cocci | 6 +++---\n 3 files changed, 9 insertions(+), 7 deletions(-)\n\ndiff --git a/commit.c b/commit.c\nindex 043ba64f17..a9e74647dc 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -345,7 +345,8 @@ static inline void set_commit_tree(struct commit *c, struct tree *t)\n \tc->maybe_tree = t;\n }\n \n-struct tree *get_commit_tree(const struct commit *commit)\n+struct tree *repo_get_commit_tree(struct repository *r,\n+\t\t\t\t  const struct commit *commit)\n {\n \tif (commit->maybe_tree || !commit->object.parsed)\n \t\treturn commit->maybe_tree;\n@@ -353,7 +354,7 @@ struct tree *get_commit_tree(const struct commit *commit)\n \tif (commit->graph_pos == COMMIT_NOT_FROM_GRAPH)\n \t\tBUG(\"commit has NULL tree, but was not loaded from commit-graph\");\n \n-\treturn get_commit_tree_in_graph(the_repository, commit);\n+\treturn get_commit_tree_in_graph(r, commit);\n }\n \n struct object_id *get_commit_tree_oid(const struct commit *commit)\ndiff --git a/commit.h b/commit.h\nindex 42728c2906..f1aa4c0472 100644\n--- a/commit.h\n+++ b/commit.h\n@@ -32,7 +32,7 @@ struct commit {\n \n \t/*\n \t * If the commit is loaded from the commit-graph file, then this\n-\t * member may be NULL. Only access it through get_commit_tree()\n+\t * member may be NULL. Only access it through repo_get_commit_tree()\n \t * or get_commit_tree_oid().\n \t */\n \tstruct tree *maybe_tree;\n@@ -143,7 +143,8 @@ void repo_unuse_commit_buffer(struct repository *r,\n  */\n void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);\n \n-struct tree *get_commit_tree(const struct commit *);\n+struct tree *repo_get_commit_tree(struct repository *, const struct commit *);\n+#define get_commit_tree(c) repo_get_commit_tree(the_repository, c)\n struct object_id *get_commit_tree_oid(const struct commit *);\n \n /*\ndiff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci\nindex 663658a127..d03453341e 100644\n--- a/contrib/coccinelle/commit.cocci\n+++ b/contrib/coccinelle/commit.cocci\n@@ -23,12 +23,12 @@ expression s;\n // These excluded functions must access c->maybe_tree direcly.\n // Note that if c->maybe_tree is written somewhere outside of these\n // functions, then the recommended transformation will be bogus with\n-// get_commit_tree() on the LHS.\n+// repo_get_commit_tree() on the LHS.\n @@\n-identifier f !~ \"^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|set_commit_tree)$\";\n+identifier f !~ \"^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|set_commit_tree)$\";\n expression c;\n @@\n   f(...) {<...\n - c->maybe_tree\n-+ get_commit_tree(c)\n++ repo_get_commit_tree(specify_the_right_repo_here, c)\n   ...>}\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373945","messageId":"20190416093341.17079-14-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 13/34] sha1-name.c: remove the_repo from sort_ambiguous()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:20Z","receivedAt":"2019-04-16T09:35:45Z","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 | 15 ++++++++++++---\n 1 file changed, 12 insertions(+), 3 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 15a1107998..7558ce51a3 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -383,10 +383,11 @@ static int collect_ambiguous(const struct object_id *oid, void *data)\n \treturn 0;\n }\n \n+static struct repository *sort_ambiguous_repo;\n static int sort_ambiguous(const void *a, const void *b)\n {\n-\tint a_type = oid_object_info(the_repository, a, NULL);\n-\tint b_type = oid_object_info(the_repository, b, NULL);\n+\tint a_type = oid_object_info(sort_ambiguous_repo, a, NULL);\n+\tint b_type = oid_object_info(sort_ambiguous_repo, b, NULL);\n \tint a_type_sort;\n \tint b_type_sort;\n \n@@ -411,6 +412,14 @@ static int sort_ambiguous(const void *a, const void *b)\n \treturn a_type_sort > b_type_sort ? 1 : -1;\n }\n \n+static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)\n+{\n+\t/* mutex will be needed if this code is to be made thread safe */\n+\tsort_ambiguous_repo = r;\n+\tQSORT(a->oid, a->nr, sort_ambiguous);\n+\tsort_ambiguous_repo = NULL;\n+}\n+\n static enum get_oid_result get_short_oid(const char *name, int len,\n \t\t\t\t\t struct object_id *oid,\n \t\t\t\t\t unsigned flags)\n@@ -458,7 +467,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \n \t\tadvise(_(\"The candidates are:\"));\n \t\tfor_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect);\n-\t\tQSORT(collect.oid, collect.nr, sort_ambiguous);\n+\t\tsort_ambiguous_oid_array(the_repository, &collect);\n \n \t\tif (oid_array_for_each(&collect, show_ambiguous_object, &ds))\n \t\t\tBUG(\"show_ambiguous_object shouldn't return non-zero\");\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373946","messageId":"20190416093341.17079-15-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 14/34] sha1-name.c: remove the_repo from find_abbrev_len_packed()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:21Z","receivedAt":"2019-04-16T09:35:51Z","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 | 6 ++++--\n 1 file changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 7558ce51a3..b9381aaba6 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -514,6 +514,7 @@ struct min_abbrev_data {\n \tunsigned int init_len;\n \tunsigned int cur_len;\n \tchar *hex;\n+\tstruct repository *repo;\n \tconst struct object_id *oid;\n };\n \n@@ -619,9 +620,9 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)\n \tstruct multi_pack_index *m;\n \tstruct packed_git *p;\n \n-\tfor (m = get_multi_pack_index(the_repository); m; m = m->next)\n+\tfor (m = get_multi_pack_index(mad->repo); m; m = m->next)\n \t\tfind_abbrev_len_for_midx(m, mad);\n-\tfor (p = get_packed_git(the_repository); p; p = p->next)\n+\tfor (p = get_packed_git(mad->repo); p; p = p->next)\n \t\tfind_abbrev_len_for_pack(p, mad);\n }\n \n@@ -658,6 +659,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)\n \tif (len == hexsz || !len)\n \t\treturn hexsz;\n \n+\tmad.repo = the_repository;\n \tmad.init_len = len;\n \tmad.cur_len = len;\n \tmad.hex = hex;\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373947","messageId":"20190416093341.17079-16-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 15/34] sha1-name.c: add repo_find_unique_abbrev_r()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:22Z","receivedAt":"2019-04-16T09:35:59Z","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     |  6 ++++--\n sha1-name.c | 15 +++++++++------\n 2 files changed, 13 insertions(+), 8 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex fcb24b5781..4f8ebb0a67 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1045,8 +1045,10 @@ extern void check_repository_format(void);\n  * Note that while this version avoids the static buffer, it is not fully\n  * reentrant, as it calls into other non-reentrant git code.\n  */\n-extern const char *find_unique_abbrev(const struct object_id *oid, int len);\n-extern int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len);\n+const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len);\n+#define find_unique_abbrev(oid, len) repo_find_unique_abbrev(the_repository, oid, len)\n+int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);\n+#define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len)\n \n extern const unsigned char null_sha1[GIT_MAX_RAWSZ];\n extern const struct object_id null_oid;\ndiff --git a/sha1-name.c b/sha1-name.c\nindex b9381aaba6..9b57787b76 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -626,15 +626,16 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)\n \t\tfind_abbrev_len_for_pack(p, mad);\n }\n \n-int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)\n+int repo_find_unique_abbrev_r(struct repository *r, char *hex,\n+\t\t\t      const struct object_id *oid, int len)\n {\n \tstruct disambiguate_state ds;\n \tstruct min_abbrev_data mad;\n \tstruct object_id oid_ret;\n-\tconst unsigned hexsz = the_hash_algo->hexsz;\n+\tconst unsigned hexsz = r->hash_algo->hexsz;\n \n \tif (len < 0) {\n-\t\tunsigned long count = approximate_object_count();\n+\t\tunsigned long count = repo_approximate_object_count(r);\n \t\t/*\n \t\t * Add one because the MSB only tells us the highest bit set,\n \t\t * not including the value of all the _other_ bits (so \"15\"\n@@ -659,7 +660,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)\n \tif (len == hexsz || !len)\n \t\treturn hexsz;\n \n-\tmad.repo = the_repository;\n+\tmad.repo = r;\n \tmad.init_len = len;\n \tmad.cur_len = len;\n \tmad.hex = hex;\n@@ -681,13 +682,15 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)\n \treturn mad.cur_len;\n }\n \n-const char *find_unique_abbrev(const struct object_id *oid, int len)\n+const char *repo_find_unique_abbrev(struct repository *r,\n+\t\t\t\t    const struct object_id *oid,\n+\t\t\t\t    int len)\n {\n \tstatic int bufno;\n \tstatic char hexbuffer[4][GIT_MAX_HEXSZ + 1];\n \tchar *hex = hexbuffer[bufno];\n \tbufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);\n-\tfind_unique_abbrev_r(hex, oid, len);\n+\trepo_find_unique_abbrev_r(r, hex, oid, len);\n \treturn hex;\n }\n \n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373948","messageId":"20190416093341.17079-17-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 16/34] sha1-name.c: store and use repo in struct disambiguate_state","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:23Z","receivedAt":"2019-04-16T09:36:05Z","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 | 95 +++++++++++++++++++++++++++++++++--------------------\n 1 file changed, 59 insertions(+), 36 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 9b57787b76..a75992eb54 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -17,13 +17,14 @@\n \n static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);\n \n-typedef int (*disambiguate_hint_fn)(const struct object_id *, void *);\n+typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);\n \n struct disambiguate_state {\n \tint len; /* length of prefix in hex chars */\n \tchar hex_pfx[GIT_MAX_HEXSZ + 1];\n \tstruct object_id bin_pfx;\n \n+\tstruct repository *repo;\n \tdisambiguate_hint_fn fn;\n \tvoid *cb_data;\n \tstruct object_id candidate;\n@@ -38,7 +39,7 @@ struct disambiguate_state {\n static void update_candidates(struct disambiguate_state *ds, const struct object_id *current)\n {\n \tif (ds->always_call_fn) {\n-\t\tds->ambiguous = ds->fn(current, ds->cb_data) ? 1 : 0;\n+\t\tds->ambiguous = ds->fn(ds->repo, current, ds->cb_data) ? 1 : 0;\n \t\treturn;\n \t}\n \tif (!ds->candidate_exists) {\n@@ -58,7 +59,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object\n \t}\n \n \tif (!ds->candidate_checked) {\n-\t\tds->candidate_ok = ds->fn(&ds->candidate, ds->cb_data);\n+\t\tds->candidate_ok = ds->fn(ds->repo, &ds->candidate, ds->cb_data);\n \t\tds->disambiguate_fn_used = 1;\n \t\tds->candidate_checked = 1;\n \t}\n@@ -71,7 +72,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object\n \t}\n \n \t/* if we reach this point, we know ds->candidate satisfies fn */\n-\tif (ds->fn(current, ds->cb_data)) {\n+\tif (ds->fn(ds->repo, current, ds->cb_data)) {\n \t\t/*\n \t\t * if both current and candidate satisfy fn, we cannot\n \t\t * disambiguate.\n@@ -89,9 +90,7 @@ static void find_short_object_filename(struct disambiguate_state *ds)\n {\n \tstruct object_directory *odb;\n \n-\tfor (odb = the_repository->objects->odb;\n-\t     odb && !ds->ambiguous;\n-\t     odb = odb->next) {\n+\tfor (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next) {\n \t\tint pos;\n \t\tstruct oid_array *loose_objects;\n \n@@ -182,10 +181,10 @@ static void find_short_packed_object(struct disambiguate_state *ds)\n \tstruct multi_pack_index *m;\n \tstruct packed_git *p;\n \n-\tfor (m = get_multi_pack_index(the_repository); m && !ds->ambiguous;\n+\tfor (m = get_multi_pack_index(ds->repo); m && !ds->ambiguous;\n \t     m = m->next)\n \t\tunique_in_midx(m, ds);\n-\tfor (p = get_packed_git(the_repository); p && !ds->ambiguous;\n+\tfor (p = get_packed_git(ds->repo); p && !ds->ambiguous;\n \t     p = p->next)\n \t\tunique_in_pack(p, ds);\n }\n@@ -215,7 +214,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,\n \t\t * same repository!\n \t\t */\n \t\tds->candidate_ok = (!ds->disambiguate_fn_used ||\n-\t\t\t\t    ds->fn(&ds->candidate, ds->cb_data));\n+\t\t\t\t    ds->fn(ds->repo, &ds->candidate, ds->cb_data));\n \n \tif (!ds->candidate_ok)\n \t\treturn SHORT_NAME_AMBIGUOUS;\n@@ -224,59 +223,67 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,\n \treturn 0;\n }\n \n-static int disambiguate_commit_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_commit_only(struct repository *r,\n+\t\t\t\t    const struct object_id *oid,\n+\t\t\t\t    void *cb_data_unused)\n {\n-\tint kind = oid_object_info(the_repository, oid, NULL);\n+\tint kind = oid_object_info(r, oid, NULL);\n \treturn kind == OBJ_COMMIT;\n }\n \n-static int disambiguate_committish_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_committish_only(struct repository *r,\n+\t\t\t\t\tconst struct object_id *oid,\n+\t\t\t\t\tvoid *cb_data_unused)\n {\n \tstruct object *obj;\n \tint kind;\n \n-\tkind = oid_object_info(the_repository, oid, NULL);\n+\tkind = oid_object_info(r, oid, NULL);\n \tif (kind == OBJ_COMMIT)\n \t\treturn 1;\n \tif (kind != OBJ_TAG)\n \t\treturn 0;\n \n \t/* We need to do this the hard way... */\n-\tobj = deref_tag(the_repository, parse_object(the_repository, oid),\n-\t\t\tNULL, 0);\n+\tobj = deref_tag(r, parse_object(r, oid), NULL, 0);\n \tif (obj && obj->type == OBJ_COMMIT)\n \t\treturn 1;\n \treturn 0;\n }\n \n-static int disambiguate_tree_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_tree_only(struct repository *r,\n+\t\t\t\t  const struct object_id *oid,\n+\t\t\t\t  void *cb_data_unused)\n {\n-\tint kind = oid_object_info(the_repository, oid, NULL);\n+\tint kind = oid_object_info(r, oid, NULL);\n \treturn kind == OBJ_TREE;\n }\n \n-static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_treeish_only(struct repository *r,\n+\t\t\t\t     const struct object_id *oid,\n+\t\t\t\t     void *cb_data_unused)\n {\n \tstruct object *obj;\n \tint kind;\n \n-\tkind = oid_object_info(the_repository, oid, NULL);\n+\tkind = oid_object_info(r, oid, NULL);\n \tif (kind == OBJ_TREE || kind == OBJ_COMMIT)\n \t\treturn 1;\n \tif (kind != OBJ_TAG)\n \t\treturn 0;\n \n \t/* We need to do this the hard way... */\n-\tobj = deref_tag(the_repository, parse_object(the_repository, oid),\n-\t\t\tNULL, 0);\n+\tobj = deref_tag(r, parse_object(r, oid), NULL, 0);\n \tif (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))\n \t\treturn 1;\n \treturn 0;\n }\n \n-static int disambiguate_blob_only(const struct object_id *oid, void *cb_data_unused)\n+static int disambiguate_blob_only(struct repository *r,\n+\t\t\t\t  const struct object_id *oid,\n+\t\t\t\t  void *cb_data_unused)\n {\n-\tint kind = oid_object_info(the_repository, oid, NULL);\n+\tint kind = oid_object_info(r, oid, NULL);\n \treturn kind == OBJ_BLOB;\n }\n \n@@ -310,7 +317,8 @@ int set_disambiguate_hint_config(const char *var, const char *value)\n \treturn error(\"unknown hint type for '%s': %s\", var, value);\n }\n \n-static int init_object_disambiguation(const char *name, int len,\n+static int init_object_disambiguation(struct repository *r,\n+\t\t\t\t      const char *name, int len,\n \t\t\t\t      struct disambiguate_state *ds)\n {\n \tint i;\n@@ -341,7 +349,8 @@ static int init_object_disambiguation(const char *name, int len,\n \n \tds->len = len;\n \tds->hex_pfx[len] = '\\0';\n-\tprepare_alt_odb(the_repository);\n+\tds->repo = r;\n+\tprepare_alt_odb(r);\n \treturn 0;\n }\n \n@@ -351,25 +360,25 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)\n \tstruct strbuf desc = STRBUF_INIT;\n \tint type;\n \n-\tif (ds->fn && !ds->fn(oid, ds->cb_data))\n+\tif (ds->fn && !ds->fn(ds->repo, oid, ds->cb_data))\n \t\treturn 0;\n \n-\ttype = oid_object_info(the_repository, oid, NULL);\n+\ttype = oid_object_info(ds->repo, oid, NULL);\n \tif (type == OBJ_COMMIT) {\n-\t\tstruct commit *commit = lookup_commit(the_repository, oid);\n+\t\tstruct commit *commit = lookup_commit(ds->repo, oid);\n \t\tif (commit) {\n \t\t\tstruct pretty_print_context pp = {0};\n \t\t\tpp.date_mode.type = DATE_SHORT;\n \t\t\tformat_commit_message(commit, \" %ad - %s\", &desc, &pp);\n \t\t}\n \t} else if (type == OBJ_TAG) {\n-\t\tstruct tag *tag = lookup_tag(the_repository, oid);\n+\t\tstruct tag *tag = lookup_tag(ds->repo, oid);\n \t\tif (!parse_tag(tag) && tag->tag)\n \t\t\tstrbuf_addf(&desc, \" %s\", tag->tag);\n \t}\n \n \tadvise(\"  %s %s%s\",\n-\t       find_unique_abbrev(oid, DEFAULT_ABBREV),\n+\t       repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV),\n \t       type_name(type) ? type_name(type) : \"unknown type\",\n \t       desc.buf);\n \n@@ -383,6 +392,13 @@ static int collect_ambiguous(const struct object_id *oid, void *data)\n \treturn 0;\n }\n \n+static int repo_collect_ambiguous(struct repository *r,\n+\t\t\t\t  const struct object_id *oid,\n+\t\t\t\t  void *data)\n+{\n+\treturn collect_ambiguous(oid, data);\n+}\n+\n static struct repository *sort_ambiguous_repo;\n static int sort_ambiguous(const void *a, const void *b)\n {\n@@ -428,7 +444,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \tstruct disambiguate_state ds;\n \tint quietly = !!(flags & GET_OID_QUIETLY);\n \n-\tif (init_object_disambiguation(name, len, &ds) < 0)\n+\tif (init_object_disambiguation(the_repository, name, len, &ds) < 0)\n \t\treturn -1;\n \n \tif (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))\n@@ -483,11 +499,11 @@ int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)\n \tstruct disambiguate_state ds;\n \tint ret;\n \n-\tif (init_object_disambiguation(prefix, strlen(prefix), &ds) < 0)\n+\tif (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0)\n \t\treturn -1;\n \n \tds.always_call_fn = 1;\n-\tds.fn = collect_ambiguous;\n+\tds.fn = repo_collect_ambiguous;\n \tds.cb_data = &collect;\n \tfind_short_object_filename(&ds);\n \tfind_short_packed_object(&ds);\n@@ -543,6 +559,13 @@ static int extend_abbrev_len(const struct object_id *oid, void *cb_data)\n \treturn 0;\n }\n \n+static int repo_extend_abbrev_len(struct repository *r,\n+\t\t\t\t  const struct object_id *oid,\n+\t\t\t\t  void *cb_data)\n+{\n+\treturn extend_abbrev_len(oid, cb_data);\n+}\n+\n static void find_abbrev_len_for_midx(struct multi_pack_index *m,\n \t\t\t\t     struct min_abbrev_data *mad)\n {\n@@ -668,10 +691,10 @@ int repo_find_unique_abbrev_r(struct repository *r, char *hex,\n \n \tfind_abbrev_len_packed(&mad);\n \n-\tif (init_object_disambiguation(hex, mad.cur_len, &ds) < 0)\n+\tif (init_object_disambiguation(r, hex, mad.cur_len, &ds) < 0)\n \t\treturn -1;\n \n-\tds.fn = extend_abbrev_len;\n+\tds.fn = repo_extend_abbrev_len;\n \tds.always_call_fn = 1;\n \tds.cb_data = (void *)&mad;\n \n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373949","messageId":"20190416093341.17079-18-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 17/34] sha1-name.c: add repo_for_each_abbrev()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:24Z","receivedAt":"2019-04-16T09:36:10Z","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     | 3 ++-\n sha1-name.c | 5 +++--\n 2 files changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 4f8ebb0a67..0cb95c0d4f 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1392,7 +1392,8 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c\n \t\t\t\tstruct object_context *oc);\n \n typedef int each_abbrev_fn(const struct object_id *oid, void *);\n-extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);\n+int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);\n+#define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data)\n \n extern int set_disambiguate_hint_config(const char *var, const char *value);\n \ndiff --git a/sha1-name.c b/sha1-name.c\nindex a75992eb54..cdcf84b826 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -493,13 +493,14 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \treturn status;\n }\n \n-int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)\n+int repo_for_each_abbrev(struct repository *r, const char *prefix,\n+\t\t\t each_abbrev_fn fn, void *cb_data)\n {\n \tstruct oid_array collect = OID_ARRAY_INIT;\n \tstruct disambiguate_state ds;\n \tint ret;\n \n-\tif (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0)\n+\tif (init_object_disambiguation(r, prefix, strlen(prefix), &ds) < 0)\n \t\treturn -1;\n \n \tds.always_call_fn = 1;\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373950","messageId":"20190416093341.17079-19-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 18/34] sha1-name.c: remove the_repo from get_short_oid()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:25Z","receivedAt":"2019-04-16T09:36:24Z","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 | 17 ++++++++++-------\n 1 file changed, 10 insertions(+), 7 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex cdcf84b826..2643b75b54 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -436,7 +436,8 @@ static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)\n \tsort_ambiguous_repo = NULL;\n }\n \n-static enum get_oid_result get_short_oid(const char *name, int len,\n+static enum get_oid_result get_short_oid(struct repository *r,\n+\t\t\t\t\t const char *name, int len,\n \t\t\t\t\t struct object_id *oid,\n \t\t\t\t\t unsigned flags)\n {\n@@ -444,7 +445,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \tstruct disambiguate_state ds;\n \tint quietly = !!(flags & GET_OID_QUIETLY);\n \n-\tif (init_object_disambiguation(the_repository, name, len, &ds) < 0)\n+\tif (init_object_disambiguation(r, name, len, &ds) < 0)\n \t\treturn -1;\n \n \tif (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))\n@@ -482,8 +483,8 @@ static enum get_oid_result get_short_oid(const char *name, int len,\n \t\t\tds.fn = NULL;\n \n \t\tadvise(_(\"The candidates are:\"));\n-\t\tfor_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect);\n-\t\tsort_ambiguous_oid_array(the_repository, &collect);\n+\t\trepo_for_each_abbrev(r, ds.hex_pfx, collect_ambiguous, &collect);\n+\t\tsort_ambiguous_oid_array(r, &collect);\n \n \t\tif (oid_array_for_each(&collect, show_ambiguous_object, &ds))\n \t\t\tBUG(\"show_ambiguous_object shouldn't return non-zero\");\n@@ -855,7 +856,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \n \tif (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&\n \t    (refs_found > 1 ||\n-\t     !get_short_oid(str, len, &tmp_oid, GET_OID_QUIETLY)))\n+\t     !get_short_oid(the_repository,\n+\t\t\t    str, len, &tmp_oid, GET_OID_QUIETLY)))\n \t\twarning(warn_msg, len, str);\n \n \tif (reflog_len) {\n@@ -1109,7 +1111,8 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)\n \t\t\tif (ch == 'g' && cp[-1] == '-') {\n \t\t\t\tcp++;\n \t\t\t\tlen -= cp - name;\n-\t\t\t\treturn get_short_oid(cp, len, oid, flags);\n+\t\t\t\treturn get_short_oid(the_repository,\n+\t\t\t\t\t\t     cp, len, oid, flags);\n \t\t\t}\n \t\t}\n \t}\n@@ -1163,7 +1166,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,\n \tif (!ret)\n \t\treturn FOUND;\n \n-\treturn get_short_oid(name, len, oid, lookup_flags);\n+\treturn get_short_oid(the_repository, name, len, oid, lookup_flags);\n }\n \n /*\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373951","messageId":"20190416093341.17079-20-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 19/34] sha1-name.c: remove the_repo from interpret_nth_prior_checkout()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:26Z","receivedAt":"2019-04-16T09:36: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 sha1-name.c | 17 ++++++++++-------\n 1 file changed, 10 insertions(+), 7 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 2643b75b54..af8bf5b351 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -771,7 +771,7 @@ static inline int push_mark(const char *string, int len)\n }\n \n static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);\n-static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);\n+static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);\n \n static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\t\t  unsigned int flags)\n@@ -835,7 +835,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tint detached;\n \n-\t\tif (interpret_nth_prior_checkout(str, len, &buf) > 0) {\n+\t\tif (interpret_nth_prior_checkout(the_repository, str, len, &buf) > 0) {\n \t\t\tdetached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));\n \t\t\tstrbuf_release(&buf);\n \t\t\tif (detached)\n@@ -1288,7 +1288,8 @@ static int grab_nth_branch_switch(struct object_id *ooid, struct object_id *noid\n  * Parse @{-N} syntax, return the number of characters parsed\n  * if successful; otherwise signal an error with negative value.\n  */\n-static int interpret_nth_prior_checkout(const char *name, int namelen,\n+static int interpret_nth_prior_checkout(struct repository *r,\n+\t\t\t\t\tconst char *name, int namelen,\n \t\t\t\t\tstruct strbuf *buf)\n {\n \tlong nth;\n@@ -1312,12 +1313,14 @@ static int interpret_nth_prior_checkout(const char *name, int namelen,\n \tcb.remaining = nth;\n \tstrbuf_init(&cb.buf, 20);\n \n-\tretval = 0;\n-\tif (0 < for_each_reflog_ent_reverse(\"HEAD\", grab_nth_branch_switch, &cb)) {\n+\tretval = refs_for_each_reflog_ent_reverse(get_main_ref_store(r),\n+\t\t\t\"HEAD\", grab_nth_branch_switch, &cb);\n+\tif (0 < retval) {\n \t\tstrbuf_reset(buf);\n \t\tstrbuf_addbuf(buf, &cb.buf);\n \t\tretval = brace - name + 1;\n-\t}\n+\t} else\n+\t\tretval = 0;\n \n \tstrbuf_release(&cb.buf);\n \treturn retval;\n@@ -1484,7 +1487,7 @@ int repo_interpret_branch_name(struct repository *r,\n \t\tnamelen = strlen(name);\n \n \tif (!allowed || (allowed & INTERPRET_BRANCH_LOCAL)) {\n-\t\tlen = interpret_nth_prior_checkout(name, namelen, buf);\n+\t\tlen = interpret_nth_prior_checkout(the_repository, name, namelen, buf);\n \t\tif (!len) {\n \t\t\treturn len; /* syntax Ok, not enough switches */\n \t\t} else if (len > 0) {\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373952","messageId":"20190416093341.17079-21-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 20/34] sha1-name.c: remove the_repo from interpret_branch_mark()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:27Z","receivedAt":"2019-04-16T09:36:35Z","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 | 13 +++++++------\n 1 file changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex af8bf5b351..7d9512ac44 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1412,9 +1412,9 @@ static int reinterpret(const char *name, int namelen, int len,\n \treturn ret - used + len;\n }\n \n-static void set_shortened_ref(struct strbuf *buf, const char *ref)\n+static void set_shortened_ref(struct repository *r, struct strbuf *buf, const char *ref)\n {\n-\tchar *s = shorten_unambiguous_ref(ref, 0);\n+\tchar *s = refs_shorten_unambiguous_ref(get_main_ref_store(r), ref, 0);\n \tstrbuf_reset(buf);\n \tstrbuf_addstr(buf, s);\n \tfree(s);\n@@ -1435,7 +1435,8 @@ static int branch_interpret_allowed(const char *refname, unsigned allowed)\n \treturn 0;\n }\n \n-static int interpret_branch_mark(const char *name, int namelen,\n+static int interpret_branch_mark(struct repository *r,\n+\t\t\t\t const char *name, int namelen,\n \t\t\t\t int at, struct strbuf *buf,\n \t\t\t\t int (*get_mark)(const char *, int),\n \t\t\t\t const char *(*get_data)(struct branch *,\n@@ -1468,7 +1469,7 @@ static int interpret_branch_mark(const char *name, int namelen,\n \tif (!branch_interpret_allowed(value, allowed))\n \t\treturn -1;\n \n-\tset_shortened_ref(buf, value);\n+\tset_shortened_ref(r, buf, value);\n \treturn len + at;\n }\n \n@@ -1509,13 +1510,13 @@ int repo_interpret_branch_name(struct repository *r,\n \t\t\t\t\t\t   allowed);\n \t\t}\n \n-\t\tlen = interpret_branch_mark(name, namelen, at - name, buf,\n+\t\tlen = interpret_branch_mark(the_repository, name, namelen, at - name, buf,\n \t\t\t\t\t    upstream_mark, branch_get_upstream,\n \t\t\t\t\t    allowed);\n \t\tif (len > 0)\n \t\t\treturn len;\n \n-\t\tlen = interpret_branch_mark(name, namelen, at - name, buf,\n+\t\tlen = interpret_branch_mark(the_repository, name, namelen, at - name, buf,\n \t\t\t\t\t    push_mark, branch_get_push,\n \t\t\t\t\t    allowed);\n \t\tif (len > 0)\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373953","messageId":"20190416093341.17079-22-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 21/34] sha1-name.c: add repo_interpret_branch_name()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:28Z","receivedAt":"2019-04-16T09:36: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>\n---\n sha1-name.c | 17 ++++++++---------\n 1 file changed, 8 insertions(+), 9 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 7d9512ac44..49c62d5254 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1390,7 +1390,8 @@ static int interpret_empty_at(const char *name, int namelen, int len, struct str\n \treturn 1;\n }\n \n-static int reinterpret(const char *name, int namelen, int len,\n+static int reinterpret(struct repository *r,\n+\t\t       const char *name, int namelen, int len,\n \t\t       struct strbuf *buf, unsigned allowed)\n {\n \t/* we have extra data, which might need further processing */\n@@ -1399,7 +1400,7 @@ static int reinterpret(const char *name, int namelen, int len,\n \tint ret;\n \n \tstrbuf_add(buf, name + len, namelen - len);\n-\tret = interpret_branch_name(buf->buf, buf->len, &tmp, allowed);\n+\tret = repo_interpret_branch_name(r, buf->buf, buf->len, &tmp, allowed);\n \t/* that data was not interpreted, remove our cruft */\n \tif (ret < 0) {\n \t\tstrbuf_setlen(buf, used);\n@@ -1482,20 +1483,18 @@ int repo_interpret_branch_name(struct repository *r,\n \tconst char *start;\n \tint len;\n \n-\tif (r != the_repository)\n-\t\tBUG(\"interpret_branch_name() does not really use 'r' yet\");\n \tif (!namelen)\n \t\tnamelen = strlen(name);\n \n \tif (!allowed || (allowed & INTERPRET_BRANCH_LOCAL)) {\n-\t\tlen = interpret_nth_prior_checkout(the_repository, name, namelen, buf);\n+\t\tlen = interpret_nth_prior_checkout(r, name, namelen, buf);\n \t\tif (!len) {\n \t\t\treturn len; /* syntax Ok, not enough switches */\n \t\t} else if (len > 0) {\n \t\t\tif (len == namelen)\n \t\t\t\treturn len; /* consumed all */\n \t\t\telse\n-\t\t\t\treturn reinterpret(name, namelen, len, buf, allowed);\n+\t\t\t\treturn reinterpret(r, name, namelen, len, buf, allowed);\n \t\t}\n \t}\n \n@@ -1506,17 +1505,17 @@ int repo_interpret_branch_name(struct repository *r,\n \t\tif (!allowed || (allowed & INTERPRET_BRANCH_HEAD)) {\n \t\t\tlen = interpret_empty_at(name, namelen, at - name, buf);\n \t\t\tif (len > 0)\n-\t\t\t\treturn reinterpret(name, namelen, len, buf,\n+\t\t\t\treturn reinterpret(r, name, namelen, len, buf,\n \t\t\t\t\t\t   allowed);\n \t\t}\n \n-\t\tlen = interpret_branch_mark(the_repository, name, namelen, at - name, buf,\n+\t\tlen = interpret_branch_mark(r, name, namelen, at - name, buf,\n \t\t\t\t\t    upstream_mark, branch_get_upstream,\n \t\t\t\t\t    allowed);\n \t\tif (len > 0)\n \t\t\treturn len;\n \n-\t\tlen = interpret_branch_mark(the_repository, name, namelen, at - name, buf,\n+\t\tlen = interpret_branch_mark(r, name, namelen, at - name, buf,\n \t\t\t\t\t    push_mark, branch_get_push,\n \t\t\t\t\t    allowed);\n \t\tif (len > 0)\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373954","messageId":"20190416093341.17079-23-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 22/34] sha1-name.c: remove the_repo from get_oid_oneline()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:29Z","receivedAt":"2019-04-16T09:36:48Z","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 | 13 +++++++------\n 1 file changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 49c62d5254..fb80306f1a 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -15,7 +15,7 @@\n #include \"midx.h\"\n #include \"commit-reach.h\"\n \n-static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);\n+static int get_oid_oneline(struct repository *r, const char *, struct object_id *, struct commit_list *);\n \n typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);\n \n@@ -1090,7 +1090,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \n \t\tprefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));\n \t\tcommit_list_insert((struct commit *)o, &list);\n-\t\tret = get_oid_oneline(prefix, oid, list);\n+\t\tret = get_oid_oneline(the_repository, prefix, oid, list);\n \t\tfree(prefix);\n \t\treturn ret;\n \t}\n@@ -1204,8 +1204,9 @@ static int handle_one_ref(const char *path, const struct object_id *oid,\n \treturn 0;\n }\n \n-static int get_oid_oneline(const char *prefix, struct object_id *oid,\n-\t\t\t    struct commit_list *list)\n+static int get_oid_oneline(struct repository *r,\n+\t\t\t   const char *prefix, struct object_id *oid,\n+\t\t\t   struct commit_list *list)\n {\n \tstruct commit_list *backup = NULL, *l;\n \tint found = 0;\n@@ -1236,7 +1237,7 @@ static int get_oid_oneline(const char *prefix, struct object_id *oid,\n \t\tint matches;\n \n \t\tcommit = pop_most_recent_commit(&list, ONELINE_SEEN);\n-\t\tif (!parse_object(the_repository, &commit->object.oid))\n+\t\tif (!parse_object(r, &commit->object.oid))\n \t\t\tcontinue;\n \t\tbuf = get_commit_buffer(commit, NULL);\n \t\tp = strstr(buf, \"\\n\\n\");\n@@ -1760,7 +1761,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\tfor_each_ref(handle_one_ref, &list);\n \t\t\thead_ref(handle_one_ref, &list);\n \t\t\tcommit_list_sort_by_date(&list);\n-\t\t\treturn get_oid_oneline(name + 2, oid, list);\n+\t\t\treturn get_oid_oneline(repo, name + 2, oid, list);\n \t\t}\n \t\tif (namelen < 3 ||\n \t\t    name[2] != ':' ||\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373955","messageId":"20190416093341.17079-24-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 23/34] sha1-name.c: remove the_repo from get_describe_name()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:30Z","receivedAt":"2019-04-16T09:36:53Z","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 | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex fb80306f1a..1cda854f02 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1097,7 +1097,9 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \treturn 0;\n }\n \n-static int get_describe_name(const char *name, int len, struct object_id *oid)\n+static int get_describe_name(struct repository *r,\n+\t\t\t     const char *name, int len,\n+\t\t\t     struct object_id *oid)\n {\n \tconst char *cp;\n \tunsigned flags = GET_OID_QUIETLY | GET_OID_COMMIT;\n@@ -1111,7 +1113,7 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)\n \t\t\tif (ch == 'g' && cp[-1] == '-') {\n \t\t\t\tcp++;\n \t\t\t\tlen -= cp - name;\n-\t\t\t\treturn get_short_oid(the_repository,\n+\t\t\t\treturn get_short_oid(r,\n \t\t\t\t\t\t     cp, len, oid, flags);\n \t\t\t}\n \t\t}\n@@ -1162,7 +1164,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,\n \t\treturn FOUND;\n \n \t/* It could be describe output that is \"SOMETHING-gXXXX\" */\n-\tret = get_describe_name(name, len, oid);\n+\tret = get_describe_name(the_repository, name, len, oid);\n \tif (!ret)\n \t\treturn FOUND;\n \n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373956","messageId":"20190416093341.17079-25-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 24/34] sha1-name.c: remove the_repo from get_oid_basic()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:31Z","receivedAt":"2019-04-16T09:36:59Z","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 | 25 ++++++++++++-------------\n 1 file changed, 12 insertions(+), 13 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 1cda854f02..d4c135aea8 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -773,8 +773,8 @@ static inline int push_mark(const char *string, int len)\n static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);\n static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);\n \n-static int get_oid_basic(const char *str, int len, struct object_id *oid,\n-\t\t\t  unsigned int flags)\n+static int get_oid_basic(struct repository *r, const char *str, int len,\n+\t\t\t struct object_id *oid, unsigned int flags)\n {\n \tstatic const char *warn_msg = \"refname '%.*s' is ambiguous.\";\n \tstatic const char *object_name_msg = N_(\n@@ -792,9 +792,9 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \tint refs_found = 0;\n \tint at, reflog_len, nth_prior = 0;\n \n-\tif (len == the_hash_algo->hexsz && !get_oid_hex(str, oid)) {\n+\tif (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {\n \t\tif (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {\n-\t\t\trefs_found = dwim_ref(str, len, &tmp_oid, &real_ref);\n+\t\t\trefs_found = repo_dwim_ref(r, str, len, &tmp_oid, &real_ref);\n \t\t\tif (refs_found > 0) {\n \t\t\t\twarning(warn_msg, len, str);\n \t\t\t\tif (advice_object_name_warning)\n@@ -835,8 +835,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\tstruct strbuf buf = STRBUF_INIT;\n \t\tint detached;\n \n-\t\tif (interpret_nth_prior_checkout(the_repository, str, len, &buf) > 0) {\n-\t\t\tdetached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));\n+\t\tif (interpret_nth_prior_checkout(r, str, len, &buf) > 0) {\n+\t\t\tdetached = (buf.len == r->hash_algo->hexsz && !get_oid_hex(buf.buf, oid));\n \t\t\tstrbuf_release(&buf);\n \t\t\tif (detached)\n \t\t\t\treturn 0;\n@@ -845,19 +845,18 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \n \tif (!len && reflog_len)\n \t\t/* allow \"@{...}\" to mean the current branch reflog */\n-\t\trefs_found = dwim_ref(\"HEAD\", 4, oid, &real_ref);\n+\t\trefs_found = repo_dwim_ref(r, \"HEAD\", 4, oid, &real_ref);\n \telse if (reflog_len)\n-\t\trefs_found = dwim_log(str, len, oid, &real_ref);\n+\t\trefs_found = repo_dwim_log(r, str, len, oid, &real_ref);\n \telse\n-\t\trefs_found = dwim_ref(str, len, oid, &real_ref);\n+\t\trefs_found = repo_dwim_ref(r, str, len, oid, &real_ref);\n \n \tif (!refs_found)\n \t\treturn -1;\n \n \tif (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&\n \t    (refs_found > 1 ||\n-\t     !get_short_oid(the_repository,\n-\t\t\t    str, len, &tmp_oid, GET_OID_QUIETLY)))\n+\t     !get_short_oid(r, str, len, &tmp_oid, GET_OID_QUIETLY)))\n \t\twarning(warn_msg, len, str);\n \n \tif (reflog_len) {\n@@ -889,7 +888,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,\n \t\t\t\treturn -1;\n \t\t\t}\n \t\t}\n-\t\tif (read_ref_at(get_main_ref_store(the_repository),\n+\t\tif (read_ref_at(get_main_ref_store(r),\n \t\t\t\treal_ref, flags, at_time, nth, oid, NULL,\n \t\t\t\t&co_time, &co_tz, &co_cnt)) {\n \t\t\tif (!len) {\n@@ -1159,7 +1158,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,\n \tif (!ret)\n \t\treturn FOUND;\n \n-\tret = get_oid_basic(name, len, oid, lookup_flags);\n+\tret = get_oid_basic(the_repository, name, len, oid, lookup_flags);\n \tif (!ret)\n \t\treturn FOUND;\n \n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373957","messageId":"20190416093341.17079-26-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 25/34] sha1-name.c: remove the_repo from get_oid_1()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:32Z","receivedAt":"2019-04-16T09:37:08Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"There is a cyclic dependency between one of these functions so they\ncannot be converted one by one, so all related functions are converted\nat once.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n cache.h     |  7 +++++--\n sha1-name.c | 59 ++++++++++++++++++++++++++++-------------------------\n 2 files changed, 36 insertions(+), 30 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 0cb95c0d4f..2149dc4f56 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1491,8 +1491,11 @@ extern void *read_object_with_reference(const struct object_id *oid,\n \t\t\t\t\tunsigned long *size,\n \t\t\t\t\tstruct object_id *oid_ret);\n \n-extern struct object *peel_to_type(const char *name, int namelen,\n-\t\t\t\t   struct object *o, enum object_type);\n+struct object *repo_peel_to_type(struct repository *r,\n+\t\t\t\t const char *name, int namelen,\n+\t\t\t\t struct object *o, enum object_type);\n+#define peel_to_type(name, namelen, obj, type) \\\n+\trepo_peel_to_type(the_repository, name, namelen, obj, type)\n \n enum date_mode_type {\n \tDATE_NORMAL = 0,\ndiff --git a/sha1-name.c b/sha1-name.c\nindex d4c135aea8..5741a9f821 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -770,7 +770,7 @@ static inline int push_mark(const char *string, int len)\n \treturn at_mark(string, len, suffix, ARRAY_SIZE(suffix));\n }\n \n-static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);\n+static enum get_oid_result get_oid_1(struct repository *r, const char *name, int len, struct object_id *oid, unsigned lookup_flags);\n static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);\n \n static int get_oid_basic(struct repository *r, const char *str, int len,\n@@ -921,18 +921,19 @@ static int get_oid_basic(struct repository *r, const char *str, int len,\n \treturn 0;\n }\n \n-static enum get_oid_result get_parent(const char *name, int len,\n+static enum get_oid_result get_parent(struct repository *r,\n+\t\t\t\t      const char *name, int len,\n \t\t\t\t      struct object_id *result, int idx)\n {\n \tstruct object_id oid;\n-\tenum get_oid_result ret = get_oid_1(name, len, &oid,\n+\tenum get_oid_result ret = get_oid_1(r, name, len, &oid,\n \t\t\t\t\t    GET_OID_COMMITTISH);\n \tstruct commit *commit;\n \tstruct commit_list *p;\n \n \tif (ret)\n \t\treturn ret;\n-\tcommit = lookup_commit_reference(the_repository, &oid);\n+\tcommit = lookup_commit_reference(r, &oid);\n \tif (parse_commit(commit))\n \t\treturn MISSING_OBJECT;\n \tif (!idx) {\n@@ -950,7 +951,8 @@ static enum get_oid_result get_parent(const char *name, int len,\n \treturn MISSING_OBJECT;\n }\n \n-static enum get_oid_result get_nth_ancestor(const char *name, int len,\n+static enum get_oid_result get_nth_ancestor(struct repository *r,\n+\t\t\t\t\t    const char *name, int len,\n \t\t\t\t\t    struct object_id *result,\n \t\t\t\t\t    int generation)\n {\n@@ -958,10 +960,10 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,\n \tstruct commit *commit;\n \tint ret;\n \n-\tret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);\n+\tret = get_oid_1(r, name, len, &oid, GET_OID_COMMITTISH);\n \tif (ret)\n \t\treturn ret;\n-\tcommit = lookup_commit_reference(the_repository, &oid);\n+\tcommit = lookup_commit_reference(r, &oid);\n \tif (!commit)\n \t\treturn MISSING_OBJECT;\n \n@@ -974,20 +976,20 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,\n \treturn FOUND;\n }\n \n-struct object *peel_to_type(const char *name, int namelen,\n-\t\t\t    struct object *o, enum object_type expected_type)\n+struct object *repo_peel_to_type(struct repository *r, const char *name, int namelen,\n+\t\t\t\t struct object *o, enum object_type expected_type)\n {\n \tif (name && !namelen)\n \t\tnamelen = strlen(name);\n \twhile (1) {\n-\t\tif (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))\n+\t\tif (!o || (!o->parsed && !parse_object(r, &o->oid)))\n \t\t\treturn NULL;\n \t\tif (expected_type == OBJ_ANY || o->type == expected_type)\n \t\t\treturn o;\n \t\tif (o->type == OBJ_TAG)\n \t\t\to = ((struct tag*) o)->tagged;\n \t\telse if (o->type == OBJ_COMMIT)\n-\t\t\to = &(get_commit_tree(((struct commit *)o))->object);\n+\t\t\to = &(repo_get_commit_tree(r, ((struct commit *)o))->object);\n \t\telse {\n \t\t\tif (name)\n \t\t\t\terror(\"%.*s: expected %s type, but the object \"\n@@ -999,8 +1001,8 @@ struct object *peel_to_type(const char *name, int namelen,\n \t}\n }\n \n-static int peel_onion(const char *name, int len, struct object_id *oid,\n-\t\t      unsigned lookup_flags)\n+static int peel_onion(struct repository *r, const char *name, int len,\n+\t\t      struct object_id *oid, unsigned lookup_flags)\n {\n \tstruct object_id outer;\n \tconst char *sp;\n@@ -1050,15 +1052,15 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \telse if (expected_type == OBJ_TREE)\n \t\tlookup_flags |= GET_OID_TREEISH;\n \n-\tif (get_oid_1(name, sp - name - 2, &outer, lookup_flags))\n+\tif (get_oid_1(r, name, sp - name - 2, &outer, lookup_flags))\n \t\treturn -1;\n \n-\to = parse_object(the_repository, &outer);\n+\to = parse_object(r, &outer);\n \tif (!o)\n \t\treturn -1;\n \tif (!expected_type) {\n-\t\to = deref_tag(the_repository, o, name, sp - name - 2);\n-\t\tif (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))\n+\t\to = deref_tag(r, o, name, sp - name - 2);\n+\t\tif (!o || (!o->parsed && !parse_object(r, &o->oid)))\n \t\t\treturn -1;\n \t\toidcpy(oid, &o->oid);\n \t\treturn 0;\n@@ -1069,7 +1071,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \t * if we do not get the needed object, we should\n \t * barf.\n \t */\n-\to = peel_to_type(name, len, o, expected_type);\n+\to = repo_peel_to_type(r, name, len, o, expected_type);\n \tif (!o)\n \t\treturn -1;\n \n@@ -1089,7 +1091,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,\n \n \t\tprefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));\n \t\tcommit_list_insert((struct commit *)o, &list);\n-\t\tret = get_oid_oneline(the_repository, prefix, oid, list);\n+\t\tret = get_oid_oneline(r, prefix, oid, list);\n \t\tfree(prefix);\n \t\treturn ret;\n \t}\n@@ -1120,7 +1122,8 @@ static int get_describe_name(struct repository *r,\n \treturn -1;\n }\n \n-static enum get_oid_result get_oid_1(const char *name, int len,\n+static enum get_oid_result get_oid_1(struct repository *r,\n+\t\t\t\t     const char *name, int len,\n \t\t\t\t     struct object_id *oid,\n \t\t\t\t     unsigned lookup_flags)\n {\n@@ -1149,25 +1152,25 @@ static enum get_oid_result get_oid_1(const char *name, int len,\n \t\tif (!num && len1 == len - 1)\n \t\t\tnum = 1;\n \t\tif (has_suffix == '^')\n-\t\t\treturn get_parent(name, len1, oid, num);\n+\t\t\treturn get_parent(r, name, len1, oid, num);\n \t\t/* else if (has_suffix == '~') -- goes without saying */\n-\t\treturn get_nth_ancestor(name, len1, oid, num);\n+\t\treturn get_nth_ancestor(r, name, len1, oid, num);\n \t}\n \n-\tret = peel_onion(name, len, oid, lookup_flags);\n+\tret = peel_onion(r, name, len, oid, lookup_flags);\n \tif (!ret)\n \t\treturn FOUND;\n \n-\tret = get_oid_basic(the_repository, name, len, oid, lookup_flags);\n+\tret = get_oid_basic(r, name, len, oid, lookup_flags);\n \tif (!ret)\n \t\treturn FOUND;\n \n \t/* It could be describe output that is \"SOMETHING-gXXXX\" */\n-\tret = get_describe_name(the_repository, name, len, oid);\n+\tret = get_describe_name(r, name, len, oid);\n \tif (!ret)\n \t\treturn FOUND;\n \n-\treturn get_short_oid(the_repository, name, len, oid, lookup_flags);\n+\treturn get_short_oid(r, name, len, oid, lookup_flags);\n }\n \n /*\n@@ -1741,7 +1744,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \tmemset(oc, 0, sizeof(*oc));\n \toc->mode = S_IFINVALID;\n \tstrbuf_init(&oc->symlink_path, 0);\n-\tret = get_oid_1(name, namelen, oid, flags);\n+\tret = get_oid_1(repo, name, namelen, oid, flags);\n \tif (!ret)\n \t\treturn ret;\n \t/*\n@@ -1822,7 +1825,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\tsub_flags &= ~GET_OID_DISAMBIGUATORS;\n \t\tsub_flags |= GET_OID_TREEISH;\n \n-\t\tif (!get_oid_1(name, len, &tree_oid, sub_flags)) {\n+\t\tif (!get_oid_1(repo, name, len, &tree_oid, sub_flags)) {\n \t\t\tconst char *filename = cp+1;\n \t\t\tchar *new_filename = NULL;\n \n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373958","messageId":"20190416093341.17079-27-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 26/34] sha1-name.c: remove the_repo from handle_one_ref()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:33Z","receivedAt":"2019-04-16T09:37:12Z","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 | 19 ++++++++++++++-----\n 1 file changed, 14 insertions(+), 5 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 5741a9f821..d9050776dd 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1189,15 +1189,21 @@ static enum get_oid_result get_oid_1(struct repository *r,\n /* Remember to update object flag allocation in object.h */\n #define ONELINE_SEEN (1u<<20)\n \n+struct handle_one_ref_cb {\n+\tstruct repository *repo;\n+\tstruct commit_list **list;\n+};\n+\n static int handle_one_ref(const char *path, const struct object_id *oid,\n \t\t\t  int flag, void *cb_data)\n {\n-\tstruct commit_list **list = cb_data;\n-\tstruct object *object = parse_object(the_repository, oid);\n+\tstruct handle_one_ref_cb *cb = cb_data;\n+\tstruct commit_list **list = cb->list;\n+\tstruct object *object = parse_object(cb->repo, oid);\n \tif (!object)\n \t\treturn 0;\n \tif (object->type == OBJ_TAG) {\n-\t\tobject = deref_tag(the_repository, object, path,\n+\t\tobject = deref_tag(cb->repo, object, path,\n \t\t\t\t   strlen(path));\n \t\tif (!object)\n \t\t\treturn 0;\n@@ -1760,10 +1766,13 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\tchar *new_path = NULL;\n \t\tint pos;\n \t\tif (!only_to_die && namelen > 2 && name[1] == '/') {\n+\t\t\tstruct handle_one_ref_cb cb;\n \t\t\tstruct commit_list *list = NULL;\n \n-\t\t\tfor_each_ref(handle_one_ref, &list);\n-\t\t\thead_ref(handle_one_ref, &list);\n+\t\t\tcb.repo = repo;\n+\t\t\tcb.list = &list;\n+\t\t\trefs_for_each_ref(repo->refs, handle_one_ref, &cb);\n+\t\t\trefs_head_ref(repo->refs, handle_one_ref, &cb);\n \t\t\tcommit_list_sort_by_date(&list);\n \t\t\treturn get_oid_oneline(repo, name + 2, oid, list);\n \t\t}\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373959","messageId":"20190416093341.17079-28-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 27/34] sha1-name.c: remove the_repo from diagnose_invalid_index_path()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:34Z","receivedAt":"2019-04-16T09:37:21Z","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 dir.c       | 8 ++++++++\n dir.h       | 4 +++-\n sha1-name.c | 7 ++++---\n 3 files changed, 15 insertions(+), 4 deletions(-)\n\ndiff --git a/dir.c b/dir.c\nindex b2cabadf25..e6d97343f4 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -2315,6 +2315,14 @@ int file_exists(const char *f)\n \treturn lstat(f, &sb) == 0;\n }\n \n+int repo_file_exists(struct repository *repo, const char *path)\n+{\n+\tif (repo != the_repository)\n+\t\tBUG(\"do not know how to check file existence in arbitrary repo\");\n+\n+\treturn file_exists(path);\n+}\n+\n static int cmp_icase(char a, char b)\n {\n \tif (a == b)\ndiff --git a/dir.h b/dir.h\nindex e3ec26143d..47c5409ced 100644\n--- a/dir.h\n+++ b/dir.h\n@@ -269,7 +269,9 @@ extern void add_exclude(const char *string, const char *base,\n \t\t\tint baselen, struct exclude_list *el, int srcpos);\n extern void clear_exclude_list(struct exclude_list *el);\n extern void clear_directory(struct dir_struct *dir);\n-extern int file_exists(const char *);\n+\n+int repo_file_exists(struct repository *repo, const char *path);\n+int file_exists(const char *);\n \n extern int is_inside_dir(const char *dir);\n extern int dir_inside_of(const char *subdir, const char *dir);\ndiff --git a/sha1-name.c b/sha1-name.c\nindex d9050776dd..6caf3f4e3a 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1664,11 +1664,12 @@ static void diagnose_invalid_oid_path(const char *prefix,\n }\n \n /* Must be called only when :stage:filename doesn't exist. */\n-static void diagnose_invalid_index_path(struct index_state *istate,\n+static void diagnose_invalid_index_path(struct repository *r,\n \t\t\t\t\tint stage,\n \t\t\t\t\tconst char *prefix,\n \t\t\t\t\tconst char *filename)\n {\n+\tstruct index_state *istate = r->index;\n \tconst struct cache_entry *ce;\n \tint pos;\n \tunsigned namelen = strlen(filename);\n@@ -1708,7 +1709,7 @@ static void diagnose_invalid_index_path(struct index_state *istate,\n \t\t\t    ce_stage(ce), filename);\n \t}\n \n-\tif (file_exists(filename))\n+\tif (repo_file_exists(r, filename))\n \t\tdie(\"Path '%s' exists on disk, but not in the index.\", filename);\n \tif (is_missing_file_error(errno))\n \t\tdie(\"Path '%s' does not exist (neither on disk nor in the index).\",\n@@ -1814,7 +1815,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\tpos++;\n \t\t}\n \t\tif (only_to_die && name[1] && name[1] != '/')\n-\t\t\tdiagnose_invalid_index_path(repo->index, stage, prefix, cp);\n+\t\t\tdiagnose_invalid_index_path(repo, stage, prefix, cp);\n \t\tfree(new_path);\n \t\treturn -1;\n \t}\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373960","messageId":"20190416093341.17079-29-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 28/34] sha1-name.c: remove the_repo from resolve_relative_path()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:35Z","receivedAt":"2019-04-16T09:37:25Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\"remove\" is not entirely correct. But at least the function is aware\nthat if the given repo is not the_repository, then $CWD and\nis_inside_work_tree() means nothing.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n sha1-name.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 6caf3f4e3a..6b53ea2eeb 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1719,12 +1719,12 @@ static void diagnose_invalid_index_path(struct repository *r,\n }\n \n \n-static char *resolve_relative_path(const char *rel)\n+static char *resolve_relative_path(struct repository *r, const char *rel)\n {\n \tif (!starts_with(rel, \"./\") && !starts_with(rel, \"../\"))\n \t\treturn NULL;\n \n-\tif (!is_inside_work_tree())\n+\tif (r != the_repository || !is_inside_work_tree())\n \t\tdie(\"relative path syntax can't be used outside working tree.\");\n \n \t/* die() inside prefix_path() if resolved path is outside worktree */\n@@ -1785,7 +1785,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\tstage = name[1] - '0';\n \t\t\tcp = name + 3;\n \t\t}\n-\t\tnew_path = resolve_relative_path(cp);\n+\t\tnew_path = resolve_relative_path(repo, cp);\n \t\tif (!new_path) {\n \t\t\tnamelen = namelen - (cp - name);\n \t\t} else {\n@@ -1839,7 +1839,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\tconst char *filename = cp+1;\n \t\t\tchar *new_filename = NULL;\n \n-\t\t\tnew_filename = resolve_relative_path(filename);\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\tif (flags & GET_OID_FOLLOW_SYMLINKS) {\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373961","messageId":"20190416093341.17079-30-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 29/34] sha1-name.c: remove the_repo from get_oid_with_context_1()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:36Z","receivedAt":"2019-04-16T09:37:31Z","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 | 11 ++++++++++-\n 1 file changed, 10 insertions(+), 1 deletion(-)\n\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 6b53ea2eeb..64a50d1291 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -12,6 +12,7 @@\n #include \"packfile.h\"\n #include \"object-store.h\"\n #include \"repository.h\"\n+#include \"submodule.h\"\n #include \"midx.h\"\n #include \"commit-reach.h\"\n \n@@ -1797,7 +1798,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n \t\t\toc->path = xstrdup(cp);\n \n \t\tif (!repo->index->cache)\n-\t\t\trepo_read_index(the_repository);\n+\t\t\trepo_read_index(repo);\n \t\tpos = index_name_pos(repo->index, cp, namelen);\n \t\tif (pos < 0)\n \t\t\tpos = -pos - 1;\n@@ -1842,6 +1843,14 @@ 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\t\tfilename, oid, &oc->symlink_path,\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373962","messageId":"20190416093341.17079-31-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 30/34] sha1-name.c: add repo_get_oid()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:37Z","receivedAt":"2019-04-16T09:37:36Z","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     | 3 ++-\n sha1-name.c | 4 ++--\n 2 files changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 2149dc4f56..f6e87194d0 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1380,7 +1380,8 @@ enum get_oid_result {\n \t\t       */\n };\n \n-extern int get_oid(const char *str, struct object_id *oid);\n+int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);\n+#define get_oid(str, oid) repo_get_oid(the_repository, str, oid)\n extern int get_oid_commit(const char *str, struct object_id *oid);\n extern int get_oid_committish(const char *str, struct object_id *oid);\n extern int get_oid_tree(const char *str, struct object_id *oid);\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 64a50d1291..953df0d692 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1573,10 +1573,10 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)\n  * This is like \"get_oid_basic()\", except it allows \"object ID expressions\",\n  * notably \"xyz^\" for \"parent of xyz\"\n  */\n-int get_oid(const char *name, struct object_id *oid)\n+int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository, name, 0, oid, &unused);\n+\treturn get_oid_with_context(r, name, 0, oid, &unused);\n }\n \n \n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373963","messageId":"20190416093341.17079-32-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 31/34] submodule-config.c: use repo_get_oid for reading .gitmodules","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:38Z","receivedAt":"2019-04-16T09:37:41Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Since 76e9bdc437 (submodule: support reading .gitmodules when it's not\nin the working tree - 2018-10-25), every time you do\n\n    git grep --recurse-submodules\n\nyou are likely to see one warning line per submodule (unless all those\nsubmodules also have submodules). On a superproject with plenty of\nsubmodules (I've seen one with 67) this is really annoying.\n\nThe warning was there because we could not resolve extended SHA-1\nsyntax on a submodule. We can now. Make use of the new API and get rid\nof the warning.\n\nIt would be even better if config_with_options() supports multiple\nrepositories too. But one step at a time.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n submodule-config.c                 | 20 +++++++-------------\n t/t7814-grep-recurse-submodules.sh |  6 +-----\n 2 files changed, 8 insertions(+), 18 deletions(-)\n\ndiff --git a/submodule-config.c b/submodule-config.c\nindex 66653e86b9..4264ee216f 100644\n--- a/submodule-config.c\n+++ b/submodule-config.c\n@@ -625,23 +625,16 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void\n \t\tconst struct config_options opts = { 0 };\n \t\tstruct object_id oid;\n \t\tchar *file;\n+\t\tchar *oidstr = NULL;\n \n \t\tfile = repo_worktree_path(repo, GITMODULES_FILE);\n \t\tif (file_exists(file)) {\n \t\t\tconfig_source.file = file;\n-\t\t} else if (repo->submodule_prefix) {\n-\t\t\t/*\n-\t\t\t * When get_oid and config_with_options, used below,\n-\t\t\t * become able to work on a specific repository, this\n-\t\t\t * warning branch can be removed.\n-\t\t\t */\n-\t\t\twarning(\"nested submodules without %s in the working tree are not supported yet\",\n-\t\t\t\tGITMODULES_FILE);\n-\t\t\tgoto out;\n-\t\t} else if (get_oid(GITMODULES_INDEX, &oid) >= 0) {\n-\t\t\tconfig_source.blob = GITMODULES_INDEX;\n-\t\t} else if (get_oid(GITMODULES_HEAD, &oid) >= 0) {\n-\t\t\tconfig_source.blob = GITMODULES_HEAD;\n+\t\t} else if (repo_get_oid(repo, GITMODULES_INDEX, &oid) >= 0 ||\n+\t\t\t   repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {\n+\t\t\tconfig_source.blob = oidstr = xstrdup(oid_to_hex(&oid));\n+\t\t\tif (repo != the_repository)\n+\t\t\t\tadd_to_alternates_memory(repo->objects->odb->path);\n \t\t} else {\n \t\t\tgoto out;\n \t\t}\n@@ -649,6 +642,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void\n \t\tconfig_with_options(fn, data, &config_source, &opts);\n \n out:\n+\t\tfree(oidstr);\n \t\tfree(file);\n \t}\n }\ndiff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh\nindex fa475d52fa..134a694516 100755\n--- a/t/t7814-grep-recurse-submodules.sh\n+++ b/t/t7814-grep-recurse-submodules.sh\n@@ -380,11 +380,7 @@ test_expect_success 'grep --recurse-submodules should pass the pattern type alon\n \tfi\n '\n \n-# Recursing down into nested submodules which do not have .gitmodules in their\n-# working tree does not work yet. This is because config_from_gitmodules()\n-# uses get_oid() and the latter is still not able to get objects from an\n-# arbitrary repository (the nested submodule, in this case).\n-test_expect_failure 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '\n+test_expect_success 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '\n \ttest_when_finished \"git -C submodule checkout .gitmodules\" &&\n \trm submodule/.gitmodules &&\n \tgit grep --recurse-submodules -e \"(.|.)[\\d]\" >actual &&\n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373964","messageId":"20190416093341.17079-33-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 32/34] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:39Z","receivedAt":"2019-04-16T09:37:46Z","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 setup.c     | 7 ++++---\n sha1-name.c | 6 ++++--\n 3 files changed, 11 insertions(+), 6 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex f6e87194d0..3718b3db8a 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1387,7 +1387,9 @@ extern int get_oid_committish(const char *str, struct object_id *oid);\n extern int get_oid_tree(const char *str, struct object_id *oid);\n extern int get_oid_treeish(const char *str, struct object_id *oid);\n extern int get_oid_blob(const char *str, struct object_id *oid);\n-extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);\n+void maybe_die_on_misspelt_object_name(struct repository *repo,\n+\t\t\t\t       const char *name,\n+\t\t\t\t       const char *prefix);\n extern enum get_oid_result get_oid_with_context(struct repository *repo, const char *str,\n \t\t\t\tunsigned flags, struct object_id *oid,\n \t\t\t\tstruct object_context *oc);\ndiff --git a/setup.c b/setup.c\nindex d0c958c3b2..8dcb4631f7 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -164,7 +164,8 @@ int check_filename(const char *prefix, const char *arg)\n \tdie_errno(_(\"failed to stat '%s'\"), arg);\n }\n \n-static void NORETURN die_verify_filename(const char *prefix,\n+static void NORETURN die_verify_filename(struct repository *r,\n+\t\t\t\t\t const char *prefix,\n \t\t\t\t\t const char *arg,\n \t\t\t\t\t int diagnose_misspelt_rev)\n {\n@@ -179,7 +180,7 @@ static void NORETURN die_verify_filename(const char *prefix,\n \t * let maybe_die_on_misspelt_object_name() even trigger.\n \t */\n \tif (!(arg[0] == ':' && !isalnum(arg[1])))\n-\t\tmaybe_die_on_misspelt_object_name(arg, prefix);\n+\t\tmaybe_die_on_misspelt_object_name(r, arg, prefix);\n \n \t/* ... or fall back the most general message. */\n \tdie(_(\"ambiguous argument '%s': unknown revision or path not in the working tree.\\n\"\n@@ -234,7 +235,7 @@ void verify_filename(const char *prefix,\n \t\tdie(_(\"option '%s' must come before non-option arguments\"), arg);\n \tif (looks_like_pathspec(arg) || check_filename(prefix, arg))\n \t\treturn;\n-\tdie_verify_filename(prefix, arg, diagnose_misspelt_rev);\n+\tdie_verify_filename(the_repository, prefix, arg, diagnose_misspelt_rev);\n }\n \n /*\ndiff --git a/sha1-name.c b/sha1-name.c\nindex 953df0d692..b94d381bef 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1885,11 +1885,13 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,\n  * exist in 'HEAD'\" when given \"HEAD:doc\", or it may return in which case\n  * you have a chance to diagnose the error further.\n  */\n-void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)\n+void maybe_die_on_misspelt_object_name(struct repository *r,\n+\t\t\t\t       const char *name,\n+\t\t\t\t       const char *prefix)\n {\n \tstruct object_context oc;\n \tstruct object_id oid;\n-\tget_oid_with_context_1(the_repository, name, GET_OID_ONLY_TO_DIE,\n+\tget_oid_with_context_1(r, name, GET_OID_ONLY_TO_DIE,\n \t\t\t       prefix, &oid, &oc);\n }\n \n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373965","messageId":"20190416093341.17079-34-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 33/34] sha1-name.c: remove the_repo from other get_oid_*","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:40Z","receivedAt":"2019-04-16T09:37:52Z","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     | 18 ++++++++++++------\n sha1-name.c | 35 ++++++++++++++++++++---------------\n 2 files changed, 32 insertions(+), 21 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 3718b3db8a..871a167bf8 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1381,12 +1381,11 @@ enum get_oid_result {\n };\n \n int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);\n-#define get_oid(str, oid) repo_get_oid(the_repository, str, oid)\n-extern int get_oid_commit(const char *str, struct object_id *oid);\n-extern int get_oid_committish(const char *str, struct object_id *oid);\n-extern int get_oid_tree(const char *str, struct object_id *oid);\n-extern int get_oid_treeish(const char *str, struct object_id *oid);\n-extern int get_oid_blob(const char *str, struct object_id *oid);\n+int repo_get_oid_commit(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_committish(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid);\n void maybe_die_on_misspelt_object_name(struct repository *repo,\n \t\t\t\t       const char *name,\n \t\t\t\t       const char *prefix);\n@@ -1394,6 +1393,13 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c\n \t\t\t\tunsigned flags, struct object_id *oid,\n \t\t\t\tstruct object_context *oc);\n \n+#define get_oid(str, oid)\t\trepo_get_oid(the_repository, str, oid)\n+#define get_oid_commit(str, oid)\trepo_get_oid_commit(the_repository, str, oid)\n+#define get_oid_committish(str, oid)\trepo_get_oid_committish(the_repository, str, oid)\n+#define get_oid_tree(str, oid)\t\trepo_get_oid_tree(the_repository, str, oid)\n+#define get_oid_treeish(str, oid)\trepo_get_oid_treeish(the_repository, str, oid)\n+#define get_oid_blob(str, oid)\t\trepo_get_oid_blob(the_repository, str, oid)\n+\n typedef int each_abbrev_fn(const struct object_id *oid, void *);\n int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);\n #define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data)\ndiff --git a/sha1-name.c b/sha1-name.c\nindex b94d381bef..d49496397d 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1590,43 +1590,48 @@ int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)\n  * commit-ish. It is merely to give a hint to the disambiguation\n  * machinery.\n  */\n-int get_oid_committish(const char *name, struct object_id *oid)\n+int repo_get_oid_committish(struct repository *r,\n+\t\t\t    const char *name,\n+\t\t\t    struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_COMMITTISH,\n+\treturn get_oid_with_context(r, name, GET_OID_COMMITTISH,\n \t\t\t\t    oid, &unused);\n }\n \n-int get_oid_treeish(const char *name, struct object_id *oid)\n+int repo_get_oid_treeish(struct repository *r,\n+\t\t\t const char *name,\n+\t\t\t struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_TREEISH,\n+\treturn get_oid_with_context(r, name, GET_OID_TREEISH,\n \t\t\t\t    oid, &unused);\n }\n \n-int get_oid_commit(const char *name, struct object_id *oid)\n+int repo_get_oid_commit(struct repository *r,\n+\t\t\tconst char *name,\n+\t\t\tstruct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_COMMIT,\n+\treturn get_oid_with_context(r, name, GET_OID_COMMIT,\n \t\t\t\t    oid, &unused);\n }\n \n-int get_oid_tree(const char *name, struct object_id *oid)\n+int repo_get_oid_tree(struct repository *r,\n+\t\t      const char *name,\n+\t\t      struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_TREE,\n+\treturn get_oid_with_context(r, name, GET_OID_TREE,\n \t\t\t\t    oid, &unused);\n }\n \n-int get_oid_blob(const char *name, struct object_id *oid)\n+int repo_get_oid_blob(struct repository *r,\n+\t\t      const char *name,\n+\t\t      struct object_id *oid)\n {\n \tstruct object_context unused;\n-\treturn get_oid_with_context(the_repository,\n-\t\t\t\t    name, GET_OID_BLOB,\n+\treturn get_oid_with_context(r, name, GET_OID_BLOB,\n \t\t\t\t    oid, &unused);\n }\n \n-- \n2.21.0.682.g30d2204636\n\n"},{"id":"373966","messageId":"20190416093341.17079-35-pclouds@gmail.com","threadId":"50841","inReplyTo":"20190416093341.17079-1-pclouds@gmail.com","subject":"[PATCH v4 34/34] sha1-name.c: remove the_repo from get_oid_mb()","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-04-16T09:33:41Z","receivedAt":"2019-04-16T09:37:57Z","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     |  3 ++-\n sha1-name.c | 18 +++++++++++-------\n 2 files changed, 13 insertions(+), 8 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 871a167bf8..9a600a8b50 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1386,6 +1386,7 @@ int repo_get_oid_committish(struct repository *r, const char *str, struct object\n int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid);\n int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid);\n int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid);\n+int repo_get_oid_mb(struct repository *r, const char *str, struct object_id *oid);\n void maybe_die_on_misspelt_object_name(struct repository *repo,\n \t\t\t\t       const char *name,\n \t\t\t\t       const char *prefix);\n@@ -1399,6 +1400,7 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c\n #define get_oid_tree(str, oid)\t\trepo_get_oid_tree(the_repository, str, oid)\n #define get_oid_treeish(str, oid)\trepo_get_oid_treeish(the_repository, str, oid)\n #define get_oid_blob(str, oid)\t\trepo_get_oid_blob(the_repository, str, oid)\n+#define get_oid_mb(str, oid) \t\trepo_get_oid_mb(the_repository, str, oid)\n \n typedef int each_abbrev_fn(const struct object_id *oid, void *);\n int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);\n@@ -1486,7 +1488,6 @@ int repo_interpret_branch_name(struct repository *r,\n \t\t\t       unsigned allowed);\n #define interpret_branch_name(str, len, buf, allowed) \\\n \trepo_interpret_branch_name(the_repository, str, len, buf, allowed)\n-extern int get_oid_mb(const char *str, struct object_id *oid);\n \n extern int validate_headref(const char *ref);\n \ndiff --git a/sha1-name.c b/sha1-name.c\nindex d49496397d..cf314ebb29 100644\n--- a/sha1-name.c\n+++ b/sha1-name.c\n@@ -1338,7 +1338,9 @@ static int interpret_nth_prior_checkout(struct repository *r,\n \treturn retval;\n }\n \n-int get_oid_mb(const char *name, struct object_id *oid)\n+int repo_get_oid_mb(struct repository *r,\n+\t\t    const char *name,\n+\t\t    struct object_id *oid)\n {\n \tstruct commit *one, *two;\n \tstruct commit_list *mbs;\n@@ -1348,27 +1350,29 @@ int get_oid_mb(const char *name, struct object_id *oid)\n \n \tdots = strstr(name, \"...\");\n \tif (!dots)\n-\t\treturn get_oid(name, oid);\n+\t\treturn repo_get_oid(r, name, oid);\n \tif (dots == name)\n-\t\tst = get_oid(\"HEAD\", &oid_tmp);\n+\t\tst = repo_get_oid(r, \"HEAD\", &oid_tmp);\n \telse {\n \t\tstruct strbuf sb;\n \t\tstrbuf_init(&sb, dots - name);\n \t\tstrbuf_add(&sb, name, dots - name);\n-\t\tst = get_oid_committish(sb.buf, &oid_tmp);\n+\t\tst = repo_get_oid_committish(r, sb.buf, &oid_tmp);\n \t\tstrbuf_release(&sb);\n \t}\n \tif (st)\n \t\treturn st;\n-\tone = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);\n+\tone = lookup_commit_reference_gently(r, &oid_tmp, 0);\n \tif (!one)\n \t\treturn -1;\n \n-\tif (get_oid_committish(dots[3] ? (dots + 3) : \"HEAD\", &oid_tmp))\n+\tif (repo_get_oid_committish(r, dots[3] ? (dots + 3) : \"HEAD\", &oid_tmp))\n \t\treturn -1;\n-\ttwo = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);\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 \tif (!mbs || mbs->next)\n \t\tst = -1;\n-- \n2.21.0.682.g30d2204636\n\n"}]}