{"thread":{"id":"50527","subject":"[PATCH 00/31] Kill the_repository in sha1-name.c","startedAt":"2019-02-17T10:09:21Z","lastAt":"2019-02-17T10:11:36Z","messageCount":32,"participants":["Nguyễn Thái Ngọc Duy"],"isPatch":true,"patchVersion":1,"patchTotal":31},"messages":[{"id":"369479","messageId":"20190217100913.4127-1-pclouds@gmail.com","threadId":"50527","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-02-17T10:08:42Z","receivedAt":"2019-02-17T10:09:21Z","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.rc0.328.g0e39304f8d\n\n"},{"id":"369480","messageId":"20190217100913.4127-2-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:08:43Z","receivedAt":"2019-02-17T10:09:25Z","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.rc0.328.g0e39304f8d\n\n"},{"id":"369481","messageId":"20190217100913.4127-3-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:08:44Z","receivedAt":"2019-02-17T10:09: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 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.rc0.328.g0e39304f8d\n\n"},{"id":"369482","messageId":"20190217100913.4127-4-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:08:45Z","receivedAt":"2019-02-17T10:09: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 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.rc0.328.g0e39304f8d\n\n"},{"id":"369483","messageId":"20190217100913.4127-5-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:08:46Z","receivedAt":"2019-02-17T10:09: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 27fe635f62..aa52850d84 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1442,8 +1442,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.rc0.328.g0e39304f8d\n\n"},{"id":"369484","messageId":"20190217100913.4127-6-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:08:47Z","receivedAt":"2019-02-17T10:09: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 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.rc0.328.g0e39304f8d\n\n"},{"id":"369485","messageId":"20190217100913.4127-7-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:08:48Z","receivedAt":"2019-02-17T10:09:47Z","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.rc0.328.g0e39304f8d\n\n"},{"id":"369486","messageId":"20190217100913.4127-8-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:08:49Z","receivedAt":"2019-02-17T10:09: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 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.rc0.328.g0e39304f8d\n\n"},{"id":"369487","messageId":"20190217100913.4127-9-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:08:50Z","receivedAt":"2019-02-17T10:09: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 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.rc0.328.g0e39304f8d\n\n"},{"id":"369488","messageId":"20190217100913.4127-10-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:08:51Z","receivedAt":"2019-02-17T10:10: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 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.rc0.328.g0e39304f8d\n\n"},{"id":"369489","messageId":"20190217100913.4127-11-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:08:52Z","receivedAt":"2019-02-17T10:10: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 | 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.rc0.328.g0e39304f8d\n\n"},{"id":"369490","messageId":"20190217100913.4127-12-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:08:53Z","receivedAt":"2019-02-17T10:10: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 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.rc0.328.g0e39304f8d\n\n"},{"id":"369491","messageId":"20190217100913.4127-13-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:08:54Z","receivedAt":"2019-02-17T10:10: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 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 aa52850d84..524a44110a 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1019,8 +1019,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.rc0.328.g0e39304f8d\n\n"},{"id":"369492","messageId":"20190217100913.4127-14-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:08:55Z","receivedAt":"2019-02-17T10:10: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 | 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.rc0.328.g0e39304f8d\n\n"},{"id":"369493","messageId":"20190217100913.4127-15-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:08:56Z","receivedAt":"2019-02-17T10:10: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 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 524a44110a..92973e7ae0 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1366,7 +1366,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.rc0.328.g0e39304f8d\n\n"},{"id":"369494","messageId":"20190217100913.4127-16-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:08:57Z","receivedAt":"2019-02-17T10:10: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 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.rc0.328.g0e39304f8d\n\n"},{"id":"369495","messageId":"20190217100913.4127-17-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:08:58Z","receivedAt":"2019-02-17T10:10: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 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.rc0.328.g0e39304f8d\n\n"},{"id":"369496","messageId":"20190217100913.4127-18-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:08:59Z","receivedAt":"2019-02-17T10:10: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 | 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.rc0.328.g0e39304f8d\n\n"},{"id":"369497","messageId":"20190217100913.4127-19-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:09:00Z","receivedAt":"2019-02-17T10:10:41Z","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.rc0.328.g0e39304f8d\n\n"},{"id":"369498","messageId":"20190217100913.4127-20-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:09:01Z","receivedAt":"2019-02-17T10:10: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 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.rc0.328.g0e39304f8d\n\n"},{"id":"369499","messageId":"20190217100913.4127-21-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:09:02Z","receivedAt":"2019-02-17T10:10: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 | 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.rc0.328.g0e39304f8d\n\n"},{"id":"369500","messageId":"20190217100913.4127-22-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:09:03Z","receivedAt":"2019-02-17T10:10: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 | 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.rc0.328.g0e39304f8d\n\n"},{"id":"369501","messageId":"20190217100913.4127-24-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:09:05Z","receivedAt":"2019-02-17T10:11:02Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n sha1-name.c | 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.rc0.328.g0e39304f8d\n\n"},{"id":"369502","messageId":"20190217100913.4127-23-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:09:04Z","receivedAt":"2019-02-17T10:11:04Z","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 92973e7ae0..9ff5af0bef 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1465,8 +1465,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.rc0.328.g0e39304f8d\n\n"},{"id":"369503","messageId":"20190217100913.4127-25-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:09:06Z","receivedAt":"2019-02-17T10:11: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 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.rc0.328.g0e39304f8d\n\n"},{"id":"369504","messageId":"20190217100913.4127-26-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:09:07Z","receivedAt":"2019-02-17T10:11:11Z","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.rc0.328.g0e39304f8d\n\n"},{"id":"369505","messageId":"20190217100913.4127-27-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:09:08Z","receivedAt":"2019-02-17T10:11: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 | 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.rc0.328.g0e39304f8d\n\n"},{"id":"369506","messageId":"20190217100913.4127-28-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:09:09Z","receivedAt":"2019-02-17T10:11: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 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 9ff5af0bef..942d9912a2 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1354,7 +1354,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.rc0.328.g0e39304f8d\n\n"},{"id":"369507","messageId":"20190217100913.4127-29-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:09:10Z","receivedAt":"2019-02-17T10:11:24Z","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 52702c62d9..ad4e2cf330 100644\n--- a/submodule-config.c\n+++ b/submodule-config.c\n@@ -618,23 +618,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@@ -642,6 +635,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.rc0.328.g0e39304f8d\n\n"},{"id":"369508","messageId":"20190217100913.4127-30-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:09:11Z","receivedAt":"2019-02-17T10:11:28Z","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 942d9912a2..da7035c261 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1361,7 +1361,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 ca9e8a949e..a56df63d1e 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.rc0.328.g0e39304f8d\n\n"},{"id":"369509","messageId":"20190217100913.4127-31-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:09:12Z","receivedAt":"2019-02-17T10:11: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     | 18 ++++++++++++------\n sha1-name.c | 35 ++++++++++++++++++++---------------\n 2 files changed, 32 insertions(+), 21 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex da7035c261..7ce8c566fc 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1355,12 +1355,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@@ -1368,6 +1367,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.rc0.328.g0e39304f8d\n\n"},{"id":"369510","messageId":"20190217100913.4127-32-pclouds@gmail.com","threadId":"50527","inReplyTo":"20190217100913.4127-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-02-17T10:09:13Z","receivedAt":"2019-02-17T10:11: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 | 18 +++++++++++-------\n 2 files changed, 13 insertions(+), 8 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 7ce8c566fc..24fbff94f7 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1360,6 +1360,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@@ -1373,6 +1374,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@@ -1460,7 +1462,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.rc0.328.g0e39304f8d\n\n"}]}