git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 16/31] sha1-name.c: remove the_repo from interpret_nth_prior_checkout()
  2019-02-17 10:08 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
@ 2019-02-17 10:08 ` Nguyễn Thái Ngọc Duy
  0 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-02-17 10:08 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 2643b75b54..af8bf5b351 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -771,7 +771,7 @@ static inline int push_mark(const char *string, int len)
 }
 
 static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
-static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);
+static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);
 
 static int get_oid_basic(const char *str, int len, struct object_id *oid,
 			  unsigned int flags)
@@ -835,7 +835,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 		struct strbuf buf = STRBUF_INIT;
 		int detached;
 
-		if (interpret_nth_prior_checkout(str, len, &buf) > 0) {
+		if (interpret_nth_prior_checkout(the_repository, str, len, &buf) > 0) {
 			detached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));
 			strbuf_release(&buf);
 			if (detached)
@@ -1288,7 +1288,8 @@ static int grab_nth_branch_switch(struct object_id *ooid, struct object_id *noid
  * Parse @{-N} syntax, return the number of characters parsed
  * if successful; otherwise signal an error with negative value.
  */
-static int interpret_nth_prior_checkout(const char *name, int namelen,
+static int interpret_nth_prior_checkout(struct repository *r,
+					const char *name, int namelen,
 					struct strbuf *buf)
 {
 	long nth;
@@ -1312,12 +1313,14 @@ static int interpret_nth_prior_checkout(const char *name, int namelen,
 	cb.remaining = nth;
 	strbuf_init(&cb.buf, 20);
 
-	retval = 0;
-	if (0 < for_each_reflog_ent_reverse("HEAD", grab_nth_branch_switch, &cb)) {
+	retval = refs_for_each_reflog_ent_reverse(get_main_ref_store(r),
+			"HEAD", grab_nth_branch_switch, &cb);
+	if (0 < retval) {
 		strbuf_reset(buf);
 		strbuf_addbuf(buf, &cb.buf);
 		retval = brace - name + 1;
-	}
+	} else
+		retval = 0;
 
 	strbuf_release(&cb.buf);
 	return retval;
@@ -1484,7 +1487,7 @@ int repo_interpret_branch_name(struct repository *r,
 		namelen = strlen(name);
 
 	if (!allowed || (allowed & INTERPRET_BRANCH_LOCAL)) {
-		len = interpret_nth_prior_checkout(name, namelen, buf);
+		len = interpret_nth_prior_checkout(the_repository, name, namelen, buf);
 		if (!len) {
 			return len; /* syntax Ok, not enough switches */
 		} else if (len > 0) {
-- 
2.21.0.rc0.328.g0e39304f8d


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 00/31] Kill the_repository in sha1-name.c
@ 2019-03-30 11:18 Nguyễn Thái Ngọc Duy
  2019-03-30 11:18 ` [PATCH 01/31] packfile.c: add repo_approximate_object_count() Nguyễn Thái Ngọc Duy
                   ` (31 more replies)
  0 siblings, 32 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:18 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

This whole series is to fix a known issue from
ao/submodule-wo-gitmodules-checked-out. Commit 76e9bdc437 (submodule:
support reading .gitmodules when it's not in the working tree -
2018-10-25) makes "git grep --recurse-submodules" print

    warning: nested submodules ... not supported yet

one line per submodule. And it's really annoying when a repo has lots
of (non-nested) submodules.

Fixing it requires resolving an extended SHA-1 syntax from a separate
repository. Which basically means the whole sha1-name.c has to be
aware of 'struct repository' (and a bit more from refs.c as well).

Technically merge-recursive.c, tree-walk.c and config.c have to take
'struct repository *' too, but I reduce the scope a bit since it's
already long.

The main fix is 28/31. The rest is just converting code to use 'struct
repository *'. Patches after 28/31 are technically not needed, but
since I have converted most of sha1-name.c, might as well convert the
rest.

There is a new function get_oidf() from another series on 'pu', which
can't be converted right now of course. But it could be fixed easily
later. It also causes a conflict in cache.h but resolving is straight
forward.

Nguyễn Thái Ngọc Duy (31):
  packfile.c: add repo_approximate_object_count()
  refs.c: add refs_ref_exists()
  refs.c: add refs_shorten_unambiguous_ref()
  refs.c: remove the_repo from substitute_branch_name()
  refs.c: remove the_repo from expand_ref()
  refs.c: add repo_dwim_ref()
  refs.c: add repo_dwim_log()
  refs.c: remove the_repo from read_ref_at()
  commit.c: add repo_get_commit_tree()
  sha1-name.c: remove the_repo from sort_ambiguous()
  sha1-name.c: remove the_repo from find_abbrev_len_packed()
  sha1-name.c: add repo_find_unique_abbrev_r()
  sha1-name.c: store and use repo in struct disambiguate_state
  sha1-name.c: add repo_for_each_abbrev()
  sha1-name.c: remove the_repo from get_short_oid()
  sha1-name.c: remove the_repo from interpret_nth_prior_checkout()
  sha1-name.c: remove the_repo from interpret_branch_mark()
  sha1-name.c: add repo_interpret_branch_name()
  sha1-name.c: remove the_repo from get_oid_oneline()
  sha1-name.c: remove the_repo from get_describe_name()
  sha1-name.c: remove the_repo from get_oid_basic()
  sha1-name.c: remove the_repo from get_oid_1()
  sha1-name.c: remove the_repo from handle_one_ref()
  sha1-name.c: remove the_repo from diagnose_invalid_index_path()
  sha1-name.c: remove the_repo from resolve_relative_path()
  sha1-name.c: remove the_repo from get_oid_with_context_1()
  sha1-name.c: add repo_get_oid()
  submodule-config.c: use repo_get_oid for reading .gitmodules
  sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name
  sha1-name.c: remove the_repo from other get_oid_*
  sha1-name.c: remove the_repo from get_oid_mb()

 builtin/show-branch.c              |   6 +-
 cache.h                            |  50 ++--
 commit.c                           |   5 +-
 commit.h                           |   3 +-
 dir.c                              |   8 +
 dir.h                              |   4 +-
 packfile.c                         |  14 +-
 packfile.h                         |   3 +-
 refs.c                             |  71 ++++--
 refs.h                             |   9 +-
 setup.c                            |   7 +-
 sha1-name.c                        | 388 ++++++++++++++++++-----------
 submodule-config.c                 |  20 +-
 t/t7814-grep-recurse-submodules.sh |   6 +-
 upload-pack.c                      |   2 +-
 15 files changed, 371 insertions(+), 225 deletions(-)

-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply	[flat|nested] 154+ messages in thread

* [PATCH 01/31] packfile.c: add repo_approximate_object_count()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:18 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:18 ` [PATCH 02/31] refs.c: add refs_ref_exists() Nguyễn Thái Ngọc Duy
                   ` (30 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:18 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 packfile.c | 14 +++++++-------
 packfile.h |  3 ++-
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/packfile.c b/packfile.c
index 16bcb75262..2ad4fab2f8 100644
--- a/packfile.c
+++ b/packfile.c
@@ -893,25 +893,25 @@ static void prepare_packed_git(struct repository *r);
  * all unreachable objects about to be pruned, in which case they're not really
  * interesting as a measure of repo size in the first place.
  */
-unsigned long approximate_object_count(void)
+unsigned long repo_approximate_object_count(struct repository *r)
 {
-	if (!the_repository->objects->approximate_object_count_valid) {
+	if (!r->objects->approximate_object_count_valid) {
 		unsigned long count;
 		struct multi_pack_index *m;
 		struct packed_git *p;
 
-		prepare_packed_git(the_repository);
+		prepare_packed_git(r);
 		count = 0;
-		for (m = get_multi_pack_index(the_repository); m; m = m->next)
+		for (m = get_multi_pack_index(r); m; m = m->next)
 			count += m->num_objects;
-		for (p = the_repository->objects->packed_git; p; p = p->next) {
+		for (p = r->objects->packed_git; p; p = p->next) {
 			if (open_pack_index(p))
 				continue;
 			count += p->num_objects;
 		}
-		the_repository->objects->approximate_object_count = count;
+		r->objects->approximate_object_count = count;
 	}
-	return the_repository->objects->approximate_object_count;
+	return r->objects->approximate_object_count;
 }
 
 static void *get_next_packed_git(const void *p)
diff --git a/packfile.h b/packfile.h
index d70c6d9afb..f04440f984 100644
--- a/packfile.h
+++ b/packfile.h
@@ -57,7 +57,8 @@ struct packed_git *get_all_packs(struct repository *r);
  * Give a rough count of objects in the repository. This sacrifices accuracy
  * for speed.
  */
-unsigned long approximate_object_count(void);
+unsigned long repo_approximate_object_count(struct repository *r);
+#define approximate_object_count() repo_approximate_object_count(the_repository)
 
 extern struct packed_git *find_sha1_pack(const unsigned char *sha1,
 					 struct packed_git *packs);
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 02/31] refs.c: add refs_ref_exists()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
  2019-03-30 11:18 ` [PATCH 01/31] packfile.c: add repo_approximate_object_count() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:18 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:18 ` [PATCH 03/31] refs.c: add refs_shorten_unambiguous_ref() Nguyễn Thái Ngọc Duy
                   ` (29 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:18 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/refs.c b/refs.c
index 142888a40a..b869f32d8b 100644
--- a/refs.c
+++ b/refs.c
@@ -241,9 +241,14 @@ int read_ref(const char *refname, struct object_id *oid)
 	return read_ref_full(refname, RESOLVE_REF_READING, oid, NULL);
 }
 
+static int refs_ref_exists(struct ref_store *refs, const char *refname)
+{
+	return !!refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING, NULL, NULL);
+}
+
 int ref_exists(const char *refname)
 {
-	return !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, NULL, NULL);
+	return refs_ref_exists(get_main_ref_store(the_repository), refname);
 }
 
 static int match_ref_pattern(const char *refname,
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 03/31] refs.c: add refs_shorten_unambiguous_ref()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
  2019-03-30 11:18 ` [PATCH 01/31] packfile.c: add repo_approximate_object_count() Nguyễn Thái Ngọc Duy
  2019-03-30 11:18 ` [PATCH 02/31] refs.c: add refs_ref_exists() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:18 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 04/31] refs.c: remove the_repo from substitute_branch_name() Nguyễn Thái Ngọc Duy
                   ` (28 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:18 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c | 11 +++++++++--
 refs.h |  2 ++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/refs.c b/refs.c
index b869f32d8b..3dde824aab 100644
--- a/refs.c
+++ b/refs.c
@@ -1169,7 +1169,8 @@ int update_ref(const char *msg, const char *refname,
 			       old_oid, flags, onerr);
 }
 
-char *shorten_unambiguous_ref(const char *refname, int strict)
+char *refs_shorten_unambiguous_ref(struct ref_store *refs,
+				   const char *refname, int strict)
 {
 	int i;
 	static char **scanf_fmts;
@@ -1247,7 +1248,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
 			strbuf_reset(&resolved_buf);
 			strbuf_addf(&resolved_buf, rule,
 				    short_name_len, short_name);
-			if (ref_exists(resolved_buf.buf))
+			if (refs_ref_exists(refs, resolved_buf.buf))
 				break;
 		}
 
@@ -1266,6 +1267,12 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
 	return xstrdup(refname);
 }
 
+char *shorten_unambiguous_ref(const char *refname, int strict)
+{
+	return refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
+					    refname, strict);
+}
+
 static struct string_list *hide_refs;
 
 int parse_hide_refs_config(const char *var, const char *value, const char *section)
diff --git a/refs.h b/refs.h
index 308fa1f03b..5627570241 100644
--- a/refs.h
+++ b/refs.h
@@ -462,6 +462,8 @@ int check_refname_format(const char *refname, int flags);
 
 const char *prettify_refname(const char *refname);
 
+char *refs_shorten_unambiguous_ref(struct ref_store *refs,
+				   const char *refname, int strict);
 char *shorten_unambiguous_ref(const char *refname, int strict);
 
 /** rename ref, return 0 on success **/
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 04/31] refs.c: remove the_repo from substitute_branch_name()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (2 preceding siblings ...)
  2019-03-30 11:18 ` [PATCH 03/31] refs.c: add refs_shorten_unambiguous_ref() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 05/31] refs.c: remove the_repo from expand_ref() Nguyễn Thái Ngọc Duy
                   ` (27 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 8 ++++++--
 refs.c      | 9 +++++----
 sha1-name.c | 8 ++++++--
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/cache.h b/cache.h
index ac92421f3a..fcb24b5781 100644
--- a/cache.h
+++ b/cache.h
@@ -1468,8 +1468,12 @@ extern int parse_oid_hex(const char *hex, struct object_id *oid, const char **en
 #define INTERPRET_BRANCH_LOCAL (1<<0)
 #define INTERPRET_BRANCH_REMOTE (1<<1)
 #define INTERPRET_BRANCH_HEAD (1<<2)
-extern int interpret_branch_name(const char *str, int len, struct strbuf *,
-				 unsigned allowed);
+int repo_interpret_branch_name(struct repository *r,
+			       const char *str, int len,
+			       struct strbuf *buf,
+			       unsigned allowed);
+#define interpret_branch_name(str, len, buf, allowed) \
+	repo_interpret_branch_name(the_repository, str, len, buf, allowed)
 extern int get_oid_mb(const char *str, struct object_id *oid);
 
 extern int validate_headref(const char *ref);
diff --git a/refs.c b/refs.c
index 3dde824aab..44df049796 100644
--- a/refs.c
+++ b/refs.c
@@ -539,10 +539,11 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)
  * later free()ing) if the string passed in is a magic short-hand form
  * to name a branch.
  */
-static char *substitute_branch_name(const char **string, int *len)
+static char *substitute_branch_name(struct repository *r,
+				    const char **string, int *len)
 {
 	struct strbuf buf = STRBUF_INIT;
-	int ret = interpret_branch_name(*string, *len, &buf, 0);
+	int ret = repo_interpret_branch_name(r, *string, *len, &buf, 0);
 
 	if (ret == *len) {
 		size_t size;
@@ -556,7 +557,7 @@ static char *substitute_branch_name(const char **string, int *len)
 
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
 {
-	char *last_branch = substitute_branch_name(&str, &len);
+	char *last_branch = substitute_branch_name(the_repository, &str, &len);
 	int   refs_found  = expand_ref(str, len, oid, ref);
 	free(last_branch);
 	return refs_found;
@@ -596,7 +597,7 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
 
 int dwim_log(const char *str, int len, struct object_id *oid, char **log)
 {
-	char *last_branch = substitute_branch_name(&str, &len);
+	char *last_branch = substitute_branch_name(the_repository, &str, &len);
 	const char **p;
 	int logs_found = 0;
 	struct strbuf path = STRBUF_INIT;
diff --git a/sha1-name.c b/sha1-name.c
index 6dda2c16df..d535bb82f7 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1427,13 +1427,17 @@ static int interpret_branch_mark(const char *name, int namelen,
 	return len + at;
 }
 
-int interpret_branch_name(const char *name, int namelen, struct strbuf *buf,
-			  unsigned allowed)
+int repo_interpret_branch_name(struct repository *r,
+			       const char *name, int namelen,
+			       struct strbuf *buf,
+			       unsigned allowed)
 {
 	char *at;
 	const char *start;
 	int len;
 
+	if (r != the_repository)
+		BUG("interpret_branch_name() does not really use 'r' yet");
 	if (!namelen)
 		namelen = strlen(name);
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 05/31] refs.c: remove the_repo from expand_ref()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (3 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 04/31] refs.c: remove the_repo from substitute_branch_name() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 06/31] refs.c: add repo_dwim_ref() Nguyễn Thái Ngọc Duy
                   ` (26 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c        | 10 ++++++----
 refs.h        |  2 +-
 upload-pack.c |  2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/refs.c b/refs.c
index 44df049796..1f5864aa36 100644
--- a/refs.c
+++ b/refs.c
@@ -558,12 +558,13 @@ static char *substitute_branch_name(struct repository *r,
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
 {
 	char *last_branch = substitute_branch_name(the_repository, &str, &len);
-	int   refs_found  = expand_ref(str, len, oid, ref);
+	int   refs_found  = expand_ref(the_repository, str, len, oid, ref);
 	free(last_branch);
 	return refs_found;
 }
 
-int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
+int expand_ref(struct repository *repo, const char *str, int len,
+	       struct object_id *oid, char **ref)
 {
 	const char **p, *r;
 	int refs_found = 0;
@@ -578,8 +579,9 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
 		this_result = refs_found ? &oid_from_ref : oid;
 		strbuf_reset(&fullref);
 		strbuf_addf(&fullref, *p, len, str);
-		r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
-				       this_result, &flag);
+		r = refs_resolve_ref_unsafe(get_main_ref_store(repo),
+					    fullref.buf, RESOLVE_REF_READING,
+					    this_result, &flag);
 		if (r) {
 			if (!refs_found++)
 				*ref = xstrdup(r);
diff --git a/refs.h b/refs.h
index 5627570241..b630d5bde7 100644
--- a/refs.h
+++ b/refs.h
@@ -148,7 +148,7 @@ int refname_match(const char *abbrev_name, const char *full_name);
 struct argv_array;
 void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);
 
-int expand_ref(const char *str, int len, struct object_id *oid, char **ref);
+int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
 int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
 
diff --git a/upload-pack.c b/upload-pack.c
index d098ef5982..56505d60c3 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -834,7 +834,7 @@ static int process_deepen_not(const char *line, struct string_list *deepen_not,
 	if (skip_prefix(line, "deepen-not ", &arg)) {
 		char *ref = NULL;
 		struct object_id oid;
-		if (expand_ref(arg, strlen(arg), &oid, &ref) != 1)
+		if (expand_ref(the_repository, arg, strlen(arg), &oid, &ref) != 1)
 			die("git upload-pack: ambiguous deepen-not: %s", line);
 		string_list_append(deepen_not, ref);
 		free(ref);
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 06/31] refs.c: add repo_dwim_ref()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (4 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 05/31] refs.c: remove the_repo from expand_ref() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 07/31] refs.c: add repo_dwim_log() Nguyễn Thái Ngọc Duy
                   ` (25 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c | 12 +++++++++---
 refs.h |  1 +
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/refs.c b/refs.c
index 1f5864aa36..bd0fec5776 100644
--- a/refs.c
+++ b/refs.c
@@ -555,14 +555,20 @@ static char *substitute_branch_name(struct repository *r,
 	return NULL;
 }
 
-int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
+int repo_dwim_ref(struct repository *r, const char *str, int len,
+		  struct object_id *oid, char **ref)
 {
-	char *last_branch = substitute_branch_name(the_repository, &str, &len);
-	int   refs_found  = expand_ref(the_repository, str, len, oid, ref);
+	char *last_branch = substitute_branch_name(r, &str, &len);
+	int   refs_found  = expand_ref(r, str, len, oid, ref);
 	free(last_branch);
 	return refs_found;
 }
 
+int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
+{
+	return repo_dwim_ref(the_repository, str, len, oid, ref);
+}
+
 int expand_ref(struct repository *repo, const char *str, int len,
 	       struct object_id *oid, char **ref)
 {
diff --git a/refs.h b/refs.h
index b630d5bde7..fd3dc1d0f4 100644
--- a/refs.h
+++ b/refs.h
@@ -149,6 +149,7 @@ struct argv_array;
 void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);
 
 int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
+int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
 int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 07/31] refs.c: add repo_dwim_log()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (5 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 06/31] refs.c: add repo_dwim_ref() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 08/31] refs.c: remove the_repo from read_ref_at() Nguyễn Thái Ngọc Duy
                   ` (24 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c | 21 +++++++++++++++------
 refs.h |  1 +
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/refs.c b/refs.c
index bd0fec5776..edea001446 100644
--- a/refs.c
+++ b/refs.c
@@ -603,9 +603,11 @@ int expand_ref(struct repository *repo, const char *str, int len,
 	return refs_found;
 }
 
-int dwim_log(const char *str, int len, struct object_id *oid, char **log)
+int repo_dwim_log(struct repository *r, const char *str, int len,
+		  struct object_id *oid, char **log)
 {
-	char *last_branch = substitute_branch_name(the_repository, &str, &len);
+	struct ref_store *refs = get_main_ref_store(r);
+	char *last_branch = substitute_branch_name(r, &str, &len);
 	const char **p;
 	int logs_found = 0;
 	struct strbuf path = STRBUF_INIT;
@@ -617,13 +619,15 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
 
 		strbuf_reset(&path);
 		strbuf_addf(&path, *p, len, str);
-		ref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,
-					 &hash, NULL);
+		ref = refs_resolve_ref_unsafe(refs, path.buf,
+					      RESOLVE_REF_READING,
+					      &hash, NULL);
 		if (!ref)
 			continue;
-		if (reflog_exists(path.buf))
+		if (refs_reflog_exists(refs, path.buf))
 			it = path.buf;
-		else if (strcmp(ref, path.buf) && reflog_exists(ref))
+		else if (strcmp(ref, path.buf) &&
+			 refs_reflog_exists(refs, ref))
 			it = ref;
 		else
 			continue;
@@ -639,6 +643,11 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
 	return logs_found;
 }
 
+int dwim_log(const char *str, int len, struct object_id *oid, char **log)
+{
+	return repo_dwim_log(the_repository, str, len, oid, log);
+}
+
 static int is_per_worktree_ref(const char *refname)
 {
 	return !strcmp(refname, "HEAD") ||
diff --git a/refs.h b/refs.h
index fd3dc1d0f4..859dffe691 100644
--- a/refs.h
+++ b/refs.h
@@ -150,6 +150,7 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);
 
 int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
 int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
+int repo_dwim_log(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
 int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 08/31] refs.c: remove the_repo from read_ref_at()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (6 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 07/31] refs.c: add repo_dwim_log() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 09/31] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
                   ` (23 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/show-branch.c | 6 ++++--
 refs.c                | 7 ++++---
 refs.h                | 3 ++-
 sha1-name.c           | 3 ++-
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 934e514944..082daeac32 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -753,7 +753,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 				/* Ah, that is a date spec... */
 				timestamp_t at;
 				at = approxidate(reflog_base);
-				read_ref_at(ref, flags, at, -1, &oid, NULL,
+				read_ref_at(get_main_ref_store(the_repository),
+					    ref, flags, at, -1, &oid, NULL,
 					    NULL, NULL, &base);
 			}
 		}
@@ -765,7 +766,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 			timestamp_t timestamp;
 			int tz;
 
-			if (read_ref_at(ref, flags, 0, base + i, &oid, &logmsg,
+			if (read_ref_at(get_main_ref_store(the_repository),
+					ref, flags, 0, base + i, &oid, &logmsg,
 					&timestamp, &tz, NULL)) {
 				reflog = i;
 				break;
diff --git a/refs.c b/refs.c
index edea001446..92d1f6dbdd 100644
--- a/refs.c
+++ b/refs.c
@@ -967,7 +967,8 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid
 	return 1;
 }
 
-int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, int cnt,
+int read_ref_at(struct ref_store *refs, const char *refname,
+		unsigned int flags, timestamp_t at_time, int cnt,
 		struct object_id *oid, char **msg,
 		timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt)
 {
@@ -983,7 +984,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in
 	cb.cutoff_cnt = cutoff_cnt;
 	cb.oid = oid;
 
-	for_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);
+	refs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent, &cb);
 
 	if (!cb.reccnt) {
 		if (flags & GET_OID_QUIETLY)
@@ -994,7 +995,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in
 	if (cb.found_it)
 		return 0;
 
-	for_each_reflog_ent(refname, read_ref_at_ent_oldest, &cb);
+	refs_for_each_reflog_ent(refs, refname, read_ref_at_ent_oldest, &cb);
 
 	return 1;
 }
diff --git a/refs.h b/refs.h
index 859dffe691..8f9cbf8a93 100644
--- a/refs.h
+++ b/refs.h
@@ -388,7 +388,8 @@ int refs_create_reflog(struct ref_store *refs, const char *refname,
 int safe_create_reflog(const char *refname, int force_create, struct strbuf *err);
 
 /** Reads log for the value of ref during at_time. **/
-int read_ref_at(const char *refname, unsigned int flags,
+int read_ref_at(struct ref_store *refs,
+		const char *refname, unsigned int flags,
 		timestamp_t at_time, int cnt,
 		struct object_id *oid, char **msg,
 		timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt);
diff --git a/sha1-name.c b/sha1-name.c
index d535bb82f7..15a1107998 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -849,7 +849,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 				return -1;
 			}
 		}
-		if (read_ref_at(real_ref, flags, at_time, nth, oid, NULL,
+		if (read_ref_at(get_main_ref_store(the_repository),
+				real_ref, flags, at_time, nth, oid, NULL,
 				&co_time, &co_tz, &co_cnt)) {
 			if (!len) {
 				if (starts_with(real_ref, "refs/heads/")) {
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 09/31] commit.c: add repo_get_commit_tree()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (7 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 08/31] refs.c: remove the_repo from read_ref_at() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-04-02 15:39   ` SZEDER Gábor
  2019-03-30 11:19 ` [PATCH 10/31] sha1-name.c: remove the_repo from sort_ambiguous() Nguyễn Thái Ngọc Duy
                   ` (22 subsequent siblings)
  31 siblings, 1 reply; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 commit.c | 5 +++--
 commit.h | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/commit.c b/commit.c
index a5333c7ac6..f0a5506f04 100644
--- a/commit.c
+++ b/commit.c
@@ -340,7 +340,8 @@ void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)
 	}
 }
 
-struct tree *get_commit_tree(const struct commit *commit)
+struct tree *repo_get_commit_tree(struct repository *r,
+				  const struct commit *commit)
 {
 	if (commit->maybe_tree || !commit->object.parsed)
 		return commit->maybe_tree;
@@ -348,7 +349,7 @@ struct tree *get_commit_tree(const struct commit *commit)
 	if (commit->graph_pos == COMMIT_NOT_FROM_GRAPH)
 		BUG("commit has NULL tree, but was not loaded from commit-graph");
 
-	return get_commit_tree_in_graph(the_repository, commit);
+	return get_commit_tree_in_graph(r, commit);
 }
 
 struct object_id *get_commit_tree_oid(const struct commit *commit)
diff --git a/commit.h b/commit.h
index 42728c2906..b576201be8 100644
--- a/commit.h
+++ b/commit.h
@@ -143,7 +143,8 @@ void repo_unuse_commit_buffer(struct repository *r,
  */
 void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);
 
-struct tree *get_commit_tree(const struct commit *);
+struct tree *repo_get_commit_tree(struct repository *, const struct commit *);
+#define get_commit_tree(c) repo_get_commit_tree(the_repository, c)
 struct object_id *get_commit_tree_oid(const struct commit *);
 
 /*
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 10/31] sha1-name.c: remove the_repo from sort_ambiguous()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (8 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 09/31] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 11/31] sha1-name.c: remove the_repo from find_abbrev_len_packed() Nguyễn Thái Ngọc Duy
                   ` (21 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 15a1107998..7558ce51a3 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -383,10 +383,11 @@ static int collect_ambiguous(const struct object_id *oid, void *data)
 	return 0;
 }
 
+static struct repository *sort_ambiguous_repo;
 static int sort_ambiguous(const void *a, const void *b)
 {
-	int a_type = oid_object_info(the_repository, a, NULL);
-	int b_type = oid_object_info(the_repository, b, NULL);
+	int a_type = oid_object_info(sort_ambiguous_repo, a, NULL);
+	int b_type = oid_object_info(sort_ambiguous_repo, b, NULL);
 	int a_type_sort;
 	int b_type_sort;
 
@@ -411,6 +412,14 @@ static int sort_ambiguous(const void *a, const void *b)
 	return a_type_sort > b_type_sort ? 1 : -1;
 }
 
+static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)
+{
+	/* mutex will be needed if this code is to be made thread safe */
+	sort_ambiguous_repo = r;
+	QSORT(a->oid, a->nr, sort_ambiguous);
+	sort_ambiguous_repo = NULL;
+}
+
 static enum get_oid_result get_short_oid(const char *name, int len,
 					 struct object_id *oid,
 					 unsigned flags)
@@ -458,7 +467,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 
 		advise(_("The candidates are:"));
 		for_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect);
-		QSORT(collect.oid, collect.nr, sort_ambiguous);
+		sort_ambiguous_oid_array(the_repository, &collect);
 
 		if (oid_array_for_each(&collect, show_ambiguous_object, &ds))
 			BUG("show_ambiguous_object shouldn't return non-zero");
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 11/31] sha1-name.c: remove the_repo from find_abbrev_len_packed()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (9 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 10/31] sha1-name.c: remove the_repo from sort_ambiguous() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 12/31] sha1-name.c: add repo_find_unique_abbrev_r() Nguyễn Thái Ngọc Duy
                   ` (20 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 7558ce51a3..b9381aaba6 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -514,6 +514,7 @@ struct min_abbrev_data {
 	unsigned int init_len;
 	unsigned int cur_len;
 	char *hex;
+	struct repository *repo;
 	const struct object_id *oid;
 };
 
@@ -619,9 +620,9 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
 	struct multi_pack_index *m;
 	struct packed_git *p;
 
-	for (m = get_multi_pack_index(the_repository); m; m = m->next)
+	for (m = get_multi_pack_index(mad->repo); m; m = m->next)
 		find_abbrev_len_for_midx(m, mad);
-	for (p = get_packed_git(the_repository); p; p = p->next)
+	for (p = get_packed_git(mad->repo); p; p = p->next)
 		find_abbrev_len_for_pack(p, mad);
 }
 
@@ -658,6 +659,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
 	if (len == hexsz || !len)
 		return hexsz;
 
+	mad.repo = the_repository;
 	mad.init_len = len;
 	mad.cur_len = len;
 	mad.hex = hex;
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 12/31] sha1-name.c: add repo_find_unique_abbrev_r()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (10 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 11/31] sha1-name.c: remove the_repo from find_abbrev_len_packed() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 13/31] sha1-name.c: store and use repo in struct disambiguate_state Nguyễn Thái Ngọc Duy
                   ` (19 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     |  6 ++++--
 sha1-name.c | 15 +++++++++------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/cache.h b/cache.h
index fcb24b5781..4f8ebb0a67 100644
--- a/cache.h
+++ b/cache.h
@@ -1045,8 +1045,10 @@ extern void check_repository_format(void);
  * Note that while this version avoids the static buffer, it is not fully
  * reentrant, as it calls into other non-reentrant git code.
  */
-extern const char *find_unique_abbrev(const struct object_id *oid, int len);
-extern int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len);
+const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len);
+#define find_unique_abbrev(oid, len) repo_find_unique_abbrev(the_repository, oid, len)
+int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);
+#define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len)
 
 extern const unsigned char null_sha1[GIT_MAX_RAWSZ];
 extern const struct object_id null_oid;
diff --git a/sha1-name.c b/sha1-name.c
index b9381aaba6..9b57787b76 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -626,15 +626,16 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
 		find_abbrev_len_for_pack(p, mad);
 }
 
-int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
+int repo_find_unique_abbrev_r(struct repository *r, char *hex,
+			      const struct object_id *oid, int len)
 {
 	struct disambiguate_state ds;
 	struct min_abbrev_data mad;
 	struct object_id oid_ret;
-	const unsigned hexsz = the_hash_algo->hexsz;
+	const unsigned hexsz = r->hash_algo->hexsz;
 
 	if (len < 0) {
-		unsigned long count = approximate_object_count();
+		unsigned long count = repo_approximate_object_count(r);
 		/*
 		 * Add one because the MSB only tells us the highest bit set,
 		 * not including the value of all the _other_ bits (so "15"
@@ -659,7 +660,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
 	if (len == hexsz || !len)
 		return hexsz;
 
-	mad.repo = the_repository;
+	mad.repo = r;
 	mad.init_len = len;
 	mad.cur_len = len;
 	mad.hex = hex;
@@ -681,13 +682,15 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
 	return mad.cur_len;
 }
 
-const char *find_unique_abbrev(const struct object_id *oid, int len)
+const char *repo_find_unique_abbrev(struct repository *r,
+				    const struct object_id *oid,
+				    int len)
 {
 	static int bufno;
 	static char hexbuffer[4][GIT_MAX_HEXSZ + 1];
 	char *hex = hexbuffer[bufno];
 	bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
-	find_unique_abbrev_r(hex, oid, len);
+	repo_find_unique_abbrev_r(r, hex, oid, len);
 	return hex;
 }
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 13/31] sha1-name.c: store and use repo in struct disambiguate_state
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (11 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 12/31] sha1-name.c: add repo_find_unique_abbrev_r() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 14/31] sha1-name.c: add repo_for_each_abbrev() Nguyễn Thái Ngọc Duy
                   ` (18 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 95 +++++++++++++++++++++++++++++++++--------------------
 1 file changed, 59 insertions(+), 36 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 9b57787b76..a75992eb54 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -17,13 +17,14 @@
 
 static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
 
-typedef int (*disambiguate_hint_fn)(const struct object_id *, void *);
+typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);
 
 struct disambiguate_state {
 	int len; /* length of prefix in hex chars */
 	char hex_pfx[GIT_MAX_HEXSZ + 1];
 	struct object_id bin_pfx;
 
+	struct repository *repo;
 	disambiguate_hint_fn fn;
 	void *cb_data;
 	struct object_id candidate;
@@ -38,7 +39,7 @@ struct disambiguate_state {
 static void update_candidates(struct disambiguate_state *ds, const struct object_id *current)
 {
 	if (ds->always_call_fn) {
-		ds->ambiguous = ds->fn(current, ds->cb_data) ? 1 : 0;
+		ds->ambiguous = ds->fn(ds->repo, current, ds->cb_data) ? 1 : 0;
 		return;
 	}
 	if (!ds->candidate_exists) {
@@ -58,7 +59,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object
 	}
 
 	if (!ds->candidate_checked) {
-		ds->candidate_ok = ds->fn(&ds->candidate, ds->cb_data);
+		ds->candidate_ok = ds->fn(ds->repo, &ds->candidate, ds->cb_data);
 		ds->disambiguate_fn_used = 1;
 		ds->candidate_checked = 1;
 	}
@@ -71,7 +72,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object
 	}
 
 	/* if we reach this point, we know ds->candidate satisfies fn */
-	if (ds->fn(current, ds->cb_data)) {
+	if (ds->fn(ds->repo, current, ds->cb_data)) {
 		/*
 		 * if both current and candidate satisfy fn, we cannot
 		 * disambiguate.
@@ -89,9 +90,7 @@ static void find_short_object_filename(struct disambiguate_state *ds)
 {
 	struct object_directory *odb;
 
-	for (odb = the_repository->objects->odb;
-	     odb && !ds->ambiguous;
-	     odb = odb->next) {
+	for (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next) {
 		int pos;
 		struct oid_array *loose_objects;
 
@@ -182,10 +181,10 @@ static void find_short_packed_object(struct disambiguate_state *ds)
 	struct multi_pack_index *m;
 	struct packed_git *p;
 
-	for (m = get_multi_pack_index(the_repository); m && !ds->ambiguous;
+	for (m = get_multi_pack_index(ds->repo); m && !ds->ambiguous;
 	     m = m->next)
 		unique_in_midx(m, ds);
-	for (p = get_packed_git(the_repository); p && !ds->ambiguous;
+	for (p = get_packed_git(ds->repo); p && !ds->ambiguous;
 	     p = p->next)
 		unique_in_pack(p, ds);
 }
@@ -215,7 +214,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
 		 * same repository!
 		 */
 		ds->candidate_ok = (!ds->disambiguate_fn_used ||
-				    ds->fn(&ds->candidate, ds->cb_data));
+				    ds->fn(ds->repo, &ds->candidate, ds->cb_data));
 
 	if (!ds->candidate_ok)
 		return SHORT_NAME_AMBIGUOUS;
@@ -224,59 +223,67 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
 	return 0;
 }
 
-static int disambiguate_commit_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_commit_only(struct repository *r,
+				    const struct object_id *oid,
+				    void *cb_data_unused)
 {
-	int kind = oid_object_info(the_repository, oid, NULL);
+	int kind = oid_object_info(r, oid, NULL);
 	return kind == OBJ_COMMIT;
 }
 
-static int disambiguate_committish_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_committish_only(struct repository *r,
+					const struct object_id *oid,
+					void *cb_data_unused)
 {
 	struct object *obj;
 	int kind;
 
-	kind = oid_object_info(the_repository, oid, NULL);
+	kind = oid_object_info(r, oid, NULL);
 	if (kind == OBJ_COMMIT)
 		return 1;
 	if (kind != OBJ_TAG)
 		return 0;
 
 	/* We need to do this the hard way... */
-	obj = deref_tag(the_repository, parse_object(the_repository, oid),
-			NULL, 0);
+	obj = deref_tag(r, parse_object(r, oid), NULL, 0);
 	if (obj && obj->type == OBJ_COMMIT)
 		return 1;
 	return 0;
 }
 
-static int disambiguate_tree_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_tree_only(struct repository *r,
+				  const struct object_id *oid,
+				  void *cb_data_unused)
 {
-	int kind = oid_object_info(the_repository, oid, NULL);
+	int kind = oid_object_info(r, oid, NULL);
 	return kind == OBJ_TREE;
 }
 
-static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_treeish_only(struct repository *r,
+				     const struct object_id *oid,
+				     void *cb_data_unused)
 {
 	struct object *obj;
 	int kind;
 
-	kind = oid_object_info(the_repository, oid, NULL);
+	kind = oid_object_info(r, oid, NULL);
 	if (kind == OBJ_TREE || kind == OBJ_COMMIT)
 		return 1;
 	if (kind != OBJ_TAG)
 		return 0;
 
 	/* We need to do this the hard way... */
-	obj = deref_tag(the_repository, parse_object(the_repository, oid),
-			NULL, 0);
+	obj = deref_tag(r, parse_object(r, oid), NULL, 0);
 	if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))
 		return 1;
 	return 0;
 }
 
-static int disambiguate_blob_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_blob_only(struct repository *r,
+				  const struct object_id *oid,
+				  void *cb_data_unused)
 {
-	int kind = oid_object_info(the_repository, oid, NULL);
+	int kind = oid_object_info(r, oid, NULL);
 	return kind == OBJ_BLOB;
 }
 
@@ -310,7 +317,8 @@ int set_disambiguate_hint_config(const char *var, const char *value)
 	return error("unknown hint type for '%s': %s", var, value);
 }
 
-static int init_object_disambiguation(const char *name, int len,
+static int init_object_disambiguation(struct repository *r,
+				      const char *name, int len,
 				      struct disambiguate_state *ds)
 {
 	int i;
@@ -341,7 +349,8 @@ static int init_object_disambiguation(const char *name, int len,
 
 	ds->len = len;
 	ds->hex_pfx[len] = '\0';
-	prepare_alt_odb(the_repository);
+	ds->repo = r;
+	prepare_alt_odb(r);
 	return 0;
 }
 
@@ -351,25 +360,25 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
 	struct strbuf desc = STRBUF_INIT;
 	int type;
 
-	if (ds->fn && !ds->fn(oid, ds->cb_data))
+	if (ds->fn && !ds->fn(ds->repo, oid, ds->cb_data))
 		return 0;
 
-	type = oid_object_info(the_repository, oid, NULL);
+	type = oid_object_info(ds->repo, oid, NULL);
 	if (type == OBJ_COMMIT) {
-		struct commit *commit = lookup_commit(the_repository, oid);
+		struct commit *commit = lookup_commit(ds->repo, oid);
 		if (commit) {
 			struct pretty_print_context pp = {0};
 			pp.date_mode.type = DATE_SHORT;
 			format_commit_message(commit, " %ad - %s", &desc, &pp);
 		}
 	} else if (type == OBJ_TAG) {
-		struct tag *tag = lookup_tag(the_repository, oid);
+		struct tag *tag = lookup_tag(ds->repo, oid);
 		if (!parse_tag(tag) && tag->tag)
 			strbuf_addf(&desc, " %s", tag->tag);
 	}
 
 	advise("  %s %s%s",
-	       find_unique_abbrev(oid, DEFAULT_ABBREV),
+	       repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV),
 	       type_name(type) ? type_name(type) : "unknown type",
 	       desc.buf);
 
@@ -383,6 +392,13 @@ static int collect_ambiguous(const struct object_id *oid, void *data)
 	return 0;
 }
 
+static int repo_collect_ambiguous(struct repository *r,
+				  const struct object_id *oid,
+				  void *data)
+{
+	return collect_ambiguous(oid, data);
+}
+
 static struct repository *sort_ambiguous_repo;
 static int sort_ambiguous(const void *a, const void *b)
 {
@@ -428,7 +444,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 	struct disambiguate_state ds;
 	int quietly = !!(flags & GET_OID_QUIETLY);
 
-	if (init_object_disambiguation(name, len, &ds) < 0)
+	if (init_object_disambiguation(the_repository, name, len, &ds) < 0)
 		return -1;
 
 	if (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))
@@ -483,11 +499,11 @@ int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)
 	struct disambiguate_state ds;
 	int ret;
 
-	if (init_object_disambiguation(prefix, strlen(prefix), &ds) < 0)
+	if (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0)
 		return -1;
 
 	ds.always_call_fn = 1;
-	ds.fn = collect_ambiguous;
+	ds.fn = repo_collect_ambiguous;
 	ds.cb_data = &collect;
 	find_short_object_filename(&ds);
 	find_short_packed_object(&ds);
@@ -543,6 +559,13 @@ static int extend_abbrev_len(const struct object_id *oid, void *cb_data)
 	return 0;
 }
 
+static int repo_extend_abbrev_len(struct repository *r,
+				  const struct object_id *oid,
+				  void *cb_data)
+{
+	return extend_abbrev_len(oid, cb_data);
+}
+
 static void find_abbrev_len_for_midx(struct multi_pack_index *m,
 				     struct min_abbrev_data *mad)
 {
@@ -668,10 +691,10 @@ int repo_find_unique_abbrev_r(struct repository *r, char *hex,
 
 	find_abbrev_len_packed(&mad);
 
-	if (init_object_disambiguation(hex, mad.cur_len, &ds) < 0)
+	if (init_object_disambiguation(r, hex, mad.cur_len, &ds) < 0)
 		return -1;
 
-	ds.fn = extend_abbrev_len;
+	ds.fn = repo_extend_abbrev_len;
 	ds.always_call_fn = 1;
 	ds.cb_data = (void *)&mad;
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 14/31] sha1-name.c: add repo_for_each_abbrev()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (12 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 13/31] sha1-name.c: store and use repo in struct disambiguate_state Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 15/31] sha1-name.c: remove the_repo from get_short_oid() Nguyễn Thái Ngọc Duy
                   ` (17 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 3 ++-
 sha1-name.c | 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/cache.h b/cache.h
index 4f8ebb0a67..0cb95c0d4f 100644
--- a/cache.h
+++ b/cache.h
@@ -1392,7 +1392,8 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c
 				struct object_context *oc);
 
 typedef int each_abbrev_fn(const struct object_id *oid, void *);
-extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
+int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);
+#define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data)
 
 extern int set_disambiguate_hint_config(const char *var, const char *value);
 
diff --git a/sha1-name.c b/sha1-name.c
index a75992eb54..cdcf84b826 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -493,13 +493,14 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 	return status;
 }
 
-int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)
+int repo_for_each_abbrev(struct repository *r, const char *prefix,
+			 each_abbrev_fn fn, void *cb_data)
 {
 	struct oid_array collect = OID_ARRAY_INIT;
 	struct disambiguate_state ds;
 	int ret;
 
-	if (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0)
+	if (init_object_disambiguation(r, prefix, strlen(prefix), &ds) < 0)
 		return -1;
 
 	ds.always_call_fn = 1;
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 15/31] sha1-name.c: remove the_repo from get_short_oid()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (13 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 14/31] sha1-name.c: add repo_for_each_abbrev() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 16/31] sha1-name.c: remove the_repo from interpret_nth_prior_checkout() Nguyễn Thái Ngọc Duy
                   ` (16 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index cdcf84b826..2643b75b54 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -436,7 +436,8 @@ static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)
 	sort_ambiguous_repo = NULL;
 }
 
-static enum get_oid_result get_short_oid(const char *name, int len,
+static enum get_oid_result get_short_oid(struct repository *r,
+					 const char *name, int len,
 					 struct object_id *oid,
 					 unsigned flags)
 {
@@ -444,7 +445,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 	struct disambiguate_state ds;
 	int quietly = !!(flags & GET_OID_QUIETLY);
 
-	if (init_object_disambiguation(the_repository, name, len, &ds) < 0)
+	if (init_object_disambiguation(r, name, len, &ds) < 0)
 		return -1;
 
 	if (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))
@@ -482,8 +483,8 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 			ds.fn = NULL;
 
 		advise(_("The candidates are:"));
-		for_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect);
-		sort_ambiguous_oid_array(the_repository, &collect);
+		repo_for_each_abbrev(r, ds.hex_pfx, collect_ambiguous, &collect);
+		sort_ambiguous_oid_array(r, &collect);
 
 		if (oid_array_for_each(&collect, show_ambiguous_object, &ds))
 			BUG("show_ambiguous_object shouldn't return non-zero");
@@ -855,7 +856,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 
 	if (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&
 	    (refs_found > 1 ||
-	     !get_short_oid(str, len, &tmp_oid, GET_OID_QUIETLY)))
+	     !get_short_oid(the_repository,
+			    str, len, &tmp_oid, GET_OID_QUIETLY)))
 		warning(warn_msg, len, str);
 
 	if (reflog_len) {
@@ -1109,7 +1111,8 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)
 			if (ch == 'g' && cp[-1] == '-') {
 				cp++;
 				len -= cp - name;
-				return get_short_oid(cp, len, oid, flags);
+				return get_short_oid(the_repository,
+						     cp, len, oid, flags);
 			}
 		}
 	}
@@ -1163,7 +1166,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,
 	if (!ret)
 		return FOUND;
 
-	return get_short_oid(name, len, oid, lookup_flags);
+	return get_short_oid(the_repository, name, len, oid, lookup_flags);
 }
 
 /*
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 16/31] sha1-name.c: remove the_repo from interpret_nth_prior_checkout()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (14 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 15/31] sha1-name.c: remove the_repo from get_short_oid() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 17/31] sha1-name.c: remove the_repo from interpret_branch_mark() Nguyễn Thái Ngọc Duy
                   ` (15 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 2643b75b54..af8bf5b351 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -771,7 +771,7 @@ static inline int push_mark(const char *string, int len)
 }
 
 static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
-static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);
+static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);
 
 static int get_oid_basic(const char *str, int len, struct object_id *oid,
 			  unsigned int flags)
@@ -835,7 +835,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 		struct strbuf buf = STRBUF_INIT;
 		int detached;
 
-		if (interpret_nth_prior_checkout(str, len, &buf) > 0) {
+		if (interpret_nth_prior_checkout(the_repository, str, len, &buf) > 0) {
 			detached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));
 			strbuf_release(&buf);
 			if (detached)
@@ -1288,7 +1288,8 @@ static int grab_nth_branch_switch(struct object_id *ooid, struct object_id *noid
  * Parse @{-N} syntax, return the number of characters parsed
  * if successful; otherwise signal an error with negative value.
  */
-static int interpret_nth_prior_checkout(const char *name, int namelen,
+static int interpret_nth_prior_checkout(struct repository *r,
+					const char *name, int namelen,
 					struct strbuf *buf)
 {
 	long nth;
@@ -1312,12 +1313,14 @@ static int interpret_nth_prior_checkout(const char *name, int namelen,
 	cb.remaining = nth;
 	strbuf_init(&cb.buf, 20);
 
-	retval = 0;
-	if (0 < for_each_reflog_ent_reverse("HEAD", grab_nth_branch_switch, &cb)) {
+	retval = refs_for_each_reflog_ent_reverse(get_main_ref_store(r),
+			"HEAD", grab_nth_branch_switch, &cb);
+	if (0 < retval) {
 		strbuf_reset(buf);
 		strbuf_addbuf(buf, &cb.buf);
 		retval = brace - name + 1;
-	}
+	} else
+		retval = 0;
 
 	strbuf_release(&cb.buf);
 	return retval;
@@ -1484,7 +1487,7 @@ int repo_interpret_branch_name(struct repository *r,
 		namelen = strlen(name);
 
 	if (!allowed || (allowed & INTERPRET_BRANCH_LOCAL)) {
-		len = interpret_nth_prior_checkout(name, namelen, buf);
+		len = interpret_nth_prior_checkout(the_repository, name, namelen, buf);
 		if (!len) {
 			return len; /* syntax Ok, not enough switches */
 		} else if (len > 0) {
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 17/31] sha1-name.c: remove the_repo from interpret_branch_mark()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (15 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 16/31] sha1-name.c: remove the_repo from interpret_nth_prior_checkout() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 18/31] sha1-name.c: add repo_interpret_branch_name() Nguyễn Thái Ngọc Duy
                   ` (14 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index af8bf5b351..7d9512ac44 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1412,9 +1412,9 @@ static int reinterpret(const char *name, int namelen, int len,
 	return ret - used + len;
 }
 
-static void set_shortened_ref(struct strbuf *buf, const char *ref)
+static void set_shortened_ref(struct repository *r, struct strbuf *buf, const char *ref)
 {
-	char *s = shorten_unambiguous_ref(ref, 0);
+	char *s = refs_shorten_unambiguous_ref(get_main_ref_store(r), ref, 0);
 	strbuf_reset(buf);
 	strbuf_addstr(buf, s);
 	free(s);
@@ -1435,7 +1435,8 @@ static int branch_interpret_allowed(const char *refname, unsigned allowed)
 	return 0;
 }
 
-static int interpret_branch_mark(const char *name, int namelen,
+static int interpret_branch_mark(struct repository *r,
+				 const char *name, int namelen,
 				 int at, struct strbuf *buf,
 				 int (*get_mark)(const char *, int),
 				 const char *(*get_data)(struct branch *,
@@ -1468,7 +1469,7 @@ static int interpret_branch_mark(const char *name, int namelen,
 	if (!branch_interpret_allowed(value, allowed))
 		return -1;
 
-	set_shortened_ref(buf, value);
+	set_shortened_ref(r, buf, value);
 	return len + at;
 }
 
@@ -1509,13 +1510,13 @@ int repo_interpret_branch_name(struct repository *r,
 						   allowed);
 		}
 
-		len = interpret_branch_mark(name, namelen, at - name, buf,
+		len = interpret_branch_mark(the_repository, name, namelen, at - name, buf,
 					    upstream_mark, branch_get_upstream,
 					    allowed);
 		if (len > 0)
 			return len;
 
-		len = interpret_branch_mark(name, namelen, at - name, buf,
+		len = interpret_branch_mark(the_repository, name, namelen, at - name, buf,
 					    push_mark, branch_get_push,
 					    allowed);
 		if (len > 0)
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 18/31] sha1-name.c: add repo_interpret_branch_name()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (16 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 17/31] sha1-name.c: remove the_repo from interpret_branch_mark() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 19/31] sha1-name.c: remove the_repo from get_oid_oneline() Nguyễn Thái Ngọc Duy
                   ` (13 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 7d9512ac44..49c62d5254 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1390,7 +1390,8 @@ static int interpret_empty_at(const char *name, int namelen, int len, struct str
 	return 1;
 }
 
-static int reinterpret(const char *name, int namelen, int len,
+static int reinterpret(struct repository *r,
+		       const char *name, int namelen, int len,
 		       struct strbuf *buf, unsigned allowed)
 {
 	/* we have extra data, which might need further processing */
@@ -1399,7 +1400,7 @@ static int reinterpret(const char *name, int namelen, int len,
 	int ret;
 
 	strbuf_add(buf, name + len, namelen - len);
-	ret = interpret_branch_name(buf->buf, buf->len, &tmp, allowed);
+	ret = repo_interpret_branch_name(r, buf->buf, buf->len, &tmp, allowed);
 	/* that data was not interpreted, remove our cruft */
 	if (ret < 0) {
 		strbuf_setlen(buf, used);
@@ -1482,20 +1483,18 @@ int repo_interpret_branch_name(struct repository *r,
 	const char *start;
 	int len;
 
-	if (r != the_repository)
-		BUG("interpret_branch_name() does not really use 'r' yet");
 	if (!namelen)
 		namelen = strlen(name);
 
 	if (!allowed || (allowed & INTERPRET_BRANCH_LOCAL)) {
-		len = interpret_nth_prior_checkout(the_repository, name, namelen, buf);
+		len = interpret_nth_prior_checkout(r, name, namelen, buf);
 		if (!len) {
 			return len; /* syntax Ok, not enough switches */
 		} else if (len > 0) {
 			if (len == namelen)
 				return len; /* consumed all */
 			else
-				return reinterpret(name, namelen, len, buf, allowed);
+				return reinterpret(r, name, namelen, len, buf, allowed);
 		}
 	}
 
@@ -1506,17 +1505,17 @@ int repo_interpret_branch_name(struct repository *r,
 		if (!allowed || (allowed & INTERPRET_BRANCH_HEAD)) {
 			len = interpret_empty_at(name, namelen, at - name, buf);
 			if (len > 0)
-				return reinterpret(name, namelen, len, buf,
+				return reinterpret(r, name, namelen, len, buf,
 						   allowed);
 		}
 
-		len = interpret_branch_mark(the_repository, name, namelen, at - name, buf,
+		len = interpret_branch_mark(r, name, namelen, at - name, buf,
 					    upstream_mark, branch_get_upstream,
 					    allowed);
 		if (len > 0)
 			return len;
 
-		len = interpret_branch_mark(the_repository, name, namelen, at - name, buf,
+		len = interpret_branch_mark(r, name, namelen, at - name, buf,
 					    push_mark, branch_get_push,
 					    allowed);
 		if (len > 0)
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 19/31] sha1-name.c: remove the_repo from get_oid_oneline()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (17 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 18/31] sha1-name.c: add repo_interpret_branch_name() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 20/31] sha1-name.c: remove the_repo from get_describe_name() Nguyễn Thái Ngọc Duy
                   ` (12 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 49c62d5254..fb80306f1a 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -15,7 +15,7 @@
 #include "midx.h"
 #include "commit-reach.h"
 
-static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
+static int get_oid_oneline(struct repository *r, const char *, struct object_id *, struct commit_list *);
 
 typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);
 
@@ -1090,7 +1090,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 
 		prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
 		commit_list_insert((struct commit *)o, &list);
-		ret = get_oid_oneline(prefix, oid, list);
+		ret = get_oid_oneline(the_repository, prefix, oid, list);
 		free(prefix);
 		return ret;
 	}
@@ -1204,8 +1204,9 @@ static int handle_one_ref(const char *path, const struct object_id *oid,
 	return 0;
 }
 
-static int get_oid_oneline(const char *prefix, struct object_id *oid,
-			    struct commit_list *list)
+static int get_oid_oneline(struct repository *r,
+			   const char *prefix, struct object_id *oid,
+			   struct commit_list *list)
 {
 	struct commit_list *backup = NULL, *l;
 	int found = 0;
@@ -1236,7 +1237,7 @@ static int get_oid_oneline(const char *prefix, struct object_id *oid,
 		int matches;
 
 		commit = pop_most_recent_commit(&list, ONELINE_SEEN);
-		if (!parse_object(the_repository, &commit->object.oid))
+		if (!parse_object(r, &commit->object.oid))
 			continue;
 		buf = get_commit_buffer(commit, NULL);
 		p = strstr(buf, "\n\n");
@@ -1760,7 +1761,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			for_each_ref(handle_one_ref, &list);
 			head_ref(handle_one_ref, &list);
 			commit_list_sort_by_date(&list);
-			return get_oid_oneline(name + 2, oid, list);
+			return get_oid_oneline(repo, name + 2, oid, list);
 		}
 		if (namelen < 3 ||
 		    name[2] != ':' ||
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 20/31] sha1-name.c: remove the_repo from get_describe_name()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (18 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 19/31] sha1-name.c: remove the_repo from get_oid_oneline() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 21/31] sha1-name.c: remove the_repo from get_oid_basic() Nguyễn Thái Ngọc Duy
                   ` (11 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index fb80306f1a..1cda854f02 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1097,7 +1097,9 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 	return 0;
 }
 
-static int get_describe_name(const char *name, int len, struct object_id *oid)
+static int get_describe_name(struct repository *r,
+			     const char *name, int len,
+			     struct object_id *oid)
 {
 	const char *cp;
 	unsigned flags = GET_OID_QUIETLY | GET_OID_COMMIT;
@@ -1111,7 +1113,7 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)
 			if (ch == 'g' && cp[-1] == '-') {
 				cp++;
 				len -= cp - name;
-				return get_short_oid(the_repository,
+				return get_short_oid(r,
 						     cp, len, oid, flags);
 			}
 		}
@@ -1162,7 +1164,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,
 		return FOUND;
 
 	/* It could be describe output that is "SOMETHING-gXXXX" */
-	ret = get_describe_name(name, len, oid);
+	ret = get_describe_name(the_repository, name, len, oid);
 	if (!ret)
 		return FOUND;
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 21/31] sha1-name.c: remove the_repo from get_oid_basic()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (19 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 20/31] sha1-name.c: remove the_repo from get_describe_name() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 22/31] sha1-name.c: remove the_repo from get_oid_1() Nguyễn Thái Ngọc Duy
                   ` (10 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 1cda854f02..d4c135aea8 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -773,8 +773,8 @@ static inline int push_mark(const char *string, int len)
 static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
 static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);
 
-static int get_oid_basic(const char *str, int len, struct object_id *oid,
-			  unsigned int flags)
+static int get_oid_basic(struct repository *r, const char *str, int len,
+			 struct object_id *oid, unsigned int flags)
 {
 	static const char *warn_msg = "refname '%.*s' is ambiguous.";
 	static const char *object_name_msg = N_(
@@ -792,9 +792,9 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 	int refs_found = 0;
 	int at, reflog_len, nth_prior = 0;
 
-	if (len == the_hash_algo->hexsz && !get_oid_hex(str, oid)) {
+	if (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {
 		if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
-			refs_found = dwim_ref(str, len, &tmp_oid, &real_ref);
+			refs_found = repo_dwim_ref(r, str, len, &tmp_oid, &real_ref);
 			if (refs_found > 0) {
 				warning(warn_msg, len, str);
 				if (advice_object_name_warning)
@@ -835,8 +835,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 		struct strbuf buf = STRBUF_INIT;
 		int detached;
 
-		if (interpret_nth_prior_checkout(the_repository, str, len, &buf) > 0) {
-			detached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));
+		if (interpret_nth_prior_checkout(r, str, len, &buf) > 0) {
+			detached = (buf.len == r->hash_algo->hexsz && !get_oid_hex(buf.buf, oid));
 			strbuf_release(&buf);
 			if (detached)
 				return 0;
@@ -845,19 +845,18 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 
 	if (!len && reflog_len)
 		/* allow "@{...}" to mean the current branch reflog */
-		refs_found = dwim_ref("HEAD", 4, oid, &real_ref);
+		refs_found = repo_dwim_ref(r, "HEAD", 4, oid, &real_ref);
 	else if (reflog_len)
-		refs_found = dwim_log(str, len, oid, &real_ref);
+		refs_found = repo_dwim_log(r, str, len, oid, &real_ref);
 	else
-		refs_found = dwim_ref(str, len, oid, &real_ref);
+		refs_found = repo_dwim_ref(r, str, len, oid, &real_ref);
 
 	if (!refs_found)
 		return -1;
 
 	if (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&
 	    (refs_found > 1 ||
-	     !get_short_oid(the_repository,
-			    str, len, &tmp_oid, GET_OID_QUIETLY)))
+	     !get_short_oid(r, str, len, &tmp_oid, GET_OID_QUIETLY)))
 		warning(warn_msg, len, str);
 
 	if (reflog_len) {
@@ -889,7 +888,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 				return -1;
 			}
 		}
-		if (read_ref_at(get_main_ref_store(the_repository),
+		if (read_ref_at(get_main_ref_store(r),
 				real_ref, flags, at_time, nth, oid, NULL,
 				&co_time, &co_tz, &co_cnt)) {
 			if (!len) {
@@ -1159,7 +1158,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,
 	if (!ret)
 		return FOUND;
 
-	ret = get_oid_basic(name, len, oid, lookup_flags);
+	ret = get_oid_basic(the_repository, name, len, oid, lookup_flags);
 	if (!ret)
 		return FOUND;
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 22/31] sha1-name.c: remove the_repo from get_oid_1()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (20 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 21/31] sha1-name.c: remove the_repo from get_oid_basic() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 23/31] sha1-name.c: remove the_repo from handle_one_ref() Nguyễn Thái Ngọc Duy
                   ` (9 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

There is a cyclic dependency between one of these functions so they
cannot be converted one by one, so all related functions are converted
at once.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     |  7 +++++--
 sha1-name.c | 59 ++++++++++++++++++++++++++++-------------------------
 2 files changed, 36 insertions(+), 30 deletions(-)

diff --git a/cache.h b/cache.h
index 0cb95c0d4f..2149dc4f56 100644
--- a/cache.h
+++ b/cache.h
@@ -1491,8 +1491,11 @@ extern void *read_object_with_reference(const struct object_id *oid,
 					unsigned long *size,
 					struct object_id *oid_ret);
 
-extern struct object *peel_to_type(const char *name, int namelen,
-				   struct object *o, enum object_type);
+struct object *repo_peel_to_type(struct repository *r,
+				 const char *name, int namelen,
+				 struct object *o, enum object_type);
+#define peel_to_type(name, namelen, obj, type) \
+	repo_peel_to_type(the_repository, name, namelen, obj, type)
 
 enum date_mode_type {
 	DATE_NORMAL = 0,
diff --git a/sha1-name.c b/sha1-name.c
index d4c135aea8..5741a9f821 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -770,7 +770,7 @@ static inline int push_mark(const char *string, int len)
 	return at_mark(string, len, suffix, ARRAY_SIZE(suffix));
 }
 
-static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
+static enum get_oid_result get_oid_1(struct repository *r, const char *name, int len, struct object_id *oid, unsigned lookup_flags);
 static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);
 
 static int get_oid_basic(struct repository *r, const char *str, int len,
@@ -921,18 +921,19 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
 	return 0;
 }
 
-static enum get_oid_result get_parent(const char *name, int len,
+static enum get_oid_result get_parent(struct repository *r,
+				      const char *name, int len,
 				      struct object_id *result, int idx)
 {
 	struct object_id oid;
-	enum get_oid_result ret = get_oid_1(name, len, &oid,
+	enum get_oid_result ret = get_oid_1(r, name, len, &oid,
 					    GET_OID_COMMITTISH);
 	struct commit *commit;
 	struct commit_list *p;
 
 	if (ret)
 		return ret;
-	commit = lookup_commit_reference(the_repository, &oid);
+	commit = lookup_commit_reference(r, &oid);
 	if (parse_commit(commit))
 		return MISSING_OBJECT;
 	if (!idx) {
@@ -950,7 +951,8 @@ static enum get_oid_result get_parent(const char *name, int len,
 	return MISSING_OBJECT;
 }
 
-static enum get_oid_result get_nth_ancestor(const char *name, int len,
+static enum get_oid_result get_nth_ancestor(struct repository *r,
+					    const char *name, int len,
 					    struct object_id *result,
 					    int generation)
 {
@@ -958,10 +960,10 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,
 	struct commit *commit;
 	int ret;
 
-	ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);
+	ret = get_oid_1(r, name, len, &oid, GET_OID_COMMITTISH);
 	if (ret)
 		return ret;
-	commit = lookup_commit_reference(the_repository, &oid);
+	commit = lookup_commit_reference(r, &oid);
 	if (!commit)
 		return MISSING_OBJECT;
 
@@ -974,20 +976,20 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,
 	return FOUND;
 }
 
-struct object *peel_to_type(const char *name, int namelen,
-			    struct object *o, enum object_type expected_type)
+struct object *repo_peel_to_type(struct repository *r, const char *name, int namelen,
+				 struct object *o, enum object_type expected_type)
 {
 	if (name && !namelen)
 		namelen = strlen(name);
 	while (1) {
-		if (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))
+		if (!o || (!o->parsed && !parse_object(r, &o->oid)))
 			return NULL;
 		if (expected_type == OBJ_ANY || o->type == expected_type)
 			return o;
 		if (o->type == OBJ_TAG)
 			o = ((struct tag*) o)->tagged;
 		else if (o->type == OBJ_COMMIT)
-			o = &(get_commit_tree(((struct commit *)o))->object);
+			o = &(repo_get_commit_tree(r, ((struct commit *)o))->object);
 		else {
 			if (name)
 				error("%.*s: expected %s type, but the object "
@@ -999,8 +1001,8 @@ struct object *peel_to_type(const char *name, int namelen,
 	}
 }
 
-static int peel_onion(const char *name, int len, struct object_id *oid,
-		      unsigned lookup_flags)
+static int peel_onion(struct repository *r, const char *name, int len,
+		      struct object_id *oid, unsigned lookup_flags)
 {
 	struct object_id outer;
 	const char *sp;
@@ -1050,15 +1052,15 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 	else if (expected_type == OBJ_TREE)
 		lookup_flags |= GET_OID_TREEISH;
 
-	if (get_oid_1(name, sp - name - 2, &outer, lookup_flags))
+	if (get_oid_1(r, name, sp - name - 2, &outer, lookup_flags))
 		return -1;
 
-	o = parse_object(the_repository, &outer);
+	o = parse_object(r, &outer);
 	if (!o)
 		return -1;
 	if (!expected_type) {
-		o = deref_tag(the_repository, o, name, sp - name - 2);
-		if (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))
+		o = deref_tag(r, o, name, sp - name - 2);
+		if (!o || (!o->parsed && !parse_object(r, &o->oid)))
 			return -1;
 		oidcpy(oid, &o->oid);
 		return 0;
@@ -1069,7 +1071,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 	 * if we do not get the needed object, we should
 	 * barf.
 	 */
-	o = peel_to_type(name, len, o, expected_type);
+	o = repo_peel_to_type(r, name, len, o, expected_type);
 	if (!o)
 		return -1;
 
@@ -1089,7 +1091,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 
 		prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
 		commit_list_insert((struct commit *)o, &list);
-		ret = get_oid_oneline(the_repository, prefix, oid, list);
+		ret = get_oid_oneline(r, prefix, oid, list);
 		free(prefix);
 		return ret;
 	}
@@ -1120,7 +1122,8 @@ static int get_describe_name(struct repository *r,
 	return -1;
 }
 
-static enum get_oid_result get_oid_1(const char *name, int len,
+static enum get_oid_result get_oid_1(struct repository *r,
+				     const char *name, int len,
 				     struct object_id *oid,
 				     unsigned lookup_flags)
 {
@@ -1149,25 +1152,25 @@ static enum get_oid_result get_oid_1(const char *name, int len,
 		if (!num && len1 == len - 1)
 			num = 1;
 		if (has_suffix == '^')
-			return get_parent(name, len1, oid, num);
+			return get_parent(r, name, len1, oid, num);
 		/* else if (has_suffix == '~') -- goes without saying */
-		return get_nth_ancestor(name, len1, oid, num);
+		return get_nth_ancestor(r, name, len1, oid, num);
 	}
 
-	ret = peel_onion(name, len, oid, lookup_flags);
+	ret = peel_onion(r, name, len, oid, lookup_flags);
 	if (!ret)
 		return FOUND;
 
-	ret = get_oid_basic(the_repository, name, len, oid, lookup_flags);
+	ret = get_oid_basic(r, name, len, oid, lookup_flags);
 	if (!ret)
 		return FOUND;
 
 	/* It could be describe output that is "SOMETHING-gXXXX" */
-	ret = get_describe_name(the_repository, name, len, oid);
+	ret = get_describe_name(r, name, len, oid);
 	if (!ret)
 		return FOUND;
 
-	return get_short_oid(the_repository, name, len, oid, lookup_flags);
+	return get_short_oid(r, name, len, oid, lookup_flags);
 }
 
 /*
@@ -1741,7 +1744,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 	memset(oc, 0, sizeof(*oc));
 	oc->mode = S_IFINVALID;
 	strbuf_init(&oc->symlink_path, 0);
-	ret = get_oid_1(name, namelen, oid, flags);
+	ret = get_oid_1(repo, name, namelen, oid, flags);
 	if (!ret)
 		return ret;
 	/*
@@ -1822,7 +1825,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 		sub_flags &= ~GET_OID_DISAMBIGUATORS;
 		sub_flags |= GET_OID_TREEISH;
 
-		if (!get_oid_1(name, len, &tree_oid, sub_flags)) {
+		if (!get_oid_1(repo, name, len, &tree_oid, sub_flags)) {
 			const char *filename = cp+1;
 			char *new_filename = NULL;
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 23/31] sha1-name.c: remove the_repo from handle_one_ref()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (21 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 22/31] sha1-name.c: remove the_repo from get_oid_1() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 24/31] sha1-name.c: remove the_repo from diagnose_invalid_index_path() Nguyễn Thái Ngọc Duy
                   ` (8 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 5741a9f821..d9050776dd 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1189,15 +1189,21 @@ static enum get_oid_result get_oid_1(struct repository *r,
 /* Remember to update object flag allocation in object.h */
 #define ONELINE_SEEN (1u<<20)
 
+struct handle_one_ref_cb {
+	struct repository *repo;
+	struct commit_list **list;
+};
+
 static int handle_one_ref(const char *path, const struct object_id *oid,
 			  int flag, void *cb_data)
 {
-	struct commit_list **list = cb_data;
-	struct object *object = parse_object(the_repository, oid);
+	struct handle_one_ref_cb *cb = cb_data;
+	struct commit_list **list = cb->list;
+	struct object *object = parse_object(cb->repo, oid);
 	if (!object)
 		return 0;
 	if (object->type == OBJ_TAG) {
-		object = deref_tag(the_repository, object, path,
+		object = deref_tag(cb->repo, object, path,
 				   strlen(path));
 		if (!object)
 			return 0;
@@ -1760,10 +1766,13 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 		char *new_path = NULL;
 		int pos;
 		if (!only_to_die && namelen > 2 && name[1] == '/') {
+			struct handle_one_ref_cb cb;
 			struct commit_list *list = NULL;
 
-			for_each_ref(handle_one_ref, &list);
-			head_ref(handle_one_ref, &list);
+			cb.repo = repo;
+			cb.list = &list;
+			refs_for_each_ref(repo->refs, handle_one_ref, &cb);
+			refs_head_ref(repo->refs, handle_one_ref, &cb);
 			commit_list_sort_by_date(&list);
 			return get_oid_oneline(repo, name + 2, oid, list);
 		}
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 24/31] sha1-name.c: remove the_repo from diagnose_invalid_index_path()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (22 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 23/31] sha1-name.c: remove the_repo from handle_one_ref() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 25/31] sha1-name.c: remove the_repo from resolve_relative_path() Nguyễn Thái Ngọc Duy
                   ` (7 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 dir.c       | 8 ++++++++
 dir.h       | 4 +++-
 sha1-name.c | 7 ++++---
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/dir.c b/dir.c
index b2cabadf25..e6d97343f4 100644
--- a/dir.c
+++ b/dir.c
@@ -2315,6 +2315,14 @@ int file_exists(const char *f)
 	return lstat(f, &sb) == 0;
 }
 
+int repo_file_exists(struct repository *repo, const char *path)
+{
+	if (repo != the_repository)
+		BUG("do not know how to check file existence in arbitrary repo");
+
+	return file_exists(path);
+}
+
 static int cmp_icase(char a, char b)
 {
 	if (a == b)
diff --git a/dir.h b/dir.h
index e3ec26143d..47c5409ced 100644
--- a/dir.h
+++ b/dir.h
@@ -269,7 +269,9 @@ extern void add_exclude(const char *string, const char *base,
 			int baselen, struct exclude_list *el, int srcpos);
 extern void clear_exclude_list(struct exclude_list *el);
 extern void clear_directory(struct dir_struct *dir);
-extern int file_exists(const char *);
+
+int repo_file_exists(struct repository *repo, const char *path);
+int file_exists(const char *);
 
 extern int is_inside_dir(const char *dir);
 extern int dir_inside_of(const char *subdir, const char *dir);
diff --git a/sha1-name.c b/sha1-name.c
index d9050776dd..6caf3f4e3a 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1664,11 +1664,12 @@ static void diagnose_invalid_oid_path(const char *prefix,
 }
 
 /* Must be called only when :stage:filename doesn't exist. */
-static void diagnose_invalid_index_path(struct index_state *istate,
+static void diagnose_invalid_index_path(struct repository *r,
 					int stage,
 					const char *prefix,
 					const char *filename)
 {
+	struct index_state *istate = r->index;
 	const struct cache_entry *ce;
 	int pos;
 	unsigned namelen = strlen(filename);
@@ -1708,7 +1709,7 @@ static void diagnose_invalid_index_path(struct index_state *istate,
 			    ce_stage(ce), filename);
 	}
 
-	if (file_exists(filename))
+	if (repo_file_exists(r, filename))
 		die("Path '%s' exists on disk, but not in the index.", filename);
 	if (is_missing_file_error(errno))
 		die("Path '%s' does not exist (neither on disk nor in the index).",
@@ -1814,7 +1815,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			pos++;
 		}
 		if (only_to_die && name[1] && name[1] != '/')
-			diagnose_invalid_index_path(repo->index, stage, prefix, cp);
+			diagnose_invalid_index_path(repo, stage, prefix, cp);
 		free(new_path);
 		return -1;
 	}
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 25/31] sha1-name.c: remove the_repo from resolve_relative_path()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (23 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 24/31] sha1-name.c: remove the_repo from diagnose_invalid_index_path() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 26/31] sha1-name.c: remove the_repo from get_oid_with_context_1() Nguyễn Thái Ngọc Duy
                   ` (6 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

"remove" is not entirely correct. But at least the function is aware
that if the given repo is not the_repository, then $CWD and
is_inside_work_tree() means nothing.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 6caf3f4e3a..6b53ea2eeb 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1719,12 +1719,12 @@ static void diagnose_invalid_index_path(struct repository *r,
 }
 
 
-static char *resolve_relative_path(const char *rel)
+static char *resolve_relative_path(struct repository *r, const char *rel)
 {
 	if (!starts_with(rel, "./") && !starts_with(rel, "../"))
 		return NULL;
 
-	if (!is_inside_work_tree())
+	if (r != the_repository || !is_inside_work_tree())
 		die("relative path syntax can't be used outside working tree.");
 
 	/* die() inside prefix_path() if resolved path is outside worktree */
@@ -1785,7 +1785,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			stage = name[1] - '0';
 			cp = name + 3;
 		}
-		new_path = resolve_relative_path(cp);
+		new_path = resolve_relative_path(repo, cp);
 		if (!new_path) {
 			namelen = namelen - (cp - name);
 		} else {
@@ -1839,7 +1839,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			const char *filename = cp+1;
 			char *new_filename = NULL;
 
-			new_filename = resolve_relative_path(filename);
+			new_filename = resolve_relative_path(repo, filename);
 			if (new_filename)
 				filename = new_filename;
 			if (flags & GET_OID_FOLLOW_SYMLINKS) {
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 26/31] sha1-name.c: remove the_repo from get_oid_with_context_1()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (24 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 25/31] sha1-name.c: remove the_repo from resolve_relative_path() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 27/31] sha1-name.c: add repo_get_oid() Nguyễn Thái Ngọc Duy
                   ` (5 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/sha1-name.c b/sha1-name.c
index 6b53ea2eeb..64a50d1291 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -12,6 +12,7 @@
 #include "packfile.h"
 #include "object-store.h"
 #include "repository.h"
+#include "submodule.h"
 #include "midx.h"
 #include "commit-reach.h"
 
@@ -1797,7 +1798,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			oc->path = xstrdup(cp);
 
 		if (!repo->index->cache)
-			repo_read_index(the_repository);
+			repo_read_index(repo);
 		pos = index_name_pos(repo->index, cp, namelen);
 		if (pos < 0)
 			pos = -pos - 1;
@@ -1842,6 +1843,14 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			new_filename = resolve_relative_path(repo, filename);
 			if (new_filename)
 				filename = new_filename;
+			/*
+			 * NEEDSWORK: Eventually get_tree_entry*() should
+			 * learn to take struct repository directly and we
+			 * would not need to inject submodule odb to the
+			 * in-core odb.
+			 */
+			if (repo != the_repository)
+				add_to_alternates_memory(repo->objects->odb->path);
 			if (flags & GET_OID_FOLLOW_SYMLINKS) {
 				ret = get_tree_entry_follow_symlinks(&tree_oid,
 					filename, oid, &oc->symlink_path,
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 27/31] sha1-name.c: add repo_get_oid()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (25 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 26/31] sha1-name.c: remove the_repo from get_oid_with_context_1() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 28/31] submodule-config.c: use repo_get_oid for reading .gitmodules Nguyễn Thái Ngọc Duy
                   ` (4 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 3 ++-
 sha1-name.c | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/cache.h b/cache.h
index 2149dc4f56..f6e87194d0 100644
--- a/cache.h
+++ b/cache.h
@@ -1380,7 +1380,8 @@ enum get_oid_result {
 		       */
 };
 
-extern int get_oid(const char *str, struct object_id *oid);
+int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);
+#define get_oid(str, oid) repo_get_oid(the_repository, str, oid)
 extern int get_oid_commit(const char *str, struct object_id *oid);
 extern int get_oid_committish(const char *str, struct object_id *oid);
 extern int get_oid_tree(const char *str, struct object_id *oid);
diff --git a/sha1-name.c b/sha1-name.c
index 64a50d1291..953df0d692 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1573,10 +1573,10 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
  * This is like "get_oid_basic()", except it allows "object ID expressions",
  * notably "xyz^" for "parent of xyz"
  */
-int get_oid(const char *name, struct object_id *oid)
+int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository, name, 0, oid, &unused);
+	return get_oid_with_context(r, name, 0, oid, &unused);
 }
 
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 28/31] submodule-config.c: use repo_get_oid for reading .gitmodules
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (26 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 27/31] sha1-name.c: add repo_get_oid() Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 29/31] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name Nguyễn Thái Ngọc Duy
                   ` (3 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Since 76e9bdc437 (submodule: support reading .gitmodules when it's not
in the working tree - 2018-10-25), every time you do

    git grep --recurse-submodules

you are likely to see one warning line per submodule (unless all those
submodules also have submodules). On a superproject with plenty of
submodules (I've seen one with 67) this is really annoying.

The warning was there because we could not resolve extended SHA-1
syntax on a submodule. We can now. Make use of the new API and get rid
of the warning.

It would be even better if config_with_options() supports multiple
repositories too. But one step at a time.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 submodule-config.c                 | 20 +++++++-------------
 t/t7814-grep-recurse-submodules.sh |  6 +-----
 2 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/submodule-config.c b/submodule-config.c
index 66653e86b9..4264ee216f 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -625,23 +625,16 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
 		const struct config_options opts = { 0 };
 		struct object_id oid;
 		char *file;
+		char *oidstr = NULL;
 
 		file = repo_worktree_path(repo, GITMODULES_FILE);
 		if (file_exists(file)) {
 			config_source.file = file;
-		} else if (repo->submodule_prefix) {
-			/*
-			 * When get_oid and config_with_options, used below,
-			 * become able to work on a specific repository, this
-			 * warning branch can be removed.
-			 */
-			warning("nested submodules without %s in the working tree are not supported yet",
-				GITMODULES_FILE);
-			goto out;
-		} else if (get_oid(GITMODULES_INDEX, &oid) >= 0) {
-			config_source.blob = GITMODULES_INDEX;
-		} else if (get_oid(GITMODULES_HEAD, &oid) >= 0) {
-			config_source.blob = GITMODULES_HEAD;
+		} else if (repo_get_oid(repo, GITMODULES_INDEX, &oid) >= 0 ||
+			   repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
+			config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
+			if (repo != the_repository)
+				add_to_alternates_memory(repo->objects->odb->path);
 		} else {
 			goto out;
 		}
@@ -649,6 +642,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
 		config_with_options(fn, data, &config_source, &opts);
 
 out:
+		free(oidstr);
 		free(file);
 	}
 }
diff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh
index fa475d52fa..134a694516 100755
--- a/t/t7814-grep-recurse-submodules.sh
+++ b/t/t7814-grep-recurse-submodules.sh
@@ -380,11 +380,7 @@ test_expect_success 'grep --recurse-submodules should pass the pattern type alon
 	fi
 '
 
-# Recursing down into nested submodules which do not have .gitmodules in their
-# working tree does not work yet. This is because config_from_gitmodules()
-# uses get_oid() and the latter is still not able to get objects from an
-# arbitrary repository (the nested submodule, in this case).
-test_expect_failure 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '
+test_expect_success 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '
 	test_when_finished "git -C submodule checkout .gitmodules" &&
 	rm submodule/.gitmodules &&
 	git grep --recurse-submodules -e "(.|.)[\d]" >actual &&
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 29/31] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (27 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 28/31] submodule-config.c: use repo_get_oid for reading .gitmodules Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 30/31] sha1-name.c: remove the_repo from other get_oid_* Nguyễn Thái Ngọc Duy
                   ` (2 subsequent siblings)
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 4 +++-
 setup.c     | 7 ++++---
 sha1-name.c | 6 ++++--
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/cache.h b/cache.h
index f6e87194d0..3718b3db8a 100644
--- a/cache.h
+++ b/cache.h
@@ -1387,7 +1387,9 @@ extern int get_oid_committish(const char *str, struct object_id *oid);
 extern int get_oid_tree(const char *str, struct object_id *oid);
 extern int get_oid_treeish(const char *str, struct object_id *oid);
 extern int get_oid_blob(const char *str, struct object_id *oid);
-extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
+void maybe_die_on_misspelt_object_name(struct repository *repo,
+				       const char *name,
+				       const char *prefix);
 extern enum get_oid_result get_oid_with_context(struct repository *repo, const char *str,
 				unsigned flags, struct object_id *oid,
 				struct object_context *oc);
diff --git a/setup.c b/setup.c
index d0c958c3b2..8dcb4631f7 100644
--- a/setup.c
+++ b/setup.c
@@ -164,7 +164,8 @@ int check_filename(const char *prefix, const char *arg)
 	die_errno(_("failed to stat '%s'"), arg);
 }
 
-static void NORETURN die_verify_filename(const char *prefix,
+static void NORETURN die_verify_filename(struct repository *r,
+					 const char *prefix,
 					 const char *arg,
 					 int diagnose_misspelt_rev)
 {
@@ -179,7 +180,7 @@ static void NORETURN die_verify_filename(const char *prefix,
 	 * let maybe_die_on_misspelt_object_name() even trigger.
 	 */
 	if (!(arg[0] == ':' && !isalnum(arg[1])))
-		maybe_die_on_misspelt_object_name(arg, prefix);
+		maybe_die_on_misspelt_object_name(r, arg, prefix);
 
 	/* ... or fall back the most general message. */
 	die(_("ambiguous argument '%s': unknown revision or path not in the working tree.\n"
@@ -234,7 +235,7 @@ void verify_filename(const char *prefix,
 		die(_("option '%s' must come before non-option arguments"), arg);
 	if (looks_like_pathspec(arg) || check_filename(prefix, arg))
 		return;
-	die_verify_filename(prefix, arg, diagnose_misspelt_rev);
+	die_verify_filename(the_repository, prefix, arg, diagnose_misspelt_rev);
 }
 
 /*
diff --git a/sha1-name.c b/sha1-name.c
index 953df0d692..b94d381bef 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1885,11 +1885,13 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
  * exist in 'HEAD'" when given "HEAD:doc", or it may return in which case
  * you have a chance to diagnose the error further.
  */
-void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
+void maybe_die_on_misspelt_object_name(struct repository *r,
+				       const char *name,
+				       const char *prefix)
 {
 	struct object_context oc;
 	struct object_id oid;
-	get_oid_with_context_1(the_repository, name, GET_OID_ONLY_TO_DIE,
+	get_oid_with_context_1(r, name, GET_OID_ONLY_TO_DIE,
 			       prefix, &oid, &oc);
 }
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 30/31] sha1-name.c: remove the_repo from other get_oid_*
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (28 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 29/31] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-03-30 11:19 ` [PATCH 31/31] sha1-name.c: remove the_repo from get_oid_mb() Nguyễn Thái Ngọc Duy
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 18 ++++++++++++------
 sha1-name.c | 35 ++++++++++++++++++++---------------
 2 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/cache.h b/cache.h
index 3718b3db8a..871a167bf8 100644
--- a/cache.h
+++ b/cache.h
@@ -1381,12 +1381,11 @@ enum get_oid_result {
 };
 
 int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);
-#define get_oid(str, oid) repo_get_oid(the_repository, str, oid)
-extern int get_oid_commit(const char *str, struct object_id *oid);
-extern int get_oid_committish(const char *str, struct object_id *oid);
-extern int get_oid_tree(const char *str, struct object_id *oid);
-extern int get_oid_treeish(const char *str, struct object_id *oid);
-extern int get_oid_blob(const char *str, struct object_id *oid);
+int repo_get_oid_commit(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_committish(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid);
 void maybe_die_on_misspelt_object_name(struct repository *repo,
 				       const char *name,
 				       const char *prefix);
@@ -1394,6 +1393,13 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c
 				unsigned flags, struct object_id *oid,
 				struct object_context *oc);
 
+#define get_oid(str, oid)		repo_get_oid(the_repository, str, oid)
+#define get_oid_commit(str, oid)	repo_get_oid_commit(the_repository, str, oid)
+#define get_oid_committish(str, oid)	repo_get_oid_committish(the_repository, str, oid)
+#define get_oid_tree(str, oid)		repo_get_oid_tree(the_repository, str, oid)
+#define get_oid_treeish(str, oid)	repo_get_oid_treeish(the_repository, str, oid)
+#define get_oid_blob(str, oid)		repo_get_oid_blob(the_repository, str, oid)
+
 typedef int each_abbrev_fn(const struct object_id *oid, void *);
 int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);
 #define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data)
diff --git a/sha1-name.c b/sha1-name.c
index b94d381bef..d49496397d 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1590,43 +1590,48 @@ int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)
  * commit-ish. It is merely to give a hint to the disambiguation
  * machinery.
  */
-int get_oid_committish(const char *name, struct object_id *oid)
+int repo_get_oid_committish(struct repository *r,
+			    const char *name,
+			    struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_COMMITTISH,
+	return get_oid_with_context(r, name, GET_OID_COMMITTISH,
 				    oid, &unused);
 }
 
-int get_oid_treeish(const char *name, struct object_id *oid)
+int repo_get_oid_treeish(struct repository *r,
+			 const char *name,
+			 struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_TREEISH,
+	return get_oid_with_context(r, name, GET_OID_TREEISH,
 				    oid, &unused);
 }
 
-int get_oid_commit(const char *name, struct object_id *oid)
+int repo_get_oid_commit(struct repository *r,
+			const char *name,
+			struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_COMMIT,
+	return get_oid_with_context(r, name, GET_OID_COMMIT,
 				    oid, &unused);
 }
 
-int get_oid_tree(const char *name, struct object_id *oid)
+int repo_get_oid_tree(struct repository *r,
+		      const char *name,
+		      struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_TREE,
+	return get_oid_with_context(r, name, GET_OID_TREE,
 				    oid, &unused);
 }
 
-int get_oid_blob(const char *name, struct object_id *oid)
+int repo_get_oid_blob(struct repository *r,
+		      const char *name,
+		      struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_BLOB,
+	return get_oid_with_context(r, name, GET_OID_BLOB,
 				    oid, &unused);
 }
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH 31/31] sha1-name.c: remove the_repo from get_oid_mb()
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (29 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 30/31] sha1-name.c: remove the_repo from other get_oid_* Nguyễn Thái Ngọc Duy
@ 2019-03-30 11:19 ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
  31 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-03-30 11:19 UTC (permalink / raw)
  To: git; +Cc: Stefan Beller, Junio C Hamano,
	Nguyễn Thái Ngọc Duy

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     |  3 ++-
 sha1-name.c | 18 +++++++++++-------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/cache.h b/cache.h
index 871a167bf8..9a600a8b50 100644
--- a/cache.h
+++ b/cache.h
@@ -1386,6 +1386,7 @@ int repo_get_oid_committish(struct repository *r, const char *str, struct object
 int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid);
 int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid);
 int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_mb(struct repository *r, const char *str, struct object_id *oid);
 void maybe_die_on_misspelt_object_name(struct repository *repo,
 				       const char *name,
 				       const char *prefix);
@@ -1399,6 +1400,7 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c
 #define get_oid_tree(str, oid)		repo_get_oid_tree(the_repository, str, oid)
 #define get_oid_treeish(str, oid)	repo_get_oid_treeish(the_repository, str, oid)
 #define get_oid_blob(str, oid)		repo_get_oid_blob(the_repository, str, oid)
+#define get_oid_mb(str, oid) 		repo_get_oid_mb(the_repository, str, oid)
 
 typedef int each_abbrev_fn(const struct object_id *oid, void *);
 int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);
@@ -1486,7 +1488,6 @@ int repo_interpret_branch_name(struct repository *r,
 			       unsigned allowed);
 #define interpret_branch_name(str, len, buf, allowed) \
 	repo_interpret_branch_name(the_repository, str, len, buf, allowed)
-extern int get_oid_mb(const char *str, struct object_id *oid);
 
 extern int validate_headref(const char *ref);
 
diff --git a/sha1-name.c b/sha1-name.c
index d49496397d..cf314ebb29 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1338,7 +1338,9 @@ static int interpret_nth_prior_checkout(struct repository *r,
 	return retval;
 }
 
-int get_oid_mb(const char *name, struct object_id *oid)
+int repo_get_oid_mb(struct repository *r,
+		    const char *name,
+		    struct object_id *oid)
 {
 	struct commit *one, *two;
 	struct commit_list *mbs;
@@ -1348,27 +1350,29 @@ int get_oid_mb(const char *name, struct object_id *oid)
 
 	dots = strstr(name, "...");
 	if (!dots)
-		return get_oid(name, oid);
+		return repo_get_oid(r, name, oid);
 	if (dots == name)
-		st = get_oid("HEAD", &oid_tmp);
+		st = repo_get_oid(r, "HEAD", &oid_tmp);
 	else {
 		struct strbuf sb;
 		strbuf_init(&sb, dots - name);
 		strbuf_add(&sb, name, dots - name);
-		st = get_oid_committish(sb.buf, &oid_tmp);
+		st = repo_get_oid_committish(r, sb.buf, &oid_tmp);
 		strbuf_release(&sb);
 	}
 	if (st)
 		return st;
-	one = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);
+	one = lookup_commit_reference_gently(r, &oid_tmp, 0);
 	if (!one)
 		return -1;
 
-	if (get_oid_committish(dots[3] ? (dots + 3) : "HEAD", &oid_tmp))
+	if (repo_get_oid_committish(r, dots[3] ? (dots + 3) : "HEAD", &oid_tmp))
 		return -1;
-	two = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);
+	two = lookup_commit_reference_gently(r, &oid_tmp, 0);
 	if (!two)
 		return -1;
+	if (r != the_repository)
+		BUG("sorry get_merge_bases() can't take struct repository yet");
 	mbs = get_merge_bases(one, two);
 	if (!mbs || mbs->next)
 		st = -1;
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* Re: [PATCH 09/31] commit.c: add repo_get_commit_tree()
  2019-03-30 11:19 ` [PATCH 09/31] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
@ 2019-04-02 15:39   ` SZEDER Gábor
  0 siblings, 0 replies; 154+ messages in thread
From: SZEDER Gábor @ 2019-04-02 15:39 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git, Stefan Beller, Junio C Hamano

On Sat, Mar 30, 2019 at 06:19:05PM +0700, Nguyễn Thái Ngọc Duy wrote:
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  commit.c | 5 +++--
>  commit.h | 3 ++-
>  2 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/commit.c b/commit.c
> index a5333c7ac6..f0a5506f04 100644
> --- a/commit.c
> +++ b/commit.c
> @@ -340,7 +340,8 @@ void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)
>  	}
>  }
>  
> -struct tree *get_commit_tree(const struct commit *commit)
> +struct tree *repo_get_commit_tree(struct repository *r,
> +				  const struct commit *commit)
>  {
>  	if (commit->maybe_tree || !commit->object.parsed)
>  		return commit->maybe_tree;

By renaming this function this patch triggers Coccinelle and
'commit.cocci', as it specifically whitelists get_commit_tree() as one
of the few functions that can legitimately access commit->maybe_tree;
for detail see 279ffad17d (coccinelle: avoid wrong transformation
suggestions from commit.cocci, 2018-04-30).

Please update 'commit.cocci' accordingly:


diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
index c49aa558f0..55679cbbed 100644
--- a/contrib/coccinelle/commit.cocci
+++ b/contrib/coccinelle/commit.cocci
@@ -12,7 +12,7 @@ expression c;
 
 // These excluded functions must access c->maybe_tree direcly.
 @@
-identifier f !~ "^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
+identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
 expression c;
 @@
   f(...) {<...


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates
  2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
                   ` (30 preceding siblings ...)
  2019-03-30 11:19 ` [PATCH 31/31] sha1-name.c: remove the_repo from get_oid_mb() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34 ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 01/32] rebase: 'make coccicheck' cleanup Nguyễn Thái Ngọc Duy
                     ` (32 more replies)
  31 siblings, 33 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

v2 fixes commit.cocci, found by Szeder. While at there I see there are
two other changes suggested by cocci that haven't made it to 'pu' so I
added them in the new 01/32.

Nguyễn Thái Ngọc Duy (32):
  rebase: 'make coccicheck' cleanup
  packfile.c: add repo_approximate_object_count()
  refs.c: add refs_ref_exists()
  refs.c: add refs_shorten_unambiguous_ref()
  refs.c: remove the_repo from substitute_branch_name()
  refs.c: remove the_repo from expand_ref()
  refs.c: add repo_dwim_ref()
  refs.c: add repo_dwim_log()
  refs.c: remove the_repo from read_ref_at()
  commit.c: add repo_get_commit_tree()
  sha1-name.c: remove the_repo from sort_ambiguous()
  sha1-name.c: remove the_repo from find_abbrev_len_packed()
  sha1-name.c: add repo_find_unique_abbrev_r()
  sha1-name.c: store and use repo in struct disambiguate_state
  sha1-name.c: add repo_for_each_abbrev()
  sha1-name.c: remove the_repo from get_short_oid()
  sha1-name.c: remove the_repo from interpret_nth_prior_checkout()
  sha1-name.c: remove the_repo from interpret_branch_mark()
  sha1-name.c: add repo_interpret_branch_name()
  sha1-name.c: remove the_repo from get_oid_oneline()
  sha1-name.c: remove the_repo from get_describe_name()
  sha1-name.c: remove the_repo from get_oid_basic()
  sha1-name.c: remove the_repo from get_oid_1()
  sha1-name.c: remove the_repo from handle_one_ref()
  sha1-name.c: remove the_repo from diagnose_invalid_index_path()
  sha1-name.c: remove the_repo from resolve_relative_path()
  sha1-name.c: remove the_repo from get_oid_with_context_1()
  sha1-name.c: add repo_get_oid()
  submodule-config.c: use repo_get_oid for reading .gitmodules
  sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name
  sha1-name.c: remove the_repo from other get_oid_*
  sha1-name.c: remove the_repo from get_oid_mb()

 builtin/rebase.c                   |   5 +-
 builtin/show-branch.c              |   6 +-
 cache.h                            |  50 ++--
 commit.c                           |   5 +-
 commit.h                           |   3 +-
 contrib/coccinelle/commit.cocci    |   4 +-
 dir.c                              |   8 +
 dir.h                              |   4 +-
 packfile.c                         |  14 +-
 packfile.h                         |   3 +-
 refs.c                             |  71 ++++--
 refs.h                             |   9 +-
 setup.c                            |   7 +-
 sha1-name.c                        | 388 ++++++++++++++++++-----------
 submodule-config.c                 |  20 +-
 t/t7814-grep-recurse-submodules.sh |   6 +-
 upload-pack.c                      |   2 +-
 17 files changed, 375 insertions(+), 230 deletions(-)

Range-diff dựa trên v1:
 -:  ---------- >  1:  b992f6c799 rebase: 'make coccicheck' cleanup
 1:  0988bf416e =  2:  e76c73a75a packfile.c: add repo_approximate_object_count()
 2:  d55d5a044d =  3:  962a168516 refs.c: add refs_ref_exists()
 3:  a01ebfaa28 =  4:  d06bea7909 refs.c: add refs_shorten_unambiguous_ref()
 4:  6bf6bdb358 =  5:  fb880154e6 refs.c: remove the_repo from substitute_branch_name()
 5:  7db71d20f0 =  6:  6fd7960522 refs.c: remove the_repo from expand_ref()
 6:  c0bbe2ea45 =  7:  f5ad3133bc refs.c: add repo_dwim_ref()
 7:  c7b5e8d9fe =  8:  7552a4085a refs.c: add repo_dwim_log()
 8:  91229dad66 =  9:  962fff4c9c refs.c: remove the_repo from read_ref_at()
 9:  ae7d2bfcee ! 10:  68876a150f commit.c: add repo_get_commit_tree()
    @@ -38,3 +38,22 @@
      struct object_id *get_commit_tree_oid(const struct commit *);
      
      /*
    +
    + diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
    + --- a/contrib/coccinelle/commit.cocci
    + +++ b/contrib/coccinelle/commit.cocci
    +@@
    + 
    + // These excluded functions must access c->maybe_tree direcly.
    + @@
    +-identifier f !~ "^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
    ++identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
    + expression c;
    + @@
    +   f(...) {<...
    + - c->maybe_tree
    +-+ get_commit_tree(c)
    +++ repo_get_commit_tree(the_repository, c)
    +   ...>}
    + 
    + @@
10:  b6bd4c86e3 = 11:  9817d150b2 sha1-name.c: remove the_repo from sort_ambiguous()
11:  8aaaf14786 = 12:  7ce23aaeb5 sha1-name.c: remove the_repo from find_abbrev_len_packed()
12:  76305c1faa = 13:  2d99af106f sha1-name.c: add repo_find_unique_abbrev_r()
13:  f07d196f41 = 14:  f63626e937 sha1-name.c: store and use repo in struct disambiguate_state
14:  0e6ef61f31 = 15:  ce9f7ebab8 sha1-name.c: add repo_for_each_abbrev()
15:  0e74d78d74 = 16:  8cb8278d6e sha1-name.c: remove the_repo from get_short_oid()
16:  a5d0f20892 = 17:  9210dd01b8 sha1-name.c: remove the_repo from interpret_nth_prior_checkout()
17:  15dd2005b4 = 18:  a161ed33d2 sha1-name.c: remove the_repo from interpret_branch_mark()
18:  23627fd251 = 19:  6bf4df0131 sha1-name.c: add repo_interpret_branch_name()
19:  167ac516e8 = 20:  94f707cb7f sha1-name.c: remove the_repo from get_oid_oneline()
20:  57bfc2f7f6 = 21:  2a1dd6368c sha1-name.c: remove the_repo from get_describe_name()
21:  1134a0c34e = 22:  f958b565db sha1-name.c: remove the_repo from get_oid_basic()
22:  c04c381031 = 23:  ec821007b2 sha1-name.c: remove the_repo from get_oid_1()
23:  c9a33014f6 = 24:  317a365f30 sha1-name.c: remove the_repo from handle_one_ref()
24:  2f8bd84d50 = 25:  3a46ea22b2 sha1-name.c: remove the_repo from diagnose_invalid_index_path()
25:  c2924466da = 26:  59a8cb9749 sha1-name.c: remove the_repo from resolve_relative_path()
26:  3b9545a48c = 27:  d1f4df1915 sha1-name.c: remove the_repo from get_oid_with_context_1()
27:  333dc19eae = 28:  3034e9cf1e sha1-name.c: add repo_get_oid()
28:  a6b08a7a2d = 29:  9c72941ec9 submodule-config.c: use repo_get_oid for reading .gitmodules
29:  42a0ce718e = 30:  40acfb6b82 sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name
30:  39aab4331a = 31:  3b8be75e77 sha1-name.c: remove the_repo from other get_oid_*
31:  1d1c4a0d5f = 32:  59cadc5deb sha1-name.c: remove the_repo from get_oid_mb()
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply	[flat|nested] 154+ messages in thread

* [PATCH v2 01/32] rebase: 'make coccicheck' cleanup
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-04 17:25     ` SZEDER Gábor
  2019-04-03 11:34   ` [PATCH v2 02/32] packfile.c: add repo_approximate_object_count() Nguyễn Thái Ngọc Duy
                     ` (31 subsequent siblings)
  32 siblings, 1 reply; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/rebase.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/builtin/rebase.c b/builtin/rebase.c
index 77deebc65c..c064909329 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -1592,8 +1592,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 				branch_name = options.head_name;
 
 		} else {
-			free(options.head_name);
-			options.head_name = NULL;
+			FREE_AND_NULL(options.head_name);
 			branch_name = "HEAD";
 		}
 		if (get_oid("HEAD", &options.orig_head))
@@ -1793,7 +1792,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 	 * we just fast-forwarded.
 	 */
 	strbuf_reset(&msg);
-	if (!oidcmp(&merge_base, &options.orig_head)) {
+	if (oideq(&merge_base, &options.orig_head)) {
 		printf(_("Fast-forwarded %s to %s.\n"),
 			branch_name, options.onto_name);
 		strbuf_addf(&msg, "rebase finished: %s onto %s",
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 02/32] packfile.c: add repo_approximate_object_count()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 01/32] rebase: 'make coccicheck' cleanup Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 03/32] refs.c: add refs_ref_exists() Nguyễn Thái Ngọc Duy
                     ` (30 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 packfile.c | 14 +++++++-------
 packfile.h |  3 ++-
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/packfile.c b/packfile.c
index 16bcb75262..2ad4fab2f8 100644
--- a/packfile.c
+++ b/packfile.c
@@ -893,25 +893,25 @@ static void prepare_packed_git(struct repository *r);
  * all unreachable objects about to be pruned, in which case they're not really
  * interesting as a measure of repo size in the first place.
  */
-unsigned long approximate_object_count(void)
+unsigned long repo_approximate_object_count(struct repository *r)
 {
-	if (!the_repository->objects->approximate_object_count_valid) {
+	if (!r->objects->approximate_object_count_valid) {
 		unsigned long count;
 		struct multi_pack_index *m;
 		struct packed_git *p;
 
-		prepare_packed_git(the_repository);
+		prepare_packed_git(r);
 		count = 0;
-		for (m = get_multi_pack_index(the_repository); m; m = m->next)
+		for (m = get_multi_pack_index(r); m; m = m->next)
 			count += m->num_objects;
-		for (p = the_repository->objects->packed_git; p; p = p->next) {
+		for (p = r->objects->packed_git; p; p = p->next) {
 			if (open_pack_index(p))
 				continue;
 			count += p->num_objects;
 		}
-		the_repository->objects->approximate_object_count = count;
+		r->objects->approximate_object_count = count;
 	}
-	return the_repository->objects->approximate_object_count;
+	return r->objects->approximate_object_count;
 }
 
 static void *get_next_packed_git(const void *p)
diff --git a/packfile.h b/packfile.h
index d70c6d9afb..f04440f984 100644
--- a/packfile.h
+++ b/packfile.h
@@ -57,7 +57,8 @@ struct packed_git *get_all_packs(struct repository *r);
  * Give a rough count of objects in the repository. This sacrifices accuracy
  * for speed.
  */
-unsigned long approximate_object_count(void);
+unsigned long repo_approximate_object_count(struct repository *r);
+#define approximate_object_count() repo_approximate_object_count(the_repository)
 
 extern struct packed_git *find_sha1_pack(const unsigned char *sha1,
 					 struct packed_git *packs);
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 03/32] refs.c: add refs_ref_exists()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 01/32] rebase: 'make coccicheck' cleanup Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 02/32] packfile.c: add repo_approximate_object_count() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 04/32] refs.c: add refs_shorten_unambiguous_ref() Nguyễn Thái Ngọc Duy
                     ` (29 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/refs.c b/refs.c
index 142888a40a..b869f32d8b 100644
--- a/refs.c
+++ b/refs.c
@@ -241,9 +241,14 @@ int read_ref(const char *refname, struct object_id *oid)
 	return read_ref_full(refname, RESOLVE_REF_READING, oid, NULL);
 }
 
+static int refs_ref_exists(struct ref_store *refs, const char *refname)
+{
+	return !!refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING, NULL, NULL);
+}
+
 int ref_exists(const char *refname)
 {
-	return !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, NULL, NULL);
+	return refs_ref_exists(get_main_ref_store(the_repository), refname);
 }
 
 static int match_ref_pattern(const char *refname,
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 04/32] refs.c: add refs_shorten_unambiguous_ref()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (2 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 03/32] refs.c: add refs_ref_exists() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 05/32] refs.c: remove the_repo from substitute_branch_name() Nguyễn Thái Ngọc Duy
                     ` (28 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c | 11 +++++++++--
 refs.h |  2 ++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/refs.c b/refs.c
index b869f32d8b..3dde824aab 100644
--- a/refs.c
+++ b/refs.c
@@ -1169,7 +1169,8 @@ int update_ref(const char *msg, const char *refname,
 			       old_oid, flags, onerr);
 }
 
-char *shorten_unambiguous_ref(const char *refname, int strict)
+char *refs_shorten_unambiguous_ref(struct ref_store *refs,
+				   const char *refname, int strict)
 {
 	int i;
 	static char **scanf_fmts;
@@ -1247,7 +1248,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
 			strbuf_reset(&resolved_buf);
 			strbuf_addf(&resolved_buf, rule,
 				    short_name_len, short_name);
-			if (ref_exists(resolved_buf.buf))
+			if (refs_ref_exists(refs, resolved_buf.buf))
 				break;
 		}
 
@@ -1266,6 +1267,12 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
 	return xstrdup(refname);
 }
 
+char *shorten_unambiguous_ref(const char *refname, int strict)
+{
+	return refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
+					    refname, strict);
+}
+
 static struct string_list *hide_refs;
 
 int parse_hide_refs_config(const char *var, const char *value, const char *section)
diff --git a/refs.h b/refs.h
index 308fa1f03b..5627570241 100644
--- a/refs.h
+++ b/refs.h
@@ -462,6 +462,8 @@ int check_refname_format(const char *refname, int flags);
 
 const char *prettify_refname(const char *refname);
 
+char *refs_shorten_unambiguous_ref(struct ref_store *refs,
+				   const char *refname, int strict);
 char *shorten_unambiguous_ref(const char *refname, int strict);
 
 /** rename ref, return 0 on success **/
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 05/32] refs.c: remove the_repo from substitute_branch_name()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (3 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 04/32] refs.c: add refs_shorten_unambiguous_ref() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 06/32] refs.c: remove the_repo from expand_ref() Nguyễn Thái Ngọc Duy
                     ` (27 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 8 ++++++--
 refs.c      | 9 +++++----
 sha1-name.c | 8 ++++++--
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/cache.h b/cache.h
index ac92421f3a..fcb24b5781 100644
--- a/cache.h
+++ b/cache.h
@@ -1468,8 +1468,12 @@ extern int parse_oid_hex(const char *hex, struct object_id *oid, const char **en
 #define INTERPRET_BRANCH_LOCAL (1<<0)
 #define INTERPRET_BRANCH_REMOTE (1<<1)
 #define INTERPRET_BRANCH_HEAD (1<<2)
-extern int interpret_branch_name(const char *str, int len, struct strbuf *,
-				 unsigned allowed);
+int repo_interpret_branch_name(struct repository *r,
+			       const char *str, int len,
+			       struct strbuf *buf,
+			       unsigned allowed);
+#define interpret_branch_name(str, len, buf, allowed) \
+	repo_interpret_branch_name(the_repository, str, len, buf, allowed)
 extern int get_oid_mb(const char *str, struct object_id *oid);
 
 extern int validate_headref(const char *ref);
diff --git a/refs.c b/refs.c
index 3dde824aab..44df049796 100644
--- a/refs.c
+++ b/refs.c
@@ -539,10 +539,11 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)
  * later free()ing) if the string passed in is a magic short-hand form
  * to name a branch.
  */
-static char *substitute_branch_name(const char **string, int *len)
+static char *substitute_branch_name(struct repository *r,
+				    const char **string, int *len)
 {
 	struct strbuf buf = STRBUF_INIT;
-	int ret = interpret_branch_name(*string, *len, &buf, 0);
+	int ret = repo_interpret_branch_name(r, *string, *len, &buf, 0);
 
 	if (ret == *len) {
 		size_t size;
@@ -556,7 +557,7 @@ static char *substitute_branch_name(const char **string, int *len)
 
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
 {
-	char *last_branch = substitute_branch_name(&str, &len);
+	char *last_branch = substitute_branch_name(the_repository, &str, &len);
 	int   refs_found  = expand_ref(str, len, oid, ref);
 	free(last_branch);
 	return refs_found;
@@ -596,7 +597,7 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
 
 int dwim_log(const char *str, int len, struct object_id *oid, char **log)
 {
-	char *last_branch = substitute_branch_name(&str, &len);
+	char *last_branch = substitute_branch_name(the_repository, &str, &len);
 	const char **p;
 	int logs_found = 0;
 	struct strbuf path = STRBUF_INIT;
diff --git a/sha1-name.c b/sha1-name.c
index 6dda2c16df..d535bb82f7 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1427,13 +1427,17 @@ static int interpret_branch_mark(const char *name, int namelen,
 	return len + at;
 }
 
-int interpret_branch_name(const char *name, int namelen, struct strbuf *buf,
-			  unsigned allowed)
+int repo_interpret_branch_name(struct repository *r,
+			       const char *name, int namelen,
+			       struct strbuf *buf,
+			       unsigned allowed)
 {
 	char *at;
 	const char *start;
 	int len;
 
+	if (r != the_repository)
+		BUG("interpret_branch_name() does not really use 'r' yet");
 	if (!namelen)
 		namelen = strlen(name);
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 06/32] refs.c: remove the_repo from expand_ref()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (4 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 05/32] refs.c: remove the_repo from substitute_branch_name() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 07/32] refs.c: add repo_dwim_ref() Nguyễn Thái Ngọc Duy
                     ` (26 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c        | 10 ++++++----
 refs.h        |  2 +-
 upload-pack.c |  2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/refs.c b/refs.c
index 44df049796..1f5864aa36 100644
--- a/refs.c
+++ b/refs.c
@@ -558,12 +558,13 @@ static char *substitute_branch_name(struct repository *r,
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
 {
 	char *last_branch = substitute_branch_name(the_repository, &str, &len);
-	int   refs_found  = expand_ref(str, len, oid, ref);
+	int   refs_found  = expand_ref(the_repository, str, len, oid, ref);
 	free(last_branch);
 	return refs_found;
 }
 
-int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
+int expand_ref(struct repository *repo, const char *str, int len,
+	       struct object_id *oid, char **ref)
 {
 	const char **p, *r;
 	int refs_found = 0;
@@ -578,8 +579,9 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
 		this_result = refs_found ? &oid_from_ref : oid;
 		strbuf_reset(&fullref);
 		strbuf_addf(&fullref, *p, len, str);
-		r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
-				       this_result, &flag);
+		r = refs_resolve_ref_unsafe(get_main_ref_store(repo),
+					    fullref.buf, RESOLVE_REF_READING,
+					    this_result, &flag);
 		if (r) {
 			if (!refs_found++)
 				*ref = xstrdup(r);
diff --git a/refs.h b/refs.h
index 5627570241..b630d5bde7 100644
--- a/refs.h
+++ b/refs.h
@@ -148,7 +148,7 @@ int refname_match(const char *abbrev_name, const char *full_name);
 struct argv_array;
 void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);
 
-int expand_ref(const char *str, int len, struct object_id *oid, char **ref);
+int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
 int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
 
diff --git a/upload-pack.c b/upload-pack.c
index d098ef5982..56505d60c3 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -834,7 +834,7 @@ static int process_deepen_not(const char *line, struct string_list *deepen_not,
 	if (skip_prefix(line, "deepen-not ", &arg)) {
 		char *ref = NULL;
 		struct object_id oid;
-		if (expand_ref(arg, strlen(arg), &oid, &ref) != 1)
+		if (expand_ref(the_repository, arg, strlen(arg), &oid, &ref) != 1)
 			die("git upload-pack: ambiguous deepen-not: %s", line);
 		string_list_append(deepen_not, ref);
 		free(ref);
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 07/32] refs.c: add repo_dwim_ref()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (5 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 06/32] refs.c: remove the_repo from expand_ref() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 08/32] refs.c: add repo_dwim_log() Nguyễn Thái Ngọc Duy
                     ` (25 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c | 12 +++++++++---
 refs.h |  1 +
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/refs.c b/refs.c
index 1f5864aa36..bd0fec5776 100644
--- a/refs.c
+++ b/refs.c
@@ -555,14 +555,20 @@ static char *substitute_branch_name(struct repository *r,
 	return NULL;
 }
 
-int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
+int repo_dwim_ref(struct repository *r, const char *str, int len,
+		  struct object_id *oid, char **ref)
 {
-	char *last_branch = substitute_branch_name(the_repository, &str, &len);
-	int   refs_found  = expand_ref(the_repository, str, len, oid, ref);
+	char *last_branch = substitute_branch_name(r, &str, &len);
+	int   refs_found  = expand_ref(r, str, len, oid, ref);
 	free(last_branch);
 	return refs_found;
 }
 
+int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
+{
+	return repo_dwim_ref(the_repository, str, len, oid, ref);
+}
+
 int expand_ref(struct repository *repo, const char *str, int len,
 	       struct object_id *oid, char **ref)
 {
diff --git a/refs.h b/refs.h
index b630d5bde7..fd3dc1d0f4 100644
--- a/refs.h
+++ b/refs.h
@@ -149,6 +149,7 @@ struct argv_array;
 void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);
 
 int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
+int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
 int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 08/32] refs.c: add repo_dwim_log()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (6 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 07/32] refs.c: add repo_dwim_ref() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 09/32] refs.c: remove the_repo from read_ref_at() Nguyễn Thái Ngọc Duy
                     ` (24 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c | 21 +++++++++++++++------
 refs.h |  1 +
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/refs.c b/refs.c
index bd0fec5776..edea001446 100644
--- a/refs.c
+++ b/refs.c
@@ -603,9 +603,11 @@ int expand_ref(struct repository *repo, const char *str, int len,
 	return refs_found;
 }
 
-int dwim_log(const char *str, int len, struct object_id *oid, char **log)
+int repo_dwim_log(struct repository *r, const char *str, int len,
+		  struct object_id *oid, char **log)
 {
-	char *last_branch = substitute_branch_name(the_repository, &str, &len);
+	struct ref_store *refs = get_main_ref_store(r);
+	char *last_branch = substitute_branch_name(r, &str, &len);
 	const char **p;
 	int logs_found = 0;
 	struct strbuf path = STRBUF_INIT;
@@ -617,13 +619,15 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
 
 		strbuf_reset(&path);
 		strbuf_addf(&path, *p, len, str);
-		ref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,
-					 &hash, NULL);
+		ref = refs_resolve_ref_unsafe(refs, path.buf,
+					      RESOLVE_REF_READING,
+					      &hash, NULL);
 		if (!ref)
 			continue;
-		if (reflog_exists(path.buf))
+		if (refs_reflog_exists(refs, path.buf))
 			it = path.buf;
-		else if (strcmp(ref, path.buf) && reflog_exists(ref))
+		else if (strcmp(ref, path.buf) &&
+			 refs_reflog_exists(refs, ref))
 			it = ref;
 		else
 			continue;
@@ -639,6 +643,11 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
 	return logs_found;
 }
 
+int dwim_log(const char *str, int len, struct object_id *oid, char **log)
+{
+	return repo_dwim_log(the_repository, str, len, oid, log);
+}
+
 static int is_per_worktree_ref(const char *refname)
 {
 	return !strcmp(refname, "HEAD") ||
diff --git a/refs.h b/refs.h
index fd3dc1d0f4..859dffe691 100644
--- a/refs.h
+++ b/refs.h
@@ -150,6 +150,7 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);
 
 int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
 int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
+int repo_dwim_log(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
 int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 09/32] refs.c: remove the_repo from read_ref_at()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (7 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 08/32] refs.c: add repo_dwim_log() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 10/32] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
                     ` (23 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/show-branch.c | 6 ++++--
 refs.c                | 7 ++++---
 refs.h                | 3 ++-
 sha1-name.c           | 3 ++-
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 934e514944..082daeac32 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -753,7 +753,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 				/* Ah, that is a date spec... */
 				timestamp_t at;
 				at = approxidate(reflog_base);
-				read_ref_at(ref, flags, at, -1, &oid, NULL,
+				read_ref_at(get_main_ref_store(the_repository),
+					    ref, flags, at, -1, &oid, NULL,
 					    NULL, NULL, &base);
 			}
 		}
@@ -765,7 +766,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 			timestamp_t timestamp;
 			int tz;
 
-			if (read_ref_at(ref, flags, 0, base + i, &oid, &logmsg,
+			if (read_ref_at(get_main_ref_store(the_repository),
+					ref, flags, 0, base + i, &oid, &logmsg,
 					&timestamp, &tz, NULL)) {
 				reflog = i;
 				break;
diff --git a/refs.c b/refs.c
index edea001446..92d1f6dbdd 100644
--- a/refs.c
+++ b/refs.c
@@ -967,7 +967,8 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid
 	return 1;
 }
 
-int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, int cnt,
+int read_ref_at(struct ref_store *refs, const char *refname,
+		unsigned int flags, timestamp_t at_time, int cnt,
 		struct object_id *oid, char **msg,
 		timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt)
 {
@@ -983,7 +984,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in
 	cb.cutoff_cnt = cutoff_cnt;
 	cb.oid = oid;
 
-	for_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);
+	refs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent, &cb);
 
 	if (!cb.reccnt) {
 		if (flags & GET_OID_QUIETLY)
@@ -994,7 +995,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in
 	if (cb.found_it)
 		return 0;
 
-	for_each_reflog_ent(refname, read_ref_at_ent_oldest, &cb);
+	refs_for_each_reflog_ent(refs, refname, read_ref_at_ent_oldest, &cb);
 
 	return 1;
 }
diff --git a/refs.h b/refs.h
index 859dffe691..8f9cbf8a93 100644
--- a/refs.h
+++ b/refs.h
@@ -388,7 +388,8 @@ int refs_create_reflog(struct ref_store *refs, const char *refname,
 int safe_create_reflog(const char *refname, int force_create, struct strbuf *err);
 
 /** Reads log for the value of ref during at_time. **/
-int read_ref_at(const char *refname, unsigned int flags,
+int read_ref_at(struct ref_store *refs,
+		const char *refname, unsigned int flags,
 		timestamp_t at_time, int cnt,
 		struct object_id *oid, char **msg,
 		timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt);
diff --git a/sha1-name.c b/sha1-name.c
index d535bb82f7..15a1107998 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -849,7 +849,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 				return -1;
 			}
 		}
-		if (read_ref_at(real_ref, flags, at_time, nth, oid, NULL,
+		if (read_ref_at(get_main_ref_store(the_repository),
+				real_ref, flags, at_time, nth, oid, NULL,
 				&co_time, &co_tz, &co_cnt)) {
 			if (!len) {
 				if (starts_with(real_ref, "refs/heads/")) {
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 10/32] commit.c: add repo_get_commit_tree()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (8 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 09/32] refs.c: remove the_repo from read_ref_at() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-04 17:04     ` SZEDER Gábor
  2019-04-03 11:34   ` [PATCH v2 11/32] sha1-name.c: remove the_repo from sort_ambiguous() Nguyễn Thái Ngọc Duy
                     ` (22 subsequent siblings)
  32 siblings, 1 reply; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 commit.c                        | 5 +++--
 commit.h                        | 3 ++-
 contrib/coccinelle/commit.cocci | 4 ++--
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/commit.c b/commit.c
index a5333c7ac6..f0a5506f04 100644
--- a/commit.c
+++ b/commit.c
@@ -340,7 +340,8 @@ void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)
 	}
 }
 
-struct tree *get_commit_tree(const struct commit *commit)
+struct tree *repo_get_commit_tree(struct repository *r,
+				  const struct commit *commit)
 {
 	if (commit->maybe_tree || !commit->object.parsed)
 		return commit->maybe_tree;
@@ -348,7 +349,7 @@ struct tree *get_commit_tree(const struct commit *commit)
 	if (commit->graph_pos == COMMIT_NOT_FROM_GRAPH)
 		BUG("commit has NULL tree, but was not loaded from commit-graph");
 
-	return get_commit_tree_in_graph(the_repository, commit);
+	return get_commit_tree_in_graph(r, commit);
 }
 
 struct object_id *get_commit_tree_oid(const struct commit *commit)
diff --git a/commit.h b/commit.h
index 42728c2906..b576201be8 100644
--- a/commit.h
+++ b/commit.h
@@ -143,7 +143,8 @@ void repo_unuse_commit_buffer(struct repository *r,
  */
 void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);
 
-struct tree *get_commit_tree(const struct commit *);
+struct tree *repo_get_commit_tree(struct repository *, const struct commit *);
+#define get_commit_tree(c) repo_get_commit_tree(the_repository, c)
 struct object_id *get_commit_tree_oid(const struct commit *);
 
 /*
diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
index c49aa558f0..f5bc639981 100644
--- a/contrib/coccinelle/commit.cocci
+++ b/contrib/coccinelle/commit.cocci
@@ -12,12 +12,12 @@ expression c;
 
 // These excluded functions must access c->maybe_tree direcly.
 @@
-identifier f !~ "^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
+identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
 expression c;
 @@
   f(...) {<...
 - c->maybe_tree
-+ get_commit_tree(c)
++ repo_get_commit_tree(the_repository, c)
   ...>}
 
 @@
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 11/32] sha1-name.c: remove the_repo from sort_ambiguous()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (9 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 10/32] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 12/32] sha1-name.c: remove the_repo from find_abbrev_len_packed() Nguyễn Thái Ngọc Duy
                     ` (21 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 15a1107998..7558ce51a3 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -383,10 +383,11 @@ static int collect_ambiguous(const struct object_id *oid, void *data)
 	return 0;
 }
 
+static struct repository *sort_ambiguous_repo;
 static int sort_ambiguous(const void *a, const void *b)
 {
-	int a_type = oid_object_info(the_repository, a, NULL);
-	int b_type = oid_object_info(the_repository, b, NULL);
+	int a_type = oid_object_info(sort_ambiguous_repo, a, NULL);
+	int b_type = oid_object_info(sort_ambiguous_repo, b, NULL);
 	int a_type_sort;
 	int b_type_sort;
 
@@ -411,6 +412,14 @@ static int sort_ambiguous(const void *a, const void *b)
 	return a_type_sort > b_type_sort ? 1 : -1;
 }
 
+static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)
+{
+	/* mutex will be needed if this code is to be made thread safe */
+	sort_ambiguous_repo = r;
+	QSORT(a->oid, a->nr, sort_ambiguous);
+	sort_ambiguous_repo = NULL;
+}
+
 static enum get_oid_result get_short_oid(const char *name, int len,
 					 struct object_id *oid,
 					 unsigned flags)
@@ -458,7 +467,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 
 		advise(_("The candidates are:"));
 		for_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect);
-		QSORT(collect.oid, collect.nr, sort_ambiguous);
+		sort_ambiguous_oid_array(the_repository, &collect);
 
 		if (oid_array_for_each(&collect, show_ambiguous_object, &ds))
 			BUG("show_ambiguous_object shouldn't return non-zero");
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 12/32] sha1-name.c: remove the_repo from find_abbrev_len_packed()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (10 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 11/32] sha1-name.c: remove the_repo from sort_ambiguous() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 13/32] sha1-name.c: add repo_find_unique_abbrev_r() Nguyễn Thái Ngọc Duy
                     ` (20 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 7558ce51a3..b9381aaba6 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -514,6 +514,7 @@ struct min_abbrev_data {
 	unsigned int init_len;
 	unsigned int cur_len;
 	char *hex;
+	struct repository *repo;
 	const struct object_id *oid;
 };
 
@@ -619,9 +620,9 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
 	struct multi_pack_index *m;
 	struct packed_git *p;
 
-	for (m = get_multi_pack_index(the_repository); m; m = m->next)
+	for (m = get_multi_pack_index(mad->repo); m; m = m->next)
 		find_abbrev_len_for_midx(m, mad);
-	for (p = get_packed_git(the_repository); p; p = p->next)
+	for (p = get_packed_git(mad->repo); p; p = p->next)
 		find_abbrev_len_for_pack(p, mad);
 }
 
@@ -658,6 +659,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
 	if (len == hexsz || !len)
 		return hexsz;
 
+	mad.repo = the_repository;
 	mad.init_len = len;
 	mad.cur_len = len;
 	mad.hex = hex;
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 13/32] sha1-name.c: add repo_find_unique_abbrev_r()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (11 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 12/32] sha1-name.c: remove the_repo from find_abbrev_len_packed() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 14/32] sha1-name.c: store and use repo in struct disambiguate_state Nguyễn Thái Ngọc Duy
                     ` (19 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     |  6 ++++--
 sha1-name.c | 15 +++++++++------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/cache.h b/cache.h
index fcb24b5781..4f8ebb0a67 100644
--- a/cache.h
+++ b/cache.h
@@ -1045,8 +1045,10 @@ extern void check_repository_format(void);
  * Note that while this version avoids the static buffer, it is not fully
  * reentrant, as it calls into other non-reentrant git code.
  */
-extern const char *find_unique_abbrev(const struct object_id *oid, int len);
-extern int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len);
+const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len);
+#define find_unique_abbrev(oid, len) repo_find_unique_abbrev(the_repository, oid, len)
+int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);
+#define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len)
 
 extern const unsigned char null_sha1[GIT_MAX_RAWSZ];
 extern const struct object_id null_oid;
diff --git a/sha1-name.c b/sha1-name.c
index b9381aaba6..9b57787b76 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -626,15 +626,16 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
 		find_abbrev_len_for_pack(p, mad);
 }
 
-int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
+int repo_find_unique_abbrev_r(struct repository *r, char *hex,
+			      const struct object_id *oid, int len)
 {
 	struct disambiguate_state ds;
 	struct min_abbrev_data mad;
 	struct object_id oid_ret;
-	const unsigned hexsz = the_hash_algo->hexsz;
+	const unsigned hexsz = r->hash_algo->hexsz;
 
 	if (len < 0) {
-		unsigned long count = approximate_object_count();
+		unsigned long count = repo_approximate_object_count(r);
 		/*
 		 * Add one because the MSB only tells us the highest bit set,
 		 * not including the value of all the _other_ bits (so "15"
@@ -659,7 +660,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
 	if (len == hexsz || !len)
 		return hexsz;
 
-	mad.repo = the_repository;
+	mad.repo = r;
 	mad.init_len = len;
 	mad.cur_len = len;
 	mad.hex = hex;
@@ -681,13 +682,15 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
 	return mad.cur_len;
 }
 
-const char *find_unique_abbrev(const struct object_id *oid, int len)
+const char *repo_find_unique_abbrev(struct repository *r,
+				    const struct object_id *oid,
+				    int len)
 {
 	static int bufno;
 	static char hexbuffer[4][GIT_MAX_HEXSZ + 1];
 	char *hex = hexbuffer[bufno];
 	bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
-	find_unique_abbrev_r(hex, oid, len);
+	repo_find_unique_abbrev_r(r, hex, oid, len);
 	return hex;
 }
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 14/32] sha1-name.c: store and use repo in struct disambiguate_state
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (12 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 13/32] sha1-name.c: add repo_find_unique_abbrev_r() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 15/32] sha1-name.c: add repo_for_each_abbrev() Nguyễn Thái Ngọc Duy
                     ` (18 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 95 +++++++++++++++++++++++++++++++++--------------------
 1 file changed, 59 insertions(+), 36 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 9b57787b76..a75992eb54 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -17,13 +17,14 @@
 
 static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
 
-typedef int (*disambiguate_hint_fn)(const struct object_id *, void *);
+typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);
 
 struct disambiguate_state {
 	int len; /* length of prefix in hex chars */
 	char hex_pfx[GIT_MAX_HEXSZ + 1];
 	struct object_id bin_pfx;
 
+	struct repository *repo;
 	disambiguate_hint_fn fn;
 	void *cb_data;
 	struct object_id candidate;
@@ -38,7 +39,7 @@ struct disambiguate_state {
 static void update_candidates(struct disambiguate_state *ds, const struct object_id *current)
 {
 	if (ds->always_call_fn) {
-		ds->ambiguous = ds->fn(current, ds->cb_data) ? 1 : 0;
+		ds->ambiguous = ds->fn(ds->repo, current, ds->cb_data) ? 1 : 0;
 		return;
 	}
 	if (!ds->candidate_exists) {
@@ -58,7 +59,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object
 	}
 
 	if (!ds->candidate_checked) {
-		ds->candidate_ok = ds->fn(&ds->candidate, ds->cb_data);
+		ds->candidate_ok = ds->fn(ds->repo, &ds->candidate, ds->cb_data);
 		ds->disambiguate_fn_used = 1;
 		ds->candidate_checked = 1;
 	}
@@ -71,7 +72,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object
 	}
 
 	/* if we reach this point, we know ds->candidate satisfies fn */
-	if (ds->fn(current, ds->cb_data)) {
+	if (ds->fn(ds->repo, current, ds->cb_data)) {
 		/*
 		 * if both current and candidate satisfy fn, we cannot
 		 * disambiguate.
@@ -89,9 +90,7 @@ static void find_short_object_filename(struct disambiguate_state *ds)
 {
 	struct object_directory *odb;
 
-	for (odb = the_repository->objects->odb;
-	     odb && !ds->ambiguous;
-	     odb = odb->next) {
+	for (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next) {
 		int pos;
 		struct oid_array *loose_objects;
 
@@ -182,10 +181,10 @@ static void find_short_packed_object(struct disambiguate_state *ds)
 	struct multi_pack_index *m;
 	struct packed_git *p;
 
-	for (m = get_multi_pack_index(the_repository); m && !ds->ambiguous;
+	for (m = get_multi_pack_index(ds->repo); m && !ds->ambiguous;
 	     m = m->next)
 		unique_in_midx(m, ds);
-	for (p = get_packed_git(the_repository); p && !ds->ambiguous;
+	for (p = get_packed_git(ds->repo); p && !ds->ambiguous;
 	     p = p->next)
 		unique_in_pack(p, ds);
 }
@@ -215,7 +214,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
 		 * same repository!
 		 */
 		ds->candidate_ok = (!ds->disambiguate_fn_used ||
-				    ds->fn(&ds->candidate, ds->cb_data));
+				    ds->fn(ds->repo, &ds->candidate, ds->cb_data));
 
 	if (!ds->candidate_ok)
 		return SHORT_NAME_AMBIGUOUS;
@@ -224,59 +223,67 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
 	return 0;
 }
 
-static int disambiguate_commit_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_commit_only(struct repository *r,
+				    const struct object_id *oid,
+				    void *cb_data_unused)
 {
-	int kind = oid_object_info(the_repository, oid, NULL);
+	int kind = oid_object_info(r, oid, NULL);
 	return kind == OBJ_COMMIT;
 }
 
-static int disambiguate_committish_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_committish_only(struct repository *r,
+					const struct object_id *oid,
+					void *cb_data_unused)
 {
 	struct object *obj;
 	int kind;
 
-	kind = oid_object_info(the_repository, oid, NULL);
+	kind = oid_object_info(r, oid, NULL);
 	if (kind == OBJ_COMMIT)
 		return 1;
 	if (kind != OBJ_TAG)
 		return 0;
 
 	/* We need to do this the hard way... */
-	obj = deref_tag(the_repository, parse_object(the_repository, oid),
-			NULL, 0);
+	obj = deref_tag(r, parse_object(r, oid), NULL, 0);
 	if (obj && obj->type == OBJ_COMMIT)
 		return 1;
 	return 0;
 }
 
-static int disambiguate_tree_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_tree_only(struct repository *r,
+				  const struct object_id *oid,
+				  void *cb_data_unused)
 {
-	int kind = oid_object_info(the_repository, oid, NULL);
+	int kind = oid_object_info(r, oid, NULL);
 	return kind == OBJ_TREE;
 }
 
-static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_treeish_only(struct repository *r,
+				     const struct object_id *oid,
+				     void *cb_data_unused)
 {
 	struct object *obj;
 	int kind;
 
-	kind = oid_object_info(the_repository, oid, NULL);
+	kind = oid_object_info(r, oid, NULL);
 	if (kind == OBJ_TREE || kind == OBJ_COMMIT)
 		return 1;
 	if (kind != OBJ_TAG)
 		return 0;
 
 	/* We need to do this the hard way... */
-	obj = deref_tag(the_repository, parse_object(the_repository, oid),
-			NULL, 0);
+	obj = deref_tag(r, parse_object(r, oid), NULL, 0);
 	if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))
 		return 1;
 	return 0;
 }
 
-static int disambiguate_blob_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_blob_only(struct repository *r,
+				  const struct object_id *oid,
+				  void *cb_data_unused)
 {
-	int kind = oid_object_info(the_repository, oid, NULL);
+	int kind = oid_object_info(r, oid, NULL);
 	return kind == OBJ_BLOB;
 }
 
@@ -310,7 +317,8 @@ int set_disambiguate_hint_config(const char *var, const char *value)
 	return error("unknown hint type for '%s': %s", var, value);
 }
 
-static int init_object_disambiguation(const char *name, int len,
+static int init_object_disambiguation(struct repository *r,
+				      const char *name, int len,
 				      struct disambiguate_state *ds)
 {
 	int i;
@@ -341,7 +349,8 @@ static int init_object_disambiguation(const char *name, int len,
 
 	ds->len = len;
 	ds->hex_pfx[len] = '\0';
-	prepare_alt_odb(the_repository);
+	ds->repo = r;
+	prepare_alt_odb(r);
 	return 0;
 }
 
@@ -351,25 +360,25 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
 	struct strbuf desc = STRBUF_INIT;
 	int type;
 
-	if (ds->fn && !ds->fn(oid, ds->cb_data))
+	if (ds->fn && !ds->fn(ds->repo, oid, ds->cb_data))
 		return 0;
 
-	type = oid_object_info(the_repository, oid, NULL);
+	type = oid_object_info(ds->repo, oid, NULL);
 	if (type == OBJ_COMMIT) {
-		struct commit *commit = lookup_commit(the_repository, oid);
+		struct commit *commit = lookup_commit(ds->repo, oid);
 		if (commit) {
 			struct pretty_print_context pp = {0};
 			pp.date_mode.type = DATE_SHORT;
 			format_commit_message(commit, " %ad - %s", &desc, &pp);
 		}
 	} else if (type == OBJ_TAG) {
-		struct tag *tag = lookup_tag(the_repository, oid);
+		struct tag *tag = lookup_tag(ds->repo, oid);
 		if (!parse_tag(tag) && tag->tag)
 			strbuf_addf(&desc, " %s", tag->tag);
 	}
 
 	advise("  %s %s%s",
-	       find_unique_abbrev(oid, DEFAULT_ABBREV),
+	       repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV),
 	       type_name(type) ? type_name(type) : "unknown type",
 	       desc.buf);
 
@@ -383,6 +392,13 @@ static int collect_ambiguous(const struct object_id *oid, void *data)
 	return 0;
 }
 
+static int repo_collect_ambiguous(struct repository *r,
+				  const struct object_id *oid,
+				  void *data)
+{
+	return collect_ambiguous(oid, data);
+}
+
 static struct repository *sort_ambiguous_repo;
 static int sort_ambiguous(const void *a, const void *b)
 {
@@ -428,7 +444,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 	struct disambiguate_state ds;
 	int quietly = !!(flags & GET_OID_QUIETLY);
 
-	if (init_object_disambiguation(name, len, &ds) < 0)
+	if (init_object_disambiguation(the_repository, name, len, &ds) < 0)
 		return -1;
 
 	if (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))
@@ -483,11 +499,11 @@ int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)
 	struct disambiguate_state ds;
 	int ret;
 
-	if (init_object_disambiguation(prefix, strlen(prefix), &ds) < 0)
+	if (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0)
 		return -1;
 
 	ds.always_call_fn = 1;
-	ds.fn = collect_ambiguous;
+	ds.fn = repo_collect_ambiguous;
 	ds.cb_data = &collect;
 	find_short_object_filename(&ds);
 	find_short_packed_object(&ds);
@@ -543,6 +559,13 @@ static int extend_abbrev_len(const struct object_id *oid, void *cb_data)
 	return 0;
 }
 
+static int repo_extend_abbrev_len(struct repository *r,
+				  const struct object_id *oid,
+				  void *cb_data)
+{
+	return extend_abbrev_len(oid, cb_data);
+}
+
 static void find_abbrev_len_for_midx(struct multi_pack_index *m,
 				     struct min_abbrev_data *mad)
 {
@@ -668,10 +691,10 @@ int repo_find_unique_abbrev_r(struct repository *r, char *hex,
 
 	find_abbrev_len_packed(&mad);
 
-	if (init_object_disambiguation(hex, mad.cur_len, &ds) < 0)
+	if (init_object_disambiguation(r, hex, mad.cur_len, &ds) < 0)
 		return -1;
 
-	ds.fn = extend_abbrev_len;
+	ds.fn = repo_extend_abbrev_len;
 	ds.always_call_fn = 1;
 	ds.cb_data = (void *)&mad;
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 15/32] sha1-name.c: add repo_for_each_abbrev()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (13 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 14/32] sha1-name.c: store and use repo in struct disambiguate_state Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 16/32] sha1-name.c: remove the_repo from get_short_oid() Nguyễn Thái Ngọc Duy
                     ` (17 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 3 ++-
 sha1-name.c | 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/cache.h b/cache.h
index 4f8ebb0a67..0cb95c0d4f 100644
--- a/cache.h
+++ b/cache.h
@@ -1392,7 +1392,8 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c
 				struct object_context *oc);
 
 typedef int each_abbrev_fn(const struct object_id *oid, void *);
-extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
+int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);
+#define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data)
 
 extern int set_disambiguate_hint_config(const char *var, const char *value);
 
diff --git a/sha1-name.c b/sha1-name.c
index a75992eb54..cdcf84b826 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -493,13 +493,14 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 	return status;
 }
 
-int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)
+int repo_for_each_abbrev(struct repository *r, const char *prefix,
+			 each_abbrev_fn fn, void *cb_data)
 {
 	struct oid_array collect = OID_ARRAY_INIT;
 	struct disambiguate_state ds;
 	int ret;
 
-	if (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0)
+	if (init_object_disambiguation(r, prefix, strlen(prefix), &ds) < 0)
 		return -1;
 
 	ds.always_call_fn = 1;
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 16/32] sha1-name.c: remove the_repo from get_short_oid()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (14 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 15/32] sha1-name.c: add repo_for_each_abbrev() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 17/32] sha1-name.c: remove the_repo from interpret_nth_prior_checkout() Nguyễn Thái Ngọc Duy
                     ` (16 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index cdcf84b826..2643b75b54 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -436,7 +436,8 @@ static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)
 	sort_ambiguous_repo = NULL;
 }
 
-static enum get_oid_result get_short_oid(const char *name, int len,
+static enum get_oid_result get_short_oid(struct repository *r,
+					 const char *name, int len,
 					 struct object_id *oid,
 					 unsigned flags)
 {
@@ -444,7 +445,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 	struct disambiguate_state ds;
 	int quietly = !!(flags & GET_OID_QUIETLY);
 
-	if (init_object_disambiguation(the_repository, name, len, &ds) < 0)
+	if (init_object_disambiguation(r, name, len, &ds) < 0)
 		return -1;
 
 	if (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))
@@ -482,8 +483,8 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 			ds.fn = NULL;
 
 		advise(_("The candidates are:"));
-		for_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect);
-		sort_ambiguous_oid_array(the_repository, &collect);
+		repo_for_each_abbrev(r, ds.hex_pfx, collect_ambiguous, &collect);
+		sort_ambiguous_oid_array(r, &collect);
 
 		if (oid_array_for_each(&collect, show_ambiguous_object, &ds))
 			BUG("show_ambiguous_object shouldn't return non-zero");
@@ -855,7 +856,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 
 	if (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&
 	    (refs_found > 1 ||
-	     !get_short_oid(str, len, &tmp_oid, GET_OID_QUIETLY)))
+	     !get_short_oid(the_repository,
+			    str, len, &tmp_oid, GET_OID_QUIETLY)))
 		warning(warn_msg, len, str);
 
 	if (reflog_len) {
@@ -1109,7 +1111,8 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)
 			if (ch == 'g' && cp[-1] == '-') {
 				cp++;
 				len -= cp - name;
-				return get_short_oid(cp, len, oid, flags);
+				return get_short_oid(the_repository,
+						     cp, len, oid, flags);
 			}
 		}
 	}
@@ -1163,7 +1166,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,
 	if (!ret)
 		return FOUND;
 
-	return get_short_oid(name, len, oid, lookup_flags);
+	return get_short_oid(the_repository, name, len, oid, lookup_flags);
 }
 
 /*
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 17/32] sha1-name.c: remove the_repo from interpret_nth_prior_checkout()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (15 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 16/32] sha1-name.c: remove the_repo from get_short_oid() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 18/32] sha1-name.c: remove the_repo from interpret_branch_mark() Nguyễn Thái Ngọc Duy
                     ` (15 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 2643b75b54..af8bf5b351 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -771,7 +771,7 @@ static inline int push_mark(const char *string, int len)
 }
 
 static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
-static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);
+static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);
 
 static int get_oid_basic(const char *str, int len, struct object_id *oid,
 			  unsigned int flags)
@@ -835,7 +835,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 		struct strbuf buf = STRBUF_INIT;
 		int detached;
 
-		if (interpret_nth_prior_checkout(str, len, &buf) > 0) {
+		if (interpret_nth_prior_checkout(the_repository, str, len, &buf) > 0) {
 			detached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));
 			strbuf_release(&buf);
 			if (detached)
@@ -1288,7 +1288,8 @@ static int grab_nth_branch_switch(struct object_id *ooid, struct object_id *noid
  * Parse @{-N} syntax, return the number of characters parsed
  * if successful; otherwise signal an error with negative value.
  */
-static int interpret_nth_prior_checkout(const char *name, int namelen,
+static int interpret_nth_prior_checkout(struct repository *r,
+					const char *name, int namelen,
 					struct strbuf *buf)
 {
 	long nth;
@@ -1312,12 +1313,14 @@ static int interpret_nth_prior_checkout(const char *name, int namelen,
 	cb.remaining = nth;
 	strbuf_init(&cb.buf, 20);
 
-	retval = 0;
-	if (0 < for_each_reflog_ent_reverse("HEAD", grab_nth_branch_switch, &cb)) {
+	retval = refs_for_each_reflog_ent_reverse(get_main_ref_store(r),
+			"HEAD", grab_nth_branch_switch, &cb);
+	if (0 < retval) {
 		strbuf_reset(buf);
 		strbuf_addbuf(buf, &cb.buf);
 		retval = brace - name + 1;
-	}
+	} else
+		retval = 0;
 
 	strbuf_release(&cb.buf);
 	return retval;
@@ -1484,7 +1487,7 @@ int repo_interpret_branch_name(struct repository *r,
 		namelen = strlen(name);
 
 	if (!allowed || (allowed & INTERPRET_BRANCH_LOCAL)) {
-		len = interpret_nth_prior_checkout(name, namelen, buf);
+		len = interpret_nth_prior_checkout(the_repository, name, namelen, buf);
 		if (!len) {
 			return len; /* syntax Ok, not enough switches */
 		} else if (len > 0) {
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 18/32] sha1-name.c: remove the_repo from interpret_branch_mark()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (16 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 17/32] sha1-name.c: remove the_repo from interpret_nth_prior_checkout() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 19/32] sha1-name.c: add repo_interpret_branch_name() Nguyễn Thái Ngọc Duy
                     ` (14 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index af8bf5b351..7d9512ac44 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1412,9 +1412,9 @@ static int reinterpret(const char *name, int namelen, int len,
 	return ret - used + len;
 }
 
-static void set_shortened_ref(struct strbuf *buf, const char *ref)
+static void set_shortened_ref(struct repository *r, struct strbuf *buf, const char *ref)
 {
-	char *s = shorten_unambiguous_ref(ref, 0);
+	char *s = refs_shorten_unambiguous_ref(get_main_ref_store(r), ref, 0);
 	strbuf_reset(buf);
 	strbuf_addstr(buf, s);
 	free(s);
@@ -1435,7 +1435,8 @@ static int branch_interpret_allowed(const char *refname, unsigned allowed)
 	return 0;
 }
 
-static int interpret_branch_mark(const char *name, int namelen,
+static int interpret_branch_mark(struct repository *r,
+				 const char *name, int namelen,
 				 int at, struct strbuf *buf,
 				 int (*get_mark)(const char *, int),
 				 const char *(*get_data)(struct branch *,
@@ -1468,7 +1469,7 @@ static int interpret_branch_mark(const char *name, int namelen,
 	if (!branch_interpret_allowed(value, allowed))
 		return -1;
 
-	set_shortened_ref(buf, value);
+	set_shortened_ref(r, buf, value);
 	return len + at;
 }
 
@@ -1509,13 +1510,13 @@ int repo_interpret_branch_name(struct repository *r,
 						   allowed);
 		}
 
-		len = interpret_branch_mark(name, namelen, at - name, buf,
+		len = interpret_branch_mark(the_repository, name, namelen, at - name, buf,
 					    upstream_mark, branch_get_upstream,
 					    allowed);
 		if (len > 0)
 			return len;
 
-		len = interpret_branch_mark(name, namelen, at - name, buf,
+		len = interpret_branch_mark(the_repository, name, namelen, at - name, buf,
 					    push_mark, branch_get_push,
 					    allowed);
 		if (len > 0)
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 19/32] sha1-name.c: add repo_interpret_branch_name()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (17 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 18/32] sha1-name.c: remove the_repo from interpret_branch_mark() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 20/32] sha1-name.c: remove the_repo from get_oid_oneline() Nguyễn Thái Ngọc Duy
                     ` (13 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 7d9512ac44..49c62d5254 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1390,7 +1390,8 @@ static int interpret_empty_at(const char *name, int namelen, int len, struct str
 	return 1;
 }
 
-static int reinterpret(const char *name, int namelen, int len,
+static int reinterpret(struct repository *r,
+		       const char *name, int namelen, int len,
 		       struct strbuf *buf, unsigned allowed)
 {
 	/* we have extra data, which might need further processing */
@@ -1399,7 +1400,7 @@ static int reinterpret(const char *name, int namelen, int len,
 	int ret;
 
 	strbuf_add(buf, name + len, namelen - len);
-	ret = interpret_branch_name(buf->buf, buf->len, &tmp, allowed);
+	ret = repo_interpret_branch_name(r, buf->buf, buf->len, &tmp, allowed);
 	/* that data was not interpreted, remove our cruft */
 	if (ret < 0) {
 		strbuf_setlen(buf, used);
@@ -1482,20 +1483,18 @@ int repo_interpret_branch_name(struct repository *r,
 	const char *start;
 	int len;
 
-	if (r != the_repository)
-		BUG("interpret_branch_name() does not really use 'r' yet");
 	if (!namelen)
 		namelen = strlen(name);
 
 	if (!allowed || (allowed & INTERPRET_BRANCH_LOCAL)) {
-		len = interpret_nth_prior_checkout(the_repository, name, namelen, buf);
+		len = interpret_nth_prior_checkout(r, name, namelen, buf);
 		if (!len) {
 			return len; /* syntax Ok, not enough switches */
 		} else if (len > 0) {
 			if (len == namelen)
 				return len; /* consumed all */
 			else
-				return reinterpret(name, namelen, len, buf, allowed);
+				return reinterpret(r, name, namelen, len, buf, allowed);
 		}
 	}
 
@@ -1506,17 +1505,17 @@ int repo_interpret_branch_name(struct repository *r,
 		if (!allowed || (allowed & INTERPRET_BRANCH_HEAD)) {
 			len = interpret_empty_at(name, namelen, at - name, buf);
 			if (len > 0)
-				return reinterpret(name, namelen, len, buf,
+				return reinterpret(r, name, namelen, len, buf,
 						   allowed);
 		}
 
-		len = interpret_branch_mark(the_repository, name, namelen, at - name, buf,
+		len = interpret_branch_mark(r, name, namelen, at - name, buf,
 					    upstream_mark, branch_get_upstream,
 					    allowed);
 		if (len > 0)
 			return len;
 
-		len = interpret_branch_mark(the_repository, name, namelen, at - name, buf,
+		len = interpret_branch_mark(r, name, namelen, at - name, buf,
 					    push_mark, branch_get_push,
 					    allowed);
 		if (len > 0)
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 20/32] sha1-name.c: remove the_repo from get_oid_oneline()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (18 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 19/32] sha1-name.c: add repo_interpret_branch_name() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 21/32] sha1-name.c: remove the_repo from get_describe_name() Nguyễn Thái Ngọc Duy
                     ` (12 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 49c62d5254..fb80306f1a 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -15,7 +15,7 @@
 #include "midx.h"
 #include "commit-reach.h"
 
-static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
+static int get_oid_oneline(struct repository *r, const char *, struct object_id *, struct commit_list *);
 
 typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);
 
@@ -1090,7 +1090,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 
 		prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
 		commit_list_insert((struct commit *)o, &list);
-		ret = get_oid_oneline(prefix, oid, list);
+		ret = get_oid_oneline(the_repository, prefix, oid, list);
 		free(prefix);
 		return ret;
 	}
@@ -1204,8 +1204,9 @@ static int handle_one_ref(const char *path, const struct object_id *oid,
 	return 0;
 }
 
-static int get_oid_oneline(const char *prefix, struct object_id *oid,
-			    struct commit_list *list)
+static int get_oid_oneline(struct repository *r,
+			   const char *prefix, struct object_id *oid,
+			   struct commit_list *list)
 {
 	struct commit_list *backup = NULL, *l;
 	int found = 0;
@@ -1236,7 +1237,7 @@ static int get_oid_oneline(const char *prefix, struct object_id *oid,
 		int matches;
 
 		commit = pop_most_recent_commit(&list, ONELINE_SEEN);
-		if (!parse_object(the_repository, &commit->object.oid))
+		if (!parse_object(r, &commit->object.oid))
 			continue;
 		buf = get_commit_buffer(commit, NULL);
 		p = strstr(buf, "\n\n");
@@ -1760,7 +1761,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			for_each_ref(handle_one_ref, &list);
 			head_ref(handle_one_ref, &list);
 			commit_list_sort_by_date(&list);
-			return get_oid_oneline(name + 2, oid, list);
+			return get_oid_oneline(repo, name + 2, oid, list);
 		}
 		if (namelen < 3 ||
 		    name[2] != ':' ||
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 21/32] sha1-name.c: remove the_repo from get_describe_name()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (19 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 20/32] sha1-name.c: remove the_repo from get_oid_oneline() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 22/32] sha1-name.c: remove the_repo from get_oid_basic() Nguyễn Thái Ngọc Duy
                     ` (11 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index fb80306f1a..1cda854f02 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1097,7 +1097,9 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 	return 0;
 }
 
-static int get_describe_name(const char *name, int len, struct object_id *oid)
+static int get_describe_name(struct repository *r,
+			     const char *name, int len,
+			     struct object_id *oid)
 {
 	const char *cp;
 	unsigned flags = GET_OID_QUIETLY | GET_OID_COMMIT;
@@ -1111,7 +1113,7 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)
 			if (ch == 'g' && cp[-1] == '-') {
 				cp++;
 				len -= cp - name;
-				return get_short_oid(the_repository,
+				return get_short_oid(r,
 						     cp, len, oid, flags);
 			}
 		}
@@ -1162,7 +1164,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,
 		return FOUND;
 
 	/* It could be describe output that is "SOMETHING-gXXXX" */
-	ret = get_describe_name(name, len, oid);
+	ret = get_describe_name(the_repository, name, len, oid);
 	if (!ret)
 		return FOUND;
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 22/32] sha1-name.c: remove the_repo from get_oid_basic()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (20 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 21/32] sha1-name.c: remove the_repo from get_describe_name() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 23/32] sha1-name.c: remove the_repo from get_oid_1() Nguyễn Thái Ngọc Duy
                     ` (10 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 1cda854f02..d4c135aea8 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -773,8 +773,8 @@ static inline int push_mark(const char *string, int len)
 static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
 static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);
 
-static int get_oid_basic(const char *str, int len, struct object_id *oid,
-			  unsigned int flags)
+static int get_oid_basic(struct repository *r, const char *str, int len,
+			 struct object_id *oid, unsigned int flags)
 {
 	static const char *warn_msg = "refname '%.*s' is ambiguous.";
 	static const char *object_name_msg = N_(
@@ -792,9 +792,9 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 	int refs_found = 0;
 	int at, reflog_len, nth_prior = 0;
 
-	if (len == the_hash_algo->hexsz && !get_oid_hex(str, oid)) {
+	if (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {
 		if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
-			refs_found = dwim_ref(str, len, &tmp_oid, &real_ref);
+			refs_found = repo_dwim_ref(r, str, len, &tmp_oid, &real_ref);
 			if (refs_found > 0) {
 				warning(warn_msg, len, str);
 				if (advice_object_name_warning)
@@ -835,8 +835,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 		struct strbuf buf = STRBUF_INIT;
 		int detached;
 
-		if (interpret_nth_prior_checkout(the_repository, str, len, &buf) > 0) {
-			detached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));
+		if (interpret_nth_prior_checkout(r, str, len, &buf) > 0) {
+			detached = (buf.len == r->hash_algo->hexsz && !get_oid_hex(buf.buf, oid));
 			strbuf_release(&buf);
 			if (detached)
 				return 0;
@@ -845,19 +845,18 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 
 	if (!len && reflog_len)
 		/* allow "@{...}" to mean the current branch reflog */
-		refs_found = dwim_ref("HEAD", 4, oid, &real_ref);
+		refs_found = repo_dwim_ref(r, "HEAD", 4, oid, &real_ref);
 	else if (reflog_len)
-		refs_found = dwim_log(str, len, oid, &real_ref);
+		refs_found = repo_dwim_log(r, str, len, oid, &real_ref);
 	else
-		refs_found = dwim_ref(str, len, oid, &real_ref);
+		refs_found = repo_dwim_ref(r, str, len, oid, &real_ref);
 
 	if (!refs_found)
 		return -1;
 
 	if (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&
 	    (refs_found > 1 ||
-	     !get_short_oid(the_repository,
-			    str, len, &tmp_oid, GET_OID_QUIETLY)))
+	     !get_short_oid(r, str, len, &tmp_oid, GET_OID_QUIETLY)))
 		warning(warn_msg, len, str);
 
 	if (reflog_len) {
@@ -889,7 +888,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 				return -1;
 			}
 		}
-		if (read_ref_at(get_main_ref_store(the_repository),
+		if (read_ref_at(get_main_ref_store(r),
 				real_ref, flags, at_time, nth, oid, NULL,
 				&co_time, &co_tz, &co_cnt)) {
 			if (!len) {
@@ -1159,7 +1158,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,
 	if (!ret)
 		return FOUND;
 
-	ret = get_oid_basic(name, len, oid, lookup_flags);
+	ret = get_oid_basic(the_repository, name, len, oid, lookup_flags);
 	if (!ret)
 		return FOUND;
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 23/32] sha1-name.c: remove the_repo from get_oid_1()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (21 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 22/32] sha1-name.c: remove the_repo from get_oid_basic() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 24/32] sha1-name.c: remove the_repo from handle_one_ref() Nguyễn Thái Ngọc Duy
                     ` (9 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

There is a cyclic dependency between one of these functions so they
cannot be converted one by one, so all related functions are converted
at once.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     |  7 +++++--
 sha1-name.c | 59 ++++++++++++++++++++++++++++-------------------------
 2 files changed, 36 insertions(+), 30 deletions(-)

diff --git a/cache.h b/cache.h
index 0cb95c0d4f..2149dc4f56 100644
--- a/cache.h
+++ b/cache.h
@@ -1491,8 +1491,11 @@ extern void *read_object_with_reference(const struct object_id *oid,
 					unsigned long *size,
 					struct object_id *oid_ret);
 
-extern struct object *peel_to_type(const char *name, int namelen,
-				   struct object *o, enum object_type);
+struct object *repo_peel_to_type(struct repository *r,
+				 const char *name, int namelen,
+				 struct object *o, enum object_type);
+#define peel_to_type(name, namelen, obj, type) \
+	repo_peel_to_type(the_repository, name, namelen, obj, type)
 
 enum date_mode_type {
 	DATE_NORMAL = 0,
diff --git a/sha1-name.c b/sha1-name.c
index d4c135aea8..5741a9f821 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -770,7 +770,7 @@ static inline int push_mark(const char *string, int len)
 	return at_mark(string, len, suffix, ARRAY_SIZE(suffix));
 }
 
-static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
+static enum get_oid_result get_oid_1(struct repository *r, const char *name, int len, struct object_id *oid, unsigned lookup_flags);
 static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);
 
 static int get_oid_basic(struct repository *r, const char *str, int len,
@@ -921,18 +921,19 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
 	return 0;
 }
 
-static enum get_oid_result get_parent(const char *name, int len,
+static enum get_oid_result get_parent(struct repository *r,
+				      const char *name, int len,
 				      struct object_id *result, int idx)
 {
 	struct object_id oid;
-	enum get_oid_result ret = get_oid_1(name, len, &oid,
+	enum get_oid_result ret = get_oid_1(r, name, len, &oid,
 					    GET_OID_COMMITTISH);
 	struct commit *commit;
 	struct commit_list *p;
 
 	if (ret)
 		return ret;
-	commit = lookup_commit_reference(the_repository, &oid);
+	commit = lookup_commit_reference(r, &oid);
 	if (parse_commit(commit))
 		return MISSING_OBJECT;
 	if (!idx) {
@@ -950,7 +951,8 @@ static enum get_oid_result get_parent(const char *name, int len,
 	return MISSING_OBJECT;
 }
 
-static enum get_oid_result get_nth_ancestor(const char *name, int len,
+static enum get_oid_result get_nth_ancestor(struct repository *r,
+					    const char *name, int len,
 					    struct object_id *result,
 					    int generation)
 {
@@ -958,10 +960,10 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,
 	struct commit *commit;
 	int ret;
 
-	ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);
+	ret = get_oid_1(r, name, len, &oid, GET_OID_COMMITTISH);
 	if (ret)
 		return ret;
-	commit = lookup_commit_reference(the_repository, &oid);
+	commit = lookup_commit_reference(r, &oid);
 	if (!commit)
 		return MISSING_OBJECT;
 
@@ -974,20 +976,20 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,
 	return FOUND;
 }
 
-struct object *peel_to_type(const char *name, int namelen,
-			    struct object *o, enum object_type expected_type)
+struct object *repo_peel_to_type(struct repository *r, const char *name, int namelen,
+				 struct object *o, enum object_type expected_type)
 {
 	if (name && !namelen)
 		namelen = strlen(name);
 	while (1) {
-		if (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))
+		if (!o || (!o->parsed && !parse_object(r, &o->oid)))
 			return NULL;
 		if (expected_type == OBJ_ANY || o->type == expected_type)
 			return o;
 		if (o->type == OBJ_TAG)
 			o = ((struct tag*) o)->tagged;
 		else if (o->type == OBJ_COMMIT)
-			o = &(get_commit_tree(((struct commit *)o))->object);
+			o = &(repo_get_commit_tree(r, ((struct commit *)o))->object);
 		else {
 			if (name)
 				error("%.*s: expected %s type, but the object "
@@ -999,8 +1001,8 @@ struct object *peel_to_type(const char *name, int namelen,
 	}
 }
 
-static int peel_onion(const char *name, int len, struct object_id *oid,
-		      unsigned lookup_flags)
+static int peel_onion(struct repository *r, const char *name, int len,
+		      struct object_id *oid, unsigned lookup_flags)
 {
 	struct object_id outer;
 	const char *sp;
@@ -1050,15 +1052,15 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 	else if (expected_type == OBJ_TREE)
 		lookup_flags |= GET_OID_TREEISH;
 
-	if (get_oid_1(name, sp - name - 2, &outer, lookup_flags))
+	if (get_oid_1(r, name, sp - name - 2, &outer, lookup_flags))
 		return -1;
 
-	o = parse_object(the_repository, &outer);
+	o = parse_object(r, &outer);
 	if (!o)
 		return -1;
 	if (!expected_type) {
-		o = deref_tag(the_repository, o, name, sp - name - 2);
-		if (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))
+		o = deref_tag(r, o, name, sp - name - 2);
+		if (!o || (!o->parsed && !parse_object(r, &o->oid)))
 			return -1;
 		oidcpy(oid, &o->oid);
 		return 0;
@@ -1069,7 +1071,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 	 * if we do not get the needed object, we should
 	 * barf.
 	 */
-	o = peel_to_type(name, len, o, expected_type);
+	o = repo_peel_to_type(r, name, len, o, expected_type);
 	if (!o)
 		return -1;
 
@@ -1089,7 +1091,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 
 		prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
 		commit_list_insert((struct commit *)o, &list);
-		ret = get_oid_oneline(the_repository, prefix, oid, list);
+		ret = get_oid_oneline(r, prefix, oid, list);
 		free(prefix);
 		return ret;
 	}
@@ -1120,7 +1122,8 @@ static int get_describe_name(struct repository *r,
 	return -1;
 }
 
-static enum get_oid_result get_oid_1(const char *name, int len,
+static enum get_oid_result get_oid_1(struct repository *r,
+				     const char *name, int len,
 				     struct object_id *oid,
 				     unsigned lookup_flags)
 {
@@ -1149,25 +1152,25 @@ static enum get_oid_result get_oid_1(const char *name, int len,
 		if (!num && len1 == len - 1)
 			num = 1;
 		if (has_suffix == '^')
-			return get_parent(name, len1, oid, num);
+			return get_parent(r, name, len1, oid, num);
 		/* else if (has_suffix == '~') -- goes without saying */
-		return get_nth_ancestor(name, len1, oid, num);
+		return get_nth_ancestor(r, name, len1, oid, num);
 	}
 
-	ret = peel_onion(name, len, oid, lookup_flags);
+	ret = peel_onion(r, name, len, oid, lookup_flags);
 	if (!ret)
 		return FOUND;
 
-	ret = get_oid_basic(the_repository, name, len, oid, lookup_flags);
+	ret = get_oid_basic(r, name, len, oid, lookup_flags);
 	if (!ret)
 		return FOUND;
 
 	/* It could be describe output that is "SOMETHING-gXXXX" */
-	ret = get_describe_name(the_repository, name, len, oid);
+	ret = get_describe_name(r, name, len, oid);
 	if (!ret)
 		return FOUND;
 
-	return get_short_oid(the_repository, name, len, oid, lookup_flags);
+	return get_short_oid(r, name, len, oid, lookup_flags);
 }
 
 /*
@@ -1741,7 +1744,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 	memset(oc, 0, sizeof(*oc));
 	oc->mode = S_IFINVALID;
 	strbuf_init(&oc->symlink_path, 0);
-	ret = get_oid_1(name, namelen, oid, flags);
+	ret = get_oid_1(repo, name, namelen, oid, flags);
 	if (!ret)
 		return ret;
 	/*
@@ -1822,7 +1825,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 		sub_flags &= ~GET_OID_DISAMBIGUATORS;
 		sub_flags |= GET_OID_TREEISH;
 
-		if (!get_oid_1(name, len, &tree_oid, sub_flags)) {
+		if (!get_oid_1(repo, name, len, &tree_oid, sub_flags)) {
 			const char *filename = cp+1;
 			char *new_filename = NULL;
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 24/32] sha1-name.c: remove the_repo from handle_one_ref()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (22 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 23/32] sha1-name.c: remove the_repo from get_oid_1() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 25/32] sha1-name.c: remove the_repo from diagnose_invalid_index_path() Nguyễn Thái Ngọc Duy
                     ` (8 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 5741a9f821..d9050776dd 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1189,15 +1189,21 @@ static enum get_oid_result get_oid_1(struct repository *r,
 /* Remember to update object flag allocation in object.h */
 #define ONELINE_SEEN (1u<<20)
 
+struct handle_one_ref_cb {
+	struct repository *repo;
+	struct commit_list **list;
+};
+
 static int handle_one_ref(const char *path, const struct object_id *oid,
 			  int flag, void *cb_data)
 {
-	struct commit_list **list = cb_data;
-	struct object *object = parse_object(the_repository, oid);
+	struct handle_one_ref_cb *cb = cb_data;
+	struct commit_list **list = cb->list;
+	struct object *object = parse_object(cb->repo, oid);
 	if (!object)
 		return 0;
 	if (object->type == OBJ_TAG) {
-		object = deref_tag(the_repository, object, path,
+		object = deref_tag(cb->repo, object, path,
 				   strlen(path));
 		if (!object)
 			return 0;
@@ -1760,10 +1766,13 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 		char *new_path = NULL;
 		int pos;
 		if (!only_to_die && namelen > 2 && name[1] == '/') {
+			struct handle_one_ref_cb cb;
 			struct commit_list *list = NULL;
 
-			for_each_ref(handle_one_ref, &list);
-			head_ref(handle_one_ref, &list);
+			cb.repo = repo;
+			cb.list = &list;
+			refs_for_each_ref(repo->refs, handle_one_ref, &cb);
+			refs_head_ref(repo->refs, handle_one_ref, &cb);
 			commit_list_sort_by_date(&list);
 			return get_oid_oneline(repo, name + 2, oid, list);
 		}
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 25/32] sha1-name.c: remove the_repo from diagnose_invalid_index_path()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (23 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 24/32] sha1-name.c: remove the_repo from handle_one_ref() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 26/32] sha1-name.c: remove the_repo from resolve_relative_path() Nguyễn Thái Ngọc Duy
                     ` (7 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 dir.c       | 8 ++++++++
 dir.h       | 4 +++-
 sha1-name.c | 7 ++++---
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/dir.c b/dir.c
index b2cabadf25..e6d97343f4 100644
--- a/dir.c
+++ b/dir.c
@@ -2315,6 +2315,14 @@ int file_exists(const char *f)
 	return lstat(f, &sb) == 0;
 }
 
+int repo_file_exists(struct repository *repo, const char *path)
+{
+	if (repo != the_repository)
+		BUG("do not know how to check file existence in arbitrary repo");
+
+	return file_exists(path);
+}
+
 static int cmp_icase(char a, char b)
 {
 	if (a == b)
diff --git a/dir.h b/dir.h
index e3ec26143d..47c5409ced 100644
--- a/dir.h
+++ b/dir.h
@@ -269,7 +269,9 @@ extern void add_exclude(const char *string, const char *base,
 			int baselen, struct exclude_list *el, int srcpos);
 extern void clear_exclude_list(struct exclude_list *el);
 extern void clear_directory(struct dir_struct *dir);
-extern int file_exists(const char *);
+
+int repo_file_exists(struct repository *repo, const char *path);
+int file_exists(const char *);
 
 extern int is_inside_dir(const char *dir);
 extern int dir_inside_of(const char *subdir, const char *dir);
diff --git a/sha1-name.c b/sha1-name.c
index d9050776dd..6caf3f4e3a 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1664,11 +1664,12 @@ static void diagnose_invalid_oid_path(const char *prefix,
 }
 
 /* Must be called only when :stage:filename doesn't exist. */
-static void diagnose_invalid_index_path(struct index_state *istate,
+static void diagnose_invalid_index_path(struct repository *r,
 					int stage,
 					const char *prefix,
 					const char *filename)
 {
+	struct index_state *istate = r->index;
 	const struct cache_entry *ce;
 	int pos;
 	unsigned namelen = strlen(filename);
@@ -1708,7 +1709,7 @@ static void diagnose_invalid_index_path(struct index_state *istate,
 			    ce_stage(ce), filename);
 	}
 
-	if (file_exists(filename))
+	if (repo_file_exists(r, filename))
 		die("Path '%s' exists on disk, but not in the index.", filename);
 	if (is_missing_file_error(errno))
 		die("Path '%s' does not exist (neither on disk nor in the index).",
@@ -1814,7 +1815,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			pos++;
 		}
 		if (only_to_die && name[1] && name[1] != '/')
-			diagnose_invalid_index_path(repo->index, stage, prefix, cp);
+			diagnose_invalid_index_path(repo, stage, prefix, cp);
 		free(new_path);
 		return -1;
 	}
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 26/32] sha1-name.c: remove the_repo from resolve_relative_path()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (24 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 25/32] sha1-name.c: remove the_repo from diagnose_invalid_index_path() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 27/32] sha1-name.c: remove the_repo from get_oid_with_context_1() Nguyễn Thái Ngọc Duy
                     ` (6 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

"remove" is not entirely correct. But at least the function is aware
that if the given repo is not the_repository, then $CWD and
is_inside_work_tree() means nothing.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 6caf3f4e3a..6b53ea2eeb 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1719,12 +1719,12 @@ static void diagnose_invalid_index_path(struct repository *r,
 }
 
 
-static char *resolve_relative_path(const char *rel)
+static char *resolve_relative_path(struct repository *r, const char *rel)
 {
 	if (!starts_with(rel, "./") && !starts_with(rel, "../"))
 		return NULL;
 
-	if (!is_inside_work_tree())
+	if (r != the_repository || !is_inside_work_tree())
 		die("relative path syntax can't be used outside working tree.");
 
 	/* die() inside prefix_path() if resolved path is outside worktree */
@@ -1785,7 +1785,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			stage = name[1] - '0';
 			cp = name + 3;
 		}
-		new_path = resolve_relative_path(cp);
+		new_path = resolve_relative_path(repo, cp);
 		if (!new_path) {
 			namelen = namelen - (cp - name);
 		} else {
@@ -1839,7 +1839,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			const char *filename = cp+1;
 			char *new_filename = NULL;
 
-			new_filename = resolve_relative_path(filename);
+			new_filename = resolve_relative_path(repo, filename);
 			if (new_filename)
 				filename = new_filename;
 			if (flags & GET_OID_FOLLOW_SYMLINKS) {
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 27/32] sha1-name.c: remove the_repo from get_oid_with_context_1()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (25 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 26/32] sha1-name.c: remove the_repo from resolve_relative_path() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 28/32] sha1-name.c: add repo_get_oid() Nguyễn Thái Ngọc Duy
                     ` (5 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/sha1-name.c b/sha1-name.c
index 6b53ea2eeb..64a50d1291 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -12,6 +12,7 @@
 #include "packfile.h"
 #include "object-store.h"
 #include "repository.h"
+#include "submodule.h"
 #include "midx.h"
 #include "commit-reach.h"
 
@@ -1797,7 +1798,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			oc->path = xstrdup(cp);
 
 		if (!repo->index->cache)
-			repo_read_index(the_repository);
+			repo_read_index(repo);
 		pos = index_name_pos(repo->index, cp, namelen);
 		if (pos < 0)
 			pos = -pos - 1;
@@ -1842,6 +1843,14 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			new_filename = resolve_relative_path(repo, filename);
 			if (new_filename)
 				filename = new_filename;
+			/*
+			 * NEEDSWORK: Eventually get_tree_entry*() should
+			 * learn to take struct repository directly and we
+			 * would not need to inject submodule odb to the
+			 * in-core odb.
+			 */
+			if (repo != the_repository)
+				add_to_alternates_memory(repo->objects->odb->path);
 			if (flags & GET_OID_FOLLOW_SYMLINKS) {
 				ret = get_tree_entry_follow_symlinks(&tree_oid,
 					filename, oid, &oc->symlink_path,
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 28/32] sha1-name.c: add repo_get_oid()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (26 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 27/32] sha1-name.c: remove the_repo from get_oid_with_context_1() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 29/32] submodule-config.c: use repo_get_oid for reading .gitmodules Nguyễn Thái Ngọc Duy
                     ` (4 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 3 ++-
 sha1-name.c | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/cache.h b/cache.h
index 2149dc4f56..f6e87194d0 100644
--- a/cache.h
+++ b/cache.h
@@ -1380,7 +1380,8 @@ enum get_oid_result {
 		       */
 };
 
-extern int get_oid(const char *str, struct object_id *oid);
+int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);
+#define get_oid(str, oid) repo_get_oid(the_repository, str, oid)
 extern int get_oid_commit(const char *str, struct object_id *oid);
 extern int get_oid_committish(const char *str, struct object_id *oid);
 extern int get_oid_tree(const char *str, struct object_id *oid);
diff --git a/sha1-name.c b/sha1-name.c
index 64a50d1291..953df0d692 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1573,10 +1573,10 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
  * This is like "get_oid_basic()", except it allows "object ID expressions",
  * notably "xyz^" for "parent of xyz"
  */
-int get_oid(const char *name, struct object_id *oid)
+int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository, name, 0, oid, &unused);
+	return get_oid_with_context(r, name, 0, oid, &unused);
 }
 
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 29/32] submodule-config.c: use repo_get_oid for reading .gitmodules
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (27 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 28/32] sha1-name.c: add repo_get_oid() Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 30/32] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name Nguyễn Thái Ngọc Duy
                     ` (3 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Since 76e9bdc437 (submodule: support reading .gitmodules when it's not
in the working tree - 2018-10-25), every time you do

    git grep --recurse-submodules

you are likely to see one warning line per submodule (unless all those
submodules also have submodules). On a superproject with plenty of
submodules (I've seen one with 67) this is really annoying.

The warning was there because we could not resolve extended SHA-1
syntax on a submodule. We can now. Make use of the new API and get rid
of the warning.

It would be even better if config_with_options() supports multiple
repositories too. But one step at a time.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 submodule-config.c                 | 20 +++++++-------------
 t/t7814-grep-recurse-submodules.sh |  6 +-----
 2 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/submodule-config.c b/submodule-config.c
index 66653e86b9..4264ee216f 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -625,23 +625,16 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
 		const struct config_options opts = { 0 };
 		struct object_id oid;
 		char *file;
+		char *oidstr = NULL;
 
 		file = repo_worktree_path(repo, GITMODULES_FILE);
 		if (file_exists(file)) {
 			config_source.file = file;
-		} else if (repo->submodule_prefix) {
-			/*
-			 * When get_oid and config_with_options, used below,
-			 * become able to work on a specific repository, this
-			 * warning branch can be removed.
-			 */
-			warning("nested submodules without %s in the working tree are not supported yet",
-				GITMODULES_FILE);
-			goto out;
-		} else if (get_oid(GITMODULES_INDEX, &oid) >= 0) {
-			config_source.blob = GITMODULES_INDEX;
-		} else if (get_oid(GITMODULES_HEAD, &oid) >= 0) {
-			config_source.blob = GITMODULES_HEAD;
+		} else if (repo_get_oid(repo, GITMODULES_INDEX, &oid) >= 0 ||
+			   repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
+			config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
+			if (repo != the_repository)
+				add_to_alternates_memory(repo->objects->odb->path);
 		} else {
 			goto out;
 		}
@@ -649,6 +642,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
 		config_with_options(fn, data, &config_source, &opts);
 
 out:
+		free(oidstr);
 		free(file);
 	}
 }
diff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh
index fa475d52fa..134a694516 100755
--- a/t/t7814-grep-recurse-submodules.sh
+++ b/t/t7814-grep-recurse-submodules.sh
@@ -380,11 +380,7 @@ test_expect_success 'grep --recurse-submodules should pass the pattern type alon
 	fi
 '
 
-# Recursing down into nested submodules which do not have .gitmodules in their
-# working tree does not work yet. This is because config_from_gitmodules()
-# uses get_oid() and the latter is still not able to get objects from an
-# arbitrary repository (the nested submodule, in this case).
-test_expect_failure 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '
+test_expect_success 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '
 	test_when_finished "git -C submodule checkout .gitmodules" &&
 	rm submodule/.gitmodules &&
 	git grep --recurse-submodules -e "(.|.)[\d]" >actual &&
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 30/32] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (28 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 29/32] submodule-config.c: use repo_get_oid for reading .gitmodules Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 31/32] sha1-name.c: remove the_repo from other get_oid_* Nguyễn Thái Ngọc Duy
                     ` (2 subsequent siblings)
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 4 +++-
 setup.c     | 7 ++++---
 sha1-name.c | 6 ++++--
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/cache.h b/cache.h
index f6e87194d0..3718b3db8a 100644
--- a/cache.h
+++ b/cache.h
@@ -1387,7 +1387,9 @@ extern int get_oid_committish(const char *str, struct object_id *oid);
 extern int get_oid_tree(const char *str, struct object_id *oid);
 extern int get_oid_treeish(const char *str, struct object_id *oid);
 extern int get_oid_blob(const char *str, struct object_id *oid);
-extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
+void maybe_die_on_misspelt_object_name(struct repository *repo,
+				       const char *name,
+				       const char *prefix);
 extern enum get_oid_result get_oid_with_context(struct repository *repo, const char *str,
 				unsigned flags, struct object_id *oid,
 				struct object_context *oc);
diff --git a/setup.c b/setup.c
index d0c958c3b2..8dcb4631f7 100644
--- a/setup.c
+++ b/setup.c
@@ -164,7 +164,8 @@ int check_filename(const char *prefix, const char *arg)
 	die_errno(_("failed to stat '%s'"), arg);
 }
 
-static void NORETURN die_verify_filename(const char *prefix,
+static void NORETURN die_verify_filename(struct repository *r,
+					 const char *prefix,
 					 const char *arg,
 					 int diagnose_misspelt_rev)
 {
@@ -179,7 +180,7 @@ static void NORETURN die_verify_filename(const char *prefix,
 	 * let maybe_die_on_misspelt_object_name() even trigger.
 	 */
 	if (!(arg[0] == ':' && !isalnum(arg[1])))
-		maybe_die_on_misspelt_object_name(arg, prefix);
+		maybe_die_on_misspelt_object_name(r, arg, prefix);
 
 	/* ... or fall back the most general message. */
 	die(_("ambiguous argument '%s': unknown revision or path not in the working tree.\n"
@@ -234,7 +235,7 @@ void verify_filename(const char *prefix,
 		die(_("option '%s' must come before non-option arguments"), arg);
 	if (looks_like_pathspec(arg) || check_filename(prefix, arg))
 		return;
-	die_verify_filename(prefix, arg, diagnose_misspelt_rev);
+	die_verify_filename(the_repository, prefix, arg, diagnose_misspelt_rev);
 }
 
 /*
diff --git a/sha1-name.c b/sha1-name.c
index 953df0d692..b94d381bef 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1885,11 +1885,13 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
  * exist in 'HEAD'" when given "HEAD:doc", or it may return in which case
  * you have a chance to diagnose the error further.
  */
-void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
+void maybe_die_on_misspelt_object_name(struct repository *r,
+				       const char *name,
+				       const char *prefix)
 {
 	struct object_context oc;
 	struct object_id oid;
-	get_oid_with_context_1(the_repository, name, GET_OID_ONLY_TO_DIE,
+	get_oid_with_context_1(r, name, GET_OID_ONLY_TO_DIE,
 			       prefix, &oid, &oc);
 }
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 31/32] sha1-name.c: remove the_repo from other get_oid_*
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (29 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 30/32] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-03 11:34   ` [PATCH v2 32/32] sha1-name.c: remove the_repo from get_oid_mb() Nguyễn Thái Ngọc Duy
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 18 ++++++++++++------
 sha1-name.c | 35 ++++++++++++++++++++---------------
 2 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/cache.h b/cache.h
index 3718b3db8a..871a167bf8 100644
--- a/cache.h
+++ b/cache.h
@@ -1381,12 +1381,11 @@ enum get_oid_result {
 };
 
 int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);
-#define get_oid(str, oid) repo_get_oid(the_repository, str, oid)
-extern int get_oid_commit(const char *str, struct object_id *oid);
-extern int get_oid_committish(const char *str, struct object_id *oid);
-extern int get_oid_tree(const char *str, struct object_id *oid);
-extern int get_oid_treeish(const char *str, struct object_id *oid);
-extern int get_oid_blob(const char *str, struct object_id *oid);
+int repo_get_oid_commit(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_committish(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid);
 void maybe_die_on_misspelt_object_name(struct repository *repo,
 				       const char *name,
 				       const char *prefix);
@@ -1394,6 +1393,13 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c
 				unsigned flags, struct object_id *oid,
 				struct object_context *oc);
 
+#define get_oid(str, oid)		repo_get_oid(the_repository, str, oid)
+#define get_oid_commit(str, oid)	repo_get_oid_commit(the_repository, str, oid)
+#define get_oid_committish(str, oid)	repo_get_oid_committish(the_repository, str, oid)
+#define get_oid_tree(str, oid)		repo_get_oid_tree(the_repository, str, oid)
+#define get_oid_treeish(str, oid)	repo_get_oid_treeish(the_repository, str, oid)
+#define get_oid_blob(str, oid)		repo_get_oid_blob(the_repository, str, oid)
+
 typedef int each_abbrev_fn(const struct object_id *oid, void *);
 int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);
 #define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data)
diff --git a/sha1-name.c b/sha1-name.c
index b94d381bef..d49496397d 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1590,43 +1590,48 @@ int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)
  * commit-ish. It is merely to give a hint to the disambiguation
  * machinery.
  */
-int get_oid_committish(const char *name, struct object_id *oid)
+int repo_get_oid_committish(struct repository *r,
+			    const char *name,
+			    struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_COMMITTISH,
+	return get_oid_with_context(r, name, GET_OID_COMMITTISH,
 				    oid, &unused);
 }
 
-int get_oid_treeish(const char *name, struct object_id *oid)
+int repo_get_oid_treeish(struct repository *r,
+			 const char *name,
+			 struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_TREEISH,
+	return get_oid_with_context(r, name, GET_OID_TREEISH,
 				    oid, &unused);
 }
 
-int get_oid_commit(const char *name, struct object_id *oid)
+int repo_get_oid_commit(struct repository *r,
+			const char *name,
+			struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_COMMIT,
+	return get_oid_with_context(r, name, GET_OID_COMMIT,
 				    oid, &unused);
 }
 
-int get_oid_tree(const char *name, struct object_id *oid)
+int repo_get_oid_tree(struct repository *r,
+		      const char *name,
+		      struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_TREE,
+	return get_oid_with_context(r, name, GET_OID_TREE,
 				    oid, &unused);
 }
 
-int get_oid_blob(const char *name, struct object_id *oid)
+int repo_get_oid_blob(struct repository *r,
+		      const char *name,
+		      struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_BLOB,
+	return get_oid_with_context(r, name, GET_OID_BLOB,
 				    oid, &unused);
 }
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v2 32/32] sha1-name.c: remove the_repo from get_oid_mb()
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (30 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 31/32] sha1-name.c: remove the_repo from other get_oid_* Nguyễn Thái Ngọc Duy
@ 2019-04-03 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
  32 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-03 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, SZEDER Gábor

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     |  3 ++-
 sha1-name.c | 18 +++++++++++-------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/cache.h b/cache.h
index 871a167bf8..9a600a8b50 100644
--- a/cache.h
+++ b/cache.h
@@ -1386,6 +1386,7 @@ int repo_get_oid_committish(struct repository *r, const char *str, struct object
 int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid);
 int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid);
 int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_mb(struct repository *r, const char *str, struct object_id *oid);
 void maybe_die_on_misspelt_object_name(struct repository *repo,
 				       const char *name,
 				       const char *prefix);
@@ -1399,6 +1400,7 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c
 #define get_oid_tree(str, oid)		repo_get_oid_tree(the_repository, str, oid)
 #define get_oid_treeish(str, oid)	repo_get_oid_treeish(the_repository, str, oid)
 #define get_oid_blob(str, oid)		repo_get_oid_blob(the_repository, str, oid)
+#define get_oid_mb(str, oid) 		repo_get_oid_mb(the_repository, str, oid)
 
 typedef int each_abbrev_fn(const struct object_id *oid, void *);
 int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);
@@ -1486,7 +1488,6 @@ int repo_interpret_branch_name(struct repository *r,
 			       unsigned allowed);
 #define interpret_branch_name(str, len, buf, allowed) \
 	repo_interpret_branch_name(the_repository, str, len, buf, allowed)
-extern int get_oid_mb(const char *str, struct object_id *oid);
 
 extern int validate_headref(const char *ref);
 
diff --git a/sha1-name.c b/sha1-name.c
index d49496397d..cf314ebb29 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1338,7 +1338,9 @@ static int interpret_nth_prior_checkout(struct repository *r,
 	return retval;
 }
 
-int get_oid_mb(const char *name, struct object_id *oid)
+int repo_get_oid_mb(struct repository *r,
+		    const char *name,
+		    struct object_id *oid)
 {
 	struct commit *one, *two;
 	struct commit_list *mbs;
@@ -1348,27 +1350,29 @@ int get_oid_mb(const char *name, struct object_id *oid)
 
 	dots = strstr(name, "...");
 	if (!dots)
-		return get_oid(name, oid);
+		return repo_get_oid(r, name, oid);
 	if (dots == name)
-		st = get_oid("HEAD", &oid_tmp);
+		st = repo_get_oid(r, "HEAD", &oid_tmp);
 	else {
 		struct strbuf sb;
 		strbuf_init(&sb, dots - name);
 		strbuf_add(&sb, name, dots - name);
-		st = get_oid_committish(sb.buf, &oid_tmp);
+		st = repo_get_oid_committish(r, sb.buf, &oid_tmp);
 		strbuf_release(&sb);
 	}
 	if (st)
 		return st;
-	one = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);
+	one = lookup_commit_reference_gently(r, &oid_tmp, 0);
 	if (!one)
 		return -1;
 
-	if (get_oid_committish(dots[3] ? (dots + 3) : "HEAD", &oid_tmp))
+	if (repo_get_oid_committish(r, dots[3] ? (dots + 3) : "HEAD", &oid_tmp))
 		return -1;
-	two = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);
+	two = lookup_commit_reference_gently(r, &oid_tmp, 0);
 	if (!two)
 		return -1;
+	if (r != the_repository)
+		BUG("sorry get_merge_bases() can't take struct repository yet");
 	mbs = get_merge_bases(one, two);
 	if (!mbs || mbs->next)
 		st = -1;
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* Re: [PATCH v2 10/32] commit.c: add repo_get_commit_tree()
  2019-04-03 11:34   ` [PATCH v2 10/32] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
@ 2019-04-04 17:04     ` SZEDER Gábor
  2019-04-05  9:32       ` Duy Nguyen
  0 siblings, 1 reply; 154+ messages in thread
From: SZEDER Gábor @ 2019-04-04 17:04 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git, gitster, stefanbeller

On Wed, Apr 03, 2019 at 06:34:35PM +0700, Nguyễn Thái Ngọc Duy wrote:
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>

Oh, look, an empty commit message ;)

> ---
>  commit.c                        | 5 +++--
>  commit.h                        | 3 ++-
>  contrib/coccinelle/commit.cocci | 4 ++--
>  3 files changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/commit.c b/commit.c
> index a5333c7ac6..f0a5506f04 100644
> --- a/commit.c
> +++ b/commit.c
> @@ -340,7 +340,8 @@ void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)
>  	}
>  }
>  
> -struct tree *get_commit_tree(const struct commit *commit)
> +struct tree *repo_get_commit_tree(struct repository *r,
> +				  const struct commit *commit)

A rename to accomodate the additional 'struct repository*'
parameter.  Ok.

>  {
>  	if (commit->maybe_tree || !commit->object.parsed)
>  		return commit->maybe_tree;
> @@ -348,7 +349,7 @@ struct tree *get_commit_tree(const struct commit *commit)
>  	if (commit->graph_pos == COMMIT_NOT_FROM_GRAPH)
>  		BUG("commit has NULL tree, but was not loaded from commit-graph");
>  
> -	return get_commit_tree_in_graph(the_repository, commit);
> +	return get_commit_tree_in_graph(r, commit);
>  }
>  
>  struct object_id *get_commit_tree_oid(const struct commit *commit)
> diff --git a/commit.h b/commit.h
> index 42728c2906..b576201be8 100644
> --- a/commit.h
> +++ b/commit.h
> @@ -143,7 +143,8 @@ void repo_unuse_commit_buffer(struct repository *r,
>   */
>  void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);
>  
> -struct tree *get_commit_tree(const struct commit *);
> +struct tree *repo_get_commit_tree(struct repository *, const struct commit *);
> +#define get_commit_tree(c) repo_get_commit_tree(the_repository, c)

But we still keep 'get_commit_tree' around as a macro wrapper
defaulting to 'the_repository', leaving the 30+ callsites intact.
Good.

Furthermore, the comment describing the 'maybe_tree' field in 'struct
commit's declaration still suggest get_commit_tree():

  * If the commit is loaded from the commit-graph file, then this
  * member may be NULL. Only access it through get_commit_tree()
  * or get_commit_tree_oid().


>  struct object_id *get_commit_tree_oid(const struct commit *);
>  
>  /*
> diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
> index c49aa558f0..f5bc639981 100644
> --- a/contrib/coccinelle/commit.cocci
> +++ b/contrib/coccinelle/commit.cocci
> @@ -12,12 +12,12 @@ expression c;
>  
>  // These excluded functions must access c->maybe_tree direcly.
>  @@
> -identifier f !~ "^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
> +identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
>  expression c;
>  @@
>    f(...) {<...
>  - c->maybe_tree
> -+ get_commit_tree(c)
> ++ repo_get_commit_tree(the_repository, c)

So, why this change?

It would also require furher changes to 'commit.cocci', in particular
to the last semantic patch, which is supposed to ensure that
get_commit_tree() doesn't end up on the LHS of an assignment, but with
this change Coccinelle does suggest transfomations with
repo_get_commit_tree() on the LHS.

>    ...>}
>  
>  @@
> -- 
> 2.21.0.479.g47ac719cd3
> 

^ permalink raw reply	[flat|nested] 154+ messages in thread

* Re: [PATCH v2 01/32] rebase: 'make coccicheck' cleanup
  2019-04-03 11:34   ` [PATCH v2 01/32] rebase: 'make coccicheck' cleanup Nguyễn Thái Ngọc Duy
@ 2019-04-04 17:25     ` SZEDER Gábor
  2019-04-05  9:26       ` Duy Nguyen
  0 siblings, 1 reply; 154+ messages in thread
From: SZEDER Gábor @ 2019-04-04 17:25 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git, gitster, stefanbeller

On Wed, Apr 03, 2019 at 06:34:26PM +0700, Nguyễn Thái Ngọc Duy wrote:
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  builtin/rebase.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/builtin/rebase.c b/builtin/rebase.c
> index 77deebc65c..c064909329 100644
> --- a/builtin/rebase.c
> +++ b/builtin/rebase.c
> @@ -1592,8 +1592,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
>  				branch_name = options.head_name;
>  
>  		} else {
> -			free(options.head_name);
> -			options.head_name = NULL;
> +			FREE_AND_NULL(options.head_name);
>  			branch_name = "HEAD";
>  		}
>  		if (get_oid("HEAD", &options.orig_head))
> @@ -1793,7 +1792,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
>  	 * we just fast-forwarded.
>  	 */
>  	strbuf_reset(&msg);
> -	if (!oidcmp(&merge_base, &options.orig_head)) {
> +	if (oideq(&merge_base, &options.orig_head)) {
>  		printf(_("Fast-forwarded %s to %s.\n"),
>  			branch_name, options.onto_name);
>  		strbuf_addf(&msg, "rebase finished: %s onto %s",

You are already using Coccinelle v1.0.7, aren't you?

For some reason previous versions don't notice these two
transformations.  I have patches with these transformations lying
around here for some time now, but haven't submitted them yet, because
I don't really like the way I run Coccinelle v1.0.7 in our static
analysis CI build jobs [1]

Anyway, here are my commit messages for these transformations, please
feel free to re-use them:

  -- >8 --

Subject: builtin rebase: use oideq()

Use oideq() instead of !oidcmp(), as it is more idiomatic, and might
give the compiler more opportunities to optimize.

Patch generated with 'contrib/coccinelle/free.cocci' and Coccinelle
v1.0.7 (previous Coccinelle versions don't notice this).

  -- 8< --

Subject: builtin rebase: use FREE_AND_NULL
    
Use the macro FREE_AND_NULL to release memory allocated for
'head_name' and clear its pointer.
    
Patch generated with 'contrib/coccinelle/free.cocci' and Coccinelle
v1.0.7 (previous Coccinelle versions don't notice this).

  -- >8 --


[1] https://github.com/szeder/git/commits/travis-coccinelle


^ permalink raw reply	[flat|nested] 154+ messages in thread

* Re: [PATCH v2 01/32] rebase: 'make coccicheck' cleanup
  2019-04-04 17:25     ` SZEDER Gábor
@ 2019-04-05  9:26       ` Duy Nguyen
  2019-04-09 10:58         ` SZEDER Gábor
  0 siblings, 1 reply; 154+ messages in thread
From: Duy Nguyen @ 2019-04-05  9:26 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: Git Mailing List, Junio C Hamano, Stefan Beller

On Fri, Apr 5, 2019 at 12:25 AM SZEDER Gábor <szeder.dev@gmail.com> wrote:
>
> On Wed, Apr 03, 2019 at 06:34:26PM +0700, Nguyễn Thái Ngọc Duy wrote:
> > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> > ---
> >  builtin/rebase.c | 5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/builtin/rebase.c b/builtin/rebase.c
> > index 77deebc65c..c064909329 100644
> > --- a/builtin/rebase.c
> > +++ b/builtin/rebase.c
> > @@ -1592,8 +1592,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
> >                               branch_name = options.head_name;
> >
> >               } else {
> > -                     free(options.head_name);
> > -                     options.head_name = NULL;
> > +                     FREE_AND_NULL(options.head_name);
> >                       branch_name = "HEAD";
> >               }
> >               if (get_oid("HEAD", &options.orig_head))
> > @@ -1793,7 +1792,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
> >        * we just fast-forwarded.
> >        */
> >       strbuf_reset(&msg);
> > -     if (!oidcmp(&merge_base, &options.orig_head)) {
> > +     if (oideq(&merge_base, &options.orig_head)) {
> >               printf(_("Fast-forwarded %s to %s.\n"),
> >                       branch_name, options.onto_name);
> >               strbuf_addf(&msg, "rebase finished: %s onto %s",
>
> You are already using Coccinelle v1.0.7, aren't you?

No it's 1.0.5. I guess I should upgrade then.

> For some reason previous versions don't notice these two
> transformations.  I have patches with these transformations lying
> around here for some time now, but haven't submitted them yet, because
> I don't really like the way I run Coccinelle v1.0.7 in our static
> analysis CI build jobs [1]
>
> Anyway, here are my commit messages for these transformations, please
> feel free to re-use them:

I'm not sure if even more elaboration is needed. It looks so trivial
(and at least obvious to me). But if you or Junio (or anybody else)
insists, I'll resend with updated commit messages. Or I can drop this
patch too if you have more cocci patches to send soon.

>
>   -- >8 --
>
> Subject: builtin rebase: use oideq()
>
> Use oideq() instead of !oidcmp(), as it is more idiomatic, and might
> give the compiler more opportunities to optimize.
>
> Patch generated with 'contrib/coccinelle/free.cocci' and Coccinelle
> v1.0.7 (previous Coccinelle versions don't notice this).
>
>   -- 8< --
>
> Subject: builtin rebase: use FREE_AND_NULL
>
> Use the macro FREE_AND_NULL to release memory allocated for
> 'head_name' and clear its pointer.
>
> Patch generated with 'contrib/coccinelle/free.cocci' and Coccinelle
> v1.0.7 (previous Coccinelle versions don't notice this).
>
>   -- >8 --
>
>
> [1] https://github.com/szeder/git/commits/travis-coccinelle
>


-- 
Duy

^ permalink raw reply	[flat|nested] 154+ messages in thread

* Re: [PATCH v2 10/32] commit.c: add repo_get_commit_tree()
  2019-04-04 17:04     ` SZEDER Gábor
@ 2019-04-05  9:32       ` Duy Nguyen
  2019-04-05 18:13         ` Johannes Schindelin
  0 siblings, 1 reply; 154+ messages in thread
From: Duy Nguyen @ 2019-04-05  9:32 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: Git Mailing List, Junio C Hamano, Stefan Beller

On Fri, Apr 5, 2019 at 12:04 AM SZEDER Gábor <szeder.dev@gmail.com> wrote:
> >  struct object_id *get_commit_tree_oid(const struct commit *);
> >
> >  /*
> > diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
> > index c49aa558f0..f5bc639981 100644
> > --- a/contrib/coccinelle/commit.cocci
> > +++ b/contrib/coccinelle/commit.cocci
> > @@ -12,12 +12,12 @@ expression c;
> >
> >  // These excluded functions must access c->maybe_tree direcly.
> >  @@
> > -identifier f !~ "^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
> > +identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
> >  expression c;
> >  @@
> >    f(...) {<...
> >  - c->maybe_tree
> > -+ get_commit_tree(c)
> > ++ repo_get_commit_tree(the_repository, c)
>
> So, why this change?

Because get_commit_tree() now becomes a compat wrapper (yes I'll fill
in the commit message ;) and should be avoided.

> It would also require furher changes to 'commit.cocci', in particular
> to the last semantic patch, which is supposed to ensure that
> get_commit_tree() doesn't end up on the LHS of an assignment, but with
> this change Coccinelle does suggest transfomations with
> repo_get_commit_tree() on the LHS.

Oooh.. I see now. I actually updated that then dropped, thinking that
a function call cannot be on LHS and that conversion is for
already-long-gone code anyway. But yeah when you stack that conversion
on top of this, it makes sense that we need double conversion to avoid
build error.

Since I will have to update this patch anyway, I'll update the commit
message on the first cocci patch too.

>
> >    ...>}
> >
> >  @@
> > --
> > 2.21.0.479.g47ac719cd3
> >



-- 
Duy

^ permalink raw reply	[flat|nested] 154+ messages in thread

* Re: [PATCH v2 10/32] commit.c: add repo_get_commit_tree()
  2019-04-05  9:32       ` Duy Nguyen
@ 2019-04-05 18:13         ` Johannes Schindelin
  0 siblings, 0 replies; 154+ messages in thread
From: Johannes Schindelin @ 2019-04-05 18:13 UTC (permalink / raw)
  To: Duy Nguyen
  Cc: SZEDER Gábor, Git Mailing List, Junio C Hamano,
	Stefan Beller

[-- Attachment #1: Type: text/plain, Size: 2740 bytes --]

Hi Duy,

On Fri, 5 Apr 2019, Duy Nguyen wrote:

> On Fri, Apr 5, 2019 at 12:04 AM SZEDER Gábor <szeder.dev@gmail.com> wrote:
> > >  struct object_id *get_commit_tree_oid(const struct commit *);
> > >

> > >  /*
> > > diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
> > > index c49aa558f0..f5bc639981 100644
> > > --- a/contrib/coccinelle/commit.cocci
> > > +++ b/contrib/coccinelle/commit.cocci
> > > @@ -12,12 +12,12 @@ expression c;
> > >
> > >  // These excluded functions must access c->maybe_tree direcly.
> > >  @@
> > > -identifier f !~ "^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
> > > +identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
> > >  expression c;
> > >  @@
> > >    f(...) {<...
> > >  - c->maybe_tree
> > > -+ get_commit_tree(c)
> > > ++ repo_get_commit_tree(the_repository, c)
> >
> > So, why this change?
>
> Because get_commit_tree() now becomes a compat wrapper (yes I'll fill
> in the commit message ;) and should be avoided.
>
> > It would also require furher changes to 'commit.cocci', in particular
> > to the last semantic patch, which is supposed to ensure that
> > get_commit_tree() doesn't end up on the LHS of an assignment, but with
> > this change Coccinelle does suggest transfomations with
> > repo_get_commit_tree() on the LHS.
>
> Oooh.. I see now. I actually updated that then dropped, thinking that
> a function call cannot be on LHS and that conversion is for
> already-long-gone code anyway. But yeah when you stack that conversion
> on top of this, it makes sense that we need double conversion to avoid
> build error.
>
> Since I will have to update this patch anyway, I'll update the commit
> message on the first cocci patch too.

This actually broke the build. So here is what I have on top of `pu` to
make it work again:

-- snip --
Subject: [PATCH] fixup??? commit.c: add repo_get_commit_tree()

The search/replace of this patch was apparently not done fully.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 contrib/coccinelle/commit.cocci | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
index f5bc639981..7f53f361c7 100644
--- a/contrib/coccinelle/commit.cocci
+++ b/contrib/coccinelle/commit.cocci
@@ -24,5 +24,5 @@ expression c;
 expression c;
 expression s;
 @@
-- get_commit_tree(c) = s
+- repo_get_commit_tree(the_repository, c) = s
 + c->maybe_tree = s
-- snap --

Ciao,
Johannes

>
> >
> > >    ...>}
> > >
> > >  @@
> > > --
> > > 2.21.0.479.g47ac719cd3
> > >
>
>
>
> --
> Duy
>

^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates
  2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                     ` (31 preceding siblings ...)
  2019-04-03 11:34   ` [PATCH v2 32/32] sha1-name.c: remove the_repo from get_oid_mb() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34   ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 01/33] builtin rebase: use FREE_AND_NULL Nguyễn Thái Ngọc Duy
                       ` (34 more replies)
  32 siblings, 35 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Hopefully the final fix for commit.cocci in 11/33. Instead of adding
more commit details on 01/33 I replaced it with the two commits from
Szeder, he put more efforts into them anyway.

Range-diff dựa trên v2:
 1:  b992f6c799 !  1:  aa603ea09e rebase: 'make coccicheck' cleanup
    @@ -1,6 +1,14 @@
    -Author: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
    +Author: SZEDER Gábor <szeder.dev@gmail.com>
     
    -    rebase: 'make coccicheck' cleanup
    +    builtin rebase: use FREE_AND_NULL
    +
    +    Use the macro FREE_AND_NULL to release memory allocated for
    +    'head_name' and clear its pointer.
    +
    +    Patch generated with 'contrib/coccinelle/free.cocci' and Coccinelle
    +    v1.0.7 (previous Coccinelle versions don't notice this).
    +
    +    Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
     
      diff --git a/builtin/rebase.c b/builtin/rebase.c
      --- a/builtin/rebase.c
    @@ -15,12 +23,3 @@
      			branch_name = "HEAD";
      		}
      		if (get_oid("HEAD", &options.orig_head))
    -@@
    - 	 * we just fast-forwarded.
    - 	 */
    - 	strbuf_reset(&msg);
    --	if (!oidcmp(&merge_base, &options.orig_head)) {
    -+	if (oideq(&merge_base, &options.orig_head)) {
    - 		printf(_("Fast-forwarded %s to %s.\n"),
    - 			branch_name, options.onto_name);
    - 		strbuf_addf(&msg, "rebase finished: %s onto %s",
 -:  ---------- >  2:  b03cd28a4e builtin rebase: use oideq()
 2:  e76c73a75a =  3:  3a68454479 packfile.c: add repo_approximate_object_count()
 3:  962a168516 =  4:  9738ab8797 refs.c: add refs_ref_exists()
 4:  d06bea7909 =  5:  1a2cb46fe9 refs.c: add refs_shorten_unambiguous_ref()
 5:  fb880154e6 =  6:  ffdf9ad9bf refs.c: remove the_repo from substitute_branch_name()
 6:  6fd7960522 =  7:  697daf317f refs.c: remove the_repo from expand_ref()
 7:  f5ad3133bc =  8:  fac41b3b1c refs.c: add repo_dwim_ref()
 8:  7552a4085a =  9:  db528690fd refs.c: add repo_dwim_log()
 9:  962fff4c9c = 10:  9318416f94 refs.c: remove the_repo from read_ref_at()
10:  68876a150f ! 11:  848456f59c commit.c: add repo_get_commit_tree()
    @@ -2,6 +2,11 @@
     
         commit.c: add repo_get_commit_tree()
     
    +    Remove the implicit dependency on the_repository in this function.
    +    It will be used in sha1-name.c functions when they are updated to take
    +    any 'struct repository'. get_commit_tree() remains as a compat wrapper,
    +    to be slowly replaced later.
    +
      diff --git a/commit.c b/commit.c
      --- a/commit.c
      +++ b/commit.c
    @@ -29,6 +34,15 @@
      --- a/commit.h
      +++ b/commit.h
     @@
    + 
    + 	/*
    + 	 * If the commit is loaded from the commit-graph file, then this
    +-	 * member may be NULL. Only access it through get_commit_tree()
    ++	 * member may be NULL. Only access it through repo_get_commit_tree()
    + 	 * or get_commit_tree_oid().
    + 	 */
    + 	struct tree *maybe_tree;
    +@@
       */
      void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);
      
    @@ -57,3 +71,10 @@
        ...>}
      
      @@
    + expression c;
    ++expression r;
    + expression s;
    + @@
    +-- get_commit_tree(c) = s
    ++- repo_get_commit_tree(r, c) = s
    + + c->maybe_tree = s
11:  9817d150b2 = 12:  a60c06b63a sha1-name.c: remove the_repo from sort_ambiguous()
12:  7ce23aaeb5 = 13:  3cbbe5de4a sha1-name.c: remove the_repo from find_abbrev_len_packed()
13:  2d99af106f = 14:  a79bf276bd sha1-name.c: add repo_find_unique_abbrev_r()
14:  f63626e937 = 15:  aa0fa191d9 sha1-name.c: store and use repo in struct disambiguate_state
15:  ce9f7ebab8 = 16:  ad00c19d30 sha1-name.c: add repo_for_each_abbrev()
16:  8cb8278d6e = 17:  d9ff762461 sha1-name.c: remove the_repo from get_short_oid()
17:  9210dd01b8 = 18:  46b8a05d8c sha1-name.c: remove the_repo from interpret_nth_prior_checkout()
18:  a161ed33d2 = 19:  52ec37f2d7 sha1-name.c: remove the_repo from interpret_branch_mark()
19:  6bf4df0131 = 20:  f50562b480 sha1-name.c: add repo_interpret_branch_name()
20:  94f707cb7f = 21:  66619e37cb sha1-name.c: remove the_repo from get_oid_oneline()
21:  2a1dd6368c = 22:  d960f47821 sha1-name.c: remove the_repo from get_describe_name()
22:  f958b565db = 23:  f38960304d sha1-name.c: remove the_repo from get_oid_basic()
23:  ec821007b2 = 24:  3b69cfcd8b sha1-name.c: remove the_repo from get_oid_1()
24:  317a365f30 = 25:  e889ae729a sha1-name.c: remove the_repo from handle_one_ref()
25:  3a46ea22b2 = 26:  386b6f4654 sha1-name.c: remove the_repo from diagnose_invalid_index_path()
26:  59a8cb9749 = 27:  d3ff3ee163 sha1-name.c: remove the_repo from resolve_relative_path()
27:  d1f4df1915 = 28:  226a30e6f6 sha1-name.c: remove the_repo from get_oid_with_context_1()
28:  3034e9cf1e = 29:  5d0aed2f70 sha1-name.c: add repo_get_oid()
29:  9c72941ec9 = 30:  72ab26a247 submodule-config.c: use repo_get_oid for reading .gitmodules
30:  40acfb6b82 = 31:  53dc11463d sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name
31:  3b8be75e77 = 32:  01b4deaa8a sha1-name.c: remove the_repo from other get_oid_*
32:  59cadc5deb = 33:  03a7283ef3 sha1-name.c: remove the_repo from get_oid_mb()

Nguyễn Thái Ngọc Duy (31):
  packfile.c: add repo_approximate_object_count()
  refs.c: add refs_ref_exists()
  refs.c: add refs_shorten_unambiguous_ref()
  refs.c: remove the_repo from substitute_branch_name()
  refs.c: remove the_repo from expand_ref()
  refs.c: add repo_dwim_ref()
  refs.c: add repo_dwim_log()
  refs.c: remove the_repo from read_ref_at()
  commit.c: add repo_get_commit_tree()
  sha1-name.c: remove the_repo from sort_ambiguous()
  sha1-name.c: remove the_repo from find_abbrev_len_packed()
  sha1-name.c: add repo_find_unique_abbrev_r()
  sha1-name.c: store and use repo in struct disambiguate_state
  sha1-name.c: add repo_for_each_abbrev()
  sha1-name.c: remove the_repo from get_short_oid()
  sha1-name.c: remove the_repo from interpret_nth_prior_checkout()
  sha1-name.c: remove the_repo from interpret_branch_mark()
  sha1-name.c: add repo_interpret_branch_name()
  sha1-name.c: remove the_repo from get_oid_oneline()
  sha1-name.c: remove the_repo from get_describe_name()
  sha1-name.c: remove the_repo from get_oid_basic()
  sha1-name.c: remove the_repo from get_oid_1()
  sha1-name.c: remove the_repo from handle_one_ref()
  sha1-name.c: remove the_repo from diagnose_invalid_index_path()
  sha1-name.c: remove the_repo from resolve_relative_path()
  sha1-name.c: remove the_repo from get_oid_with_context_1()
  sha1-name.c: add repo_get_oid()
  submodule-config.c: use repo_get_oid for reading .gitmodules
  sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name
  sha1-name.c: remove the_repo from other get_oid_*
  sha1-name.c: remove the_repo from get_oid_mb()

SZEDER Gábor (2):
  builtin rebase: use FREE_AND_NULL
  builtin rebase: use oideq()

 builtin/rebase.c                   |   5 +-
 builtin/show-branch.c              |   6 +-
 cache.h                            |  50 ++--
 commit.c                           |   5 +-
 commit.h                           |   5 +-
 contrib/coccinelle/commit.cocci    |   7 +-
 dir.c                              |   8 +
 dir.h                              |   4 +-
 packfile.c                         |  14 +-
 packfile.h                         |   3 +-
 refs.c                             |  71 ++++--
 refs.h                             |   9 +-
 setup.c                            |   7 +-
 sha1-name.c                        | 388 ++++++++++++++++++-----------
 submodule-config.c                 |  20 +-
 t/t7814-grep-recurse-submodules.sh |   6 +-
 upload-pack.c                      |   2 +-
 17 files changed, 378 insertions(+), 232 deletions(-)
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply	[flat|nested] 154+ messages in thread

* [PATCH v3 01/33] builtin rebase: use FREE_AND_NULL
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 02/33] builtin rebase: use oideq() Nguyễn Thái Ngọc Duy
                       ` (33 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

From: SZEDER Gábor <szeder.dev@gmail.com>

Use the macro FREE_AND_NULL to release memory allocated for
'head_name' and clear its pointer.

Patch generated with 'contrib/coccinelle/free.cocci' and Coccinelle
v1.0.7 (previous Coccinelle versions don't notice this).

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/rebase.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/builtin/rebase.c b/builtin/rebase.c
index 77deebc65c..868bcd1446 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -1592,8 +1592,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 				branch_name = options.head_name;
 
 		} else {
-			free(options.head_name);
-			options.head_name = NULL;
+			FREE_AND_NULL(options.head_name);
 			branch_name = "HEAD";
 		}
 		if (get_oid("HEAD", &options.orig_head))
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 02/33] builtin rebase: use oideq()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 01/33] builtin rebase: use FREE_AND_NULL Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 03/33] packfile.c: add repo_approximate_object_count() Nguyễn Thái Ngọc Duy
                       ` (32 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

From: SZEDER Gábor <szeder.dev@gmail.com>

Use oideq() instead of !oidcmp(), as it is more idiomatic, and might
give the compiler more opportunities to optimize.

Patch generated with 'contrib/coccinelle/free.cocci' and Coccinelle
v1.0.7 (previous Coccinelle versions don't notice this).

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/rebase.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/rebase.c b/builtin/rebase.c
index 868bcd1446..c064909329 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -1792,7 +1792,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 	 * we just fast-forwarded.
 	 */
 	strbuf_reset(&msg);
-	if (!oidcmp(&merge_base, &options.orig_head)) {
+	if (oideq(&merge_base, &options.orig_head)) {
 		printf(_("Fast-forwarded %s to %s.\n"),
 			branch_name, options.onto_name);
 		strbuf_addf(&msg, "rebase finished: %s onto %s",
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 03/33] packfile.c: add repo_approximate_object_count()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 01/33] builtin rebase: use FREE_AND_NULL Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 02/33] builtin rebase: use oideq() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 04/33] refs.c: add refs_ref_exists() Nguyễn Thái Ngọc Duy
                       ` (31 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 packfile.c | 14 +++++++-------
 packfile.h |  3 ++-
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/packfile.c b/packfile.c
index 16bcb75262..2ad4fab2f8 100644
--- a/packfile.c
+++ b/packfile.c
@@ -893,25 +893,25 @@ static void prepare_packed_git(struct repository *r);
  * all unreachable objects about to be pruned, in which case they're not really
  * interesting as a measure of repo size in the first place.
  */
-unsigned long approximate_object_count(void)
+unsigned long repo_approximate_object_count(struct repository *r)
 {
-	if (!the_repository->objects->approximate_object_count_valid) {
+	if (!r->objects->approximate_object_count_valid) {
 		unsigned long count;
 		struct multi_pack_index *m;
 		struct packed_git *p;
 
-		prepare_packed_git(the_repository);
+		prepare_packed_git(r);
 		count = 0;
-		for (m = get_multi_pack_index(the_repository); m; m = m->next)
+		for (m = get_multi_pack_index(r); m; m = m->next)
 			count += m->num_objects;
-		for (p = the_repository->objects->packed_git; p; p = p->next) {
+		for (p = r->objects->packed_git; p; p = p->next) {
 			if (open_pack_index(p))
 				continue;
 			count += p->num_objects;
 		}
-		the_repository->objects->approximate_object_count = count;
+		r->objects->approximate_object_count = count;
 	}
-	return the_repository->objects->approximate_object_count;
+	return r->objects->approximate_object_count;
 }
 
 static void *get_next_packed_git(const void *p)
diff --git a/packfile.h b/packfile.h
index d70c6d9afb..f04440f984 100644
--- a/packfile.h
+++ b/packfile.h
@@ -57,7 +57,8 @@ struct packed_git *get_all_packs(struct repository *r);
  * Give a rough count of objects in the repository. This sacrifices accuracy
  * for speed.
  */
-unsigned long approximate_object_count(void);
+unsigned long repo_approximate_object_count(struct repository *r);
+#define approximate_object_count() repo_approximate_object_count(the_repository)
 
 extern struct packed_git *find_sha1_pack(const unsigned char *sha1,
 					 struct packed_git *packs);
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 04/33] refs.c: add refs_ref_exists()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (2 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 03/33] packfile.c: add repo_approximate_object_count() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 05/33] refs.c: add refs_shorten_unambiguous_ref() Nguyễn Thái Ngọc Duy
                       ` (30 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/refs.c b/refs.c
index 142888a40a..b869f32d8b 100644
--- a/refs.c
+++ b/refs.c
@@ -241,9 +241,14 @@ int read_ref(const char *refname, struct object_id *oid)
 	return read_ref_full(refname, RESOLVE_REF_READING, oid, NULL);
 }
 
+static int refs_ref_exists(struct ref_store *refs, const char *refname)
+{
+	return !!refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING, NULL, NULL);
+}
+
 int ref_exists(const char *refname)
 {
-	return !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, NULL, NULL);
+	return refs_ref_exists(get_main_ref_store(the_repository), refname);
 }
 
 static int match_ref_pattern(const char *refname,
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 05/33] refs.c: add refs_shorten_unambiguous_ref()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (3 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 04/33] refs.c: add refs_ref_exists() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 06/33] refs.c: remove the_repo from substitute_branch_name() Nguyễn Thái Ngọc Duy
                       ` (29 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c | 11 +++++++++--
 refs.h |  2 ++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/refs.c b/refs.c
index b869f32d8b..3dde824aab 100644
--- a/refs.c
+++ b/refs.c
@@ -1169,7 +1169,8 @@ int update_ref(const char *msg, const char *refname,
 			       old_oid, flags, onerr);
 }
 
-char *shorten_unambiguous_ref(const char *refname, int strict)
+char *refs_shorten_unambiguous_ref(struct ref_store *refs,
+				   const char *refname, int strict)
 {
 	int i;
 	static char **scanf_fmts;
@@ -1247,7 +1248,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
 			strbuf_reset(&resolved_buf);
 			strbuf_addf(&resolved_buf, rule,
 				    short_name_len, short_name);
-			if (ref_exists(resolved_buf.buf))
+			if (refs_ref_exists(refs, resolved_buf.buf))
 				break;
 		}
 
@@ -1266,6 +1267,12 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
 	return xstrdup(refname);
 }
 
+char *shorten_unambiguous_ref(const char *refname, int strict)
+{
+	return refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
+					    refname, strict);
+}
+
 static struct string_list *hide_refs;
 
 int parse_hide_refs_config(const char *var, const char *value, const char *section)
diff --git a/refs.h b/refs.h
index 308fa1f03b..5627570241 100644
--- a/refs.h
+++ b/refs.h
@@ -462,6 +462,8 @@ int check_refname_format(const char *refname, int flags);
 
 const char *prettify_refname(const char *refname);
 
+char *refs_shorten_unambiguous_ref(struct ref_store *refs,
+				   const char *refname, int strict);
 char *shorten_unambiguous_ref(const char *refname, int strict);
 
 /** rename ref, return 0 on success **/
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 06/33] refs.c: remove the_repo from substitute_branch_name()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (4 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 05/33] refs.c: add refs_shorten_unambiguous_ref() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 07/33] refs.c: remove the_repo from expand_ref() Nguyễn Thái Ngọc Duy
                       ` (28 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 8 ++++++--
 refs.c      | 9 +++++----
 sha1-name.c | 8 ++++++--
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/cache.h b/cache.h
index ac92421f3a..fcb24b5781 100644
--- a/cache.h
+++ b/cache.h
@@ -1468,8 +1468,12 @@ extern int parse_oid_hex(const char *hex, struct object_id *oid, const char **en
 #define INTERPRET_BRANCH_LOCAL (1<<0)
 #define INTERPRET_BRANCH_REMOTE (1<<1)
 #define INTERPRET_BRANCH_HEAD (1<<2)
-extern int interpret_branch_name(const char *str, int len, struct strbuf *,
-				 unsigned allowed);
+int repo_interpret_branch_name(struct repository *r,
+			       const char *str, int len,
+			       struct strbuf *buf,
+			       unsigned allowed);
+#define interpret_branch_name(str, len, buf, allowed) \
+	repo_interpret_branch_name(the_repository, str, len, buf, allowed)
 extern int get_oid_mb(const char *str, struct object_id *oid);
 
 extern int validate_headref(const char *ref);
diff --git a/refs.c b/refs.c
index 3dde824aab..44df049796 100644
--- a/refs.c
+++ b/refs.c
@@ -539,10 +539,11 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)
  * later free()ing) if the string passed in is a magic short-hand form
  * to name a branch.
  */
-static char *substitute_branch_name(const char **string, int *len)
+static char *substitute_branch_name(struct repository *r,
+				    const char **string, int *len)
 {
 	struct strbuf buf = STRBUF_INIT;
-	int ret = interpret_branch_name(*string, *len, &buf, 0);
+	int ret = repo_interpret_branch_name(r, *string, *len, &buf, 0);
 
 	if (ret == *len) {
 		size_t size;
@@ -556,7 +557,7 @@ static char *substitute_branch_name(const char **string, int *len)
 
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
 {
-	char *last_branch = substitute_branch_name(&str, &len);
+	char *last_branch = substitute_branch_name(the_repository, &str, &len);
 	int   refs_found  = expand_ref(str, len, oid, ref);
 	free(last_branch);
 	return refs_found;
@@ -596,7 +597,7 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
 
 int dwim_log(const char *str, int len, struct object_id *oid, char **log)
 {
-	char *last_branch = substitute_branch_name(&str, &len);
+	char *last_branch = substitute_branch_name(the_repository, &str, &len);
 	const char **p;
 	int logs_found = 0;
 	struct strbuf path = STRBUF_INIT;
diff --git a/sha1-name.c b/sha1-name.c
index 6dda2c16df..d535bb82f7 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1427,13 +1427,17 @@ static int interpret_branch_mark(const char *name, int namelen,
 	return len + at;
 }
 
-int interpret_branch_name(const char *name, int namelen, struct strbuf *buf,
-			  unsigned allowed)
+int repo_interpret_branch_name(struct repository *r,
+			       const char *name, int namelen,
+			       struct strbuf *buf,
+			       unsigned allowed)
 {
 	char *at;
 	const char *start;
 	int len;
 
+	if (r != the_repository)
+		BUG("interpret_branch_name() does not really use 'r' yet");
 	if (!namelen)
 		namelen = strlen(name);
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 07/33] refs.c: remove the_repo from expand_ref()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (5 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 06/33] refs.c: remove the_repo from substitute_branch_name() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 08/33] refs.c: add repo_dwim_ref() Nguyễn Thái Ngọc Duy
                       ` (27 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c        | 10 ++++++----
 refs.h        |  2 +-
 upload-pack.c |  2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/refs.c b/refs.c
index 44df049796..1f5864aa36 100644
--- a/refs.c
+++ b/refs.c
@@ -558,12 +558,13 @@ static char *substitute_branch_name(struct repository *r,
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
 {
 	char *last_branch = substitute_branch_name(the_repository, &str, &len);
-	int   refs_found  = expand_ref(str, len, oid, ref);
+	int   refs_found  = expand_ref(the_repository, str, len, oid, ref);
 	free(last_branch);
 	return refs_found;
 }
 
-int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
+int expand_ref(struct repository *repo, const char *str, int len,
+	       struct object_id *oid, char **ref)
 {
 	const char **p, *r;
 	int refs_found = 0;
@@ -578,8 +579,9 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
 		this_result = refs_found ? &oid_from_ref : oid;
 		strbuf_reset(&fullref);
 		strbuf_addf(&fullref, *p, len, str);
-		r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
-				       this_result, &flag);
+		r = refs_resolve_ref_unsafe(get_main_ref_store(repo),
+					    fullref.buf, RESOLVE_REF_READING,
+					    this_result, &flag);
 		if (r) {
 			if (!refs_found++)
 				*ref = xstrdup(r);
diff --git a/refs.h b/refs.h
index 5627570241..b630d5bde7 100644
--- a/refs.h
+++ b/refs.h
@@ -148,7 +148,7 @@ int refname_match(const char *abbrev_name, const char *full_name);
 struct argv_array;
 void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);
 
-int expand_ref(const char *str, int len, struct object_id *oid, char **ref);
+int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
 int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
 
diff --git a/upload-pack.c b/upload-pack.c
index d098ef5982..56505d60c3 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -834,7 +834,7 @@ static int process_deepen_not(const char *line, struct string_list *deepen_not,
 	if (skip_prefix(line, "deepen-not ", &arg)) {
 		char *ref = NULL;
 		struct object_id oid;
-		if (expand_ref(arg, strlen(arg), &oid, &ref) != 1)
+		if (expand_ref(the_repository, arg, strlen(arg), &oid, &ref) != 1)
 			die("git upload-pack: ambiguous deepen-not: %s", line);
 		string_list_append(deepen_not, ref);
 		free(ref);
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 08/33] refs.c: add repo_dwim_ref()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (6 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 07/33] refs.c: remove the_repo from expand_ref() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 09/33] refs.c: add repo_dwim_log() Nguyễn Thái Ngọc Duy
                       ` (26 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c | 12 +++++++++---
 refs.h |  1 +
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/refs.c b/refs.c
index 1f5864aa36..bd0fec5776 100644
--- a/refs.c
+++ b/refs.c
@@ -555,14 +555,20 @@ static char *substitute_branch_name(struct repository *r,
 	return NULL;
 }
 
-int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
+int repo_dwim_ref(struct repository *r, const char *str, int len,
+		  struct object_id *oid, char **ref)
 {
-	char *last_branch = substitute_branch_name(the_repository, &str, &len);
-	int   refs_found  = expand_ref(the_repository, str, len, oid, ref);
+	char *last_branch = substitute_branch_name(r, &str, &len);
+	int   refs_found  = expand_ref(r, str, len, oid, ref);
 	free(last_branch);
 	return refs_found;
 }
 
+int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
+{
+	return repo_dwim_ref(the_repository, str, len, oid, ref);
+}
+
 int expand_ref(struct repository *repo, const char *str, int len,
 	       struct object_id *oid, char **ref)
 {
diff --git a/refs.h b/refs.h
index b630d5bde7..fd3dc1d0f4 100644
--- a/refs.h
+++ b/refs.h
@@ -149,6 +149,7 @@ struct argv_array;
 void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);
 
 int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
+int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
 int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 09/33] refs.c: add repo_dwim_log()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (7 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 08/33] refs.c: add repo_dwim_ref() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 10/33] refs.c: remove the_repo from read_ref_at() Nguyễn Thái Ngọc Duy
                       ` (25 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c | 21 +++++++++++++++------
 refs.h |  1 +
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/refs.c b/refs.c
index bd0fec5776..edea001446 100644
--- a/refs.c
+++ b/refs.c
@@ -603,9 +603,11 @@ int expand_ref(struct repository *repo, const char *str, int len,
 	return refs_found;
 }
 
-int dwim_log(const char *str, int len, struct object_id *oid, char **log)
+int repo_dwim_log(struct repository *r, const char *str, int len,
+		  struct object_id *oid, char **log)
 {
-	char *last_branch = substitute_branch_name(the_repository, &str, &len);
+	struct ref_store *refs = get_main_ref_store(r);
+	char *last_branch = substitute_branch_name(r, &str, &len);
 	const char **p;
 	int logs_found = 0;
 	struct strbuf path = STRBUF_INIT;
@@ -617,13 +619,15 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
 
 		strbuf_reset(&path);
 		strbuf_addf(&path, *p, len, str);
-		ref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,
-					 &hash, NULL);
+		ref = refs_resolve_ref_unsafe(refs, path.buf,
+					      RESOLVE_REF_READING,
+					      &hash, NULL);
 		if (!ref)
 			continue;
-		if (reflog_exists(path.buf))
+		if (refs_reflog_exists(refs, path.buf))
 			it = path.buf;
-		else if (strcmp(ref, path.buf) && reflog_exists(ref))
+		else if (strcmp(ref, path.buf) &&
+			 refs_reflog_exists(refs, ref))
 			it = ref;
 		else
 			continue;
@@ -639,6 +643,11 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
 	return logs_found;
 }
 
+int dwim_log(const char *str, int len, struct object_id *oid, char **log)
+{
+	return repo_dwim_log(the_repository, str, len, oid, log);
+}
+
 static int is_per_worktree_ref(const char *refname)
 {
 	return !strcmp(refname, "HEAD") ||
diff --git a/refs.h b/refs.h
index fd3dc1d0f4..859dffe691 100644
--- a/refs.h
+++ b/refs.h
@@ -150,6 +150,7 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);
 
 int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
 int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
+int repo_dwim_log(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
 int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 10/33] refs.c: remove the_repo from read_ref_at()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (8 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 09/33] refs.c: add repo_dwim_log() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 11/33] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
                       ` (24 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/show-branch.c | 6 ++++--
 refs.c                | 7 ++++---
 refs.h                | 3 ++-
 sha1-name.c           | 3 ++-
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 934e514944..082daeac32 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -753,7 +753,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 				/* Ah, that is a date spec... */
 				timestamp_t at;
 				at = approxidate(reflog_base);
-				read_ref_at(ref, flags, at, -1, &oid, NULL,
+				read_ref_at(get_main_ref_store(the_repository),
+					    ref, flags, at, -1, &oid, NULL,
 					    NULL, NULL, &base);
 			}
 		}
@@ -765,7 +766,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 			timestamp_t timestamp;
 			int tz;
 
-			if (read_ref_at(ref, flags, 0, base + i, &oid, &logmsg,
+			if (read_ref_at(get_main_ref_store(the_repository),
+					ref, flags, 0, base + i, &oid, &logmsg,
 					&timestamp, &tz, NULL)) {
 				reflog = i;
 				break;
diff --git a/refs.c b/refs.c
index edea001446..92d1f6dbdd 100644
--- a/refs.c
+++ b/refs.c
@@ -967,7 +967,8 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid
 	return 1;
 }
 
-int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, int cnt,
+int read_ref_at(struct ref_store *refs, const char *refname,
+		unsigned int flags, timestamp_t at_time, int cnt,
 		struct object_id *oid, char **msg,
 		timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt)
 {
@@ -983,7 +984,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in
 	cb.cutoff_cnt = cutoff_cnt;
 	cb.oid = oid;
 
-	for_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);
+	refs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent, &cb);
 
 	if (!cb.reccnt) {
 		if (flags & GET_OID_QUIETLY)
@@ -994,7 +995,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in
 	if (cb.found_it)
 		return 0;
 
-	for_each_reflog_ent(refname, read_ref_at_ent_oldest, &cb);
+	refs_for_each_reflog_ent(refs, refname, read_ref_at_ent_oldest, &cb);
 
 	return 1;
 }
diff --git a/refs.h b/refs.h
index 859dffe691..8f9cbf8a93 100644
--- a/refs.h
+++ b/refs.h
@@ -388,7 +388,8 @@ int refs_create_reflog(struct ref_store *refs, const char *refname,
 int safe_create_reflog(const char *refname, int force_create, struct strbuf *err);
 
 /** Reads log for the value of ref during at_time. **/
-int read_ref_at(const char *refname, unsigned int flags,
+int read_ref_at(struct ref_store *refs,
+		const char *refname, unsigned int flags,
 		timestamp_t at_time, int cnt,
 		struct object_id *oid, char **msg,
 		timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt);
diff --git a/sha1-name.c b/sha1-name.c
index d535bb82f7..15a1107998 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -849,7 +849,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 				return -1;
 			}
 		}
-		if (read_ref_at(real_ref, flags, at_time, nth, oid, NULL,
+		if (read_ref_at(get_main_ref_store(the_repository),
+				real_ref, flags, at_time, nth, oid, NULL,
 				&co_time, &co_tz, &co_cnt)) {
 			if (!len) {
 				if (starts_with(real_ref, "refs/heads/")) {
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 11/33] commit.c: add repo_get_commit_tree()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (9 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 10/33] refs.c: remove the_repo from read_ref_at() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 12/33] sha1-name.c: remove the_repo from sort_ambiguous() Nguyễn Thái Ngọc Duy
                       ` (23 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Remove the implicit dependency on the_repository in this function.
It will be used in sha1-name.c functions when they are updated to take
any 'struct repository'. get_commit_tree() remains as a compat wrapper,
to be slowly replaced later.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 commit.c                        | 5 +++--
 commit.h                        | 5 +++--
 contrib/coccinelle/commit.cocci | 7 ++++---
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/commit.c b/commit.c
index a5333c7ac6..f0a5506f04 100644
--- a/commit.c
+++ b/commit.c
@@ -340,7 +340,8 @@ void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)
 	}
 }
 
-struct tree *get_commit_tree(const struct commit *commit)
+struct tree *repo_get_commit_tree(struct repository *r,
+				  const struct commit *commit)
 {
 	if (commit->maybe_tree || !commit->object.parsed)
 		return commit->maybe_tree;
@@ -348,7 +349,7 @@ struct tree *get_commit_tree(const struct commit *commit)
 	if (commit->graph_pos == COMMIT_NOT_FROM_GRAPH)
 		BUG("commit has NULL tree, but was not loaded from commit-graph");
 
-	return get_commit_tree_in_graph(the_repository, commit);
+	return get_commit_tree_in_graph(r, commit);
 }
 
 struct object_id *get_commit_tree_oid(const struct commit *commit)
diff --git a/commit.h b/commit.h
index 42728c2906..f1aa4c0472 100644
--- a/commit.h
+++ b/commit.h
@@ -32,7 +32,7 @@ struct commit {
 
 	/*
 	 * If the commit is loaded from the commit-graph file, then this
-	 * member may be NULL. Only access it through get_commit_tree()
+	 * member may be NULL. Only access it through repo_get_commit_tree()
 	 * or get_commit_tree_oid().
 	 */
 	struct tree *maybe_tree;
@@ -143,7 +143,8 @@ void repo_unuse_commit_buffer(struct repository *r,
  */
 void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);
 
-struct tree *get_commit_tree(const struct commit *);
+struct tree *repo_get_commit_tree(struct repository *, const struct commit *);
+#define get_commit_tree(c) repo_get_commit_tree(the_repository, c)
 struct object_id *get_commit_tree_oid(const struct commit *);
 
 /*
diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
index c49aa558f0..57c8f71479 100644
--- a/contrib/coccinelle/commit.cocci
+++ b/contrib/coccinelle/commit.cocci
@@ -12,17 +12,18 @@ expression c;
 
 // These excluded functions must access c->maybe_tree direcly.
 @@
-identifier f !~ "^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
+identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
 expression c;
 @@
   f(...) {<...
 - c->maybe_tree
-+ get_commit_tree(c)
++ repo_get_commit_tree(the_repository, c)
   ...>}
 
 @@
 expression c;
+expression r;
 expression s;
 @@
-- get_commit_tree(c) = s
+- repo_get_commit_tree(r, c) = s
 + c->maybe_tree = s
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 12/33] sha1-name.c: remove the_repo from sort_ambiguous()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (10 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 11/33] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 13/33] sha1-name.c: remove the_repo from find_abbrev_len_packed() Nguyễn Thái Ngọc Duy
                       ` (22 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 15a1107998..7558ce51a3 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -383,10 +383,11 @@ static int collect_ambiguous(const struct object_id *oid, void *data)
 	return 0;
 }
 
+static struct repository *sort_ambiguous_repo;
 static int sort_ambiguous(const void *a, const void *b)
 {
-	int a_type = oid_object_info(the_repository, a, NULL);
-	int b_type = oid_object_info(the_repository, b, NULL);
+	int a_type = oid_object_info(sort_ambiguous_repo, a, NULL);
+	int b_type = oid_object_info(sort_ambiguous_repo, b, NULL);
 	int a_type_sort;
 	int b_type_sort;
 
@@ -411,6 +412,14 @@ static int sort_ambiguous(const void *a, const void *b)
 	return a_type_sort > b_type_sort ? 1 : -1;
 }
 
+static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)
+{
+	/* mutex will be needed if this code is to be made thread safe */
+	sort_ambiguous_repo = r;
+	QSORT(a->oid, a->nr, sort_ambiguous);
+	sort_ambiguous_repo = NULL;
+}
+
 static enum get_oid_result get_short_oid(const char *name, int len,
 					 struct object_id *oid,
 					 unsigned flags)
@@ -458,7 +467,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 
 		advise(_("The candidates are:"));
 		for_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect);
-		QSORT(collect.oid, collect.nr, sort_ambiguous);
+		sort_ambiguous_oid_array(the_repository, &collect);
 
 		if (oid_array_for_each(&collect, show_ambiguous_object, &ds))
 			BUG("show_ambiguous_object shouldn't return non-zero");
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 13/33] sha1-name.c: remove the_repo from find_abbrev_len_packed()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (11 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 12/33] sha1-name.c: remove the_repo from sort_ambiguous() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 14/33] sha1-name.c: add repo_find_unique_abbrev_r() Nguyễn Thái Ngọc Duy
                       ` (21 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 7558ce51a3..b9381aaba6 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -514,6 +514,7 @@ struct min_abbrev_data {
 	unsigned int init_len;
 	unsigned int cur_len;
 	char *hex;
+	struct repository *repo;
 	const struct object_id *oid;
 };
 
@@ -619,9 +620,9 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
 	struct multi_pack_index *m;
 	struct packed_git *p;
 
-	for (m = get_multi_pack_index(the_repository); m; m = m->next)
+	for (m = get_multi_pack_index(mad->repo); m; m = m->next)
 		find_abbrev_len_for_midx(m, mad);
-	for (p = get_packed_git(the_repository); p; p = p->next)
+	for (p = get_packed_git(mad->repo); p; p = p->next)
 		find_abbrev_len_for_pack(p, mad);
 }
 
@@ -658,6 +659,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
 	if (len == hexsz || !len)
 		return hexsz;
 
+	mad.repo = the_repository;
 	mad.init_len = len;
 	mad.cur_len = len;
 	mad.hex = hex;
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 14/33] sha1-name.c: add repo_find_unique_abbrev_r()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (12 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 13/33] sha1-name.c: remove the_repo from find_abbrev_len_packed() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 15/33] sha1-name.c: store and use repo in struct disambiguate_state Nguyễn Thái Ngọc Duy
                       ` (20 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     |  6 ++++--
 sha1-name.c | 15 +++++++++------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/cache.h b/cache.h
index fcb24b5781..4f8ebb0a67 100644
--- a/cache.h
+++ b/cache.h
@@ -1045,8 +1045,10 @@ extern void check_repository_format(void);
  * Note that while this version avoids the static buffer, it is not fully
  * reentrant, as it calls into other non-reentrant git code.
  */
-extern const char *find_unique_abbrev(const struct object_id *oid, int len);
-extern int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len);
+const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len);
+#define find_unique_abbrev(oid, len) repo_find_unique_abbrev(the_repository, oid, len)
+int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);
+#define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len)
 
 extern const unsigned char null_sha1[GIT_MAX_RAWSZ];
 extern const struct object_id null_oid;
diff --git a/sha1-name.c b/sha1-name.c
index b9381aaba6..9b57787b76 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -626,15 +626,16 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
 		find_abbrev_len_for_pack(p, mad);
 }
 
-int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
+int repo_find_unique_abbrev_r(struct repository *r, char *hex,
+			      const struct object_id *oid, int len)
 {
 	struct disambiguate_state ds;
 	struct min_abbrev_data mad;
 	struct object_id oid_ret;
-	const unsigned hexsz = the_hash_algo->hexsz;
+	const unsigned hexsz = r->hash_algo->hexsz;
 
 	if (len < 0) {
-		unsigned long count = approximate_object_count();
+		unsigned long count = repo_approximate_object_count(r);
 		/*
 		 * Add one because the MSB only tells us the highest bit set,
 		 * not including the value of all the _other_ bits (so "15"
@@ -659,7 +660,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
 	if (len == hexsz || !len)
 		return hexsz;
 
-	mad.repo = the_repository;
+	mad.repo = r;
 	mad.init_len = len;
 	mad.cur_len = len;
 	mad.hex = hex;
@@ -681,13 +682,15 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
 	return mad.cur_len;
 }
 
-const char *find_unique_abbrev(const struct object_id *oid, int len)
+const char *repo_find_unique_abbrev(struct repository *r,
+				    const struct object_id *oid,
+				    int len)
 {
 	static int bufno;
 	static char hexbuffer[4][GIT_MAX_HEXSZ + 1];
 	char *hex = hexbuffer[bufno];
 	bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
-	find_unique_abbrev_r(hex, oid, len);
+	repo_find_unique_abbrev_r(r, hex, oid, len);
 	return hex;
 }
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 15/33] sha1-name.c: store and use repo in struct disambiguate_state
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (13 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 14/33] sha1-name.c: add repo_find_unique_abbrev_r() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 16/33] sha1-name.c: add repo_for_each_abbrev() Nguyễn Thái Ngọc Duy
                       ` (19 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 95 +++++++++++++++++++++++++++++++++--------------------
 1 file changed, 59 insertions(+), 36 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 9b57787b76..a75992eb54 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -17,13 +17,14 @@
 
 static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
 
-typedef int (*disambiguate_hint_fn)(const struct object_id *, void *);
+typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);
 
 struct disambiguate_state {
 	int len; /* length of prefix in hex chars */
 	char hex_pfx[GIT_MAX_HEXSZ + 1];
 	struct object_id bin_pfx;
 
+	struct repository *repo;
 	disambiguate_hint_fn fn;
 	void *cb_data;
 	struct object_id candidate;
@@ -38,7 +39,7 @@ struct disambiguate_state {
 static void update_candidates(struct disambiguate_state *ds, const struct object_id *current)
 {
 	if (ds->always_call_fn) {
-		ds->ambiguous = ds->fn(current, ds->cb_data) ? 1 : 0;
+		ds->ambiguous = ds->fn(ds->repo, current, ds->cb_data) ? 1 : 0;
 		return;
 	}
 	if (!ds->candidate_exists) {
@@ -58,7 +59,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object
 	}
 
 	if (!ds->candidate_checked) {
-		ds->candidate_ok = ds->fn(&ds->candidate, ds->cb_data);
+		ds->candidate_ok = ds->fn(ds->repo, &ds->candidate, ds->cb_data);
 		ds->disambiguate_fn_used = 1;
 		ds->candidate_checked = 1;
 	}
@@ -71,7 +72,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object
 	}
 
 	/* if we reach this point, we know ds->candidate satisfies fn */
-	if (ds->fn(current, ds->cb_data)) {
+	if (ds->fn(ds->repo, current, ds->cb_data)) {
 		/*
 		 * if both current and candidate satisfy fn, we cannot
 		 * disambiguate.
@@ -89,9 +90,7 @@ static void find_short_object_filename(struct disambiguate_state *ds)
 {
 	struct object_directory *odb;
 
-	for (odb = the_repository->objects->odb;
-	     odb && !ds->ambiguous;
-	     odb = odb->next) {
+	for (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next) {
 		int pos;
 		struct oid_array *loose_objects;
 
@@ -182,10 +181,10 @@ static void find_short_packed_object(struct disambiguate_state *ds)
 	struct multi_pack_index *m;
 	struct packed_git *p;
 
-	for (m = get_multi_pack_index(the_repository); m && !ds->ambiguous;
+	for (m = get_multi_pack_index(ds->repo); m && !ds->ambiguous;
 	     m = m->next)
 		unique_in_midx(m, ds);
-	for (p = get_packed_git(the_repository); p && !ds->ambiguous;
+	for (p = get_packed_git(ds->repo); p && !ds->ambiguous;
 	     p = p->next)
 		unique_in_pack(p, ds);
 }
@@ -215,7 +214,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
 		 * same repository!
 		 */
 		ds->candidate_ok = (!ds->disambiguate_fn_used ||
-				    ds->fn(&ds->candidate, ds->cb_data));
+				    ds->fn(ds->repo, &ds->candidate, ds->cb_data));
 
 	if (!ds->candidate_ok)
 		return SHORT_NAME_AMBIGUOUS;
@@ -224,59 +223,67 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
 	return 0;
 }
 
-static int disambiguate_commit_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_commit_only(struct repository *r,
+				    const struct object_id *oid,
+				    void *cb_data_unused)
 {
-	int kind = oid_object_info(the_repository, oid, NULL);
+	int kind = oid_object_info(r, oid, NULL);
 	return kind == OBJ_COMMIT;
 }
 
-static int disambiguate_committish_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_committish_only(struct repository *r,
+					const struct object_id *oid,
+					void *cb_data_unused)
 {
 	struct object *obj;
 	int kind;
 
-	kind = oid_object_info(the_repository, oid, NULL);
+	kind = oid_object_info(r, oid, NULL);
 	if (kind == OBJ_COMMIT)
 		return 1;
 	if (kind != OBJ_TAG)
 		return 0;
 
 	/* We need to do this the hard way... */
-	obj = deref_tag(the_repository, parse_object(the_repository, oid),
-			NULL, 0);
+	obj = deref_tag(r, parse_object(r, oid), NULL, 0);
 	if (obj && obj->type == OBJ_COMMIT)
 		return 1;
 	return 0;
 }
 
-static int disambiguate_tree_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_tree_only(struct repository *r,
+				  const struct object_id *oid,
+				  void *cb_data_unused)
 {
-	int kind = oid_object_info(the_repository, oid, NULL);
+	int kind = oid_object_info(r, oid, NULL);
 	return kind == OBJ_TREE;
 }
 
-static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_treeish_only(struct repository *r,
+				     const struct object_id *oid,
+				     void *cb_data_unused)
 {
 	struct object *obj;
 	int kind;
 
-	kind = oid_object_info(the_repository, oid, NULL);
+	kind = oid_object_info(r, oid, NULL);
 	if (kind == OBJ_TREE || kind == OBJ_COMMIT)
 		return 1;
 	if (kind != OBJ_TAG)
 		return 0;
 
 	/* We need to do this the hard way... */
-	obj = deref_tag(the_repository, parse_object(the_repository, oid),
-			NULL, 0);
+	obj = deref_tag(r, parse_object(r, oid), NULL, 0);
 	if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))
 		return 1;
 	return 0;
 }
 
-static int disambiguate_blob_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_blob_only(struct repository *r,
+				  const struct object_id *oid,
+				  void *cb_data_unused)
 {
-	int kind = oid_object_info(the_repository, oid, NULL);
+	int kind = oid_object_info(r, oid, NULL);
 	return kind == OBJ_BLOB;
 }
 
@@ -310,7 +317,8 @@ int set_disambiguate_hint_config(const char *var, const char *value)
 	return error("unknown hint type for '%s': %s", var, value);
 }
 
-static int init_object_disambiguation(const char *name, int len,
+static int init_object_disambiguation(struct repository *r,
+				      const char *name, int len,
 				      struct disambiguate_state *ds)
 {
 	int i;
@@ -341,7 +349,8 @@ static int init_object_disambiguation(const char *name, int len,
 
 	ds->len = len;
 	ds->hex_pfx[len] = '\0';
-	prepare_alt_odb(the_repository);
+	ds->repo = r;
+	prepare_alt_odb(r);
 	return 0;
 }
 
@@ -351,25 +360,25 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
 	struct strbuf desc = STRBUF_INIT;
 	int type;
 
-	if (ds->fn && !ds->fn(oid, ds->cb_data))
+	if (ds->fn && !ds->fn(ds->repo, oid, ds->cb_data))
 		return 0;
 
-	type = oid_object_info(the_repository, oid, NULL);
+	type = oid_object_info(ds->repo, oid, NULL);
 	if (type == OBJ_COMMIT) {
-		struct commit *commit = lookup_commit(the_repository, oid);
+		struct commit *commit = lookup_commit(ds->repo, oid);
 		if (commit) {
 			struct pretty_print_context pp = {0};
 			pp.date_mode.type = DATE_SHORT;
 			format_commit_message(commit, " %ad - %s", &desc, &pp);
 		}
 	} else if (type == OBJ_TAG) {
-		struct tag *tag = lookup_tag(the_repository, oid);
+		struct tag *tag = lookup_tag(ds->repo, oid);
 		if (!parse_tag(tag) && tag->tag)
 			strbuf_addf(&desc, " %s", tag->tag);
 	}
 
 	advise("  %s %s%s",
-	       find_unique_abbrev(oid, DEFAULT_ABBREV),
+	       repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV),
 	       type_name(type) ? type_name(type) : "unknown type",
 	       desc.buf);
 
@@ -383,6 +392,13 @@ static int collect_ambiguous(const struct object_id *oid, void *data)
 	return 0;
 }
 
+static int repo_collect_ambiguous(struct repository *r,
+				  const struct object_id *oid,
+				  void *data)
+{
+	return collect_ambiguous(oid, data);
+}
+
 static struct repository *sort_ambiguous_repo;
 static int sort_ambiguous(const void *a, const void *b)
 {
@@ -428,7 +444,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 	struct disambiguate_state ds;
 	int quietly = !!(flags & GET_OID_QUIETLY);
 
-	if (init_object_disambiguation(name, len, &ds) < 0)
+	if (init_object_disambiguation(the_repository, name, len, &ds) < 0)
 		return -1;
 
 	if (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))
@@ -483,11 +499,11 @@ int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)
 	struct disambiguate_state ds;
 	int ret;
 
-	if (init_object_disambiguation(prefix, strlen(prefix), &ds) < 0)
+	if (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0)
 		return -1;
 
 	ds.always_call_fn = 1;
-	ds.fn = collect_ambiguous;
+	ds.fn = repo_collect_ambiguous;
 	ds.cb_data = &collect;
 	find_short_object_filename(&ds);
 	find_short_packed_object(&ds);
@@ -543,6 +559,13 @@ static int extend_abbrev_len(const struct object_id *oid, void *cb_data)
 	return 0;
 }
 
+static int repo_extend_abbrev_len(struct repository *r,
+				  const struct object_id *oid,
+				  void *cb_data)
+{
+	return extend_abbrev_len(oid, cb_data);
+}
+
 static void find_abbrev_len_for_midx(struct multi_pack_index *m,
 				     struct min_abbrev_data *mad)
 {
@@ -668,10 +691,10 @@ int repo_find_unique_abbrev_r(struct repository *r, char *hex,
 
 	find_abbrev_len_packed(&mad);
 
-	if (init_object_disambiguation(hex, mad.cur_len, &ds) < 0)
+	if (init_object_disambiguation(r, hex, mad.cur_len, &ds) < 0)
 		return -1;
 
-	ds.fn = extend_abbrev_len;
+	ds.fn = repo_extend_abbrev_len;
 	ds.always_call_fn = 1;
 	ds.cb_data = (void *)&mad;
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 16/33] sha1-name.c: add repo_for_each_abbrev()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (14 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 15/33] sha1-name.c: store and use repo in struct disambiguate_state Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 17/33] sha1-name.c: remove the_repo from get_short_oid() Nguyễn Thái Ngọc Duy
                       ` (18 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 3 ++-
 sha1-name.c | 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/cache.h b/cache.h
index 4f8ebb0a67..0cb95c0d4f 100644
--- a/cache.h
+++ b/cache.h
@@ -1392,7 +1392,8 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c
 				struct object_context *oc);
 
 typedef int each_abbrev_fn(const struct object_id *oid, void *);
-extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
+int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);
+#define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data)
 
 extern int set_disambiguate_hint_config(const char *var, const char *value);
 
diff --git a/sha1-name.c b/sha1-name.c
index a75992eb54..cdcf84b826 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -493,13 +493,14 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 	return status;
 }
 
-int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)
+int repo_for_each_abbrev(struct repository *r, const char *prefix,
+			 each_abbrev_fn fn, void *cb_data)
 {
 	struct oid_array collect = OID_ARRAY_INIT;
 	struct disambiguate_state ds;
 	int ret;
 
-	if (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0)
+	if (init_object_disambiguation(r, prefix, strlen(prefix), &ds) < 0)
 		return -1;
 
 	ds.always_call_fn = 1;
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 17/33] sha1-name.c: remove the_repo from get_short_oid()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (15 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 16/33] sha1-name.c: add repo_for_each_abbrev() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 18/33] sha1-name.c: remove the_repo from interpret_nth_prior_checkout() Nguyễn Thái Ngọc Duy
                       ` (17 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index cdcf84b826..2643b75b54 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -436,7 +436,8 @@ static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)
 	sort_ambiguous_repo = NULL;
 }
 
-static enum get_oid_result get_short_oid(const char *name, int len,
+static enum get_oid_result get_short_oid(struct repository *r,
+					 const char *name, int len,
 					 struct object_id *oid,
 					 unsigned flags)
 {
@@ -444,7 +445,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 	struct disambiguate_state ds;
 	int quietly = !!(flags & GET_OID_QUIETLY);
 
-	if (init_object_disambiguation(the_repository, name, len, &ds) < 0)
+	if (init_object_disambiguation(r, name, len, &ds) < 0)
 		return -1;
 
 	if (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))
@@ -482,8 +483,8 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 			ds.fn = NULL;
 
 		advise(_("The candidates are:"));
-		for_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect);
-		sort_ambiguous_oid_array(the_repository, &collect);
+		repo_for_each_abbrev(r, ds.hex_pfx, collect_ambiguous, &collect);
+		sort_ambiguous_oid_array(r, &collect);
 
 		if (oid_array_for_each(&collect, show_ambiguous_object, &ds))
 			BUG("show_ambiguous_object shouldn't return non-zero");
@@ -855,7 +856,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 
 	if (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&
 	    (refs_found > 1 ||
-	     !get_short_oid(str, len, &tmp_oid, GET_OID_QUIETLY)))
+	     !get_short_oid(the_repository,
+			    str, len, &tmp_oid, GET_OID_QUIETLY)))
 		warning(warn_msg, len, str);
 
 	if (reflog_len) {
@@ -1109,7 +1111,8 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)
 			if (ch == 'g' && cp[-1] == '-') {
 				cp++;
 				len -= cp - name;
-				return get_short_oid(cp, len, oid, flags);
+				return get_short_oid(the_repository,
+						     cp, len, oid, flags);
 			}
 		}
 	}
@@ -1163,7 +1166,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,
 	if (!ret)
 		return FOUND;
 
-	return get_short_oid(name, len, oid, lookup_flags);
+	return get_short_oid(the_repository, name, len, oid, lookup_flags);
 }
 
 /*
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 18/33] sha1-name.c: remove the_repo from interpret_nth_prior_checkout()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (16 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 17/33] sha1-name.c: remove the_repo from get_short_oid() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 19/33] sha1-name.c: remove the_repo from interpret_branch_mark() Nguyễn Thái Ngọc Duy
                       ` (16 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 2643b75b54..af8bf5b351 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -771,7 +771,7 @@ static inline int push_mark(const char *string, int len)
 }
 
 static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
-static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);
+static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);
 
 static int get_oid_basic(const char *str, int len, struct object_id *oid,
 			  unsigned int flags)
@@ -835,7 +835,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 		struct strbuf buf = STRBUF_INIT;
 		int detached;
 
-		if (interpret_nth_prior_checkout(str, len, &buf) > 0) {
+		if (interpret_nth_prior_checkout(the_repository, str, len, &buf) > 0) {
 			detached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));
 			strbuf_release(&buf);
 			if (detached)
@@ -1288,7 +1288,8 @@ static int grab_nth_branch_switch(struct object_id *ooid, struct object_id *noid
  * Parse @{-N} syntax, return the number of characters parsed
  * if successful; otherwise signal an error with negative value.
  */
-static int interpret_nth_prior_checkout(const char *name, int namelen,
+static int interpret_nth_prior_checkout(struct repository *r,
+					const char *name, int namelen,
 					struct strbuf *buf)
 {
 	long nth;
@@ -1312,12 +1313,14 @@ static int interpret_nth_prior_checkout(const char *name, int namelen,
 	cb.remaining = nth;
 	strbuf_init(&cb.buf, 20);
 
-	retval = 0;
-	if (0 < for_each_reflog_ent_reverse("HEAD", grab_nth_branch_switch, &cb)) {
+	retval = refs_for_each_reflog_ent_reverse(get_main_ref_store(r),
+			"HEAD", grab_nth_branch_switch, &cb);
+	if (0 < retval) {
 		strbuf_reset(buf);
 		strbuf_addbuf(buf, &cb.buf);
 		retval = brace - name + 1;
-	}
+	} else
+		retval = 0;
 
 	strbuf_release(&cb.buf);
 	return retval;
@@ -1484,7 +1487,7 @@ int repo_interpret_branch_name(struct repository *r,
 		namelen = strlen(name);
 
 	if (!allowed || (allowed & INTERPRET_BRANCH_LOCAL)) {
-		len = interpret_nth_prior_checkout(name, namelen, buf);
+		len = interpret_nth_prior_checkout(the_repository, name, namelen, buf);
 		if (!len) {
 			return len; /* syntax Ok, not enough switches */
 		} else if (len > 0) {
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 19/33] sha1-name.c: remove the_repo from interpret_branch_mark()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (17 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 18/33] sha1-name.c: remove the_repo from interpret_nth_prior_checkout() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 20/33] sha1-name.c: add repo_interpret_branch_name() Nguyễn Thái Ngọc Duy
                       ` (15 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index af8bf5b351..7d9512ac44 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1412,9 +1412,9 @@ static int reinterpret(const char *name, int namelen, int len,
 	return ret - used + len;
 }
 
-static void set_shortened_ref(struct strbuf *buf, const char *ref)
+static void set_shortened_ref(struct repository *r, struct strbuf *buf, const char *ref)
 {
-	char *s = shorten_unambiguous_ref(ref, 0);
+	char *s = refs_shorten_unambiguous_ref(get_main_ref_store(r), ref, 0);
 	strbuf_reset(buf);
 	strbuf_addstr(buf, s);
 	free(s);
@@ -1435,7 +1435,8 @@ static int branch_interpret_allowed(const char *refname, unsigned allowed)
 	return 0;
 }
 
-static int interpret_branch_mark(const char *name, int namelen,
+static int interpret_branch_mark(struct repository *r,
+				 const char *name, int namelen,
 				 int at, struct strbuf *buf,
 				 int (*get_mark)(const char *, int),
 				 const char *(*get_data)(struct branch *,
@@ -1468,7 +1469,7 @@ static int interpret_branch_mark(const char *name, int namelen,
 	if (!branch_interpret_allowed(value, allowed))
 		return -1;
 
-	set_shortened_ref(buf, value);
+	set_shortened_ref(r, buf, value);
 	return len + at;
 }
 
@@ -1509,13 +1510,13 @@ int repo_interpret_branch_name(struct repository *r,
 						   allowed);
 		}
 
-		len = interpret_branch_mark(name, namelen, at - name, buf,
+		len = interpret_branch_mark(the_repository, name, namelen, at - name, buf,
 					    upstream_mark, branch_get_upstream,
 					    allowed);
 		if (len > 0)
 			return len;
 
-		len = interpret_branch_mark(name, namelen, at - name, buf,
+		len = interpret_branch_mark(the_repository, name, namelen, at - name, buf,
 					    push_mark, branch_get_push,
 					    allowed);
 		if (len > 0)
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 20/33] sha1-name.c: add repo_interpret_branch_name()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (18 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 19/33] sha1-name.c: remove the_repo from interpret_branch_mark() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 21/33] sha1-name.c: remove the_repo from get_oid_oneline() Nguyễn Thái Ngọc Duy
                       ` (14 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 7d9512ac44..49c62d5254 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1390,7 +1390,8 @@ static int interpret_empty_at(const char *name, int namelen, int len, struct str
 	return 1;
 }
 
-static int reinterpret(const char *name, int namelen, int len,
+static int reinterpret(struct repository *r,
+		       const char *name, int namelen, int len,
 		       struct strbuf *buf, unsigned allowed)
 {
 	/* we have extra data, which might need further processing */
@@ -1399,7 +1400,7 @@ static int reinterpret(const char *name, int namelen, int len,
 	int ret;
 
 	strbuf_add(buf, name + len, namelen - len);
-	ret = interpret_branch_name(buf->buf, buf->len, &tmp, allowed);
+	ret = repo_interpret_branch_name(r, buf->buf, buf->len, &tmp, allowed);
 	/* that data was not interpreted, remove our cruft */
 	if (ret < 0) {
 		strbuf_setlen(buf, used);
@@ -1482,20 +1483,18 @@ int repo_interpret_branch_name(struct repository *r,
 	const char *start;
 	int len;
 
-	if (r != the_repository)
-		BUG("interpret_branch_name() does not really use 'r' yet");
 	if (!namelen)
 		namelen = strlen(name);
 
 	if (!allowed || (allowed & INTERPRET_BRANCH_LOCAL)) {
-		len = interpret_nth_prior_checkout(the_repository, name, namelen, buf);
+		len = interpret_nth_prior_checkout(r, name, namelen, buf);
 		if (!len) {
 			return len; /* syntax Ok, not enough switches */
 		} else if (len > 0) {
 			if (len == namelen)
 				return len; /* consumed all */
 			else
-				return reinterpret(name, namelen, len, buf, allowed);
+				return reinterpret(r, name, namelen, len, buf, allowed);
 		}
 	}
 
@@ -1506,17 +1505,17 @@ int repo_interpret_branch_name(struct repository *r,
 		if (!allowed || (allowed & INTERPRET_BRANCH_HEAD)) {
 			len = interpret_empty_at(name, namelen, at - name, buf);
 			if (len > 0)
-				return reinterpret(name, namelen, len, buf,
+				return reinterpret(r, name, namelen, len, buf,
 						   allowed);
 		}
 
-		len = interpret_branch_mark(the_repository, name, namelen, at - name, buf,
+		len = interpret_branch_mark(r, name, namelen, at - name, buf,
 					    upstream_mark, branch_get_upstream,
 					    allowed);
 		if (len > 0)
 			return len;
 
-		len = interpret_branch_mark(the_repository, name, namelen, at - name, buf,
+		len = interpret_branch_mark(r, name, namelen, at - name, buf,
 					    push_mark, branch_get_push,
 					    allowed);
 		if (len > 0)
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 21/33] sha1-name.c: remove the_repo from get_oid_oneline()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (19 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 20/33] sha1-name.c: add repo_interpret_branch_name() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 22/33] sha1-name.c: remove the_repo from get_describe_name() Nguyễn Thái Ngọc Duy
                       ` (13 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 49c62d5254..fb80306f1a 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -15,7 +15,7 @@
 #include "midx.h"
 #include "commit-reach.h"
 
-static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
+static int get_oid_oneline(struct repository *r, const char *, struct object_id *, struct commit_list *);
 
 typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);
 
@@ -1090,7 +1090,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 
 		prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
 		commit_list_insert((struct commit *)o, &list);
-		ret = get_oid_oneline(prefix, oid, list);
+		ret = get_oid_oneline(the_repository, prefix, oid, list);
 		free(prefix);
 		return ret;
 	}
@@ -1204,8 +1204,9 @@ static int handle_one_ref(const char *path, const struct object_id *oid,
 	return 0;
 }
 
-static int get_oid_oneline(const char *prefix, struct object_id *oid,
-			    struct commit_list *list)
+static int get_oid_oneline(struct repository *r,
+			   const char *prefix, struct object_id *oid,
+			   struct commit_list *list)
 {
 	struct commit_list *backup = NULL, *l;
 	int found = 0;
@@ -1236,7 +1237,7 @@ static int get_oid_oneline(const char *prefix, struct object_id *oid,
 		int matches;
 
 		commit = pop_most_recent_commit(&list, ONELINE_SEEN);
-		if (!parse_object(the_repository, &commit->object.oid))
+		if (!parse_object(r, &commit->object.oid))
 			continue;
 		buf = get_commit_buffer(commit, NULL);
 		p = strstr(buf, "\n\n");
@@ -1760,7 +1761,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			for_each_ref(handle_one_ref, &list);
 			head_ref(handle_one_ref, &list);
 			commit_list_sort_by_date(&list);
-			return get_oid_oneline(name + 2, oid, list);
+			return get_oid_oneline(repo, name + 2, oid, list);
 		}
 		if (namelen < 3 ||
 		    name[2] != ':' ||
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 22/33] sha1-name.c: remove the_repo from get_describe_name()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (20 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 21/33] sha1-name.c: remove the_repo from get_oid_oneline() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 23/33] sha1-name.c: remove the_repo from get_oid_basic() Nguyễn Thái Ngọc Duy
                       ` (12 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index fb80306f1a..1cda854f02 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1097,7 +1097,9 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 	return 0;
 }
 
-static int get_describe_name(const char *name, int len, struct object_id *oid)
+static int get_describe_name(struct repository *r,
+			     const char *name, int len,
+			     struct object_id *oid)
 {
 	const char *cp;
 	unsigned flags = GET_OID_QUIETLY | GET_OID_COMMIT;
@@ -1111,7 +1113,7 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)
 			if (ch == 'g' && cp[-1] == '-') {
 				cp++;
 				len -= cp - name;
-				return get_short_oid(the_repository,
+				return get_short_oid(r,
 						     cp, len, oid, flags);
 			}
 		}
@@ -1162,7 +1164,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,
 		return FOUND;
 
 	/* It could be describe output that is "SOMETHING-gXXXX" */
-	ret = get_describe_name(name, len, oid);
+	ret = get_describe_name(the_repository, name, len, oid);
 	if (!ret)
 		return FOUND;
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 23/33] sha1-name.c: remove the_repo from get_oid_basic()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (21 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 22/33] sha1-name.c: remove the_repo from get_describe_name() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 24/33] sha1-name.c: remove the_repo from get_oid_1() Nguyễn Thái Ngọc Duy
                       ` (11 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 1cda854f02..d4c135aea8 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -773,8 +773,8 @@ static inline int push_mark(const char *string, int len)
 static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
 static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);
 
-static int get_oid_basic(const char *str, int len, struct object_id *oid,
-			  unsigned int flags)
+static int get_oid_basic(struct repository *r, const char *str, int len,
+			 struct object_id *oid, unsigned int flags)
 {
 	static const char *warn_msg = "refname '%.*s' is ambiguous.";
 	static const char *object_name_msg = N_(
@@ -792,9 +792,9 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 	int refs_found = 0;
 	int at, reflog_len, nth_prior = 0;
 
-	if (len == the_hash_algo->hexsz && !get_oid_hex(str, oid)) {
+	if (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {
 		if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
-			refs_found = dwim_ref(str, len, &tmp_oid, &real_ref);
+			refs_found = repo_dwim_ref(r, str, len, &tmp_oid, &real_ref);
 			if (refs_found > 0) {
 				warning(warn_msg, len, str);
 				if (advice_object_name_warning)
@@ -835,8 +835,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 		struct strbuf buf = STRBUF_INIT;
 		int detached;
 
-		if (interpret_nth_prior_checkout(the_repository, str, len, &buf) > 0) {
-			detached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));
+		if (interpret_nth_prior_checkout(r, str, len, &buf) > 0) {
+			detached = (buf.len == r->hash_algo->hexsz && !get_oid_hex(buf.buf, oid));
 			strbuf_release(&buf);
 			if (detached)
 				return 0;
@@ -845,19 +845,18 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 
 	if (!len && reflog_len)
 		/* allow "@{...}" to mean the current branch reflog */
-		refs_found = dwim_ref("HEAD", 4, oid, &real_ref);
+		refs_found = repo_dwim_ref(r, "HEAD", 4, oid, &real_ref);
 	else if (reflog_len)
-		refs_found = dwim_log(str, len, oid, &real_ref);
+		refs_found = repo_dwim_log(r, str, len, oid, &real_ref);
 	else
-		refs_found = dwim_ref(str, len, oid, &real_ref);
+		refs_found = repo_dwim_ref(r, str, len, oid, &real_ref);
 
 	if (!refs_found)
 		return -1;
 
 	if (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&
 	    (refs_found > 1 ||
-	     !get_short_oid(the_repository,
-			    str, len, &tmp_oid, GET_OID_QUIETLY)))
+	     !get_short_oid(r, str, len, &tmp_oid, GET_OID_QUIETLY)))
 		warning(warn_msg, len, str);
 
 	if (reflog_len) {
@@ -889,7 +888,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 				return -1;
 			}
 		}
-		if (read_ref_at(get_main_ref_store(the_repository),
+		if (read_ref_at(get_main_ref_store(r),
 				real_ref, flags, at_time, nth, oid, NULL,
 				&co_time, &co_tz, &co_cnt)) {
 			if (!len) {
@@ -1159,7 +1158,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,
 	if (!ret)
 		return FOUND;
 
-	ret = get_oid_basic(name, len, oid, lookup_flags);
+	ret = get_oid_basic(the_repository, name, len, oid, lookup_flags);
 	if (!ret)
 		return FOUND;
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 24/33] sha1-name.c: remove the_repo from get_oid_1()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (22 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 23/33] sha1-name.c: remove the_repo from get_oid_basic() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 25/33] sha1-name.c: remove the_repo from handle_one_ref() Nguyễn Thái Ngọc Duy
                       ` (10 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

There is a cyclic dependency between one of these functions so they
cannot be converted one by one, so all related functions are converted
at once.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     |  7 +++++--
 sha1-name.c | 59 ++++++++++++++++++++++++++++-------------------------
 2 files changed, 36 insertions(+), 30 deletions(-)

diff --git a/cache.h b/cache.h
index 0cb95c0d4f..2149dc4f56 100644
--- a/cache.h
+++ b/cache.h
@@ -1491,8 +1491,11 @@ extern void *read_object_with_reference(const struct object_id *oid,
 					unsigned long *size,
 					struct object_id *oid_ret);
 
-extern struct object *peel_to_type(const char *name, int namelen,
-				   struct object *o, enum object_type);
+struct object *repo_peel_to_type(struct repository *r,
+				 const char *name, int namelen,
+				 struct object *o, enum object_type);
+#define peel_to_type(name, namelen, obj, type) \
+	repo_peel_to_type(the_repository, name, namelen, obj, type)
 
 enum date_mode_type {
 	DATE_NORMAL = 0,
diff --git a/sha1-name.c b/sha1-name.c
index d4c135aea8..5741a9f821 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -770,7 +770,7 @@ static inline int push_mark(const char *string, int len)
 	return at_mark(string, len, suffix, ARRAY_SIZE(suffix));
 }
 
-static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
+static enum get_oid_result get_oid_1(struct repository *r, const char *name, int len, struct object_id *oid, unsigned lookup_flags);
 static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);
 
 static int get_oid_basic(struct repository *r, const char *str, int len,
@@ -921,18 +921,19 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
 	return 0;
 }
 
-static enum get_oid_result get_parent(const char *name, int len,
+static enum get_oid_result get_parent(struct repository *r,
+				      const char *name, int len,
 				      struct object_id *result, int idx)
 {
 	struct object_id oid;
-	enum get_oid_result ret = get_oid_1(name, len, &oid,
+	enum get_oid_result ret = get_oid_1(r, name, len, &oid,
 					    GET_OID_COMMITTISH);
 	struct commit *commit;
 	struct commit_list *p;
 
 	if (ret)
 		return ret;
-	commit = lookup_commit_reference(the_repository, &oid);
+	commit = lookup_commit_reference(r, &oid);
 	if (parse_commit(commit))
 		return MISSING_OBJECT;
 	if (!idx) {
@@ -950,7 +951,8 @@ static enum get_oid_result get_parent(const char *name, int len,
 	return MISSING_OBJECT;
 }
 
-static enum get_oid_result get_nth_ancestor(const char *name, int len,
+static enum get_oid_result get_nth_ancestor(struct repository *r,
+					    const char *name, int len,
 					    struct object_id *result,
 					    int generation)
 {
@@ -958,10 +960,10 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,
 	struct commit *commit;
 	int ret;
 
-	ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);
+	ret = get_oid_1(r, name, len, &oid, GET_OID_COMMITTISH);
 	if (ret)
 		return ret;
-	commit = lookup_commit_reference(the_repository, &oid);
+	commit = lookup_commit_reference(r, &oid);
 	if (!commit)
 		return MISSING_OBJECT;
 
@@ -974,20 +976,20 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,
 	return FOUND;
 }
 
-struct object *peel_to_type(const char *name, int namelen,
-			    struct object *o, enum object_type expected_type)
+struct object *repo_peel_to_type(struct repository *r, const char *name, int namelen,
+				 struct object *o, enum object_type expected_type)
 {
 	if (name && !namelen)
 		namelen = strlen(name);
 	while (1) {
-		if (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))
+		if (!o || (!o->parsed && !parse_object(r, &o->oid)))
 			return NULL;
 		if (expected_type == OBJ_ANY || o->type == expected_type)
 			return o;
 		if (o->type == OBJ_TAG)
 			o = ((struct tag*) o)->tagged;
 		else if (o->type == OBJ_COMMIT)
-			o = &(get_commit_tree(((struct commit *)o))->object);
+			o = &(repo_get_commit_tree(r, ((struct commit *)o))->object);
 		else {
 			if (name)
 				error("%.*s: expected %s type, but the object "
@@ -999,8 +1001,8 @@ struct object *peel_to_type(const char *name, int namelen,
 	}
 }
 
-static int peel_onion(const char *name, int len, struct object_id *oid,
-		      unsigned lookup_flags)
+static int peel_onion(struct repository *r, const char *name, int len,
+		      struct object_id *oid, unsigned lookup_flags)
 {
 	struct object_id outer;
 	const char *sp;
@@ -1050,15 +1052,15 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 	else if (expected_type == OBJ_TREE)
 		lookup_flags |= GET_OID_TREEISH;
 
-	if (get_oid_1(name, sp - name - 2, &outer, lookup_flags))
+	if (get_oid_1(r, name, sp - name - 2, &outer, lookup_flags))
 		return -1;
 
-	o = parse_object(the_repository, &outer);
+	o = parse_object(r, &outer);
 	if (!o)
 		return -1;
 	if (!expected_type) {
-		o = deref_tag(the_repository, o, name, sp - name - 2);
-		if (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))
+		o = deref_tag(r, o, name, sp - name - 2);
+		if (!o || (!o->parsed && !parse_object(r, &o->oid)))
 			return -1;
 		oidcpy(oid, &o->oid);
 		return 0;
@@ -1069,7 +1071,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 	 * if we do not get the needed object, we should
 	 * barf.
 	 */
-	o = peel_to_type(name, len, o, expected_type);
+	o = repo_peel_to_type(r, name, len, o, expected_type);
 	if (!o)
 		return -1;
 
@@ -1089,7 +1091,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 
 		prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
 		commit_list_insert((struct commit *)o, &list);
-		ret = get_oid_oneline(the_repository, prefix, oid, list);
+		ret = get_oid_oneline(r, prefix, oid, list);
 		free(prefix);
 		return ret;
 	}
@@ -1120,7 +1122,8 @@ static int get_describe_name(struct repository *r,
 	return -1;
 }
 
-static enum get_oid_result get_oid_1(const char *name, int len,
+static enum get_oid_result get_oid_1(struct repository *r,
+				     const char *name, int len,
 				     struct object_id *oid,
 				     unsigned lookup_flags)
 {
@@ -1149,25 +1152,25 @@ static enum get_oid_result get_oid_1(const char *name, int len,
 		if (!num && len1 == len - 1)
 			num = 1;
 		if (has_suffix == '^')
-			return get_parent(name, len1, oid, num);
+			return get_parent(r, name, len1, oid, num);
 		/* else if (has_suffix == '~') -- goes without saying */
-		return get_nth_ancestor(name, len1, oid, num);
+		return get_nth_ancestor(r, name, len1, oid, num);
 	}
 
-	ret = peel_onion(name, len, oid, lookup_flags);
+	ret = peel_onion(r, name, len, oid, lookup_flags);
 	if (!ret)
 		return FOUND;
 
-	ret = get_oid_basic(the_repository, name, len, oid, lookup_flags);
+	ret = get_oid_basic(r, name, len, oid, lookup_flags);
 	if (!ret)
 		return FOUND;
 
 	/* It could be describe output that is "SOMETHING-gXXXX" */
-	ret = get_describe_name(the_repository, name, len, oid);
+	ret = get_describe_name(r, name, len, oid);
 	if (!ret)
 		return FOUND;
 
-	return get_short_oid(the_repository, name, len, oid, lookup_flags);
+	return get_short_oid(r, name, len, oid, lookup_flags);
 }
 
 /*
@@ -1741,7 +1744,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 	memset(oc, 0, sizeof(*oc));
 	oc->mode = S_IFINVALID;
 	strbuf_init(&oc->symlink_path, 0);
-	ret = get_oid_1(name, namelen, oid, flags);
+	ret = get_oid_1(repo, name, namelen, oid, flags);
 	if (!ret)
 		return ret;
 	/*
@@ -1822,7 +1825,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 		sub_flags &= ~GET_OID_DISAMBIGUATORS;
 		sub_flags |= GET_OID_TREEISH;
 
-		if (!get_oid_1(name, len, &tree_oid, sub_flags)) {
+		if (!get_oid_1(repo, name, len, &tree_oid, sub_flags)) {
 			const char *filename = cp+1;
 			char *new_filename = NULL;
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 25/33] sha1-name.c: remove the_repo from handle_one_ref()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (23 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 24/33] sha1-name.c: remove the_repo from get_oid_1() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 26/33] sha1-name.c: remove the_repo from diagnose_invalid_index_path() Nguyễn Thái Ngọc Duy
                       ` (9 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 5741a9f821..d9050776dd 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1189,15 +1189,21 @@ static enum get_oid_result get_oid_1(struct repository *r,
 /* Remember to update object flag allocation in object.h */
 #define ONELINE_SEEN (1u<<20)
 
+struct handle_one_ref_cb {
+	struct repository *repo;
+	struct commit_list **list;
+};
+
 static int handle_one_ref(const char *path, const struct object_id *oid,
 			  int flag, void *cb_data)
 {
-	struct commit_list **list = cb_data;
-	struct object *object = parse_object(the_repository, oid);
+	struct handle_one_ref_cb *cb = cb_data;
+	struct commit_list **list = cb->list;
+	struct object *object = parse_object(cb->repo, oid);
 	if (!object)
 		return 0;
 	if (object->type == OBJ_TAG) {
-		object = deref_tag(the_repository, object, path,
+		object = deref_tag(cb->repo, object, path,
 				   strlen(path));
 		if (!object)
 			return 0;
@@ -1760,10 +1766,13 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 		char *new_path = NULL;
 		int pos;
 		if (!only_to_die && namelen > 2 && name[1] == '/') {
+			struct handle_one_ref_cb cb;
 			struct commit_list *list = NULL;
 
-			for_each_ref(handle_one_ref, &list);
-			head_ref(handle_one_ref, &list);
+			cb.repo = repo;
+			cb.list = &list;
+			refs_for_each_ref(repo->refs, handle_one_ref, &cb);
+			refs_head_ref(repo->refs, handle_one_ref, &cb);
 			commit_list_sort_by_date(&list);
 			return get_oid_oneline(repo, name + 2, oid, list);
 		}
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 26/33] sha1-name.c: remove the_repo from diagnose_invalid_index_path()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (24 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 25/33] sha1-name.c: remove the_repo from handle_one_ref() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 27/33] sha1-name.c: remove the_repo from resolve_relative_path() Nguyễn Thái Ngọc Duy
                       ` (8 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 dir.c       | 8 ++++++++
 dir.h       | 4 +++-
 sha1-name.c | 7 ++++---
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/dir.c b/dir.c
index b2cabadf25..e6d97343f4 100644
--- a/dir.c
+++ b/dir.c
@@ -2315,6 +2315,14 @@ int file_exists(const char *f)
 	return lstat(f, &sb) == 0;
 }
 
+int repo_file_exists(struct repository *repo, const char *path)
+{
+	if (repo != the_repository)
+		BUG("do not know how to check file existence in arbitrary repo");
+
+	return file_exists(path);
+}
+
 static int cmp_icase(char a, char b)
 {
 	if (a == b)
diff --git a/dir.h b/dir.h
index e3ec26143d..47c5409ced 100644
--- a/dir.h
+++ b/dir.h
@@ -269,7 +269,9 @@ extern void add_exclude(const char *string, const char *base,
 			int baselen, struct exclude_list *el, int srcpos);
 extern void clear_exclude_list(struct exclude_list *el);
 extern void clear_directory(struct dir_struct *dir);
-extern int file_exists(const char *);
+
+int repo_file_exists(struct repository *repo, const char *path);
+int file_exists(const char *);
 
 extern int is_inside_dir(const char *dir);
 extern int dir_inside_of(const char *subdir, const char *dir);
diff --git a/sha1-name.c b/sha1-name.c
index d9050776dd..6caf3f4e3a 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1664,11 +1664,12 @@ static void diagnose_invalid_oid_path(const char *prefix,
 }
 
 /* Must be called only when :stage:filename doesn't exist. */
-static void diagnose_invalid_index_path(struct index_state *istate,
+static void diagnose_invalid_index_path(struct repository *r,
 					int stage,
 					const char *prefix,
 					const char *filename)
 {
+	struct index_state *istate = r->index;
 	const struct cache_entry *ce;
 	int pos;
 	unsigned namelen = strlen(filename);
@@ -1708,7 +1709,7 @@ static void diagnose_invalid_index_path(struct index_state *istate,
 			    ce_stage(ce), filename);
 	}
 
-	if (file_exists(filename))
+	if (repo_file_exists(r, filename))
 		die("Path '%s' exists on disk, but not in the index.", filename);
 	if (is_missing_file_error(errno))
 		die("Path '%s' does not exist (neither on disk nor in the index).",
@@ -1814,7 +1815,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			pos++;
 		}
 		if (only_to_die && name[1] && name[1] != '/')
-			diagnose_invalid_index_path(repo->index, stage, prefix, cp);
+			diagnose_invalid_index_path(repo, stage, prefix, cp);
 		free(new_path);
 		return -1;
 	}
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 27/33] sha1-name.c: remove the_repo from resolve_relative_path()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (25 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 26/33] sha1-name.c: remove the_repo from diagnose_invalid_index_path() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 28/33] sha1-name.c: remove the_repo from get_oid_with_context_1() Nguyễn Thái Ngọc Duy
                       ` (7 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

"remove" is not entirely correct. But at least the function is aware
that if the given repo is not the_repository, then $CWD and
is_inside_work_tree() means nothing.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 6caf3f4e3a..6b53ea2eeb 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1719,12 +1719,12 @@ static void diagnose_invalid_index_path(struct repository *r,
 }
 
 
-static char *resolve_relative_path(const char *rel)
+static char *resolve_relative_path(struct repository *r, const char *rel)
 {
 	if (!starts_with(rel, "./") && !starts_with(rel, "../"))
 		return NULL;
 
-	if (!is_inside_work_tree())
+	if (r != the_repository || !is_inside_work_tree())
 		die("relative path syntax can't be used outside working tree.");
 
 	/* die() inside prefix_path() if resolved path is outside worktree */
@@ -1785,7 +1785,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			stage = name[1] - '0';
 			cp = name + 3;
 		}
-		new_path = resolve_relative_path(cp);
+		new_path = resolve_relative_path(repo, cp);
 		if (!new_path) {
 			namelen = namelen - (cp - name);
 		} else {
@@ -1839,7 +1839,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			const char *filename = cp+1;
 			char *new_filename = NULL;
 
-			new_filename = resolve_relative_path(filename);
+			new_filename = resolve_relative_path(repo, filename);
 			if (new_filename)
 				filename = new_filename;
 			if (flags & GET_OID_FOLLOW_SYMLINKS) {
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 28/33] sha1-name.c: remove the_repo from get_oid_with_context_1()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (26 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 27/33] sha1-name.c: remove the_repo from resolve_relative_path() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 29/33] sha1-name.c: add repo_get_oid() Nguyễn Thái Ngọc Duy
                       ` (6 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/sha1-name.c b/sha1-name.c
index 6b53ea2eeb..64a50d1291 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -12,6 +12,7 @@
 #include "packfile.h"
 #include "object-store.h"
 #include "repository.h"
+#include "submodule.h"
 #include "midx.h"
 #include "commit-reach.h"
 
@@ -1797,7 +1798,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			oc->path = xstrdup(cp);
 
 		if (!repo->index->cache)
-			repo_read_index(the_repository);
+			repo_read_index(repo);
 		pos = index_name_pos(repo->index, cp, namelen);
 		if (pos < 0)
 			pos = -pos - 1;
@@ -1842,6 +1843,14 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			new_filename = resolve_relative_path(repo, filename);
 			if (new_filename)
 				filename = new_filename;
+			/*
+			 * NEEDSWORK: Eventually get_tree_entry*() should
+			 * learn to take struct repository directly and we
+			 * would not need to inject submodule odb to the
+			 * in-core odb.
+			 */
+			if (repo != the_repository)
+				add_to_alternates_memory(repo->objects->odb->path);
 			if (flags & GET_OID_FOLLOW_SYMLINKS) {
 				ret = get_tree_entry_follow_symlinks(&tree_oid,
 					filename, oid, &oc->symlink_path,
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 29/33] sha1-name.c: add repo_get_oid()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (27 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 28/33] sha1-name.c: remove the_repo from get_oid_with_context_1() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 30/33] submodule-config.c: use repo_get_oid for reading .gitmodules Nguyễn Thái Ngọc Duy
                       ` (5 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 3 ++-
 sha1-name.c | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/cache.h b/cache.h
index 2149dc4f56..f6e87194d0 100644
--- a/cache.h
+++ b/cache.h
@@ -1380,7 +1380,8 @@ enum get_oid_result {
 		       */
 };
 
-extern int get_oid(const char *str, struct object_id *oid);
+int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);
+#define get_oid(str, oid) repo_get_oid(the_repository, str, oid)
 extern int get_oid_commit(const char *str, struct object_id *oid);
 extern int get_oid_committish(const char *str, struct object_id *oid);
 extern int get_oid_tree(const char *str, struct object_id *oid);
diff --git a/sha1-name.c b/sha1-name.c
index 64a50d1291..953df0d692 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1573,10 +1573,10 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
  * This is like "get_oid_basic()", except it allows "object ID expressions",
  * notably "xyz^" for "parent of xyz"
  */
-int get_oid(const char *name, struct object_id *oid)
+int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository, name, 0, oid, &unused);
+	return get_oid_with_context(r, name, 0, oid, &unused);
 }
 
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 30/33] submodule-config.c: use repo_get_oid for reading .gitmodules
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (28 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 29/33] sha1-name.c: add repo_get_oid() Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 31/33] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name Nguyễn Thái Ngọc Duy
                       ` (4 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Since 76e9bdc437 (submodule: support reading .gitmodules when it's not
in the working tree - 2018-10-25), every time you do

    git grep --recurse-submodules

you are likely to see one warning line per submodule (unless all those
submodules also have submodules). On a superproject with plenty of
submodules (I've seen one with 67) this is really annoying.

The warning was there because we could not resolve extended SHA-1
syntax on a submodule. We can now. Make use of the new API and get rid
of the warning.

It would be even better if config_with_options() supports multiple
repositories too. But one step at a time.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 submodule-config.c                 | 20 +++++++-------------
 t/t7814-grep-recurse-submodules.sh |  6 +-----
 2 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/submodule-config.c b/submodule-config.c
index 66653e86b9..4264ee216f 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -625,23 +625,16 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
 		const struct config_options opts = { 0 };
 		struct object_id oid;
 		char *file;
+		char *oidstr = NULL;
 
 		file = repo_worktree_path(repo, GITMODULES_FILE);
 		if (file_exists(file)) {
 			config_source.file = file;
-		} else if (repo->submodule_prefix) {
-			/*
-			 * When get_oid and config_with_options, used below,
-			 * become able to work on a specific repository, this
-			 * warning branch can be removed.
-			 */
-			warning("nested submodules without %s in the working tree are not supported yet",
-				GITMODULES_FILE);
-			goto out;
-		} else if (get_oid(GITMODULES_INDEX, &oid) >= 0) {
-			config_source.blob = GITMODULES_INDEX;
-		} else if (get_oid(GITMODULES_HEAD, &oid) >= 0) {
-			config_source.blob = GITMODULES_HEAD;
+		} else if (repo_get_oid(repo, GITMODULES_INDEX, &oid) >= 0 ||
+			   repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
+			config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
+			if (repo != the_repository)
+				add_to_alternates_memory(repo->objects->odb->path);
 		} else {
 			goto out;
 		}
@@ -649,6 +642,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
 		config_with_options(fn, data, &config_source, &opts);
 
 out:
+		free(oidstr);
 		free(file);
 	}
 }
diff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh
index fa475d52fa..134a694516 100755
--- a/t/t7814-grep-recurse-submodules.sh
+++ b/t/t7814-grep-recurse-submodules.sh
@@ -380,11 +380,7 @@ test_expect_success 'grep --recurse-submodules should pass the pattern type alon
 	fi
 '
 
-# Recursing down into nested submodules which do not have .gitmodules in their
-# working tree does not work yet. This is because config_from_gitmodules()
-# uses get_oid() and the latter is still not able to get objects from an
-# arbitrary repository (the nested submodule, in this case).
-test_expect_failure 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '
+test_expect_success 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '
 	test_when_finished "git -C submodule checkout .gitmodules" &&
 	rm submodule/.gitmodules &&
 	git grep --recurse-submodules -e "(.|.)[\d]" >actual &&
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 31/33] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (29 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 30/33] submodule-config.c: use repo_get_oid for reading .gitmodules Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 32/33] sha1-name.c: remove the_repo from other get_oid_* Nguyễn Thái Ngọc Duy
                       ` (3 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 4 +++-
 setup.c     | 7 ++++---
 sha1-name.c | 6 ++++--
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/cache.h b/cache.h
index f6e87194d0..3718b3db8a 100644
--- a/cache.h
+++ b/cache.h
@@ -1387,7 +1387,9 @@ extern int get_oid_committish(const char *str, struct object_id *oid);
 extern int get_oid_tree(const char *str, struct object_id *oid);
 extern int get_oid_treeish(const char *str, struct object_id *oid);
 extern int get_oid_blob(const char *str, struct object_id *oid);
-extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
+void maybe_die_on_misspelt_object_name(struct repository *repo,
+				       const char *name,
+				       const char *prefix);
 extern enum get_oid_result get_oid_with_context(struct repository *repo, const char *str,
 				unsigned flags, struct object_id *oid,
 				struct object_context *oc);
diff --git a/setup.c b/setup.c
index d0c958c3b2..8dcb4631f7 100644
--- a/setup.c
+++ b/setup.c
@@ -164,7 +164,8 @@ int check_filename(const char *prefix, const char *arg)
 	die_errno(_("failed to stat '%s'"), arg);
 }
 
-static void NORETURN die_verify_filename(const char *prefix,
+static void NORETURN die_verify_filename(struct repository *r,
+					 const char *prefix,
 					 const char *arg,
 					 int diagnose_misspelt_rev)
 {
@@ -179,7 +180,7 @@ static void NORETURN die_verify_filename(const char *prefix,
 	 * let maybe_die_on_misspelt_object_name() even trigger.
 	 */
 	if (!(arg[0] == ':' && !isalnum(arg[1])))
-		maybe_die_on_misspelt_object_name(arg, prefix);
+		maybe_die_on_misspelt_object_name(r, arg, prefix);
 
 	/* ... or fall back the most general message. */
 	die(_("ambiguous argument '%s': unknown revision or path not in the working tree.\n"
@@ -234,7 +235,7 @@ void verify_filename(const char *prefix,
 		die(_("option '%s' must come before non-option arguments"), arg);
 	if (looks_like_pathspec(arg) || check_filename(prefix, arg))
 		return;
-	die_verify_filename(prefix, arg, diagnose_misspelt_rev);
+	die_verify_filename(the_repository, prefix, arg, diagnose_misspelt_rev);
 }
 
 /*
diff --git a/sha1-name.c b/sha1-name.c
index 953df0d692..b94d381bef 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1885,11 +1885,13 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
  * exist in 'HEAD'" when given "HEAD:doc", or it may return in which case
  * you have a chance to diagnose the error further.
  */
-void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
+void maybe_die_on_misspelt_object_name(struct repository *r,
+				       const char *name,
+				       const char *prefix)
 {
 	struct object_context oc;
 	struct object_id oid;
-	get_oid_with_context_1(the_repository, name, GET_OID_ONLY_TO_DIE,
+	get_oid_with_context_1(r, name, GET_OID_ONLY_TO_DIE,
 			       prefix, &oid, &oc);
 }
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 32/33] sha1-name.c: remove the_repo from other get_oid_*
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (30 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 31/33] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-06 11:34     ` [PATCH v3 33/33] sha1-name.c: remove the_repo from get_oid_mb() Nguyễn Thái Ngọc Duy
                       ` (2 subsequent siblings)
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 18 ++++++++++++------
 sha1-name.c | 35 ++++++++++++++++++++---------------
 2 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/cache.h b/cache.h
index 3718b3db8a..871a167bf8 100644
--- a/cache.h
+++ b/cache.h
@@ -1381,12 +1381,11 @@ enum get_oid_result {
 };
 
 int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);
-#define get_oid(str, oid) repo_get_oid(the_repository, str, oid)
-extern int get_oid_commit(const char *str, struct object_id *oid);
-extern int get_oid_committish(const char *str, struct object_id *oid);
-extern int get_oid_tree(const char *str, struct object_id *oid);
-extern int get_oid_treeish(const char *str, struct object_id *oid);
-extern int get_oid_blob(const char *str, struct object_id *oid);
+int repo_get_oid_commit(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_committish(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid);
 void maybe_die_on_misspelt_object_name(struct repository *repo,
 				       const char *name,
 				       const char *prefix);
@@ -1394,6 +1393,13 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c
 				unsigned flags, struct object_id *oid,
 				struct object_context *oc);
 
+#define get_oid(str, oid)		repo_get_oid(the_repository, str, oid)
+#define get_oid_commit(str, oid)	repo_get_oid_commit(the_repository, str, oid)
+#define get_oid_committish(str, oid)	repo_get_oid_committish(the_repository, str, oid)
+#define get_oid_tree(str, oid)		repo_get_oid_tree(the_repository, str, oid)
+#define get_oid_treeish(str, oid)	repo_get_oid_treeish(the_repository, str, oid)
+#define get_oid_blob(str, oid)		repo_get_oid_blob(the_repository, str, oid)
+
 typedef int each_abbrev_fn(const struct object_id *oid, void *);
 int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);
 #define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data)
diff --git a/sha1-name.c b/sha1-name.c
index b94d381bef..d49496397d 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1590,43 +1590,48 @@ int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)
  * commit-ish. It is merely to give a hint to the disambiguation
  * machinery.
  */
-int get_oid_committish(const char *name, struct object_id *oid)
+int repo_get_oid_committish(struct repository *r,
+			    const char *name,
+			    struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_COMMITTISH,
+	return get_oid_with_context(r, name, GET_OID_COMMITTISH,
 				    oid, &unused);
 }
 
-int get_oid_treeish(const char *name, struct object_id *oid)
+int repo_get_oid_treeish(struct repository *r,
+			 const char *name,
+			 struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_TREEISH,
+	return get_oid_with_context(r, name, GET_OID_TREEISH,
 				    oid, &unused);
 }
 
-int get_oid_commit(const char *name, struct object_id *oid)
+int repo_get_oid_commit(struct repository *r,
+			const char *name,
+			struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_COMMIT,
+	return get_oid_with_context(r, name, GET_OID_COMMIT,
 				    oid, &unused);
 }
 
-int get_oid_tree(const char *name, struct object_id *oid)
+int repo_get_oid_tree(struct repository *r,
+		      const char *name,
+		      struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_TREE,
+	return get_oid_with_context(r, name, GET_OID_TREE,
 				    oid, &unused);
 }
 
-int get_oid_blob(const char *name, struct object_id *oid)
+int repo_get_oid_blob(struct repository *r,
+		      const char *name,
+		      struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_BLOB,
+	return get_oid_with_context(r, name, GET_OID_BLOB,
 				    oid, &unused);
 }
 
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v3 33/33] sha1-name.c: remove the_repo from get_oid_mb()
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (31 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 32/33] sha1-name.c: remove the_repo from other get_oid_* Nguyễn Thái Ngọc Duy
@ 2019-04-06 11:34     ` Nguyễn Thái Ngọc Duy
  2019-04-10 20:56     ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Johannes Schindelin
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
  34 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-06 11:34 UTC (permalink / raw)
  To: pclouds; +Cc: git, gitster, stefanbeller, szeder.dev, Johannes Schindelin

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     |  3 ++-
 sha1-name.c | 18 +++++++++++-------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/cache.h b/cache.h
index 871a167bf8..9a600a8b50 100644
--- a/cache.h
+++ b/cache.h
@@ -1386,6 +1386,7 @@ int repo_get_oid_committish(struct repository *r, const char *str, struct object
 int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid);
 int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid);
 int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_mb(struct repository *r, const char *str, struct object_id *oid);
 void maybe_die_on_misspelt_object_name(struct repository *repo,
 				       const char *name,
 				       const char *prefix);
@@ -1399,6 +1400,7 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c
 #define get_oid_tree(str, oid)		repo_get_oid_tree(the_repository, str, oid)
 #define get_oid_treeish(str, oid)	repo_get_oid_treeish(the_repository, str, oid)
 #define get_oid_blob(str, oid)		repo_get_oid_blob(the_repository, str, oid)
+#define get_oid_mb(str, oid) 		repo_get_oid_mb(the_repository, str, oid)
 
 typedef int each_abbrev_fn(const struct object_id *oid, void *);
 int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);
@@ -1486,7 +1488,6 @@ int repo_interpret_branch_name(struct repository *r,
 			       unsigned allowed);
 #define interpret_branch_name(str, len, buf, allowed) \
 	repo_interpret_branch_name(the_repository, str, len, buf, allowed)
-extern int get_oid_mb(const char *str, struct object_id *oid);
 
 extern int validate_headref(const char *ref);
 
diff --git a/sha1-name.c b/sha1-name.c
index d49496397d..cf314ebb29 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1338,7 +1338,9 @@ static int interpret_nth_prior_checkout(struct repository *r,
 	return retval;
 }
 
-int get_oid_mb(const char *name, struct object_id *oid)
+int repo_get_oid_mb(struct repository *r,
+		    const char *name,
+		    struct object_id *oid)
 {
 	struct commit *one, *two;
 	struct commit_list *mbs;
@@ -1348,27 +1350,29 @@ int get_oid_mb(const char *name, struct object_id *oid)
 
 	dots = strstr(name, "...");
 	if (!dots)
-		return get_oid(name, oid);
+		return repo_get_oid(r, name, oid);
 	if (dots == name)
-		st = get_oid("HEAD", &oid_tmp);
+		st = repo_get_oid(r, "HEAD", &oid_tmp);
 	else {
 		struct strbuf sb;
 		strbuf_init(&sb, dots - name);
 		strbuf_add(&sb, name, dots - name);
-		st = get_oid_committish(sb.buf, &oid_tmp);
+		st = repo_get_oid_committish(r, sb.buf, &oid_tmp);
 		strbuf_release(&sb);
 	}
 	if (st)
 		return st;
-	one = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);
+	one = lookup_commit_reference_gently(r, &oid_tmp, 0);
 	if (!one)
 		return -1;
 
-	if (get_oid_committish(dots[3] ? (dots + 3) : "HEAD", &oid_tmp))
+	if (repo_get_oid_committish(r, dots[3] ? (dots + 3) : "HEAD", &oid_tmp))
 		return -1;
-	two = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);
+	two = lookup_commit_reference_gently(r, &oid_tmp, 0);
 	if (!two)
 		return -1;
+	if (r != the_repository)
+		BUG("sorry get_merge_bases() can't take struct repository yet");
 	mbs = get_merge_bases(one, two);
 	if (!mbs || mbs->next)
 		st = -1;
-- 
2.21.0.479.g47ac719cd3


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* Re: [PATCH v2 01/32] rebase: 'make coccicheck' cleanup
  2019-04-05  9:26       ` Duy Nguyen
@ 2019-04-09 10:58         ` SZEDER Gábor
  0 siblings, 0 replies; 154+ messages in thread
From: SZEDER Gábor @ 2019-04-09 10:58 UTC (permalink / raw)
  To: Duy Nguyen; +Cc: Git Mailing List, Junio C Hamano, Stefan Beller

On Fri, Apr 05, 2019 at 04:26:10PM +0700, Duy Nguyen wrote:
> On Fri, Apr 5, 2019 at 12:25 AM SZEDER Gábor <szeder.dev@gmail.com> wrote:
> >
> > On Wed, Apr 03, 2019 at 06:34:26PM +0700, Nguyễn Thái Ngọc Duy wrote:
> > > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> > > ---
> > >  builtin/rebase.c | 5 ++---
> > >  1 file changed, 2 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/builtin/rebase.c b/builtin/rebase.c
> > > index 77deebc65c..c064909329 100644
> > > --- a/builtin/rebase.c
> > > +++ b/builtin/rebase.c
> > > @@ -1592,8 +1592,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
> > >                               branch_name = options.head_name;
> > >
> > >               } else {
> > > -                     free(options.head_name);
> > > -                     options.head_name = NULL;
> > > +                     FREE_AND_NULL(options.head_name);
> > >                       branch_name = "HEAD";
> > >               }
> > >               if (get_oid("HEAD", &options.orig_head))
> > > @@ -1793,7 +1792,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
> > >        * we just fast-forwarded.
> > >        */
> > >       strbuf_reset(&msg);
> > > -     if (!oidcmp(&merge_base, &options.orig_head)) {
> > > +     if (oideq(&merge_base, &options.orig_head)) {
> > >               printf(_("Fast-forwarded %s to %s.\n"),
> > >                       branch_name, options.onto_name);
> > >               strbuf_addf(&msg, "rebase finished: %s onto %s",
> >
> > You are already using Coccinelle v1.0.7, aren't you?
> 
> No it's 1.0.5.

Oh, you are right, Coccinelle 1.0.5 does indeed find these.

When I saw that the self-built 1.0.7 found something that the
distro-shipped 1.0.4 didn't, I checked it with a self-built 1.0.6, and
as it didn't find these, either, I didn't bother with 1.0.5.  It seems
that it got fixed 1.0.5, then regressed in 1.0.6, to be fixed again in
1.0.7.

> I guess I should upgrade then.

I found 'make coccicheck' with 1.0.7 to be about 10-15% faster than
previous versions.


^ permalink raw reply	[flat|nested] 154+ messages in thread

* Re: [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (32 preceding siblings ...)
  2019-04-06 11:34     ` [PATCH v3 33/33] sha1-name.c: remove the_repo from get_oid_mb() Nguyễn Thái Ngọc Duy
@ 2019-04-10 20:56     ` Johannes Schindelin
  2019-04-11  0:26       ` Duy Nguyen
  2019-04-11 20:51       ` SZEDER Gábor
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
  34 siblings, 2 replies; 154+ messages in thread
From: Johannes Schindelin @ 2019-04-10 20:56 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy
  Cc: git, gitster, stefanbeller, szeder.dev

[-- Attachment #1: Type: text/plain, Size: 1700 bytes --]

Hi Duy,

On Sat, 6 Apr 2019, Nguyễn Thái Ngọc Duy wrote:

> 10:  68876a150f ! 11:  848456f59c commit.c: add repo_get_commit_tree()
>     @@ -2,6 +2,11 @@
>
>          commit.c: add repo_get_commit_tree()
>
>     +    Remove the implicit dependency on the_repository in this function.
>     +    It will be used in sha1-name.c functions when they are updated to take
>     +    any 'struct repository'. get_commit_tree() remains as a compat wrapper,
>     +    to be slowly replaced later.
>     +
>       diff --git a/commit.c b/commit.c
>       --- a/commit.c
>       +++ b/commit.c
>     @@ -29,6 +34,15 @@
>       --- a/commit.h
>       +++ b/commit.h
>      @@
>     +
>     + 	/*
>     + 	 * If the commit is loaded from the commit-graph file, then this
>     +-	 * member may be NULL. Only access it through get_commit_tree()
>     ++	 * member may be NULL. Only access it through repo_get_commit_tree()
>     + 	 * or get_commit_tree_oid().
>     + 	 */
>     + 	struct tree *maybe_tree;
>     +@@
>        */
>       void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);
>
>     @@ -57,3 +71,10 @@
>         ...>}
>
>       @@
>     + expression c;
>     ++expression r;
>     + expression s;
>     + @@
>     +-- get_commit_tree(c) = s
>     ++- repo_get_commit_tree(r, c) = s
>     + + c->maybe_tree = s

I think this is wrong, and admittedly I had the very same version
originally.

When you have an arbitrary `r` in any `repo_get_commit_tree(r, c)` (as
opposed to `the_repository`), the conversion to `c->maybe_tree` is most
likely incorrect.

Therefore, I don't think that we can do that.

Ciao,
Johannes

^ permalink raw reply	[flat|nested] 154+ messages in thread

* Re: [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates
  2019-04-10 20:56     ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Johannes Schindelin
@ 2019-04-11  0:26       ` Duy Nguyen
  2019-04-11 20:36         ` Johannes Schindelin
  2019-04-11 20:51       ` SZEDER Gábor
  1 sibling, 1 reply; 154+ messages in thread
From: Duy Nguyen @ 2019-04-11  0:26 UTC (permalink / raw)
  To: Johannes Schindelin
  Cc: Git Mailing List, Junio C Hamano, Stefan Beller,
	SZEDER Gábor

On Thu, Apr 11, 2019 at 3:56 AM Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
> >       @@
> >     + expression c;
> >     ++expression r;
> >     + expression s;
> >     + @@
> >     +-- get_commit_tree(c) = s
> >     ++- repo_get_commit_tree(r, c) = s
> >     + + c->maybe_tree = s
>
> I think this is wrong, and admittedly I had the very same version
> originally.
>
> When you have an arbitrary `r` in any `repo_get_commit_tree(r, c)` (as
> opposed to `the_repository`), the conversion to `c->maybe_tree` is most
> likely incorrect.

I did read the get_commit_tree() source code before doing this. struct
repository is only used to get commit graph to speed things up and we
can't change a thing there when maybe_tree is reassigned. To reassign
maybe_tree, commit-graph does not matter. Neither does the_repository
(vs arbitrary struct repo)

>
> Therefore, I don't think that we can do that.
>
> Ciao,
> Johannes



-- 
Duy

^ permalink raw reply	[flat|nested] 154+ messages in thread

* Re: [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates
  2019-04-11  0:26       ` Duy Nguyen
@ 2019-04-11 20:36         ` Johannes Schindelin
  0 siblings, 0 replies; 154+ messages in thread
From: Johannes Schindelin @ 2019-04-11 20:36 UTC (permalink / raw)
  To: Duy Nguyen
  Cc: Git Mailing List, Junio C Hamano, Stefan Beller,
	SZEDER Gábor

Hi,

On Thu, 11 Apr 2019, Duy Nguyen wrote:

> On Thu, Apr 11, 2019 at 3:56 AM Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
> > >       @@
> > >     + expression c;
> > >     ++expression r;
> > >     + expression s;
> > >     + @@
> > >     +-- get_commit_tree(c) = s
> > >     ++- repo_get_commit_tree(r, c) = s
> > >     + + c->maybe_tree = s
> >
> > I think this is wrong, and admittedly I had the very same version
> > originally.
> >
> > When you have an arbitrary `r` in any `repo_get_commit_tree(r, c)` (as
> > opposed to `the_repository`), the conversion to `c->maybe_tree` is most
> > likely incorrect.
>
> I did read the get_commit_tree() source code before doing this. struct
> repository is only used to get commit graph to speed things up and we
> can't change a thing there when maybe_tree is reassigned. To reassign
> maybe_tree, commit-graph does not matter. Neither does the_repository
> (vs arbitrary struct repo)

You read the current code. Obviously, you had no future code to read.

The cocci patch you are changing will affect future code, too.

The safe, and correct, thing to do, then, is to not pretend to know what
future `get_commit_tree()` functions will do, and instead go with the
stricter  version of the cocci patch, as I had suggested.

Ciao,
Johannes

> >
> > Therefore, I don't think that we can do that.
> >
> > Ciao,
> > Johannes
>
>
>
> --
> Duy
>

^ permalink raw reply	[flat|nested] 154+ messages in thread

* Re: [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates
  2019-04-10 20:56     ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Johannes Schindelin
  2019-04-11  0:26       ` Duy Nguyen
@ 2019-04-11 20:51       ` SZEDER Gábor
  2019-04-11 20:58         ` SZEDER Gábor
  1 sibling, 1 reply; 154+ messages in thread
From: SZEDER Gábor @ 2019-04-11 20:51 UTC (permalink / raw)
  To: Johannes Schindelin
  Cc: Nguyễn Thái Ngọc Duy, git, gitster, stefanbeller,
	Derrick Stolee

On Wed, Apr 10, 2019 at 10:56:52PM +0200, Johannes Schindelin wrote:
> Hi Duy,
> 
> On Sat, 6 Apr 2019, Nguyễn Thái Ngọc Duy wrote:
> 
> > 10:  68876a150f ! 11:  848456f59c commit.c: add repo_get_commit_tree()
> >     @@ -2,6 +2,11 @@
> >
> >          commit.c: add repo_get_commit_tree()
> >
> >     +    Remove the implicit dependency on the_repository in this function.
> >     +    It will be used in sha1-name.c functions when they are updated to take
> >     +    any 'struct repository'. get_commit_tree() remains as a compat wrapper,
> >     +    to be slowly replaced later.
> >     +
> >       diff --git a/commit.c b/commit.c
> >       --- a/commit.c
> >       +++ b/commit.c
> >     @@ -29,6 +34,15 @@
> >       --- a/commit.h
> >       +++ b/commit.h
> >      @@
> >     +
> >     + 	/*
> >     + 	 * If the commit is loaded from the commit-graph file, then this
> >     +-	 * member may be NULL. Only access it through get_commit_tree()
> >     ++	 * member may be NULL. Only access it through repo_get_commit_tree()
> >     + 	 * or get_commit_tree_oid().
> >     + 	 */
> >     + 	struct tree *maybe_tree;
> >     +@@
> >        */
> >       void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);
> >
> >     @@ -57,3 +71,10 @@
> >         ...>}
> >
> >       @@
> >     + expression c;
> >     ++expression r;
> >     + expression s;
> >     + @@
> >     +-- get_commit_tree(c) = s
> >     ++- repo_get_commit_tree(r, c) = s
> >     + + c->maybe_tree = s
> 
> I think this is wrong, and admittedly I had the very same version
> originally.
> 
> When you have an arbitrary `r` in any `repo_get_commit_tree(r, c)` (as
> opposed to `the_repository`), the conversion to `c->maybe_tree` is most
> likely incorrect.
> 
> Therefore, I don't think that we can do that.

So, as far as I understand, the goal of these 'c->maybe_tree'-related
semantic patches is to prevent "generic" parts of Git from accessing
this field directly, as it might not be initialized in a
commit-graph-enabled repository.

Only three functions are explicitly exempt, while this last semantic
patch in question implicitly allows a few more that assign a value to
'c->maybe_tree'.  These functions are release_commit_memory() and
parse_commit_buffer() in 'commit.c' and fill_commit_in_graph() in
'commit-graph.c', and after a quick look these functions seem to be
rather fundamenal in the life-cycle of a commit object.

I think they deserve to be explicitly exempted, too, and then we could
remove this last semantic patch altogether.



^ permalink raw reply	[flat|nested] 154+ messages in thread

* Re: [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates
  2019-04-11 20:51       ` SZEDER Gábor
@ 2019-04-11 20:58         ` SZEDER Gábor
  2019-04-12  0:17           ` SZEDER Gábor
  0 siblings, 1 reply; 154+ messages in thread
From: SZEDER Gábor @ 2019-04-11 20:58 UTC (permalink / raw)
  To: Johannes Schindelin
  Cc: Nguyễn Thái Ngọc Duy, git, gitster, stefanbeller,
	Derrick Stolee

On Thu, Apr 11, 2019 at 10:51:46PM +0200, SZEDER Gábor wrote:
> On Wed, Apr 10, 2019 at 10:56:52PM +0200, Johannes Schindelin wrote:
> > >         ...>}
> > >
> > >       @@
> > >     + expression c;
> > >     ++expression r;
> > >     + expression s;
> > >     + @@
> > >     +-- get_commit_tree(c) = s
> > >     ++- repo_get_commit_tree(r, c) = s
> > >     + + c->maybe_tree = s
> > 
> > I think this is wrong, and admittedly I had the very same version
> > originally.
> > 
> > When you have an arbitrary `r` in any `repo_get_commit_tree(r, c)` (as
> > opposed to `the_repository`), the conversion to `c->maybe_tree` is most
> > likely incorrect.
> > 
> > Therefore, I don't think that we can do that.
> 
> So, as far as I understand, the goal of these 'c->maybe_tree'-related
> semantic patches is to prevent "generic" parts of Git from accessing
> this field directly, as it might not be initialized in a
> commit-graph-enabled repository.
> 
> Only three functions are explicitly exempt, while this last semantic
> patch in question implicitly allows a few more that assign a value to
> 'c->maybe_tree'.  These functions are release_commit_memory() and
> parse_commit_buffer() in 'commit.c' and fill_commit_in_graph() in
> 'commit-graph.c', and after a quick look these functions seem to be
> rather fundamenal in the life-cycle of a commit object.

Erm, not "commit object"; I meant the life-cycle of a 'struct commit'
instance.

> I think they deserve to be explicitly exempted, too, and then we could
> remove this last semantic patch altogether.
> 
> 

^ permalink raw reply	[flat|nested] 154+ messages in thread

* Re: [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates
  2019-04-11 20:58         ` SZEDER Gábor
@ 2019-04-12  0:17           ` SZEDER Gábor
  2019-04-12 14:25             ` Johannes Schindelin
  0 siblings, 1 reply; 154+ messages in thread
From: SZEDER Gábor @ 2019-04-12  0:17 UTC (permalink / raw)
  To: Johannes Schindelin
  Cc: Nguyễn Thái Ngọc Duy, git, gitster, stefanbeller,
	Derrick Stolee

On Thu, Apr 11, 2019 at 10:58:57PM +0200, SZEDER Gábor wrote:
> On Thu, Apr 11, 2019 at 10:51:46PM +0200, SZEDER Gábor wrote:
> > On Wed, Apr 10, 2019 at 10:56:52PM +0200, Johannes Schindelin wrote:
> > > >         ...>}
> > > >
> > > >       @@
> > > >     + expression c;
> > > >     ++expression r;
> > > >     + expression s;
> > > >     + @@
> > > >     +-- get_commit_tree(c) = s
> > > >     ++- repo_get_commit_tree(r, c) = s
> > > >     + + c->maybe_tree = s
> > > 
> > > I think this is wrong, and admittedly I had the very same version
> > > originally.
> > > 
> > > When you have an arbitrary `r` in any `repo_get_commit_tree(r, c)` (as
> > > opposed to `the_repository`), the conversion to `c->maybe_tree` is most
> > > likely incorrect.
> > > 
> > > Therefore, I don't think that we can do that.
> > 
> > So, as far as I understand, the goal of these 'c->maybe_tree'-related
> > semantic patches is to prevent "generic" parts of Git from accessing
> > this field directly, as it might not be initialized in a
> > commit-graph-enabled repository.
> > 
> > Only three functions are explicitly exempt, while this last semantic
> > patch in question implicitly allows a few more that assign a value to
> > 'c->maybe_tree'.  These functions are release_commit_memory() and
> > parse_commit_buffer() in 'commit.c' and fill_commit_in_graph() in
> > 'commit-graph.c', 

... and make_virtual_commit() in 'merge-recursive.c'.

> and after a quick look these functions seem to be
> > rather fundamenal in the life-cycle of a commit object.
> 
> Erm, not "commit object"; I meant the life-cycle of a 'struct commit'
> instance.
> 
> > I think they deserve to be explicitly exempted, too, and then we could
> > remove this last semantic patch altogether.

And it would look like this.  Yeah, that's a very long line there, but
I don't think we can break it up.

  -- >8 --

diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
index 57c8f71479..fe814f313e 100644
--- a/contrib/coccinelle/commit.cocci
+++ b/contrib/coccinelle/commit.cocci
@@ -10,20 +10,15 @@ expression c;
 - c->maybe_tree->object.oid.hash
 + get_commit_tree_oid(c)->hash
 
-// These excluded functions must access c->maybe_tree direcly.
+// These excluded functions must access/modify c->maybe_tree direcly.
+// Note that if c->maybe_tree is written somewhere outside of these
+// functions, then the recommended transformation will be bogus with
+// repo_get_commit_tree() on the LHS.
 @@
-identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
-expression c;
+identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|fill_commit_in_graph|parse_commit_buffer|release_commit_memory|make_virtual_commit)$";
+struct commit *c;
 @@
   f(...) {<...
 - c->maybe_tree
 + repo_get_commit_tree(the_repository, c)
   ...>}
-
-@@
-expression c;
-expression r;
-expression s;
-@@
-- repo_get_commit_tree(r, c) = s
-+ c->maybe_tree = s

^ permalink raw reply related	[flat|nested] 154+ messages in thread

* Re: [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates
  2019-04-12  0:17           ` SZEDER Gábor
@ 2019-04-12 14:25             ` Johannes Schindelin
  2019-04-13 10:16               ` [PATCH v3* 11/33] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
  2019-04-13 12:14               ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates SZEDER Gábor
  0 siblings, 2 replies; 154+ messages in thread
From: Johannes Schindelin @ 2019-04-12 14:25 UTC (permalink / raw)
  To: SZEDER Gábor
  Cc: Nguyễn Thái Ngọc Duy, git, gitster, stefanbeller,
	Derrick Stolee

[-- Attachment #1: Type: text/plain, Size: 3490 bytes --]

Hi,

On Fri, 12 Apr 2019, SZEDER Gábor wrote:

> On Thu, Apr 11, 2019 at 10:58:57PM +0200, SZEDER Gábor wrote:
> > On Thu, Apr 11, 2019 at 10:51:46PM +0200, SZEDER Gábor wrote:
> > > On Wed, Apr 10, 2019 at 10:56:52PM +0200, Johannes Schindelin wrote:
> > > > >         ...>}
> > > > >
> > > > >       @@
> > > > >     + expression c;
> > > > >     ++expression r;
> > > > >     + expression s;
> > > > >     + @@
> > > > >     +-- get_commit_tree(c) = s
> > > > >     ++- repo_get_commit_tree(r, c) = s
> > > > >     + + c->maybe_tree = s
> > > >
> > > > I think this is wrong, and admittedly I had the very same version
> > > > originally.
> > > >
> > > > When you have an arbitrary `r` in any `repo_get_commit_tree(r, c)` (as
> > > > opposed to `the_repository`), the conversion to `c->maybe_tree` is most
> > > > likely incorrect.
> > > >
> > > > Therefore, I don't think that we can do that.
> > >
> > > So, as far as I understand, the goal of these 'c->maybe_tree'-related
> > > semantic patches is to prevent "generic" parts of Git from accessing
> > > this field directly, as it might not be initialized in a
> > > commit-graph-enabled repository.
> > >
> > > Only three functions are explicitly exempt, while this last semantic
> > > patch in question implicitly allows a few more that assign a value to
> > > 'c->maybe_tree'.  These functions are release_commit_memory() and
> > > parse_commit_buffer() in 'commit.c' and fill_commit_in_graph() in
> > > 'commit-graph.c',
>
> ... and make_virtual_commit() in 'merge-recursive.c'.
>
> > and after a quick look these functions seem to be
> > > rather fundamenal in the life-cycle of a commit object.
> >
> > Erm, not "commit object"; I meant the life-cycle of a 'struct commit'
> > instance.
> >
> > > I think they deserve to be explicitly exempted, too, and then we could
> > > remove this last semantic patch altogether.
>
> And it would look like this.  Yeah, that's a very long line there, but
> I don't think we can break it up.
>
>   -- >8 --
>
> diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
> index 57c8f71479..fe814f313e 100644
> --- a/contrib/coccinelle/commit.cocci
> +++ b/contrib/coccinelle/commit.cocci
> @@ -10,20 +10,15 @@ expression c;
>  - c->maybe_tree->object.oid.hash
>  + get_commit_tree_oid(c)->hash
>
> -// These excluded functions must access c->maybe_tree direcly.
> +// These excluded functions must access/modify c->maybe_tree direcly.
> +// Note that if c->maybe_tree is written somewhere outside of these
> +// functions, then the recommended transformation will be bogus with
> +// repo_get_commit_tree() on the LHS.
>  @@
> -identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
> -expression c;
> +identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|fill_commit_in_graph|parse_commit_buffer|release_commit_memory|make_virtual_commit)$";

Hahahaha! That's *really* long.

And a good indicator that this should be hidden in a single helper
function (`set_commit_tree()`, file-local of course) that is exempted in
the cocci patch.

Ciao,
Dscho

> +struct commit *c;
>  @@
>    f(...) {<...
>  - c->maybe_tree
>  + repo_get_commit_tree(the_repository, c)
>    ...>}
> -
> -@@
> -expression c;
> -expression r;
> -expression s;
> -@@
> -- repo_get_commit_tree(r, c) = s
> -+ c->maybe_tree = s
>

^ permalink raw reply	[flat|nested] 154+ messages in thread

* [PATCH v3* 11/33] commit.c: add repo_get_commit_tree()
  2019-04-12 14:25             ` Johannes Schindelin
@ 2019-04-13 10:16               ` Nguyễn Thái Ngọc Duy
  2019-04-13 12:22                 ` SZEDER Gábor
  2019-04-15 13:20                 ` Johannes Schindelin
  2019-04-13 12:14               ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates SZEDER Gábor
  1 sibling, 2 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-13 10:16 UTC (permalink / raw)
  To: johannes.schindelin
  Cc: dstolee, git, gitster, pclouds, stefanbeller, szeder.dev,
	Johannes Schindelin

Remove the implicit dependency on the_repository in this function.
It will be used in sha1-name.c functions when they are updated to take
any 'struct repository'. get_commit_tree() remains as a compat wrapper,
to be slowly replaced later.

set_commit_tree() is added just to simplify the filtering in
commit.cocci.

Any access to "maybe_tree" field directly will result in _broken_ code
after running through commit.cocci because we can't know what is the
right repository to use.

the_repository would be correct most of the time. But we're relying less
and less on the_repository and that assumption may no longer be
true. The transformation now is more of a poor man replacement for a C++
compiler catching access to private fields.

Helped-by: SZEDER Gábor <szeder.dev@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 OK how about this? set_commit_tree() is added to keeps that long line
 in commit.cocci down. I also make commit.cocci generate invalid
 repo_get_commit_tree() code this time.

 commit-graph.c                  |  2 +-
 commit.c                        |  9 +++++----
 commit.h                        | 10 ++++++++--
 contrib/coccinelle/commit.cocci | 14 +++++---------
 merge-recursive.c               |  2 +-
 5 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/commit-graph.c b/commit-graph.c
index 47e9be0a3a..dcab53cda5 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -356,7 +356,7 @@ static int fill_commit_in_graph(struct repository *r,
 	item->object.parsed = 1;
 	item->graph_pos = pos;
 
-	item->maybe_tree = NULL;
+	set_commit_tree(item, NULL);
 
 	date_high = get_be32(commit_data + g->hash_len + 8) & 0x3;
 	date_low = get_be32(commit_data + g->hash_len + 12);
diff --git a/commit.c b/commit.c
index a5333c7ac6..d852bf60c1 100644
--- a/commit.c
+++ b/commit.c
@@ -340,7 +340,8 @@ void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)
 	}
 }
 
-struct tree *get_commit_tree(const struct commit *commit)
+struct tree *repo_get_commit_tree(struct repository *r,
+				  const struct commit *commit)
 {
 	if (commit->maybe_tree || !commit->object.parsed)
 		return commit->maybe_tree;
@@ -348,7 +349,7 @@ struct tree *get_commit_tree(const struct commit *commit)
 	if (commit->graph_pos == COMMIT_NOT_FROM_GRAPH)
 		BUG("commit has NULL tree, but was not loaded from commit-graph");
 
-	return get_commit_tree_in_graph(the_repository, commit);
+	return get_commit_tree_in_graph(r, commit);
 }
 
 struct object_id *get_commit_tree_oid(const struct commit *commit)
@@ -358,7 +359,7 @@ struct object_id *get_commit_tree_oid(const struct commit *commit)
 
 void release_commit_memory(struct parsed_object_pool *pool, struct commit *c)
 {
-	c->maybe_tree = NULL;
+	set_commit_tree(c, NULL);
 	c->index = 0;
 	free_commit_buffer(pool, c);
 	free_commit_list(c->parents);
@@ -406,7 +407,7 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b
 	if (get_oid_hex(bufptr + 5, &parent) < 0)
 		return error("bad tree pointer in commit %s",
 			     oid_to_hex(&item->object.oid));
-	item->maybe_tree = lookup_tree(r, &parent);
+	set_commit_tree(item, lookup_tree(r, &parent));
 	bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
 	pptr = &item->parents;
 
diff --git a/commit.h b/commit.h
index 42728c2906..7342727e46 100644
--- a/commit.h
+++ b/commit.h
@@ -32,7 +32,7 @@ struct commit {
 
 	/*
 	 * If the commit is loaded from the commit-graph file, then this
-	 * member may be NULL. Only access it through get_commit_tree()
+	 * member may be NULL. Only access it through repo_get_commit_tree()
 	 * or get_commit_tree_oid().
 	 */
 	struct tree *maybe_tree;
@@ -143,9 +143,15 @@ void repo_unuse_commit_buffer(struct repository *r,
  */
 void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);
 
-struct tree *get_commit_tree(const struct commit *);
+struct tree *repo_get_commit_tree(struct repository *, const struct commit *);
+#define get_commit_tree(c) repo_get_commit_tree(the_repository, c)
 struct object_id *get_commit_tree_oid(const struct commit *);
 
+static inline void set_commit_tree(struct commit *c, struct tree *t)
+{
+	c->maybe_tree = t;
+}
+
 /*
  * Release memory related to a commit, including the parent list and
  * any cached object buffer.
diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
index c49aa558f0..ee1dc29234 100644
--- a/contrib/coccinelle/commit.cocci
+++ b/contrib/coccinelle/commit.cocci
@@ -11,18 +11,14 @@ expression c;
 + get_commit_tree_oid(c)->hash
 
 // These excluded functions must access c->maybe_tree direcly.
+// Note that if c->maybe_tree is written somewhere outside of these
+// functions, then the recommended transformation will be bogus with
+// repo_get_commit_tree() on the LHS.
 @@
-identifier f !~ "^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
+identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|set_commit_tree)$";
 expression c;
 @@
   f(...) {<...
 - c->maybe_tree
-+ get_commit_tree(c)
++ repo_get_commit_tree(specify_the_right_repo_here, c)
   ...>}
-
-@@
-expression c;
-expression s;
-@@
-- get_commit_tree(c) = s
-+ c->maybe_tree = s
diff --git a/merge-recursive.c b/merge-recursive.c
index 6c40c61c47..048fea71a0 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -170,7 +170,7 @@ static struct commit *make_virtual_commit(struct repository *repo,
 	struct commit *commit = alloc_commit_node(repo);
 
 	set_merge_remote_desc(commit, comment, (struct object *)commit);
-	commit->maybe_tree = tree;
+	set_commit_tree(commit, tree);
 	commit->object.parsed = 1;
 	return commit;
 }
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* Re: [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates
  2019-04-12 14:25             ` Johannes Schindelin
  2019-04-13 10:16               ` [PATCH v3* 11/33] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
@ 2019-04-13 12:14               ` SZEDER Gábor
  2019-04-13 14:00                 ` Duy Nguyen
  1 sibling, 1 reply; 154+ messages in thread
From: SZEDER Gábor @ 2019-04-13 12:14 UTC (permalink / raw)
  To: Johannes Schindelin
  Cc: Nguyễn Thái Ngọc Duy, git, gitster, stefanbeller,
	Derrick Stolee

On Fri, Apr 12, 2019 at 04:25:08PM +0200, Johannes Schindelin wrote:
> Hi,
> 
> On Fri, 12 Apr 2019, SZEDER Gábor wrote:
> 
> > On Thu, Apr 11, 2019 at 10:58:57PM +0200, SZEDER Gábor wrote:
> > > On Thu, Apr 11, 2019 at 10:51:46PM +0200, SZEDER Gábor wrote:
> > > > On Wed, Apr 10, 2019 at 10:56:52PM +0200, Johannes Schindelin wrote:
> > > > > >         ...>}
> > > > > >
> > > > > >       @@
> > > > > >     + expression c;
> > > > > >     ++expression r;
> > > > > >     + expression s;
> > > > > >     + @@
> > > > > >     +-- get_commit_tree(c) = s
> > > > > >     ++- repo_get_commit_tree(r, c) = s
> > > > > >     + + c->maybe_tree = s
> > > > >
> > > > > I think this is wrong, and admittedly I had the very same version
> > > > > originally.
> > > > >
> > > > > When you have an arbitrary `r` in any `repo_get_commit_tree(r, c)` (as
> > > > > opposed to `the_repository`), the conversion to `c->maybe_tree` is most
> > > > > likely incorrect.
> > > > >
> > > > > Therefore, I don't think that we can do that.
> > > >
> > > > So, as far as I understand, the goal of these 'c->maybe_tree'-related
> > > > semantic patches is to prevent "generic" parts of Git from accessing
> > > > this field directly, as it might not be initialized in a
> > > > commit-graph-enabled repository.
> > > >
> > > > Only three functions are explicitly exempt, while this last semantic
> > > > patch in question implicitly allows a few more that assign a value to
> > > > 'c->maybe_tree'.  These functions are release_commit_memory() and
> > > > parse_commit_buffer() in 'commit.c' and fill_commit_in_graph() in
> > > > 'commit-graph.c',
> >
> > ... and make_virtual_commit() in 'merge-recursive.c'.
> >
> > > and after a quick look these functions seem to be
> > > > rather fundamenal in the life-cycle of a commit object.
> > >
> > > Erm, not "commit object"; I meant the life-cycle of a 'struct commit'
> > > instance.
> > >
> > > > I think they deserve to be explicitly exempted, too, and then we could
> > > > remove this last semantic patch altogether.
> >
> > And it would look like this.  Yeah, that's a very long line there, but
> > I don't think we can break it up.
> >
> >   -- >8 --
> >
> > diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
> > index 57c8f71479..fe814f313e 100644
> > --- a/contrib/coccinelle/commit.cocci
> > +++ b/contrib/coccinelle/commit.cocci
> > @@ -10,20 +10,15 @@ expression c;
> >  - c->maybe_tree->object.oid.hash
> >  + get_commit_tree_oid(c)->hash
> >
> > -// These excluded functions must access c->maybe_tree direcly.
> > +// These excluded functions must access/modify c->maybe_tree direcly.
> > +// Note that if c->maybe_tree is written somewhere outside of these
> > +// functions, then the recommended transformation will be bogus with
> > +// repo_get_commit_tree() on the LHS.
> >  @@
> > -identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
> > -expression c;
> > +identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|fill_commit_in_graph|parse_commit_buffer|release_commit_memory|make_virtual_commit)$";
> 
> Hahahaha! That's *really* long.
> 
> And a good indicator that this should be hidden in a single helper
> function (`set_commit_tree()`, file-local of course) that is exempted in
> the cocci patch.

Note that this is not only about line length, and consider the slight
differences between the three approaches:

  - Currently only direct read accesses to 'c->maybe_tree' outside of
    the listed functions are forbidden and transformed, but still any
    function can set this field directly (thanks to the last semantic
    patch in 'commit.cocci').

  - Encapsulating writes in set_commit_tree() and adding this function
    to that list would prevent other functions from setting
    'c->maybe_tree' directly, but still any function could set it
    indirectly by calling set_commit_tree().

  - With that loooong line only those few listed special functions
    would be able read or write 'c->maybe_tree'.

Does the additional restriction of the long line variant bring us
benefits?  Well, not sure.

The root tree of a commit is needed in many places, and in the past we
got used to it being always initialized in any 'struct commit'
instance.  However, with the commit graph that's not the case anymore,
and any read accesses to the uninitialized root tree object would have
bad consequences.  That's why there is get_commit_tree() helper
performing lazy-initialization, and the protection from direct reads
in the form of the semantic patch.

OTOH, apart from five functions, most parts of Git simply don't want
to create new 'struct commit' instances themselves, or, more
generally, set anything in a 'struct commit', so arguably there is not
that much danger to protect ourselves from.

Anyway, I just wanted to make sure that we fully understand the
implications, and I think any solution is an improvement that
eliminates the current "let's transform this code pattern, but then
quickly transform it back in some cases" back-and-forth.


> > +struct commit *c;
> >  @@
> >    f(...) {<...
> >  - c->maybe_tree
> >  + repo_get_commit_tree(the_repository, c)
> >    ...>}
> > -
> > -@@
> > -expression c;
> > -expression r;
> > -expression s;
> > -@@
> > -- repo_get_commit_tree(r, c) = s
> > -+ c->maybe_tree = s
> >


^ permalink raw reply	[flat|nested] 154+ messages in thread

* Re: [PATCH v3* 11/33] commit.c: add repo_get_commit_tree()
  2019-04-13 10:16               ` [PATCH v3* 11/33] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
@ 2019-04-13 12:22                 ` SZEDER Gábor
  2019-04-15 13:20                 ` Johannes Schindelin
  1 sibling, 0 replies; 154+ messages in thread
From: SZEDER Gábor @ 2019-04-13 12:22 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy
  Cc: johannes.schindelin, dstolee, git, gitster, stefanbeller

On Sat, Apr 13, 2019 at 05:16:00PM +0700, Nguyễn Thái Ngọc Duy wrote:
>  OK how about this? set_commit_tree() is added to keeps that long line
>  in commit.cocci down. I also make commit.cocci generate invalid
>  repo_get_commit_tree() code this time.

> diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
> index c49aa558f0..ee1dc29234 100644
> --- a/contrib/coccinelle/commit.cocci
> +++ b/contrib/coccinelle/commit.cocci
> @@ -11,18 +11,14 @@ expression c;
>  + get_commit_tree_oid(c)->hash
>  
>  // These excluded functions must access c->maybe_tree direcly.
> +// Note that if c->maybe_tree is written somewhere outside of these
> +// functions, then the recommended transformation will be bogus with
> +// repo_get_commit_tree() on the LHS.

We could prevent transformations putting repo_get_commit_tree() on the
LHS by inserting the semantic patch:

  @@
  identifier f !~ "^set_commit_tree$";
  expression c;
  expression s;
  @@
    f(...) {<...
  - c->maybe_tree = s
  + set_commit_tree(c, s)
    ...>}

before this one.


>  @@
> -identifier f !~ "^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
> +identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|set_commit_tree)$";
>  expression c;
>  @@
>    f(...) {<...
>  - c->maybe_tree
> -+ get_commit_tree(c)
> ++ repo_get_commit_tree(specify_the_right_repo_here, c)
>    ...>}
> -
> -@@
> -expression c;
> -expression s;
> -@@
> -- get_commit_tree(c) = s
> -+ c->maybe_tree = s

^ permalink raw reply	[flat|nested] 154+ messages in thread

* Re: [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates
  2019-04-13 12:14               ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates SZEDER Gábor
@ 2019-04-13 14:00                 ` Duy Nguyen
  0 siblings, 0 replies; 154+ messages in thread
From: Duy Nguyen @ 2019-04-13 14:00 UTC (permalink / raw)
  To: SZEDER Gábor
  Cc: Johannes Schindelin, Git Mailing List, Junio C Hamano,
	Stefan Beller, Derrick Stolee

On Sat, Apr 13, 2019 at 7:14 PM SZEDER Gábor <szeder.dev@gmail.com> wrote:
>
> On Fri, Apr 12, 2019 at 04:25:08PM +0200, Johannes Schindelin wrote:
> > Hi,
> >
> > On Fri, 12 Apr 2019, SZEDER Gábor wrote:
> >
> > > On Thu, Apr 11, 2019 at 10:58:57PM +0200, SZEDER Gábor wrote:
> > > > On Thu, Apr 11, 2019 at 10:51:46PM +0200, SZEDER Gábor wrote:
> > > > > On Wed, Apr 10, 2019 at 10:56:52PM +0200, Johannes Schindelin wrote:
> > > > > > >         ...>}
> > > > > > >
> > > > > > >       @@
> > > > > > >     + expression c;
> > > > > > >     ++expression r;
> > > > > > >     + expression s;
> > > > > > >     + @@
> > > > > > >     +-- get_commit_tree(c) = s
> > > > > > >     ++- repo_get_commit_tree(r, c) = s
> > > > > > >     + + c->maybe_tree = s
> > > > > >
> > > > > > I think this is wrong, and admittedly I had the very same version
> > > > > > originally.
> > > > > >
> > > > > > When you have an arbitrary `r` in any `repo_get_commit_tree(r, c)` (as
> > > > > > opposed to `the_repository`), the conversion to `c->maybe_tree` is most
> > > > > > likely incorrect.
> > > > > >
> > > > > > Therefore, I don't think that we can do that.
> > > > >
> > > > > So, as far as I understand, the goal of these 'c->maybe_tree'-related
> > > > > semantic patches is to prevent "generic" parts of Git from accessing
> > > > > this field directly, as it might not be initialized in a
> > > > > commit-graph-enabled repository.
> > > > >
> > > > > Only three functions are explicitly exempt, while this last semantic
> > > > > patch in question implicitly allows a few more that assign a value to
> > > > > 'c->maybe_tree'.  These functions are release_commit_memory() and
> > > > > parse_commit_buffer() in 'commit.c' and fill_commit_in_graph() in
> > > > > 'commit-graph.c',
> > >
> > > ... and make_virtual_commit() in 'merge-recursive.c'.
> > >
> > > > and after a quick look these functions seem to be
> > > > > rather fundamenal in the life-cycle of a commit object.
> > > >
> > > > Erm, not "commit object"; I meant the life-cycle of a 'struct commit'
> > > > instance.
> > > >
> > > > > I think they deserve to be explicitly exempted, too, and then we could
> > > > > remove this last semantic patch altogether.
> > >
> > > And it would look like this.  Yeah, that's a very long line there, but
> > > I don't think we can break it up.
> > >
> > >   -- >8 --
> > >
> > > diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
> > > index 57c8f71479..fe814f313e 100644
> > > --- a/contrib/coccinelle/commit.cocci
> > > +++ b/contrib/coccinelle/commit.cocci
> > > @@ -10,20 +10,15 @@ expression c;
> > >  - c->maybe_tree->object.oid.hash
> > >  + get_commit_tree_oid(c)->hash
> > >
> > > -// These excluded functions must access c->maybe_tree direcly.
> > > +// These excluded functions must access/modify c->maybe_tree direcly.
> > > +// Note that if c->maybe_tree is written somewhere outside of these
> > > +// functions, then the recommended transformation will be bogus with
> > > +// repo_get_commit_tree() on the LHS.
> > >  @@
> > > -identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
> > > -expression c;
> > > +identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|fill_commit_in_graph|parse_commit_buffer|release_commit_memory|make_virtual_commit)$";
> >
> > Hahahaha! That's *really* long.
> >
> > And a good indicator that this should be hidden in a single helper
> > function (`set_commit_tree()`, file-local of course) that is exempted in
> > the cocci patch.
>
> Note that this is not only about line length, and consider the slight
> differences between the three approaches:
>
>   - Currently only direct read accesses to 'c->maybe_tree' outside of
>     the listed functions are forbidden and transformed, but still any
>     function can set this field directly (thanks to the last semantic
>     patch in 'commit.cocci').
>
>   - Encapsulating writes in set_commit_tree() and adding this function
>     to that list would prevent other functions from setting
>     'c->maybe_tree' directly, but still any function could set it
>     indirectly by calling set_commit_tree().
>
>   - With that loooong line only those few listed special functions
>     would be able read or write 'c->maybe_tree'.
>
> Does the additional restriction of the long line variant bring us
> benefits?  Well, not sure.
>
> The root tree of a commit is needed in many places, and in the past we
> got used to it being always initialized in any 'struct commit'
> instance.  However, with the commit graph that's not the case anymore,
> and any read accesses to the uninitialized root tree object would have
> bad consequences.  That's why there is get_commit_tree() helper
> performing lazy-initialization, and the protection from direct reads
> in the form of the semantic patch.

And I think set_commit_tree() is a good way to go. Basically
"maybe_tree" is not safe to be manipulated directly because of traps
and pitfalls. If we have one entry point to update maybe_tree, we can
handle all that in one place (even though I don't foresee any special
handling when updating it). Keeping commit.cocci shorter is just a
side bonus.
-- 
Duy

^ permalink raw reply	[flat|nested] 154+ messages in thread

* Re: [PATCH v3* 11/33] commit.c: add repo_get_commit_tree()
  2019-04-13 10:16               ` [PATCH v3* 11/33] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
  2019-04-13 12:22                 ` SZEDER Gábor
@ 2019-04-15 13:20                 ` Johannes Schindelin
  1 sibling, 0 replies; 154+ messages in thread
From: Johannes Schindelin @ 2019-04-15 13:20 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy
  Cc: dstolee, git, gitster, stefanbeller, szeder.dev

[-- Attachment #1: Type: text/plain, Size: 663 bytes --]

Hi Duy,

On Sat, 13 Apr 2019, Nguyễn Thái Ngọc Duy wrote:

> diff --git a/commit.h b/commit.h
> index 42728c2906..7342727e46 100644
> --- a/commit.h
> +++ b/commit.h
> @@ -143,9 +143,15 @@ void repo_unuse_commit_buffer(struct repository *r,
>  struct object_id *get_commit_tree_oid(const struct commit *);
>
> +static inline void set_commit_tree(struct commit *c, struct tree *t)
> +{
> +	c->maybe_tree = t;
> +}
> +
>  /*

I head *really* hoped that we could keep this function file-local, i.e.
`static` *inside* the relevant file(s). Kind of making this a "private" or
"protected" function, if you know what I mean.

Ciao,
Johannes

^ permalink raw reply	[flat|nested] 154+ messages in thread

* [PATCH v4 00/34] nd/sha1-name-c-wo-the-repository updates
  2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
                       ` (33 preceding siblings ...)
  2019-04-10 20:56     ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Johannes Schindelin
@ 2019-04-16  9:33     ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 01/34] builtin rebase: use FREE_AND_NULL Nguyễn Thái Ngọc Duy
                         ` (33 more replies)
  34 siblings, 34 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

v4 is all about updating commit.c and commit.cocci 11/33. I think I have
incorporated all changes from v3 discussion. The changes are separated
to a new patch 11/34 though, the old 11/33 is now 12/34.

Diff

diff --git a/commit-graph.c b/commit-graph.c
index 47e9be0a3a..155a270457 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -343,6 +343,11 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
 	item->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
 }
 
+static inline void set_commit_tree(struct commit *c, struct tree *t)
+{
+	c->maybe_tree = t;
+}
+
 static int fill_commit_in_graph(struct repository *r,
 				struct commit *item,
 				struct commit_graph *g, uint32_t pos)
@@ -356,7 +361,7 @@ static int fill_commit_in_graph(struct repository *r,
 	item->object.parsed = 1;
 	item->graph_pos = pos;
 
-	item->maybe_tree = NULL;
+	set_commit_tree(item, NULL);
 
 	date_high = get_be32(commit_data + g->hash_len + 8) & 0x3;
 	date_low = get_be32(commit_data + g->hash_len + 12);
@@ -442,7 +447,7 @@ static struct tree *load_tree_for_commit(struct repository *r,
 					   GRAPH_DATA_WIDTH * (c->graph_pos);
 
 	hashcpy(oid.hash, commit_data);
-	c->maybe_tree = lookup_tree(r, &oid);
+	set_commit_tree(c, lookup_tree(r, &oid));
 
 	return c->maybe_tree;
 }
diff --git a/commit.c b/commit.c
index f0a5506f04..a9e74647dc 100644
--- a/commit.c
+++ b/commit.c
@@ -340,6 +340,11 @@ void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)
 	}
 }
 
+static inline void set_commit_tree(struct commit *c, struct tree *t)
+{
+	c->maybe_tree = t;
+}
+
 struct tree *repo_get_commit_tree(struct repository *r,
 				  const struct commit *commit)
 {
@@ -359,7 +364,7 @@ struct object_id *get_commit_tree_oid(const struct commit *commit)
 
 void release_commit_memory(struct parsed_object_pool *pool, struct commit *c)
 {
-	c->maybe_tree = NULL;
+	set_commit_tree(c, NULL);
 	c->index = 0;
 	free_commit_buffer(pool, c);
 	free_commit_list(c->parents);
@@ -407,7 +412,7 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b
 	if (get_oid_hex(bufptr + 5, &parent) < 0)
 		return error("bad tree pointer in commit %s",
 			     oid_to_hex(&item->object.oid));
-	item->maybe_tree = lookup_tree(r, &parent);
+	set_commit_tree(item, lookup_tree(r, &parent));
 	bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
 	pptr = &item->parents;
 
diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
index 57c8f71479..d03453341e 100644
--- a/contrib/coccinelle/commit.cocci
+++ b/contrib/coccinelle/commit.cocci
@@ -10,20 +10,25 @@ expression c;
 - c->maybe_tree->object.oid.hash
 + get_commit_tree_oid(c)->hash
 
+@@
+identifier f !~ "^set_commit_tree$";
+expression c;
+expression s;
+@@
+  f(...) {<...
+- c->maybe_tree = s
++ set_commit_tree(c, s)
+  ...>}
+
 // These excluded functions must access c->maybe_tree direcly.
+// Note that if c->maybe_tree is written somewhere outside of these
+// functions, then the recommended transformation will be bogus with
+// repo_get_commit_tree() on the LHS.
 @@
-identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
+identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|set_commit_tree)$";
 expression c;
 @@
   f(...) {<...
 - c->maybe_tree
-+ repo_get_commit_tree(the_repository, c)
++ repo_get_commit_tree(specify_the_right_repo_here, c)
   ...>}
-
-@@
-expression c;
-expression r;
-expression s;
-@@
-- repo_get_commit_tree(r, c) = s
-+ c->maybe_tree = s
diff --git a/merge-recursive.c b/merge-recursive.c
index 6c40c61c47..ca4731a719 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -163,6 +163,11 @@ static struct tree *shift_tree_object(struct repository *repo,
 	return lookup_tree(repo, &shifted);
 }
 
+static inline void set_commit_tree(struct commit *c, struct tree *t)
+{
+	c->maybe_tree = t;
+}
+
 static struct commit *make_virtual_commit(struct repository *repo,
 					  struct tree *tree,
 					  const char *comment)
@@ -170,7 +175,7 @@ static struct commit *make_virtual_commit(struct repository *repo,
 	struct commit *commit = alloc_commit_node(repo);
 
 	set_merge_remote_desc(commit, comment, (struct object *)commit);
-	commit->maybe_tree = tree;
+	set_commit_tree(commit, tree);
 	commit->object.parsed = 1;
 	return commit;
 }
 

Nguyễn Thái Ngọc Duy (32):
  packfile.c: add repo_approximate_object_count()
  refs.c: add refs_ref_exists()
  refs.c: add refs_shorten_unambiguous_ref()
  refs.c: remove the_repo from substitute_branch_name()
  refs.c: remove the_repo from expand_ref()
  refs.c: add repo_dwim_ref()
  refs.c: add repo_dwim_log()
  refs.c: remove the_repo from read_ref_at()
  commit.cocci: refactor code, avoid double rewrite
  commit.c: add repo_get_commit_tree()
  sha1-name.c: remove the_repo from sort_ambiguous()
  sha1-name.c: remove the_repo from find_abbrev_len_packed()
  sha1-name.c: add repo_find_unique_abbrev_r()
  sha1-name.c: store and use repo in struct disambiguate_state
  sha1-name.c: add repo_for_each_abbrev()
  sha1-name.c: remove the_repo from get_short_oid()
  sha1-name.c: remove the_repo from interpret_nth_prior_checkout()
  sha1-name.c: remove the_repo from interpret_branch_mark()
  sha1-name.c: add repo_interpret_branch_name()
  sha1-name.c: remove the_repo from get_oid_oneline()
  sha1-name.c: remove the_repo from get_describe_name()
  sha1-name.c: remove the_repo from get_oid_basic()
  sha1-name.c: remove the_repo from get_oid_1()
  sha1-name.c: remove the_repo from handle_one_ref()
  sha1-name.c: remove the_repo from diagnose_invalid_index_path()
  sha1-name.c: remove the_repo from resolve_relative_path()
  sha1-name.c: remove the_repo from get_oid_with_context_1()
  sha1-name.c: add repo_get_oid()
  submodule-config.c: use repo_get_oid for reading .gitmodules
  sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name
  sha1-name.c: remove the_repo from other get_oid_*
  sha1-name.c: remove the_repo from get_oid_mb()

SZEDER Gábor (2):
  builtin rebase: use FREE_AND_NULL
  builtin rebase: use oideq()

 builtin/rebase.c                   |   5 +-
 builtin/show-branch.c              |   6 +-
 cache.h                            |  50 ++--
 commit-graph.c                     |   9 +-
 commit.c                           |  14 +-
 commit.h                           |   5 +-
 contrib/coccinelle/commit.cocci    |  20 +-
 dir.c                              |   8 +
 dir.h                              |   4 +-
 merge-recursive.c                  |   7 +-
 packfile.c                         |  14 +-
 packfile.h                         |   3 +-
 refs.c                             |  71 ++++--
 refs.h                             |   9 +-
 setup.c                            |   7 +-
 sha1-name.c                        | 388 ++++++++++++++++++-----------
 submodule-config.c                 |  20 +-
 t/t7814-grep-recurse-submodules.sh |   6 +-
 upload-pack.c                      |   2 +-
 19 files changed, 407 insertions(+), 241 deletions(-)

-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 01/34] builtin rebase: use FREE_AND_NULL
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 02/34] builtin rebase: use oideq() Nguyễn Thái Ngọc Duy
                         ` (32 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

From: SZEDER Gábor <szeder.dev@gmail.com>

Use the macro FREE_AND_NULL to release memory allocated for
'head_name' and clear its pointer.

Patch generated with 'contrib/coccinelle/free.cocci' and Coccinelle
v1.0.7 (previous Coccinelle versions don't notice this).

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/rebase.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/builtin/rebase.c b/builtin/rebase.c
index 77deebc65c..868bcd1446 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -1592,8 +1592,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 				branch_name = options.head_name;
 
 		} else {
-			free(options.head_name);
-			options.head_name = NULL;
+			FREE_AND_NULL(options.head_name);
 			branch_name = "HEAD";
 		}
 		if (get_oid("HEAD", &options.orig_head))
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 02/34] builtin rebase: use oideq()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 01/34] builtin rebase: use FREE_AND_NULL Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 03/34] packfile.c: add repo_approximate_object_count() Nguyễn Thái Ngọc Duy
                         ` (31 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

From: SZEDER Gábor <szeder.dev@gmail.com>

Use oideq() instead of !oidcmp(), as it is more idiomatic, and might
give the compiler more opportunities to optimize.

Patch generated with 'contrib/coccinelle/free.cocci' and Coccinelle
v1.0.7 (previous Coccinelle versions don't notice this).

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/rebase.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/rebase.c b/builtin/rebase.c
index 868bcd1446..c064909329 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -1792,7 +1792,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 	 * we just fast-forwarded.
 	 */
 	strbuf_reset(&msg);
-	if (!oidcmp(&merge_base, &options.orig_head)) {
+	if (oideq(&merge_base, &options.orig_head)) {
 		printf(_("Fast-forwarded %s to %s.\n"),
 			branch_name, options.onto_name);
 		strbuf_addf(&msg, "rebase finished: %s onto %s",
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 03/34] packfile.c: add repo_approximate_object_count()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 01/34] builtin rebase: use FREE_AND_NULL Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 02/34] builtin rebase: use oideq() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 04/34] refs.c: add refs_ref_exists() Nguyễn Thái Ngọc Duy
                         ` (30 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 packfile.c | 14 +++++++-------
 packfile.h |  3 ++-
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/packfile.c b/packfile.c
index 16bcb75262..2ad4fab2f8 100644
--- a/packfile.c
+++ b/packfile.c
@@ -893,25 +893,25 @@ static void prepare_packed_git(struct repository *r);
  * all unreachable objects about to be pruned, in which case they're not really
  * interesting as a measure of repo size in the first place.
  */
-unsigned long approximate_object_count(void)
+unsigned long repo_approximate_object_count(struct repository *r)
 {
-	if (!the_repository->objects->approximate_object_count_valid) {
+	if (!r->objects->approximate_object_count_valid) {
 		unsigned long count;
 		struct multi_pack_index *m;
 		struct packed_git *p;
 
-		prepare_packed_git(the_repository);
+		prepare_packed_git(r);
 		count = 0;
-		for (m = get_multi_pack_index(the_repository); m; m = m->next)
+		for (m = get_multi_pack_index(r); m; m = m->next)
 			count += m->num_objects;
-		for (p = the_repository->objects->packed_git; p; p = p->next) {
+		for (p = r->objects->packed_git; p; p = p->next) {
 			if (open_pack_index(p))
 				continue;
 			count += p->num_objects;
 		}
-		the_repository->objects->approximate_object_count = count;
+		r->objects->approximate_object_count = count;
 	}
-	return the_repository->objects->approximate_object_count;
+	return r->objects->approximate_object_count;
 }
 
 static void *get_next_packed_git(const void *p)
diff --git a/packfile.h b/packfile.h
index d70c6d9afb..f04440f984 100644
--- a/packfile.h
+++ b/packfile.h
@@ -57,7 +57,8 @@ struct packed_git *get_all_packs(struct repository *r);
  * Give a rough count of objects in the repository. This sacrifices accuracy
  * for speed.
  */
-unsigned long approximate_object_count(void);
+unsigned long repo_approximate_object_count(struct repository *r);
+#define approximate_object_count() repo_approximate_object_count(the_repository)
 
 extern struct packed_git *find_sha1_pack(const unsigned char *sha1,
 					 struct packed_git *packs);
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 04/34] refs.c: add refs_ref_exists()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (2 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 03/34] packfile.c: add repo_approximate_object_count() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 05/34] refs.c: add refs_shorten_unambiguous_ref() Nguyễn Thái Ngọc Duy
                         ` (29 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/refs.c b/refs.c
index 142888a40a..b869f32d8b 100644
--- a/refs.c
+++ b/refs.c
@@ -241,9 +241,14 @@ int read_ref(const char *refname, struct object_id *oid)
 	return read_ref_full(refname, RESOLVE_REF_READING, oid, NULL);
 }
 
+static int refs_ref_exists(struct ref_store *refs, const char *refname)
+{
+	return !!refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING, NULL, NULL);
+}
+
 int ref_exists(const char *refname)
 {
-	return !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, NULL, NULL);
+	return refs_ref_exists(get_main_ref_store(the_repository), refname);
 }
 
 static int match_ref_pattern(const char *refname,
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 05/34] refs.c: add refs_shorten_unambiguous_ref()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (3 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 04/34] refs.c: add refs_ref_exists() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 06/34] refs.c: remove the_repo from substitute_branch_name() Nguyễn Thái Ngọc Duy
                         ` (28 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c | 11 +++++++++--
 refs.h |  2 ++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/refs.c b/refs.c
index b869f32d8b..3dde824aab 100644
--- a/refs.c
+++ b/refs.c
@@ -1169,7 +1169,8 @@ int update_ref(const char *msg, const char *refname,
 			       old_oid, flags, onerr);
 }
 
-char *shorten_unambiguous_ref(const char *refname, int strict)
+char *refs_shorten_unambiguous_ref(struct ref_store *refs,
+				   const char *refname, int strict)
 {
 	int i;
 	static char **scanf_fmts;
@@ -1247,7 +1248,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
 			strbuf_reset(&resolved_buf);
 			strbuf_addf(&resolved_buf, rule,
 				    short_name_len, short_name);
-			if (ref_exists(resolved_buf.buf))
+			if (refs_ref_exists(refs, resolved_buf.buf))
 				break;
 		}
 
@@ -1266,6 +1267,12 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
 	return xstrdup(refname);
 }
 
+char *shorten_unambiguous_ref(const char *refname, int strict)
+{
+	return refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
+					    refname, strict);
+}
+
 static struct string_list *hide_refs;
 
 int parse_hide_refs_config(const char *var, const char *value, const char *section)
diff --git a/refs.h b/refs.h
index 308fa1f03b..5627570241 100644
--- a/refs.h
+++ b/refs.h
@@ -462,6 +462,8 @@ int check_refname_format(const char *refname, int flags);
 
 const char *prettify_refname(const char *refname);
 
+char *refs_shorten_unambiguous_ref(struct ref_store *refs,
+				   const char *refname, int strict);
 char *shorten_unambiguous_ref(const char *refname, int strict);
 
 /** rename ref, return 0 on success **/
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 06/34] refs.c: remove the_repo from substitute_branch_name()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (4 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 05/34] refs.c: add refs_shorten_unambiguous_ref() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 07/34] refs.c: remove the_repo from expand_ref() Nguyễn Thái Ngọc Duy
                         ` (27 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 8 ++++++--
 refs.c      | 9 +++++----
 sha1-name.c | 8 ++++++--
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/cache.h b/cache.h
index ac92421f3a..fcb24b5781 100644
--- a/cache.h
+++ b/cache.h
@@ -1468,8 +1468,12 @@ extern int parse_oid_hex(const char *hex, struct object_id *oid, const char **en
 #define INTERPRET_BRANCH_LOCAL (1<<0)
 #define INTERPRET_BRANCH_REMOTE (1<<1)
 #define INTERPRET_BRANCH_HEAD (1<<2)
-extern int interpret_branch_name(const char *str, int len, struct strbuf *,
-				 unsigned allowed);
+int repo_interpret_branch_name(struct repository *r,
+			       const char *str, int len,
+			       struct strbuf *buf,
+			       unsigned allowed);
+#define interpret_branch_name(str, len, buf, allowed) \
+	repo_interpret_branch_name(the_repository, str, len, buf, allowed)
 extern int get_oid_mb(const char *str, struct object_id *oid);
 
 extern int validate_headref(const char *ref);
diff --git a/refs.c b/refs.c
index 3dde824aab..44df049796 100644
--- a/refs.c
+++ b/refs.c
@@ -539,10 +539,11 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)
  * later free()ing) if the string passed in is a magic short-hand form
  * to name a branch.
  */
-static char *substitute_branch_name(const char **string, int *len)
+static char *substitute_branch_name(struct repository *r,
+				    const char **string, int *len)
 {
 	struct strbuf buf = STRBUF_INIT;
-	int ret = interpret_branch_name(*string, *len, &buf, 0);
+	int ret = repo_interpret_branch_name(r, *string, *len, &buf, 0);
 
 	if (ret == *len) {
 		size_t size;
@@ -556,7 +557,7 @@ static char *substitute_branch_name(const char **string, int *len)
 
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
 {
-	char *last_branch = substitute_branch_name(&str, &len);
+	char *last_branch = substitute_branch_name(the_repository, &str, &len);
 	int   refs_found  = expand_ref(str, len, oid, ref);
 	free(last_branch);
 	return refs_found;
@@ -596,7 +597,7 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
 
 int dwim_log(const char *str, int len, struct object_id *oid, char **log)
 {
-	char *last_branch = substitute_branch_name(&str, &len);
+	char *last_branch = substitute_branch_name(the_repository, &str, &len);
 	const char **p;
 	int logs_found = 0;
 	struct strbuf path = STRBUF_INIT;
diff --git a/sha1-name.c b/sha1-name.c
index 6dda2c16df..d535bb82f7 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1427,13 +1427,17 @@ static int interpret_branch_mark(const char *name, int namelen,
 	return len + at;
 }
 
-int interpret_branch_name(const char *name, int namelen, struct strbuf *buf,
-			  unsigned allowed)
+int repo_interpret_branch_name(struct repository *r,
+			       const char *name, int namelen,
+			       struct strbuf *buf,
+			       unsigned allowed)
 {
 	char *at;
 	const char *start;
 	int len;
 
+	if (r != the_repository)
+		BUG("interpret_branch_name() does not really use 'r' yet");
 	if (!namelen)
 		namelen = strlen(name);
 
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 07/34] refs.c: remove the_repo from expand_ref()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (5 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 06/34] refs.c: remove the_repo from substitute_branch_name() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 08/34] refs.c: add repo_dwim_ref() Nguyễn Thái Ngọc Duy
                         ` (26 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c        | 10 ++++++----
 refs.h        |  2 +-
 upload-pack.c |  2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/refs.c b/refs.c
index 44df049796..1f5864aa36 100644
--- a/refs.c
+++ b/refs.c
@@ -558,12 +558,13 @@ static char *substitute_branch_name(struct repository *r,
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
 {
 	char *last_branch = substitute_branch_name(the_repository, &str, &len);
-	int   refs_found  = expand_ref(str, len, oid, ref);
+	int   refs_found  = expand_ref(the_repository, str, len, oid, ref);
 	free(last_branch);
 	return refs_found;
 }
 
-int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
+int expand_ref(struct repository *repo, const char *str, int len,
+	       struct object_id *oid, char **ref)
 {
 	const char **p, *r;
 	int refs_found = 0;
@@ -578,8 +579,9 @@ int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
 		this_result = refs_found ? &oid_from_ref : oid;
 		strbuf_reset(&fullref);
 		strbuf_addf(&fullref, *p, len, str);
-		r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
-				       this_result, &flag);
+		r = refs_resolve_ref_unsafe(get_main_ref_store(repo),
+					    fullref.buf, RESOLVE_REF_READING,
+					    this_result, &flag);
 		if (r) {
 			if (!refs_found++)
 				*ref = xstrdup(r);
diff --git a/refs.h b/refs.h
index 5627570241..b630d5bde7 100644
--- a/refs.h
+++ b/refs.h
@@ -148,7 +148,7 @@ int refname_match(const char *abbrev_name, const char *full_name);
 struct argv_array;
 void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);
 
-int expand_ref(const char *str, int len, struct object_id *oid, char **ref);
+int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
 int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
 
diff --git a/upload-pack.c b/upload-pack.c
index d098ef5982..56505d60c3 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -834,7 +834,7 @@ static int process_deepen_not(const char *line, struct string_list *deepen_not,
 	if (skip_prefix(line, "deepen-not ", &arg)) {
 		char *ref = NULL;
 		struct object_id oid;
-		if (expand_ref(arg, strlen(arg), &oid, &ref) != 1)
+		if (expand_ref(the_repository, arg, strlen(arg), &oid, &ref) != 1)
 			die("git upload-pack: ambiguous deepen-not: %s", line);
 		string_list_append(deepen_not, ref);
 		free(ref);
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 08/34] refs.c: add repo_dwim_ref()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (6 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 07/34] refs.c: remove the_repo from expand_ref() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 09/34] refs.c: add repo_dwim_log() Nguyễn Thái Ngọc Duy
                         ` (25 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c | 12 +++++++++---
 refs.h |  1 +
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/refs.c b/refs.c
index 1f5864aa36..bd0fec5776 100644
--- a/refs.c
+++ b/refs.c
@@ -555,14 +555,20 @@ static char *substitute_branch_name(struct repository *r,
 	return NULL;
 }
 
-int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
+int repo_dwim_ref(struct repository *r, const char *str, int len,
+		  struct object_id *oid, char **ref)
 {
-	char *last_branch = substitute_branch_name(the_repository, &str, &len);
-	int   refs_found  = expand_ref(the_repository, str, len, oid, ref);
+	char *last_branch = substitute_branch_name(r, &str, &len);
+	int   refs_found  = expand_ref(r, str, len, oid, ref);
 	free(last_branch);
 	return refs_found;
 }
 
+int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
+{
+	return repo_dwim_ref(the_repository, str, len, oid, ref);
+}
+
 int expand_ref(struct repository *repo, const char *str, int len,
 	       struct object_id *oid, char **ref)
 {
diff --git a/refs.h b/refs.h
index b630d5bde7..fd3dc1d0f4 100644
--- a/refs.h
+++ b/refs.h
@@ -149,6 +149,7 @@ struct argv_array;
 void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);
 
 int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
+int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
 int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
 
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 09/34] refs.c: add repo_dwim_log()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (7 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 08/34] refs.c: add repo_dwim_ref() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 10/34] refs.c: remove the_repo from read_ref_at() Nguyễn Thái Ngọc Duy
                         ` (24 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 refs.c | 21 +++++++++++++++------
 refs.h |  1 +
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/refs.c b/refs.c
index bd0fec5776..edea001446 100644
--- a/refs.c
+++ b/refs.c
@@ -603,9 +603,11 @@ int expand_ref(struct repository *repo, const char *str, int len,
 	return refs_found;
 }
 
-int dwim_log(const char *str, int len, struct object_id *oid, char **log)
+int repo_dwim_log(struct repository *r, const char *str, int len,
+		  struct object_id *oid, char **log)
 {
-	char *last_branch = substitute_branch_name(the_repository, &str, &len);
+	struct ref_store *refs = get_main_ref_store(r);
+	char *last_branch = substitute_branch_name(r, &str, &len);
 	const char **p;
 	int logs_found = 0;
 	struct strbuf path = STRBUF_INIT;
@@ -617,13 +619,15 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
 
 		strbuf_reset(&path);
 		strbuf_addf(&path, *p, len, str);
-		ref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,
-					 &hash, NULL);
+		ref = refs_resolve_ref_unsafe(refs, path.buf,
+					      RESOLVE_REF_READING,
+					      &hash, NULL);
 		if (!ref)
 			continue;
-		if (reflog_exists(path.buf))
+		if (refs_reflog_exists(refs, path.buf))
 			it = path.buf;
-		else if (strcmp(ref, path.buf) && reflog_exists(ref))
+		else if (strcmp(ref, path.buf) &&
+			 refs_reflog_exists(refs, ref))
 			it = ref;
 		else
 			continue;
@@ -639,6 +643,11 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
 	return logs_found;
 }
 
+int dwim_log(const char *str, int len, struct object_id *oid, char **log)
+{
+	return repo_dwim_log(the_repository, str, len, oid, log);
+}
+
 static int is_per_worktree_ref(const char *refname)
 {
 	return !strcmp(refname, "HEAD") ||
diff --git a/refs.h b/refs.h
index fd3dc1d0f4..859dffe691 100644
--- a/refs.h
+++ b/refs.h
@@ -150,6 +150,7 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);
 
 int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
 int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
+int repo_dwim_log(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
 int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
 
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 10/34] refs.c: remove the_repo from read_ref_at()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (8 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 09/34] refs.c: add repo_dwim_log() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 11/34] commit.cocci: refactor code, avoid double rewrite Nguyễn Thái Ngọc Duy
                         ` (23 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/show-branch.c | 6 ++++--
 refs.c                | 7 ++++---
 refs.h                | 3 ++-
 sha1-name.c           | 3 ++-
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 934e514944..082daeac32 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -753,7 +753,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 				/* Ah, that is a date spec... */
 				timestamp_t at;
 				at = approxidate(reflog_base);
-				read_ref_at(ref, flags, at, -1, &oid, NULL,
+				read_ref_at(get_main_ref_store(the_repository),
+					    ref, flags, at, -1, &oid, NULL,
 					    NULL, NULL, &base);
 			}
 		}
@@ -765,7 +766,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 			timestamp_t timestamp;
 			int tz;
 
-			if (read_ref_at(ref, flags, 0, base + i, &oid, &logmsg,
+			if (read_ref_at(get_main_ref_store(the_repository),
+					ref, flags, 0, base + i, &oid, &logmsg,
 					&timestamp, &tz, NULL)) {
 				reflog = i;
 				break;
diff --git a/refs.c b/refs.c
index edea001446..92d1f6dbdd 100644
--- a/refs.c
+++ b/refs.c
@@ -967,7 +967,8 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid
 	return 1;
 }
 
-int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, int cnt,
+int read_ref_at(struct ref_store *refs, const char *refname,
+		unsigned int flags, timestamp_t at_time, int cnt,
 		struct object_id *oid, char **msg,
 		timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt)
 {
@@ -983,7 +984,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in
 	cb.cutoff_cnt = cutoff_cnt;
 	cb.oid = oid;
 
-	for_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);
+	refs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent, &cb);
 
 	if (!cb.reccnt) {
 		if (flags & GET_OID_QUIETLY)
@@ -994,7 +995,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in
 	if (cb.found_it)
 		return 0;
 
-	for_each_reflog_ent(refname, read_ref_at_ent_oldest, &cb);
+	refs_for_each_reflog_ent(refs, refname, read_ref_at_ent_oldest, &cb);
 
 	return 1;
 }
diff --git a/refs.h b/refs.h
index 859dffe691..8f9cbf8a93 100644
--- a/refs.h
+++ b/refs.h
@@ -388,7 +388,8 @@ int refs_create_reflog(struct ref_store *refs, const char *refname,
 int safe_create_reflog(const char *refname, int force_create, struct strbuf *err);
 
 /** Reads log for the value of ref during at_time. **/
-int read_ref_at(const char *refname, unsigned int flags,
+int read_ref_at(struct ref_store *refs,
+		const char *refname, unsigned int flags,
 		timestamp_t at_time, int cnt,
 		struct object_id *oid, char **msg,
 		timestamp_t *cutoff_time, int *cutoff_tz, int *cutoff_cnt);
diff --git a/sha1-name.c b/sha1-name.c
index d535bb82f7..15a1107998 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -849,7 +849,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 				return -1;
 			}
 		}
-		if (read_ref_at(real_ref, flags, at_time, nth, oid, NULL,
+		if (read_ref_at(get_main_ref_store(the_repository),
+				real_ref, flags, at_time, nth, oid, NULL,
 				&co_time, &co_tz, &co_cnt)) {
 			if (!len) {
 				if (starts_with(real_ref, "refs/heads/")) {
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 11/34] commit.cocci: refactor code, avoid double rewrite
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (9 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 10/34] refs.c: remove the_repo from read_ref_at() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 12/34] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
                         ` (22 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

"maybe" pointer in 'struct commit' is tricky because it can be lazily
initialized to take advantage of commit-graph if available. This makes
it not safe to access directly.

This leads to a rule in commit.cocci to rewrite 'x->maybe_tree' to
'get_commit_tree(x)'. But that rule alone could lead to incorrectly
rewrite assignments, e.g. from

    x->maybe_tree = yes

to

    get_commit_tree(x) = yes

Because of this we have a second rule to revert this effect. Szeder
found out that we could do better by performing the assignment rewrite
rule first, then the remaining is read-only access and handled by the
current first rule.

For this to work, we need to transform "x->maybe_tree = y" to something
that does NOT contain "x->maybe_tree" to avoid the original first
rule. This is where set_commit_tree() comes in.

Helped-by: SZEDER Gábor <szeder.dev@gmail.com>
Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 commit-graph.c                  |  9 +++++++--
 commit.c                        |  9 +++++++--
 contrib/coccinelle/commit.cocci | 20 +++++++++++++-------
 merge-recursive.c               |  7 ++++++-
 4 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/commit-graph.c b/commit-graph.c
index 47e9be0a3a..155a270457 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -343,6 +343,11 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
 	item->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
 }
 
+static inline void set_commit_tree(struct commit *c, struct tree *t)
+{
+	c->maybe_tree = t;
+}
+
 static int fill_commit_in_graph(struct repository *r,
 				struct commit *item,
 				struct commit_graph *g, uint32_t pos)
@@ -356,7 +361,7 @@ static int fill_commit_in_graph(struct repository *r,
 	item->object.parsed = 1;
 	item->graph_pos = pos;
 
-	item->maybe_tree = NULL;
+	set_commit_tree(item, NULL);
 
 	date_high = get_be32(commit_data + g->hash_len + 8) & 0x3;
 	date_low = get_be32(commit_data + g->hash_len + 12);
@@ -442,7 +447,7 @@ static struct tree *load_tree_for_commit(struct repository *r,
 					   GRAPH_DATA_WIDTH * (c->graph_pos);
 
 	hashcpy(oid.hash, commit_data);
-	c->maybe_tree = lookup_tree(r, &oid);
+	set_commit_tree(c, lookup_tree(r, &oid));
 
 	return c->maybe_tree;
 }
diff --git a/commit.c b/commit.c
index a5333c7ac6..043ba64f17 100644
--- a/commit.c
+++ b/commit.c
@@ -340,6 +340,11 @@ void free_commit_buffer(struct parsed_object_pool *pool, struct commit *commit)
 	}
 }
 
+static inline void set_commit_tree(struct commit *c, struct tree *t)
+{
+	c->maybe_tree = t;
+}
+
 struct tree *get_commit_tree(const struct commit *commit)
 {
 	if (commit->maybe_tree || !commit->object.parsed)
@@ -358,7 +363,7 @@ struct object_id *get_commit_tree_oid(const struct commit *commit)
 
 void release_commit_memory(struct parsed_object_pool *pool, struct commit *c)
 {
-	c->maybe_tree = NULL;
+	set_commit_tree(c, NULL);
 	c->index = 0;
 	free_commit_buffer(pool, c);
 	free_commit_list(c->parents);
@@ -406,7 +411,7 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b
 	if (get_oid_hex(bufptr + 5, &parent) < 0)
 		return error("bad tree pointer in commit %s",
 			     oid_to_hex(&item->object.oid));
-	item->maybe_tree = lookup_tree(r, &parent);
+	set_commit_tree(item, lookup_tree(r, &parent));
 	bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
 	pptr = &item->parents;
 
diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
index c49aa558f0..663658a127 100644
--- a/contrib/coccinelle/commit.cocci
+++ b/contrib/coccinelle/commit.cocci
@@ -10,19 +10,25 @@ expression c;
 - c->maybe_tree->object.oid.hash
 + get_commit_tree_oid(c)->hash
 
-// These excluded functions must access c->maybe_tree direcly.
 @@
-identifier f !~ "^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit)$";
+identifier f !~ "^set_commit_tree$";
 expression c;
+expression s;
 @@
   f(...) {<...
-- c->maybe_tree
-+ get_commit_tree(c)
+- c->maybe_tree = s
++ set_commit_tree(c, s)
   ...>}
 
+// These excluded functions must access c->maybe_tree direcly.
+// Note that if c->maybe_tree is written somewhere outside of these
+// functions, then the recommended transformation will be bogus with
+// get_commit_tree() on the LHS.
 @@
+identifier f !~ "^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|set_commit_tree)$";
 expression c;
-expression s;
 @@
-- get_commit_tree(c) = s
-+ c->maybe_tree = s
+  f(...) {<...
+- c->maybe_tree
++ get_commit_tree(c)
+  ...>}
diff --git a/merge-recursive.c b/merge-recursive.c
index 6c40c61c47..ca4731a719 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -163,6 +163,11 @@ static struct tree *shift_tree_object(struct repository *repo,
 	return lookup_tree(repo, &shifted);
 }
 
+static inline void set_commit_tree(struct commit *c, struct tree *t)
+{
+	c->maybe_tree = t;
+}
+
 static struct commit *make_virtual_commit(struct repository *repo,
 					  struct tree *tree,
 					  const char *comment)
@@ -170,7 +175,7 @@ static struct commit *make_virtual_commit(struct repository *repo,
 	struct commit *commit = alloc_commit_node(repo);
 
 	set_merge_remote_desc(commit, comment, (struct object *)commit);
-	commit->maybe_tree = tree;
+	set_commit_tree(commit, tree);
 	commit->object.parsed = 1;
 	return commit;
 }
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 12/34] commit.c: add repo_get_commit_tree()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (10 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 11/34] commit.cocci: refactor code, avoid double rewrite Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 13/34] sha1-name.c: remove the_repo from sort_ambiguous() Nguyễn Thái Ngọc Duy
                         ` (21 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Remove the implicit dependency on the_repository in this function.
It will be used in sha1-name.c functions when they are updated to take
any 'struct repository'. get_commit_tree() remains as a compat wrapper,
to be slowly replaced later.

Any access to "maybe_tree" field directly will result in _broken_ code
after running through commit.cocci because we can't know what is the
right repository to use.

the_repository would be correct most of the time. But we're relying less
and less on the_repository and that assumption may no longer be
true. The transformation now is more of a poor man replacement for a C++
compiler catching access to private fields.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 commit.c                        | 5 +++--
 commit.h                        | 5 +++--
 contrib/coccinelle/commit.cocci | 6 +++---
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/commit.c b/commit.c
index 043ba64f17..a9e74647dc 100644
--- a/commit.c
+++ b/commit.c
@@ -345,7 +345,8 @@ static inline void set_commit_tree(struct commit *c, struct tree *t)
 	c->maybe_tree = t;
 }
 
-struct tree *get_commit_tree(const struct commit *commit)
+struct tree *repo_get_commit_tree(struct repository *r,
+				  const struct commit *commit)
 {
 	if (commit->maybe_tree || !commit->object.parsed)
 		return commit->maybe_tree;
@@ -353,7 +354,7 @@ struct tree *get_commit_tree(const struct commit *commit)
 	if (commit->graph_pos == COMMIT_NOT_FROM_GRAPH)
 		BUG("commit has NULL tree, but was not loaded from commit-graph");
 
-	return get_commit_tree_in_graph(the_repository, commit);
+	return get_commit_tree_in_graph(r, commit);
 }
 
 struct object_id *get_commit_tree_oid(const struct commit *commit)
diff --git a/commit.h b/commit.h
index 42728c2906..f1aa4c0472 100644
--- a/commit.h
+++ b/commit.h
@@ -32,7 +32,7 @@ struct commit {
 
 	/*
 	 * If the commit is loaded from the commit-graph file, then this
-	 * member may be NULL. Only access it through get_commit_tree()
+	 * member may be NULL. Only access it through repo_get_commit_tree()
 	 * or get_commit_tree_oid().
 	 */
 	struct tree *maybe_tree;
@@ -143,7 +143,8 @@ void repo_unuse_commit_buffer(struct repository *r,
  */
 void free_commit_buffer(struct parsed_object_pool *pool, struct commit *);
 
-struct tree *get_commit_tree(const struct commit *);
+struct tree *repo_get_commit_tree(struct repository *, const struct commit *);
+#define get_commit_tree(c) repo_get_commit_tree(the_repository, c)
 struct object_id *get_commit_tree_oid(const struct commit *);
 
 /*
diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
index 663658a127..d03453341e 100644
--- a/contrib/coccinelle/commit.cocci
+++ b/contrib/coccinelle/commit.cocci
@@ -23,12 +23,12 @@ expression s;
 // These excluded functions must access c->maybe_tree direcly.
 // Note that if c->maybe_tree is written somewhere outside of these
 // functions, then the recommended transformation will be bogus with
-// get_commit_tree() on the LHS.
+// repo_get_commit_tree() on the LHS.
 @@
-identifier f !~ "^(get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|set_commit_tree)$";
+identifier f !~ "^(repo_get_commit_tree|get_commit_tree_in_graph_one|load_tree_for_commit|set_commit_tree)$";
 expression c;
 @@
   f(...) {<...
 - c->maybe_tree
-+ get_commit_tree(c)
++ repo_get_commit_tree(specify_the_right_repo_here, c)
   ...>}
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 13/34] sha1-name.c: remove the_repo from sort_ambiguous()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (11 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 12/34] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 14/34] sha1-name.c: remove the_repo from find_abbrev_len_packed() Nguyễn Thái Ngọc Duy
                         ` (20 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 15a1107998..7558ce51a3 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -383,10 +383,11 @@ static int collect_ambiguous(const struct object_id *oid, void *data)
 	return 0;
 }
 
+static struct repository *sort_ambiguous_repo;
 static int sort_ambiguous(const void *a, const void *b)
 {
-	int a_type = oid_object_info(the_repository, a, NULL);
-	int b_type = oid_object_info(the_repository, b, NULL);
+	int a_type = oid_object_info(sort_ambiguous_repo, a, NULL);
+	int b_type = oid_object_info(sort_ambiguous_repo, b, NULL);
 	int a_type_sort;
 	int b_type_sort;
 
@@ -411,6 +412,14 @@ static int sort_ambiguous(const void *a, const void *b)
 	return a_type_sort > b_type_sort ? 1 : -1;
 }
 
+static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)
+{
+	/* mutex will be needed if this code is to be made thread safe */
+	sort_ambiguous_repo = r;
+	QSORT(a->oid, a->nr, sort_ambiguous);
+	sort_ambiguous_repo = NULL;
+}
+
 static enum get_oid_result get_short_oid(const char *name, int len,
 					 struct object_id *oid,
 					 unsigned flags)
@@ -458,7 +467,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 
 		advise(_("The candidates are:"));
 		for_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect);
-		QSORT(collect.oid, collect.nr, sort_ambiguous);
+		sort_ambiguous_oid_array(the_repository, &collect);
 
 		if (oid_array_for_each(&collect, show_ambiguous_object, &ds))
 			BUG("show_ambiguous_object shouldn't return non-zero");
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 14/34] sha1-name.c: remove the_repo from find_abbrev_len_packed()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (12 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 13/34] sha1-name.c: remove the_repo from sort_ambiguous() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 15/34] sha1-name.c: add repo_find_unique_abbrev_r() Nguyễn Thái Ngọc Duy
                         ` (19 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 7558ce51a3..b9381aaba6 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -514,6 +514,7 @@ struct min_abbrev_data {
 	unsigned int init_len;
 	unsigned int cur_len;
 	char *hex;
+	struct repository *repo;
 	const struct object_id *oid;
 };
 
@@ -619,9 +620,9 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
 	struct multi_pack_index *m;
 	struct packed_git *p;
 
-	for (m = get_multi_pack_index(the_repository); m; m = m->next)
+	for (m = get_multi_pack_index(mad->repo); m; m = m->next)
 		find_abbrev_len_for_midx(m, mad);
-	for (p = get_packed_git(the_repository); p; p = p->next)
+	for (p = get_packed_git(mad->repo); p; p = p->next)
 		find_abbrev_len_for_pack(p, mad);
 }
 
@@ -658,6 +659,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
 	if (len == hexsz || !len)
 		return hexsz;
 
+	mad.repo = the_repository;
 	mad.init_len = len;
 	mad.cur_len = len;
 	mad.hex = hex;
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 15/34] sha1-name.c: add repo_find_unique_abbrev_r()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (13 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 14/34] sha1-name.c: remove the_repo from find_abbrev_len_packed() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 16/34] sha1-name.c: store and use repo in struct disambiguate_state Nguyễn Thái Ngọc Duy
                         ` (18 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     |  6 ++++--
 sha1-name.c | 15 +++++++++------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/cache.h b/cache.h
index fcb24b5781..4f8ebb0a67 100644
--- a/cache.h
+++ b/cache.h
@@ -1045,8 +1045,10 @@ extern void check_repository_format(void);
  * Note that while this version avoids the static buffer, it is not fully
  * reentrant, as it calls into other non-reentrant git code.
  */
-extern const char *find_unique_abbrev(const struct object_id *oid, int len);
-extern int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len);
+const char *repo_find_unique_abbrev(struct repository *r, const struct object_id *oid, int len);
+#define find_unique_abbrev(oid, len) repo_find_unique_abbrev(the_repository, oid, len)
+int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);
+#define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len)
 
 extern const unsigned char null_sha1[GIT_MAX_RAWSZ];
 extern const struct object_id null_oid;
diff --git a/sha1-name.c b/sha1-name.c
index b9381aaba6..9b57787b76 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -626,15 +626,16 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
 		find_abbrev_len_for_pack(p, mad);
 }
 
-int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
+int repo_find_unique_abbrev_r(struct repository *r, char *hex,
+			      const struct object_id *oid, int len)
 {
 	struct disambiguate_state ds;
 	struct min_abbrev_data mad;
 	struct object_id oid_ret;
-	const unsigned hexsz = the_hash_algo->hexsz;
+	const unsigned hexsz = r->hash_algo->hexsz;
 
 	if (len < 0) {
-		unsigned long count = approximate_object_count();
+		unsigned long count = repo_approximate_object_count(r);
 		/*
 		 * Add one because the MSB only tells us the highest bit set,
 		 * not including the value of all the _other_ bits (so "15"
@@ -659,7 +660,7 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
 	if (len == hexsz || !len)
 		return hexsz;
 
-	mad.repo = the_repository;
+	mad.repo = r;
 	mad.init_len = len;
 	mad.cur_len = len;
 	mad.hex = hex;
@@ -681,13 +682,15 @@ int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
 	return mad.cur_len;
 }
 
-const char *find_unique_abbrev(const struct object_id *oid, int len)
+const char *repo_find_unique_abbrev(struct repository *r,
+				    const struct object_id *oid,
+				    int len)
 {
 	static int bufno;
 	static char hexbuffer[4][GIT_MAX_HEXSZ + 1];
 	char *hex = hexbuffer[bufno];
 	bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
-	find_unique_abbrev_r(hex, oid, len);
+	repo_find_unique_abbrev_r(r, hex, oid, len);
 	return hex;
 }
 
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 16/34] sha1-name.c: store and use repo in struct disambiguate_state
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (14 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 15/34] sha1-name.c: add repo_find_unique_abbrev_r() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 17/34] sha1-name.c: add repo_for_each_abbrev() Nguyễn Thái Ngọc Duy
                         ` (17 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 95 +++++++++++++++++++++++++++++++++--------------------
 1 file changed, 59 insertions(+), 36 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 9b57787b76..a75992eb54 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -17,13 +17,14 @@
 
 static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
 
-typedef int (*disambiguate_hint_fn)(const struct object_id *, void *);
+typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);
 
 struct disambiguate_state {
 	int len; /* length of prefix in hex chars */
 	char hex_pfx[GIT_MAX_HEXSZ + 1];
 	struct object_id bin_pfx;
 
+	struct repository *repo;
 	disambiguate_hint_fn fn;
 	void *cb_data;
 	struct object_id candidate;
@@ -38,7 +39,7 @@ struct disambiguate_state {
 static void update_candidates(struct disambiguate_state *ds, const struct object_id *current)
 {
 	if (ds->always_call_fn) {
-		ds->ambiguous = ds->fn(current, ds->cb_data) ? 1 : 0;
+		ds->ambiguous = ds->fn(ds->repo, current, ds->cb_data) ? 1 : 0;
 		return;
 	}
 	if (!ds->candidate_exists) {
@@ -58,7 +59,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object
 	}
 
 	if (!ds->candidate_checked) {
-		ds->candidate_ok = ds->fn(&ds->candidate, ds->cb_data);
+		ds->candidate_ok = ds->fn(ds->repo, &ds->candidate, ds->cb_data);
 		ds->disambiguate_fn_used = 1;
 		ds->candidate_checked = 1;
 	}
@@ -71,7 +72,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object
 	}
 
 	/* if we reach this point, we know ds->candidate satisfies fn */
-	if (ds->fn(current, ds->cb_data)) {
+	if (ds->fn(ds->repo, current, ds->cb_data)) {
 		/*
 		 * if both current and candidate satisfy fn, we cannot
 		 * disambiguate.
@@ -89,9 +90,7 @@ static void find_short_object_filename(struct disambiguate_state *ds)
 {
 	struct object_directory *odb;
 
-	for (odb = the_repository->objects->odb;
-	     odb && !ds->ambiguous;
-	     odb = odb->next) {
+	for (odb = ds->repo->objects->odb; odb && !ds->ambiguous; odb = odb->next) {
 		int pos;
 		struct oid_array *loose_objects;
 
@@ -182,10 +181,10 @@ static void find_short_packed_object(struct disambiguate_state *ds)
 	struct multi_pack_index *m;
 	struct packed_git *p;
 
-	for (m = get_multi_pack_index(the_repository); m && !ds->ambiguous;
+	for (m = get_multi_pack_index(ds->repo); m && !ds->ambiguous;
 	     m = m->next)
 		unique_in_midx(m, ds);
-	for (p = get_packed_git(the_repository); p && !ds->ambiguous;
+	for (p = get_packed_git(ds->repo); p && !ds->ambiguous;
 	     p = p->next)
 		unique_in_pack(p, ds);
 }
@@ -215,7 +214,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
 		 * same repository!
 		 */
 		ds->candidate_ok = (!ds->disambiguate_fn_used ||
-				    ds->fn(&ds->candidate, ds->cb_data));
+				    ds->fn(ds->repo, &ds->candidate, ds->cb_data));
 
 	if (!ds->candidate_ok)
 		return SHORT_NAME_AMBIGUOUS;
@@ -224,59 +223,67 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
 	return 0;
 }
 
-static int disambiguate_commit_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_commit_only(struct repository *r,
+				    const struct object_id *oid,
+				    void *cb_data_unused)
 {
-	int kind = oid_object_info(the_repository, oid, NULL);
+	int kind = oid_object_info(r, oid, NULL);
 	return kind == OBJ_COMMIT;
 }
 
-static int disambiguate_committish_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_committish_only(struct repository *r,
+					const struct object_id *oid,
+					void *cb_data_unused)
 {
 	struct object *obj;
 	int kind;
 
-	kind = oid_object_info(the_repository, oid, NULL);
+	kind = oid_object_info(r, oid, NULL);
 	if (kind == OBJ_COMMIT)
 		return 1;
 	if (kind != OBJ_TAG)
 		return 0;
 
 	/* We need to do this the hard way... */
-	obj = deref_tag(the_repository, parse_object(the_repository, oid),
-			NULL, 0);
+	obj = deref_tag(r, parse_object(r, oid), NULL, 0);
 	if (obj && obj->type == OBJ_COMMIT)
 		return 1;
 	return 0;
 }
 
-static int disambiguate_tree_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_tree_only(struct repository *r,
+				  const struct object_id *oid,
+				  void *cb_data_unused)
 {
-	int kind = oid_object_info(the_repository, oid, NULL);
+	int kind = oid_object_info(r, oid, NULL);
 	return kind == OBJ_TREE;
 }
 
-static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_treeish_only(struct repository *r,
+				     const struct object_id *oid,
+				     void *cb_data_unused)
 {
 	struct object *obj;
 	int kind;
 
-	kind = oid_object_info(the_repository, oid, NULL);
+	kind = oid_object_info(r, oid, NULL);
 	if (kind == OBJ_TREE || kind == OBJ_COMMIT)
 		return 1;
 	if (kind != OBJ_TAG)
 		return 0;
 
 	/* We need to do this the hard way... */
-	obj = deref_tag(the_repository, parse_object(the_repository, oid),
-			NULL, 0);
+	obj = deref_tag(r, parse_object(r, oid), NULL, 0);
 	if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))
 		return 1;
 	return 0;
 }
 
-static int disambiguate_blob_only(const struct object_id *oid, void *cb_data_unused)
+static int disambiguate_blob_only(struct repository *r,
+				  const struct object_id *oid,
+				  void *cb_data_unused)
 {
-	int kind = oid_object_info(the_repository, oid, NULL);
+	int kind = oid_object_info(r, oid, NULL);
 	return kind == OBJ_BLOB;
 }
 
@@ -310,7 +317,8 @@ int set_disambiguate_hint_config(const char *var, const char *value)
 	return error("unknown hint type for '%s': %s", var, value);
 }
 
-static int init_object_disambiguation(const char *name, int len,
+static int init_object_disambiguation(struct repository *r,
+				      const char *name, int len,
 				      struct disambiguate_state *ds)
 {
 	int i;
@@ -341,7 +349,8 @@ static int init_object_disambiguation(const char *name, int len,
 
 	ds->len = len;
 	ds->hex_pfx[len] = '\0';
-	prepare_alt_odb(the_repository);
+	ds->repo = r;
+	prepare_alt_odb(r);
 	return 0;
 }
 
@@ -351,25 +360,25 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
 	struct strbuf desc = STRBUF_INIT;
 	int type;
 
-	if (ds->fn && !ds->fn(oid, ds->cb_data))
+	if (ds->fn && !ds->fn(ds->repo, oid, ds->cb_data))
 		return 0;
 
-	type = oid_object_info(the_repository, oid, NULL);
+	type = oid_object_info(ds->repo, oid, NULL);
 	if (type == OBJ_COMMIT) {
-		struct commit *commit = lookup_commit(the_repository, oid);
+		struct commit *commit = lookup_commit(ds->repo, oid);
 		if (commit) {
 			struct pretty_print_context pp = {0};
 			pp.date_mode.type = DATE_SHORT;
 			format_commit_message(commit, " %ad - %s", &desc, &pp);
 		}
 	} else if (type == OBJ_TAG) {
-		struct tag *tag = lookup_tag(the_repository, oid);
+		struct tag *tag = lookup_tag(ds->repo, oid);
 		if (!parse_tag(tag) && tag->tag)
 			strbuf_addf(&desc, " %s", tag->tag);
 	}
 
 	advise("  %s %s%s",
-	       find_unique_abbrev(oid, DEFAULT_ABBREV),
+	       repo_find_unique_abbrev(ds->repo, oid, DEFAULT_ABBREV),
 	       type_name(type) ? type_name(type) : "unknown type",
 	       desc.buf);
 
@@ -383,6 +392,13 @@ static int collect_ambiguous(const struct object_id *oid, void *data)
 	return 0;
 }
 
+static int repo_collect_ambiguous(struct repository *r,
+				  const struct object_id *oid,
+				  void *data)
+{
+	return collect_ambiguous(oid, data);
+}
+
 static struct repository *sort_ambiguous_repo;
 static int sort_ambiguous(const void *a, const void *b)
 {
@@ -428,7 +444,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 	struct disambiguate_state ds;
 	int quietly = !!(flags & GET_OID_QUIETLY);
 
-	if (init_object_disambiguation(name, len, &ds) < 0)
+	if (init_object_disambiguation(the_repository, name, len, &ds) < 0)
 		return -1;
 
 	if (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))
@@ -483,11 +499,11 @@ int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)
 	struct disambiguate_state ds;
 	int ret;
 
-	if (init_object_disambiguation(prefix, strlen(prefix), &ds) < 0)
+	if (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0)
 		return -1;
 
 	ds.always_call_fn = 1;
-	ds.fn = collect_ambiguous;
+	ds.fn = repo_collect_ambiguous;
 	ds.cb_data = &collect;
 	find_short_object_filename(&ds);
 	find_short_packed_object(&ds);
@@ -543,6 +559,13 @@ static int extend_abbrev_len(const struct object_id *oid, void *cb_data)
 	return 0;
 }
 
+static int repo_extend_abbrev_len(struct repository *r,
+				  const struct object_id *oid,
+				  void *cb_data)
+{
+	return extend_abbrev_len(oid, cb_data);
+}
+
 static void find_abbrev_len_for_midx(struct multi_pack_index *m,
 				     struct min_abbrev_data *mad)
 {
@@ -668,10 +691,10 @@ int repo_find_unique_abbrev_r(struct repository *r, char *hex,
 
 	find_abbrev_len_packed(&mad);
 
-	if (init_object_disambiguation(hex, mad.cur_len, &ds) < 0)
+	if (init_object_disambiguation(r, hex, mad.cur_len, &ds) < 0)
 		return -1;
 
-	ds.fn = extend_abbrev_len;
+	ds.fn = repo_extend_abbrev_len;
 	ds.always_call_fn = 1;
 	ds.cb_data = (void *)&mad;
 
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 17/34] sha1-name.c: add repo_for_each_abbrev()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (15 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 16/34] sha1-name.c: store and use repo in struct disambiguate_state Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 18/34] sha1-name.c: remove the_repo from get_short_oid() Nguyễn Thái Ngọc Duy
                         ` (16 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 3 ++-
 sha1-name.c | 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/cache.h b/cache.h
index 4f8ebb0a67..0cb95c0d4f 100644
--- a/cache.h
+++ b/cache.h
@@ -1392,7 +1392,8 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c
 				struct object_context *oc);
 
 typedef int each_abbrev_fn(const struct object_id *oid, void *);
-extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
+int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);
+#define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data)
 
 extern int set_disambiguate_hint_config(const char *var, const char *value);
 
diff --git a/sha1-name.c b/sha1-name.c
index a75992eb54..cdcf84b826 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -493,13 +493,14 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 	return status;
 }
 
-int for_each_abbrev(const char *prefix, each_abbrev_fn fn, void *cb_data)
+int repo_for_each_abbrev(struct repository *r, const char *prefix,
+			 each_abbrev_fn fn, void *cb_data)
 {
 	struct oid_array collect = OID_ARRAY_INIT;
 	struct disambiguate_state ds;
 	int ret;
 
-	if (init_object_disambiguation(the_repository, prefix, strlen(prefix), &ds) < 0)
+	if (init_object_disambiguation(r, prefix, strlen(prefix), &ds) < 0)
 		return -1;
 
 	ds.always_call_fn = 1;
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 18/34] sha1-name.c: remove the_repo from get_short_oid()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (16 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 17/34] sha1-name.c: add repo_for_each_abbrev() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 19/34] sha1-name.c: remove the_repo from interpret_nth_prior_checkout() Nguyễn Thái Ngọc Duy
                         ` (15 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index cdcf84b826..2643b75b54 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -436,7 +436,8 @@ static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)
 	sort_ambiguous_repo = NULL;
 }
 
-static enum get_oid_result get_short_oid(const char *name, int len,
+static enum get_oid_result get_short_oid(struct repository *r,
+					 const char *name, int len,
 					 struct object_id *oid,
 					 unsigned flags)
 {
@@ -444,7 +445,7 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 	struct disambiguate_state ds;
 	int quietly = !!(flags & GET_OID_QUIETLY);
 
-	if (init_object_disambiguation(the_repository, name, len, &ds) < 0)
+	if (init_object_disambiguation(r, name, len, &ds) < 0)
 		return -1;
 
 	if (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))
@@ -482,8 +483,8 @@ static enum get_oid_result get_short_oid(const char *name, int len,
 			ds.fn = NULL;
 
 		advise(_("The candidates are:"));
-		for_each_abbrev(ds.hex_pfx, collect_ambiguous, &collect);
-		sort_ambiguous_oid_array(the_repository, &collect);
+		repo_for_each_abbrev(r, ds.hex_pfx, collect_ambiguous, &collect);
+		sort_ambiguous_oid_array(r, &collect);
 
 		if (oid_array_for_each(&collect, show_ambiguous_object, &ds))
 			BUG("show_ambiguous_object shouldn't return non-zero");
@@ -855,7 +856,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 
 	if (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&
 	    (refs_found > 1 ||
-	     !get_short_oid(str, len, &tmp_oid, GET_OID_QUIETLY)))
+	     !get_short_oid(the_repository,
+			    str, len, &tmp_oid, GET_OID_QUIETLY)))
 		warning(warn_msg, len, str);
 
 	if (reflog_len) {
@@ -1109,7 +1111,8 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)
 			if (ch == 'g' && cp[-1] == '-') {
 				cp++;
 				len -= cp - name;
-				return get_short_oid(cp, len, oid, flags);
+				return get_short_oid(the_repository,
+						     cp, len, oid, flags);
 			}
 		}
 	}
@@ -1163,7 +1166,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,
 	if (!ret)
 		return FOUND;
 
-	return get_short_oid(name, len, oid, lookup_flags);
+	return get_short_oid(the_repository, name, len, oid, lookup_flags);
 }
 
 /*
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 19/34] sha1-name.c: remove the_repo from interpret_nth_prior_checkout()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (17 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 18/34] sha1-name.c: remove the_repo from get_short_oid() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 20/34] sha1-name.c: remove the_repo from interpret_branch_mark() Nguyễn Thái Ngọc Duy
                         ` (14 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 2643b75b54..af8bf5b351 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -771,7 +771,7 @@ static inline int push_mark(const char *string, int len)
 }
 
 static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
-static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);
+static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);
 
 static int get_oid_basic(const char *str, int len, struct object_id *oid,
 			  unsigned int flags)
@@ -835,7 +835,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 		struct strbuf buf = STRBUF_INIT;
 		int detached;
 
-		if (interpret_nth_prior_checkout(str, len, &buf) > 0) {
+		if (interpret_nth_prior_checkout(the_repository, str, len, &buf) > 0) {
 			detached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));
 			strbuf_release(&buf);
 			if (detached)
@@ -1288,7 +1288,8 @@ static int grab_nth_branch_switch(struct object_id *ooid, struct object_id *noid
  * Parse @{-N} syntax, return the number of characters parsed
  * if successful; otherwise signal an error with negative value.
  */
-static int interpret_nth_prior_checkout(const char *name, int namelen,
+static int interpret_nth_prior_checkout(struct repository *r,
+					const char *name, int namelen,
 					struct strbuf *buf)
 {
 	long nth;
@@ -1312,12 +1313,14 @@ static int interpret_nth_prior_checkout(const char *name, int namelen,
 	cb.remaining = nth;
 	strbuf_init(&cb.buf, 20);
 
-	retval = 0;
-	if (0 < for_each_reflog_ent_reverse("HEAD", grab_nth_branch_switch, &cb)) {
+	retval = refs_for_each_reflog_ent_reverse(get_main_ref_store(r),
+			"HEAD", grab_nth_branch_switch, &cb);
+	if (0 < retval) {
 		strbuf_reset(buf);
 		strbuf_addbuf(buf, &cb.buf);
 		retval = brace - name + 1;
-	}
+	} else
+		retval = 0;
 
 	strbuf_release(&cb.buf);
 	return retval;
@@ -1484,7 +1487,7 @@ int repo_interpret_branch_name(struct repository *r,
 		namelen = strlen(name);
 
 	if (!allowed || (allowed & INTERPRET_BRANCH_LOCAL)) {
-		len = interpret_nth_prior_checkout(name, namelen, buf);
+		len = interpret_nth_prior_checkout(the_repository, name, namelen, buf);
 		if (!len) {
 			return len; /* syntax Ok, not enough switches */
 		} else if (len > 0) {
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 20/34] sha1-name.c: remove the_repo from interpret_branch_mark()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (18 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 19/34] sha1-name.c: remove the_repo from interpret_nth_prior_checkout() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 21/34] sha1-name.c: add repo_interpret_branch_name() Nguyễn Thái Ngọc Duy
                         ` (13 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index af8bf5b351..7d9512ac44 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1412,9 +1412,9 @@ static int reinterpret(const char *name, int namelen, int len,
 	return ret - used + len;
 }
 
-static void set_shortened_ref(struct strbuf *buf, const char *ref)
+static void set_shortened_ref(struct repository *r, struct strbuf *buf, const char *ref)
 {
-	char *s = shorten_unambiguous_ref(ref, 0);
+	char *s = refs_shorten_unambiguous_ref(get_main_ref_store(r), ref, 0);
 	strbuf_reset(buf);
 	strbuf_addstr(buf, s);
 	free(s);
@@ -1435,7 +1435,8 @@ static int branch_interpret_allowed(const char *refname, unsigned allowed)
 	return 0;
 }
 
-static int interpret_branch_mark(const char *name, int namelen,
+static int interpret_branch_mark(struct repository *r,
+				 const char *name, int namelen,
 				 int at, struct strbuf *buf,
 				 int (*get_mark)(const char *, int),
 				 const char *(*get_data)(struct branch *,
@@ -1468,7 +1469,7 @@ static int interpret_branch_mark(const char *name, int namelen,
 	if (!branch_interpret_allowed(value, allowed))
 		return -1;
 
-	set_shortened_ref(buf, value);
+	set_shortened_ref(r, buf, value);
 	return len + at;
 }
 
@@ -1509,13 +1510,13 @@ int repo_interpret_branch_name(struct repository *r,
 						   allowed);
 		}
 
-		len = interpret_branch_mark(name, namelen, at - name, buf,
+		len = interpret_branch_mark(the_repository, name, namelen, at - name, buf,
 					    upstream_mark, branch_get_upstream,
 					    allowed);
 		if (len > 0)
 			return len;
 
-		len = interpret_branch_mark(name, namelen, at - name, buf,
+		len = interpret_branch_mark(the_repository, name, namelen, at - name, buf,
 					    push_mark, branch_get_push,
 					    allowed);
 		if (len > 0)
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 21/34] sha1-name.c: add repo_interpret_branch_name()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (19 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 20/34] sha1-name.c: remove the_repo from interpret_branch_mark() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 22/34] sha1-name.c: remove the_repo from get_oid_oneline() Nguyễn Thái Ngọc Duy
                         ` (12 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 7d9512ac44..49c62d5254 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1390,7 +1390,8 @@ static int interpret_empty_at(const char *name, int namelen, int len, struct str
 	return 1;
 }
 
-static int reinterpret(const char *name, int namelen, int len,
+static int reinterpret(struct repository *r,
+		       const char *name, int namelen, int len,
 		       struct strbuf *buf, unsigned allowed)
 {
 	/* we have extra data, which might need further processing */
@@ -1399,7 +1400,7 @@ static int reinterpret(const char *name, int namelen, int len,
 	int ret;
 
 	strbuf_add(buf, name + len, namelen - len);
-	ret = interpret_branch_name(buf->buf, buf->len, &tmp, allowed);
+	ret = repo_interpret_branch_name(r, buf->buf, buf->len, &tmp, allowed);
 	/* that data was not interpreted, remove our cruft */
 	if (ret < 0) {
 		strbuf_setlen(buf, used);
@@ -1482,20 +1483,18 @@ int repo_interpret_branch_name(struct repository *r,
 	const char *start;
 	int len;
 
-	if (r != the_repository)
-		BUG("interpret_branch_name() does not really use 'r' yet");
 	if (!namelen)
 		namelen = strlen(name);
 
 	if (!allowed || (allowed & INTERPRET_BRANCH_LOCAL)) {
-		len = interpret_nth_prior_checkout(the_repository, name, namelen, buf);
+		len = interpret_nth_prior_checkout(r, name, namelen, buf);
 		if (!len) {
 			return len; /* syntax Ok, not enough switches */
 		} else if (len > 0) {
 			if (len == namelen)
 				return len; /* consumed all */
 			else
-				return reinterpret(name, namelen, len, buf, allowed);
+				return reinterpret(r, name, namelen, len, buf, allowed);
 		}
 	}
 
@@ -1506,17 +1505,17 @@ int repo_interpret_branch_name(struct repository *r,
 		if (!allowed || (allowed & INTERPRET_BRANCH_HEAD)) {
 			len = interpret_empty_at(name, namelen, at - name, buf);
 			if (len > 0)
-				return reinterpret(name, namelen, len, buf,
+				return reinterpret(r, name, namelen, len, buf,
 						   allowed);
 		}
 
-		len = interpret_branch_mark(the_repository, name, namelen, at - name, buf,
+		len = interpret_branch_mark(r, name, namelen, at - name, buf,
 					    upstream_mark, branch_get_upstream,
 					    allowed);
 		if (len > 0)
 			return len;
 
-		len = interpret_branch_mark(the_repository, name, namelen, at - name, buf,
+		len = interpret_branch_mark(r, name, namelen, at - name, buf,
 					    push_mark, branch_get_push,
 					    allowed);
 		if (len > 0)
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 22/34] sha1-name.c: remove the_repo from get_oid_oneline()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (20 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 21/34] sha1-name.c: add repo_interpret_branch_name() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 23/34] sha1-name.c: remove the_repo from get_describe_name() Nguyễn Thái Ngọc Duy
                         ` (11 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 49c62d5254..fb80306f1a 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -15,7 +15,7 @@
 #include "midx.h"
 #include "commit-reach.h"
 
-static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
+static int get_oid_oneline(struct repository *r, const char *, struct object_id *, struct commit_list *);
 
 typedef int (*disambiguate_hint_fn)(struct repository *, const struct object_id *, void *);
 
@@ -1090,7 +1090,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 
 		prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
 		commit_list_insert((struct commit *)o, &list);
-		ret = get_oid_oneline(prefix, oid, list);
+		ret = get_oid_oneline(the_repository, prefix, oid, list);
 		free(prefix);
 		return ret;
 	}
@@ -1204,8 +1204,9 @@ static int handle_one_ref(const char *path, const struct object_id *oid,
 	return 0;
 }
 
-static int get_oid_oneline(const char *prefix, struct object_id *oid,
-			    struct commit_list *list)
+static int get_oid_oneline(struct repository *r,
+			   const char *prefix, struct object_id *oid,
+			   struct commit_list *list)
 {
 	struct commit_list *backup = NULL, *l;
 	int found = 0;
@@ -1236,7 +1237,7 @@ static int get_oid_oneline(const char *prefix, struct object_id *oid,
 		int matches;
 
 		commit = pop_most_recent_commit(&list, ONELINE_SEEN);
-		if (!parse_object(the_repository, &commit->object.oid))
+		if (!parse_object(r, &commit->object.oid))
 			continue;
 		buf = get_commit_buffer(commit, NULL);
 		p = strstr(buf, "\n\n");
@@ -1760,7 +1761,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			for_each_ref(handle_one_ref, &list);
 			head_ref(handle_one_ref, &list);
 			commit_list_sort_by_date(&list);
-			return get_oid_oneline(name + 2, oid, list);
+			return get_oid_oneline(repo, name + 2, oid, list);
 		}
 		if (namelen < 3 ||
 		    name[2] != ':' ||
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 23/34] sha1-name.c: remove the_repo from get_describe_name()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (21 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 22/34] sha1-name.c: remove the_repo from get_oid_oneline() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 24/34] sha1-name.c: remove the_repo from get_oid_basic() Nguyễn Thái Ngọc Duy
                         ` (10 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index fb80306f1a..1cda854f02 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1097,7 +1097,9 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 	return 0;
 }
 
-static int get_describe_name(const char *name, int len, struct object_id *oid)
+static int get_describe_name(struct repository *r,
+			     const char *name, int len,
+			     struct object_id *oid)
 {
 	const char *cp;
 	unsigned flags = GET_OID_QUIETLY | GET_OID_COMMIT;
@@ -1111,7 +1113,7 @@ static int get_describe_name(const char *name, int len, struct object_id *oid)
 			if (ch == 'g' && cp[-1] == '-') {
 				cp++;
 				len -= cp - name;
-				return get_short_oid(the_repository,
+				return get_short_oid(r,
 						     cp, len, oid, flags);
 			}
 		}
@@ -1162,7 +1164,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,
 		return FOUND;
 
 	/* It could be describe output that is "SOMETHING-gXXXX" */
-	ret = get_describe_name(name, len, oid);
+	ret = get_describe_name(the_repository, name, len, oid);
 	if (!ret)
 		return FOUND;
 
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 24/34] sha1-name.c: remove the_repo from get_oid_basic()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (22 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 23/34] sha1-name.c: remove the_repo from get_describe_name() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 25/34] sha1-name.c: remove the_repo from get_oid_1() Nguyễn Thái Ngọc Duy
                         ` (9 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 1cda854f02..d4c135aea8 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -773,8 +773,8 @@ static inline int push_mark(const char *string, int len)
 static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
 static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);
 
-static int get_oid_basic(const char *str, int len, struct object_id *oid,
-			  unsigned int flags)
+static int get_oid_basic(struct repository *r, const char *str, int len,
+			 struct object_id *oid, unsigned int flags)
 {
 	static const char *warn_msg = "refname '%.*s' is ambiguous.";
 	static const char *object_name_msg = N_(
@@ -792,9 +792,9 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 	int refs_found = 0;
 	int at, reflog_len, nth_prior = 0;
 
-	if (len == the_hash_algo->hexsz && !get_oid_hex(str, oid)) {
+	if (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {
 		if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
-			refs_found = dwim_ref(str, len, &tmp_oid, &real_ref);
+			refs_found = repo_dwim_ref(r, str, len, &tmp_oid, &real_ref);
 			if (refs_found > 0) {
 				warning(warn_msg, len, str);
 				if (advice_object_name_warning)
@@ -835,8 +835,8 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 		struct strbuf buf = STRBUF_INIT;
 		int detached;
 
-		if (interpret_nth_prior_checkout(the_repository, str, len, &buf) > 0) {
-			detached = (buf.len == the_hash_algo->hexsz && !get_oid_hex(buf.buf, oid));
+		if (interpret_nth_prior_checkout(r, str, len, &buf) > 0) {
+			detached = (buf.len == r->hash_algo->hexsz && !get_oid_hex(buf.buf, oid));
 			strbuf_release(&buf);
 			if (detached)
 				return 0;
@@ -845,19 +845,18 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 
 	if (!len && reflog_len)
 		/* allow "@{...}" to mean the current branch reflog */
-		refs_found = dwim_ref("HEAD", 4, oid, &real_ref);
+		refs_found = repo_dwim_ref(r, "HEAD", 4, oid, &real_ref);
 	else if (reflog_len)
-		refs_found = dwim_log(str, len, oid, &real_ref);
+		refs_found = repo_dwim_log(r, str, len, oid, &real_ref);
 	else
-		refs_found = dwim_ref(str, len, oid, &real_ref);
+		refs_found = repo_dwim_ref(r, str, len, oid, &real_ref);
 
 	if (!refs_found)
 		return -1;
 
 	if (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&
 	    (refs_found > 1 ||
-	     !get_short_oid(the_repository,
-			    str, len, &tmp_oid, GET_OID_QUIETLY)))
+	     !get_short_oid(r, str, len, &tmp_oid, GET_OID_QUIETLY)))
 		warning(warn_msg, len, str);
 
 	if (reflog_len) {
@@ -889,7 +888,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 				return -1;
 			}
 		}
-		if (read_ref_at(get_main_ref_store(the_repository),
+		if (read_ref_at(get_main_ref_store(r),
 				real_ref, flags, at_time, nth, oid, NULL,
 				&co_time, &co_tz, &co_cnt)) {
 			if (!len) {
@@ -1159,7 +1158,7 @@ static enum get_oid_result get_oid_1(const char *name, int len,
 	if (!ret)
 		return FOUND;
 
-	ret = get_oid_basic(name, len, oid, lookup_flags);
+	ret = get_oid_basic(the_repository, name, len, oid, lookup_flags);
 	if (!ret)
 		return FOUND;
 
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 25/34] sha1-name.c: remove the_repo from get_oid_1()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (23 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 24/34] sha1-name.c: remove the_repo from get_oid_basic() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 26/34] sha1-name.c: remove the_repo from handle_one_ref() Nguyễn Thái Ngọc Duy
                         ` (8 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

There is a cyclic dependency between one of these functions so they
cannot be converted one by one, so all related functions are converted
at once.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     |  7 +++++--
 sha1-name.c | 59 ++++++++++++++++++++++++++++-------------------------
 2 files changed, 36 insertions(+), 30 deletions(-)

diff --git a/cache.h b/cache.h
index 0cb95c0d4f..2149dc4f56 100644
--- a/cache.h
+++ b/cache.h
@@ -1491,8 +1491,11 @@ extern void *read_object_with_reference(const struct object_id *oid,
 					unsigned long *size,
 					struct object_id *oid_ret);
 
-extern struct object *peel_to_type(const char *name, int namelen,
-				   struct object *o, enum object_type);
+struct object *repo_peel_to_type(struct repository *r,
+				 const char *name, int namelen,
+				 struct object *o, enum object_type);
+#define peel_to_type(name, namelen, obj, type) \
+	repo_peel_to_type(the_repository, name, namelen, obj, type)
 
 enum date_mode_type {
 	DATE_NORMAL = 0,
diff --git a/sha1-name.c b/sha1-name.c
index d4c135aea8..5741a9f821 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -770,7 +770,7 @@ static inline int push_mark(const char *string, int len)
 	return at_mark(string, len, suffix, ARRAY_SIZE(suffix));
 }
 
-static enum get_oid_result get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
+static enum get_oid_result get_oid_1(struct repository *r, const char *name, int len, struct object_id *oid, unsigned lookup_flags);
 static int interpret_nth_prior_checkout(struct repository *r, const char *name, int namelen, struct strbuf *buf);
 
 static int get_oid_basic(struct repository *r, const char *str, int len,
@@ -921,18 +921,19 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
 	return 0;
 }
 
-static enum get_oid_result get_parent(const char *name, int len,
+static enum get_oid_result get_parent(struct repository *r,
+				      const char *name, int len,
 				      struct object_id *result, int idx)
 {
 	struct object_id oid;
-	enum get_oid_result ret = get_oid_1(name, len, &oid,
+	enum get_oid_result ret = get_oid_1(r, name, len, &oid,
 					    GET_OID_COMMITTISH);
 	struct commit *commit;
 	struct commit_list *p;
 
 	if (ret)
 		return ret;
-	commit = lookup_commit_reference(the_repository, &oid);
+	commit = lookup_commit_reference(r, &oid);
 	if (parse_commit(commit))
 		return MISSING_OBJECT;
 	if (!idx) {
@@ -950,7 +951,8 @@ static enum get_oid_result get_parent(const char *name, int len,
 	return MISSING_OBJECT;
 }
 
-static enum get_oid_result get_nth_ancestor(const char *name, int len,
+static enum get_oid_result get_nth_ancestor(struct repository *r,
+					    const char *name, int len,
 					    struct object_id *result,
 					    int generation)
 {
@@ -958,10 +960,10 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,
 	struct commit *commit;
 	int ret;
 
-	ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);
+	ret = get_oid_1(r, name, len, &oid, GET_OID_COMMITTISH);
 	if (ret)
 		return ret;
-	commit = lookup_commit_reference(the_repository, &oid);
+	commit = lookup_commit_reference(r, &oid);
 	if (!commit)
 		return MISSING_OBJECT;
 
@@ -974,20 +976,20 @@ static enum get_oid_result get_nth_ancestor(const char *name, int len,
 	return FOUND;
 }
 
-struct object *peel_to_type(const char *name, int namelen,
-			    struct object *o, enum object_type expected_type)
+struct object *repo_peel_to_type(struct repository *r, const char *name, int namelen,
+				 struct object *o, enum object_type expected_type)
 {
 	if (name && !namelen)
 		namelen = strlen(name);
 	while (1) {
-		if (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))
+		if (!o || (!o->parsed && !parse_object(r, &o->oid)))
 			return NULL;
 		if (expected_type == OBJ_ANY || o->type == expected_type)
 			return o;
 		if (o->type == OBJ_TAG)
 			o = ((struct tag*) o)->tagged;
 		else if (o->type == OBJ_COMMIT)
-			o = &(get_commit_tree(((struct commit *)o))->object);
+			o = &(repo_get_commit_tree(r, ((struct commit *)o))->object);
 		else {
 			if (name)
 				error("%.*s: expected %s type, but the object "
@@ -999,8 +1001,8 @@ struct object *peel_to_type(const char *name, int namelen,
 	}
 }
 
-static int peel_onion(const char *name, int len, struct object_id *oid,
-		      unsigned lookup_flags)
+static int peel_onion(struct repository *r, const char *name, int len,
+		      struct object_id *oid, unsigned lookup_flags)
 {
 	struct object_id outer;
 	const char *sp;
@@ -1050,15 +1052,15 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 	else if (expected_type == OBJ_TREE)
 		lookup_flags |= GET_OID_TREEISH;
 
-	if (get_oid_1(name, sp - name - 2, &outer, lookup_flags))
+	if (get_oid_1(r, name, sp - name - 2, &outer, lookup_flags))
 		return -1;
 
-	o = parse_object(the_repository, &outer);
+	o = parse_object(r, &outer);
 	if (!o)
 		return -1;
 	if (!expected_type) {
-		o = deref_tag(the_repository, o, name, sp - name - 2);
-		if (!o || (!o->parsed && !parse_object(the_repository, &o->oid)))
+		o = deref_tag(r, o, name, sp - name - 2);
+		if (!o || (!o->parsed && !parse_object(r, &o->oid)))
 			return -1;
 		oidcpy(oid, &o->oid);
 		return 0;
@@ -1069,7 +1071,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 	 * if we do not get the needed object, we should
 	 * barf.
 	 */
-	o = peel_to_type(name, len, o, expected_type);
+	o = repo_peel_to_type(r, name, len, o, expected_type);
 	if (!o)
 		return -1;
 
@@ -1089,7 +1091,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 
 		prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
 		commit_list_insert((struct commit *)o, &list);
-		ret = get_oid_oneline(the_repository, prefix, oid, list);
+		ret = get_oid_oneline(r, prefix, oid, list);
 		free(prefix);
 		return ret;
 	}
@@ -1120,7 +1122,8 @@ static int get_describe_name(struct repository *r,
 	return -1;
 }
 
-static enum get_oid_result get_oid_1(const char *name, int len,
+static enum get_oid_result get_oid_1(struct repository *r,
+				     const char *name, int len,
 				     struct object_id *oid,
 				     unsigned lookup_flags)
 {
@@ -1149,25 +1152,25 @@ static enum get_oid_result get_oid_1(const char *name, int len,
 		if (!num && len1 == len - 1)
 			num = 1;
 		if (has_suffix == '^')
-			return get_parent(name, len1, oid, num);
+			return get_parent(r, name, len1, oid, num);
 		/* else if (has_suffix == '~') -- goes without saying */
-		return get_nth_ancestor(name, len1, oid, num);
+		return get_nth_ancestor(r, name, len1, oid, num);
 	}
 
-	ret = peel_onion(name, len, oid, lookup_flags);
+	ret = peel_onion(r, name, len, oid, lookup_flags);
 	if (!ret)
 		return FOUND;
 
-	ret = get_oid_basic(the_repository, name, len, oid, lookup_flags);
+	ret = get_oid_basic(r, name, len, oid, lookup_flags);
 	if (!ret)
 		return FOUND;
 
 	/* It could be describe output that is "SOMETHING-gXXXX" */
-	ret = get_describe_name(the_repository, name, len, oid);
+	ret = get_describe_name(r, name, len, oid);
 	if (!ret)
 		return FOUND;
 
-	return get_short_oid(the_repository, name, len, oid, lookup_flags);
+	return get_short_oid(r, name, len, oid, lookup_flags);
 }
 
 /*
@@ -1741,7 +1744,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 	memset(oc, 0, sizeof(*oc));
 	oc->mode = S_IFINVALID;
 	strbuf_init(&oc->symlink_path, 0);
-	ret = get_oid_1(name, namelen, oid, flags);
+	ret = get_oid_1(repo, name, namelen, oid, flags);
 	if (!ret)
 		return ret;
 	/*
@@ -1822,7 +1825,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 		sub_flags &= ~GET_OID_DISAMBIGUATORS;
 		sub_flags |= GET_OID_TREEISH;
 
-		if (!get_oid_1(name, len, &tree_oid, sub_flags)) {
+		if (!get_oid_1(repo, name, len, &tree_oid, sub_flags)) {
 			const char *filename = cp+1;
 			char *new_filename = NULL;
 
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 26/34] sha1-name.c: remove the_repo from handle_one_ref()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (24 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 25/34] sha1-name.c: remove the_repo from get_oid_1() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 27/34] sha1-name.c: remove the_repo from diagnose_invalid_index_path() Nguyễn Thái Ngọc Duy
                         ` (7 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 5741a9f821..d9050776dd 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1189,15 +1189,21 @@ static enum get_oid_result get_oid_1(struct repository *r,
 /* Remember to update object flag allocation in object.h */
 #define ONELINE_SEEN (1u<<20)
 
+struct handle_one_ref_cb {
+	struct repository *repo;
+	struct commit_list **list;
+};
+
 static int handle_one_ref(const char *path, const struct object_id *oid,
 			  int flag, void *cb_data)
 {
-	struct commit_list **list = cb_data;
-	struct object *object = parse_object(the_repository, oid);
+	struct handle_one_ref_cb *cb = cb_data;
+	struct commit_list **list = cb->list;
+	struct object *object = parse_object(cb->repo, oid);
 	if (!object)
 		return 0;
 	if (object->type == OBJ_TAG) {
-		object = deref_tag(the_repository, object, path,
+		object = deref_tag(cb->repo, object, path,
 				   strlen(path));
 		if (!object)
 			return 0;
@@ -1760,10 +1766,13 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 		char *new_path = NULL;
 		int pos;
 		if (!only_to_die && namelen > 2 && name[1] == '/') {
+			struct handle_one_ref_cb cb;
 			struct commit_list *list = NULL;
 
-			for_each_ref(handle_one_ref, &list);
-			head_ref(handle_one_ref, &list);
+			cb.repo = repo;
+			cb.list = &list;
+			refs_for_each_ref(repo->refs, handle_one_ref, &cb);
+			refs_head_ref(repo->refs, handle_one_ref, &cb);
 			commit_list_sort_by_date(&list);
 			return get_oid_oneline(repo, name + 2, oid, list);
 		}
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 27/34] sha1-name.c: remove the_repo from diagnose_invalid_index_path()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (25 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 26/34] sha1-name.c: remove the_repo from handle_one_ref() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 28/34] sha1-name.c: remove the_repo from resolve_relative_path() Nguyễn Thái Ngọc Duy
                         ` (6 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 dir.c       | 8 ++++++++
 dir.h       | 4 +++-
 sha1-name.c | 7 ++++---
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/dir.c b/dir.c
index b2cabadf25..e6d97343f4 100644
--- a/dir.c
+++ b/dir.c
@@ -2315,6 +2315,14 @@ int file_exists(const char *f)
 	return lstat(f, &sb) == 0;
 }
 
+int repo_file_exists(struct repository *repo, const char *path)
+{
+	if (repo != the_repository)
+		BUG("do not know how to check file existence in arbitrary repo");
+
+	return file_exists(path);
+}
+
 static int cmp_icase(char a, char b)
 {
 	if (a == b)
diff --git a/dir.h b/dir.h
index e3ec26143d..47c5409ced 100644
--- a/dir.h
+++ b/dir.h
@@ -269,7 +269,9 @@ extern void add_exclude(const char *string, const char *base,
 			int baselen, struct exclude_list *el, int srcpos);
 extern void clear_exclude_list(struct exclude_list *el);
 extern void clear_directory(struct dir_struct *dir);
-extern int file_exists(const char *);
+
+int repo_file_exists(struct repository *repo, const char *path);
+int file_exists(const char *);
 
 extern int is_inside_dir(const char *dir);
 extern int dir_inside_of(const char *subdir, const char *dir);
diff --git a/sha1-name.c b/sha1-name.c
index d9050776dd..6caf3f4e3a 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1664,11 +1664,12 @@ static void diagnose_invalid_oid_path(const char *prefix,
 }
 
 /* Must be called only when :stage:filename doesn't exist. */
-static void diagnose_invalid_index_path(struct index_state *istate,
+static void diagnose_invalid_index_path(struct repository *r,
 					int stage,
 					const char *prefix,
 					const char *filename)
 {
+	struct index_state *istate = r->index;
 	const struct cache_entry *ce;
 	int pos;
 	unsigned namelen = strlen(filename);
@@ -1708,7 +1709,7 @@ static void diagnose_invalid_index_path(struct index_state *istate,
 			    ce_stage(ce), filename);
 	}
 
-	if (file_exists(filename))
+	if (repo_file_exists(r, filename))
 		die("Path '%s' exists on disk, but not in the index.", filename);
 	if (is_missing_file_error(errno))
 		die("Path '%s' does not exist (neither on disk nor in the index).",
@@ -1814,7 +1815,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			pos++;
 		}
 		if (only_to_die && name[1] && name[1] != '/')
-			diagnose_invalid_index_path(repo->index, stage, prefix, cp);
+			diagnose_invalid_index_path(repo, stage, prefix, cp);
 		free(new_path);
 		return -1;
 	}
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 28/34] sha1-name.c: remove the_repo from resolve_relative_path()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (26 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 27/34] sha1-name.c: remove the_repo from diagnose_invalid_index_path() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 29/34] sha1-name.c: remove the_repo from get_oid_with_context_1() Nguyễn Thái Ngọc Duy
                         ` (5 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

"remove" is not entirely correct. But at least the function is aware
that if the given repo is not the_repository, then $CWD and
is_inside_work_tree() means nothing.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 6caf3f4e3a..6b53ea2eeb 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1719,12 +1719,12 @@ static void diagnose_invalid_index_path(struct repository *r,
 }
 
 
-static char *resolve_relative_path(const char *rel)
+static char *resolve_relative_path(struct repository *r, const char *rel)
 {
 	if (!starts_with(rel, "./") && !starts_with(rel, "../"))
 		return NULL;
 
-	if (!is_inside_work_tree())
+	if (r != the_repository || !is_inside_work_tree())
 		die("relative path syntax can't be used outside working tree.");
 
 	/* die() inside prefix_path() if resolved path is outside worktree */
@@ -1785,7 +1785,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			stage = name[1] - '0';
 			cp = name + 3;
 		}
-		new_path = resolve_relative_path(cp);
+		new_path = resolve_relative_path(repo, cp);
 		if (!new_path) {
 			namelen = namelen - (cp - name);
 		} else {
@@ -1839,7 +1839,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			const char *filename = cp+1;
 			char *new_filename = NULL;
 
-			new_filename = resolve_relative_path(filename);
+			new_filename = resolve_relative_path(repo, filename);
 			if (new_filename)
 				filename = new_filename;
 			if (flags & GET_OID_FOLLOW_SYMLINKS) {
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 29/34] sha1-name.c: remove the_repo from get_oid_with_context_1()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (27 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 28/34] sha1-name.c: remove the_repo from resolve_relative_path() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 30/34] sha1-name.c: add repo_get_oid() Nguyễn Thái Ngọc Duy
                         ` (4 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1-name.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/sha1-name.c b/sha1-name.c
index 6b53ea2eeb..64a50d1291 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -12,6 +12,7 @@
 #include "packfile.h"
 #include "object-store.h"
 #include "repository.h"
+#include "submodule.h"
 #include "midx.h"
 #include "commit-reach.h"
 
@@ -1797,7 +1798,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			oc->path = xstrdup(cp);
 
 		if (!repo->index->cache)
-			repo_read_index(the_repository);
+			repo_read_index(repo);
 		pos = index_name_pos(repo->index, cp, namelen);
 		if (pos < 0)
 			pos = -pos - 1;
@@ -1842,6 +1843,14 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
 			new_filename = resolve_relative_path(repo, filename);
 			if (new_filename)
 				filename = new_filename;
+			/*
+			 * NEEDSWORK: Eventually get_tree_entry*() should
+			 * learn to take struct repository directly and we
+			 * would not need to inject submodule odb to the
+			 * in-core odb.
+			 */
+			if (repo != the_repository)
+				add_to_alternates_memory(repo->objects->odb->path);
 			if (flags & GET_OID_FOLLOW_SYMLINKS) {
 				ret = get_tree_entry_follow_symlinks(&tree_oid,
 					filename, oid, &oc->symlink_path,
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 30/34] sha1-name.c: add repo_get_oid()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (28 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 29/34] sha1-name.c: remove the_repo from get_oid_with_context_1() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 31/34] submodule-config.c: use repo_get_oid for reading .gitmodules Nguyễn Thái Ngọc Duy
                         ` (3 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 3 ++-
 sha1-name.c | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/cache.h b/cache.h
index 2149dc4f56..f6e87194d0 100644
--- a/cache.h
+++ b/cache.h
@@ -1380,7 +1380,8 @@ enum get_oid_result {
 		       */
 };
 
-extern int get_oid(const char *str, struct object_id *oid);
+int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);
+#define get_oid(str, oid) repo_get_oid(the_repository, str, oid)
 extern int get_oid_commit(const char *str, struct object_id *oid);
 extern int get_oid_committish(const char *str, struct object_id *oid);
 extern int get_oid_tree(const char *str, struct object_id *oid);
diff --git a/sha1-name.c b/sha1-name.c
index 64a50d1291..953df0d692 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1573,10 +1573,10 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
  * This is like "get_oid_basic()", except it allows "object ID expressions",
  * notably "xyz^" for "parent of xyz"
  */
-int get_oid(const char *name, struct object_id *oid)
+int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository, name, 0, oid, &unused);
+	return get_oid_with_context(r, name, 0, oid, &unused);
 }
 
 
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 31/34] submodule-config.c: use repo_get_oid for reading .gitmodules
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (29 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 30/34] sha1-name.c: add repo_get_oid() Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 32/34] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name Nguyễn Thái Ngọc Duy
                         ` (2 subsequent siblings)
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Since 76e9bdc437 (submodule: support reading .gitmodules when it's not
in the working tree - 2018-10-25), every time you do

    git grep --recurse-submodules

you are likely to see one warning line per submodule (unless all those
submodules also have submodules). On a superproject with plenty of
submodules (I've seen one with 67) this is really annoying.

The warning was there because we could not resolve extended SHA-1
syntax on a submodule. We can now. Make use of the new API and get rid
of the warning.

It would be even better if config_with_options() supports multiple
repositories too. But one step at a time.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 submodule-config.c                 | 20 +++++++-------------
 t/t7814-grep-recurse-submodules.sh |  6 +-----
 2 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/submodule-config.c b/submodule-config.c
index 66653e86b9..4264ee216f 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -625,23 +625,16 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
 		const struct config_options opts = { 0 };
 		struct object_id oid;
 		char *file;
+		char *oidstr = NULL;
 
 		file = repo_worktree_path(repo, GITMODULES_FILE);
 		if (file_exists(file)) {
 			config_source.file = file;
-		} else if (repo->submodule_prefix) {
-			/*
-			 * When get_oid and config_with_options, used below,
-			 * become able to work on a specific repository, this
-			 * warning branch can be removed.
-			 */
-			warning("nested submodules without %s in the working tree are not supported yet",
-				GITMODULES_FILE);
-			goto out;
-		} else if (get_oid(GITMODULES_INDEX, &oid) >= 0) {
-			config_source.blob = GITMODULES_INDEX;
-		} else if (get_oid(GITMODULES_HEAD, &oid) >= 0) {
-			config_source.blob = GITMODULES_HEAD;
+		} else if (repo_get_oid(repo, GITMODULES_INDEX, &oid) >= 0 ||
+			   repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
+			config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
+			if (repo != the_repository)
+				add_to_alternates_memory(repo->objects->odb->path);
 		} else {
 			goto out;
 		}
@@ -649,6 +642,7 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
 		config_with_options(fn, data, &config_source, &opts);
 
 out:
+		free(oidstr);
 		free(file);
 	}
 }
diff --git a/t/t7814-grep-recurse-submodules.sh b/t/t7814-grep-recurse-submodules.sh
index fa475d52fa..134a694516 100755
--- a/t/t7814-grep-recurse-submodules.sh
+++ b/t/t7814-grep-recurse-submodules.sh
@@ -380,11 +380,7 @@ test_expect_success 'grep --recurse-submodules should pass the pattern type alon
 	fi
 '
 
-# Recursing down into nested submodules which do not have .gitmodules in their
-# working tree does not work yet. This is because config_from_gitmodules()
-# uses get_oid() and the latter is still not able to get objects from an
-# arbitrary repository (the nested submodule, in this case).
-test_expect_failure 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '
+test_expect_success 'grep --recurse-submodules with submodules without .gitmodules in the working tree' '
 	test_when_finished "git -C submodule checkout .gitmodules" &&
 	rm submodule/.gitmodules &&
 	git grep --recurse-submodules -e "(.|.)[\d]" >actual &&
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 32/34] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (30 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 31/34] submodule-config.c: use repo_get_oid for reading .gitmodules Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 33/34] sha1-name.c: remove the_repo from other get_oid_* Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 34/34] sha1-name.c: remove the_repo from get_oid_mb() Nguyễn Thái Ngọc Duy
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 4 +++-
 setup.c     | 7 ++++---
 sha1-name.c | 6 ++++--
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/cache.h b/cache.h
index f6e87194d0..3718b3db8a 100644
--- a/cache.h
+++ b/cache.h
@@ -1387,7 +1387,9 @@ extern int get_oid_committish(const char *str, struct object_id *oid);
 extern int get_oid_tree(const char *str, struct object_id *oid);
 extern int get_oid_treeish(const char *str, struct object_id *oid);
 extern int get_oid_blob(const char *str, struct object_id *oid);
-extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
+void maybe_die_on_misspelt_object_name(struct repository *repo,
+				       const char *name,
+				       const char *prefix);
 extern enum get_oid_result get_oid_with_context(struct repository *repo, const char *str,
 				unsigned flags, struct object_id *oid,
 				struct object_context *oc);
diff --git a/setup.c b/setup.c
index d0c958c3b2..8dcb4631f7 100644
--- a/setup.c
+++ b/setup.c
@@ -164,7 +164,8 @@ int check_filename(const char *prefix, const char *arg)
 	die_errno(_("failed to stat '%s'"), arg);
 }
 
-static void NORETURN die_verify_filename(const char *prefix,
+static void NORETURN die_verify_filename(struct repository *r,
+					 const char *prefix,
 					 const char *arg,
 					 int diagnose_misspelt_rev)
 {
@@ -179,7 +180,7 @@ static void NORETURN die_verify_filename(const char *prefix,
 	 * let maybe_die_on_misspelt_object_name() even trigger.
 	 */
 	if (!(arg[0] == ':' && !isalnum(arg[1])))
-		maybe_die_on_misspelt_object_name(arg, prefix);
+		maybe_die_on_misspelt_object_name(r, arg, prefix);
 
 	/* ... or fall back the most general message. */
 	die(_("ambiguous argument '%s': unknown revision or path not in the working tree.\n"
@@ -234,7 +235,7 @@ void verify_filename(const char *prefix,
 		die(_("option '%s' must come before non-option arguments"), arg);
 	if (looks_like_pathspec(arg) || check_filename(prefix, arg))
 		return;
-	die_verify_filename(prefix, arg, diagnose_misspelt_rev);
+	die_verify_filename(the_repository, prefix, arg, diagnose_misspelt_rev);
 }
 
 /*
diff --git a/sha1-name.c b/sha1-name.c
index 953df0d692..b94d381bef 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1885,11 +1885,13 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
  * exist in 'HEAD'" when given "HEAD:doc", or it may return in which case
  * you have a chance to diagnose the error further.
  */
-void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
+void maybe_die_on_misspelt_object_name(struct repository *r,
+				       const char *name,
+				       const char *prefix)
 {
 	struct object_context oc;
 	struct object_id oid;
-	get_oid_with_context_1(the_repository, name, GET_OID_ONLY_TO_DIE,
+	get_oid_with_context_1(r, name, GET_OID_ONLY_TO_DIE,
 			       prefix, &oid, &oc);
 }
 
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 33/34] sha1-name.c: remove the_repo from other get_oid_*
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (31 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 32/34] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  2019-04-16  9:33       ` [PATCH v4 34/34] sha1-name.c: remove the_repo from get_oid_mb() Nguyễn Thái Ngọc Duy
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     | 18 ++++++++++++------
 sha1-name.c | 35 ++++++++++++++++++++---------------
 2 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/cache.h b/cache.h
index 3718b3db8a..871a167bf8 100644
--- a/cache.h
+++ b/cache.h
@@ -1381,12 +1381,11 @@ enum get_oid_result {
 };
 
 int repo_get_oid(struct repository *r, const char *str, struct object_id *oid);
-#define get_oid(str, oid) repo_get_oid(the_repository, str, oid)
-extern int get_oid_commit(const char *str, struct object_id *oid);
-extern int get_oid_committish(const char *str, struct object_id *oid);
-extern int get_oid_tree(const char *str, struct object_id *oid);
-extern int get_oid_treeish(const char *str, struct object_id *oid);
-extern int get_oid_blob(const char *str, struct object_id *oid);
+int repo_get_oid_commit(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_committish(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid);
 void maybe_die_on_misspelt_object_name(struct repository *repo,
 				       const char *name,
 				       const char *prefix);
@@ -1394,6 +1393,13 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c
 				unsigned flags, struct object_id *oid,
 				struct object_context *oc);
 
+#define get_oid(str, oid)		repo_get_oid(the_repository, str, oid)
+#define get_oid_commit(str, oid)	repo_get_oid_commit(the_repository, str, oid)
+#define get_oid_committish(str, oid)	repo_get_oid_committish(the_repository, str, oid)
+#define get_oid_tree(str, oid)		repo_get_oid_tree(the_repository, str, oid)
+#define get_oid_treeish(str, oid)	repo_get_oid_treeish(the_repository, str, oid)
+#define get_oid_blob(str, oid)		repo_get_oid_blob(the_repository, str, oid)
+
 typedef int each_abbrev_fn(const struct object_id *oid, void *);
 int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);
 #define for_each_abbrev(prefix, fn, data) repo_for_each_abbrev(the_repository, prefix, fn, data)
diff --git a/sha1-name.c b/sha1-name.c
index b94d381bef..d49496397d 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1590,43 +1590,48 @@ int repo_get_oid(struct repository *r, const char *name, struct object_id *oid)
  * commit-ish. It is merely to give a hint to the disambiguation
  * machinery.
  */
-int get_oid_committish(const char *name, struct object_id *oid)
+int repo_get_oid_committish(struct repository *r,
+			    const char *name,
+			    struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_COMMITTISH,
+	return get_oid_with_context(r, name, GET_OID_COMMITTISH,
 				    oid, &unused);
 }
 
-int get_oid_treeish(const char *name, struct object_id *oid)
+int repo_get_oid_treeish(struct repository *r,
+			 const char *name,
+			 struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_TREEISH,
+	return get_oid_with_context(r, name, GET_OID_TREEISH,
 				    oid, &unused);
 }
 
-int get_oid_commit(const char *name, struct object_id *oid)
+int repo_get_oid_commit(struct repository *r,
+			const char *name,
+			struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_COMMIT,
+	return get_oid_with_context(r, name, GET_OID_COMMIT,
 				    oid, &unused);
 }
 
-int get_oid_tree(const char *name, struct object_id *oid)
+int repo_get_oid_tree(struct repository *r,
+		      const char *name,
+		      struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_TREE,
+	return get_oid_with_context(r, name, GET_OID_TREE,
 				    oid, &unused);
 }
 
-int get_oid_blob(const char *name, struct object_id *oid)
+int repo_get_oid_blob(struct repository *r,
+		      const char *name,
+		      struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(the_repository,
-				    name, GET_OID_BLOB,
+	return get_oid_with_context(r, name, GET_OID_BLOB,
 				    oid, &unused);
 }
 
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

* [PATCH v4 34/34] sha1-name.c: remove the_repo from get_oid_mb()
  2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
                         ` (32 preceding siblings ...)
  2019-04-16  9:33       ` [PATCH v4 33/34] sha1-name.c: remove the_repo from other get_oid_* Nguyễn Thái Ngọc Duy
@ 2019-04-16  9:33       ` Nguyễn Thái Ngọc Duy
  33 siblings, 0 replies; 154+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-04-16  9:33 UTC (permalink / raw)
  To: pclouds; +Cc: Johannes.Schindelin, git, gitster, stefanbeller, szeder.dev

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 cache.h     |  3 ++-
 sha1-name.c | 18 +++++++++++-------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/cache.h b/cache.h
index 871a167bf8..9a600a8b50 100644
--- a/cache.h
+++ b/cache.h
@@ -1386,6 +1386,7 @@ int repo_get_oid_committish(struct repository *r, const char *str, struct object
 int repo_get_oid_tree(struct repository *r, const char *str, struct object_id *oid);
 int repo_get_oid_treeish(struct repository *r, const char *str, struct object_id *oid);
 int repo_get_oid_blob(struct repository *r, const char *str, struct object_id *oid);
+int repo_get_oid_mb(struct repository *r, const char *str, struct object_id *oid);
 void maybe_die_on_misspelt_object_name(struct repository *repo,
 				       const char *name,
 				       const char *prefix);
@@ -1399,6 +1400,7 @@ extern enum get_oid_result get_oid_with_context(struct repository *repo, const c
 #define get_oid_tree(str, oid)		repo_get_oid_tree(the_repository, str, oid)
 #define get_oid_treeish(str, oid)	repo_get_oid_treeish(the_repository, str, oid)
 #define get_oid_blob(str, oid)		repo_get_oid_blob(the_repository, str, oid)
+#define get_oid_mb(str, oid) 		repo_get_oid_mb(the_repository, str, oid)
 
 typedef int each_abbrev_fn(const struct object_id *oid, void *);
 int repo_for_each_abbrev(struct repository *r, const char *prefix, each_abbrev_fn, void *);
@@ -1486,7 +1488,6 @@ int repo_interpret_branch_name(struct repository *r,
 			       unsigned allowed);
 #define interpret_branch_name(str, len, buf, allowed) \
 	repo_interpret_branch_name(the_repository, str, len, buf, allowed)
-extern int get_oid_mb(const char *str, struct object_id *oid);
 
 extern int validate_headref(const char *ref);
 
diff --git a/sha1-name.c b/sha1-name.c
index d49496397d..cf314ebb29 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -1338,7 +1338,9 @@ static int interpret_nth_prior_checkout(struct repository *r,
 	return retval;
 }
 
-int get_oid_mb(const char *name, struct object_id *oid)
+int repo_get_oid_mb(struct repository *r,
+		    const char *name,
+		    struct object_id *oid)
 {
 	struct commit *one, *two;
 	struct commit_list *mbs;
@@ -1348,27 +1350,29 @@ int get_oid_mb(const char *name, struct object_id *oid)
 
 	dots = strstr(name, "...");
 	if (!dots)
-		return get_oid(name, oid);
+		return repo_get_oid(r, name, oid);
 	if (dots == name)
-		st = get_oid("HEAD", &oid_tmp);
+		st = repo_get_oid(r, "HEAD", &oid_tmp);
 	else {
 		struct strbuf sb;
 		strbuf_init(&sb, dots - name);
 		strbuf_add(&sb, name, dots - name);
-		st = get_oid_committish(sb.buf, &oid_tmp);
+		st = repo_get_oid_committish(r, sb.buf, &oid_tmp);
 		strbuf_release(&sb);
 	}
 	if (st)
 		return st;
-	one = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);
+	one = lookup_commit_reference_gently(r, &oid_tmp, 0);
 	if (!one)
 		return -1;
 
-	if (get_oid_committish(dots[3] ? (dots + 3) : "HEAD", &oid_tmp))
+	if (repo_get_oid_committish(r, dots[3] ? (dots + 3) : "HEAD", &oid_tmp))
 		return -1;
-	two = lookup_commit_reference_gently(the_repository, &oid_tmp, 0);
+	two = lookup_commit_reference_gently(r, &oid_tmp, 0);
 	if (!two)
 		return -1;
+	if (r != the_repository)
+		BUG("sorry get_merge_bases() can't take struct repository yet");
 	mbs = get_merge_bases(one, two);
 	if (!mbs || mbs->next)
 		st = -1;
-- 
2.21.0.682.g30d2204636


^ permalink raw reply related	[flat|nested] 154+ messages in thread

end of thread, other threads:[~2019-04-16  9:37 UTC | newest]

Thread overview: 154+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-30 11:18 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
2019-03-30 11:18 ` [PATCH 01/31] packfile.c: add repo_approximate_object_count() Nguyễn Thái Ngọc Duy
2019-03-30 11:18 ` [PATCH 02/31] refs.c: add refs_ref_exists() Nguyễn Thái Ngọc Duy
2019-03-30 11:18 ` [PATCH 03/31] refs.c: add refs_shorten_unambiguous_ref() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 04/31] refs.c: remove the_repo from substitute_branch_name() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 05/31] refs.c: remove the_repo from expand_ref() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 06/31] refs.c: add repo_dwim_ref() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 07/31] refs.c: add repo_dwim_log() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 08/31] refs.c: remove the_repo from read_ref_at() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 09/31] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
2019-04-02 15:39   ` SZEDER Gábor
2019-03-30 11:19 ` [PATCH 10/31] sha1-name.c: remove the_repo from sort_ambiguous() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 11/31] sha1-name.c: remove the_repo from find_abbrev_len_packed() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 12/31] sha1-name.c: add repo_find_unique_abbrev_r() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 13/31] sha1-name.c: store and use repo in struct disambiguate_state Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 14/31] sha1-name.c: add repo_for_each_abbrev() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 15/31] sha1-name.c: remove the_repo from get_short_oid() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 16/31] sha1-name.c: remove the_repo from interpret_nth_prior_checkout() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 17/31] sha1-name.c: remove the_repo from interpret_branch_mark() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 18/31] sha1-name.c: add repo_interpret_branch_name() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 19/31] sha1-name.c: remove the_repo from get_oid_oneline() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 20/31] sha1-name.c: remove the_repo from get_describe_name() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 21/31] sha1-name.c: remove the_repo from get_oid_basic() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 22/31] sha1-name.c: remove the_repo from get_oid_1() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 23/31] sha1-name.c: remove the_repo from handle_one_ref() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 24/31] sha1-name.c: remove the_repo from diagnose_invalid_index_path() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 25/31] sha1-name.c: remove the_repo from resolve_relative_path() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 26/31] sha1-name.c: remove the_repo from get_oid_with_context_1() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 27/31] sha1-name.c: add repo_get_oid() Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 28/31] submodule-config.c: use repo_get_oid for reading .gitmodules Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 29/31] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 30/31] sha1-name.c: remove the_repo from other get_oid_* Nguyễn Thái Ngọc Duy
2019-03-30 11:19 ` [PATCH 31/31] sha1-name.c: remove the_repo from get_oid_mb() Nguyễn Thái Ngọc Duy
2019-04-03 11:34 ` [PATCH v2 00/32] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 01/32] rebase: 'make coccicheck' cleanup Nguyễn Thái Ngọc Duy
2019-04-04 17:25     ` SZEDER Gábor
2019-04-05  9:26       ` Duy Nguyen
2019-04-09 10:58         ` SZEDER Gábor
2019-04-03 11:34   ` [PATCH v2 02/32] packfile.c: add repo_approximate_object_count() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 03/32] refs.c: add refs_ref_exists() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 04/32] refs.c: add refs_shorten_unambiguous_ref() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 05/32] refs.c: remove the_repo from substitute_branch_name() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 06/32] refs.c: remove the_repo from expand_ref() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 07/32] refs.c: add repo_dwim_ref() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 08/32] refs.c: add repo_dwim_log() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 09/32] refs.c: remove the_repo from read_ref_at() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 10/32] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
2019-04-04 17:04     ` SZEDER Gábor
2019-04-05  9:32       ` Duy Nguyen
2019-04-05 18:13         ` Johannes Schindelin
2019-04-03 11:34   ` [PATCH v2 11/32] sha1-name.c: remove the_repo from sort_ambiguous() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 12/32] sha1-name.c: remove the_repo from find_abbrev_len_packed() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 13/32] sha1-name.c: add repo_find_unique_abbrev_r() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 14/32] sha1-name.c: store and use repo in struct disambiguate_state Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 15/32] sha1-name.c: add repo_for_each_abbrev() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 16/32] sha1-name.c: remove the_repo from get_short_oid() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 17/32] sha1-name.c: remove the_repo from interpret_nth_prior_checkout() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 18/32] sha1-name.c: remove the_repo from interpret_branch_mark() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 19/32] sha1-name.c: add repo_interpret_branch_name() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 20/32] sha1-name.c: remove the_repo from get_oid_oneline() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 21/32] sha1-name.c: remove the_repo from get_describe_name() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 22/32] sha1-name.c: remove the_repo from get_oid_basic() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 23/32] sha1-name.c: remove the_repo from get_oid_1() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 24/32] sha1-name.c: remove the_repo from handle_one_ref() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 25/32] sha1-name.c: remove the_repo from diagnose_invalid_index_path() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 26/32] sha1-name.c: remove the_repo from resolve_relative_path() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 27/32] sha1-name.c: remove the_repo from get_oid_with_context_1() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 28/32] sha1-name.c: add repo_get_oid() Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 29/32] submodule-config.c: use repo_get_oid for reading .gitmodules Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 30/32] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 31/32] sha1-name.c: remove the_repo from other get_oid_* Nguyễn Thái Ngọc Duy
2019-04-03 11:34   ` [PATCH v2 32/32] sha1-name.c: remove the_repo from get_oid_mb() Nguyễn Thái Ngọc Duy
2019-04-06 11:34   ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 01/33] builtin rebase: use FREE_AND_NULL Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 02/33] builtin rebase: use oideq() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 03/33] packfile.c: add repo_approximate_object_count() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 04/33] refs.c: add refs_ref_exists() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 05/33] refs.c: add refs_shorten_unambiguous_ref() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 06/33] refs.c: remove the_repo from substitute_branch_name() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 07/33] refs.c: remove the_repo from expand_ref() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 08/33] refs.c: add repo_dwim_ref() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 09/33] refs.c: add repo_dwim_log() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 10/33] refs.c: remove the_repo from read_ref_at() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 11/33] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 12/33] sha1-name.c: remove the_repo from sort_ambiguous() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 13/33] sha1-name.c: remove the_repo from find_abbrev_len_packed() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 14/33] sha1-name.c: add repo_find_unique_abbrev_r() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 15/33] sha1-name.c: store and use repo in struct disambiguate_state Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 16/33] sha1-name.c: add repo_for_each_abbrev() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 17/33] sha1-name.c: remove the_repo from get_short_oid() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 18/33] sha1-name.c: remove the_repo from interpret_nth_prior_checkout() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 19/33] sha1-name.c: remove the_repo from interpret_branch_mark() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 20/33] sha1-name.c: add repo_interpret_branch_name() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 21/33] sha1-name.c: remove the_repo from get_oid_oneline() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 22/33] sha1-name.c: remove the_repo from get_describe_name() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 23/33] sha1-name.c: remove the_repo from get_oid_basic() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 24/33] sha1-name.c: remove the_repo from get_oid_1() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 25/33] sha1-name.c: remove the_repo from handle_one_ref() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 26/33] sha1-name.c: remove the_repo from diagnose_invalid_index_path() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 27/33] sha1-name.c: remove the_repo from resolve_relative_path() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 28/33] sha1-name.c: remove the_repo from get_oid_with_context_1() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 29/33] sha1-name.c: add repo_get_oid() Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 30/33] submodule-config.c: use repo_get_oid for reading .gitmodules Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 31/33] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 32/33] sha1-name.c: remove the_repo from other get_oid_* Nguyễn Thái Ngọc Duy
2019-04-06 11:34     ` [PATCH v3 33/33] sha1-name.c: remove the_repo from get_oid_mb() Nguyễn Thái Ngọc Duy
2019-04-10 20:56     ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates Johannes Schindelin
2019-04-11  0:26       ` Duy Nguyen
2019-04-11 20:36         ` Johannes Schindelin
2019-04-11 20:51       ` SZEDER Gábor
2019-04-11 20:58         ` SZEDER Gábor
2019-04-12  0:17           ` SZEDER Gábor
2019-04-12 14:25             ` Johannes Schindelin
2019-04-13 10:16               ` [PATCH v3* 11/33] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
2019-04-13 12:22                 ` SZEDER Gábor
2019-04-15 13:20                 ` Johannes Schindelin
2019-04-13 12:14               ` [PATCH v3 00/33] nd/sha1-name-c-wo-the-repository updates SZEDER Gábor
2019-04-13 14:00                 ` Duy Nguyen
2019-04-16  9:33     ` [PATCH v4 00/34] " Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 01/34] builtin rebase: use FREE_AND_NULL Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 02/34] builtin rebase: use oideq() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 03/34] packfile.c: add repo_approximate_object_count() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 04/34] refs.c: add refs_ref_exists() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 05/34] refs.c: add refs_shorten_unambiguous_ref() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 06/34] refs.c: remove the_repo from substitute_branch_name() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 07/34] refs.c: remove the_repo from expand_ref() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 08/34] refs.c: add repo_dwim_ref() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 09/34] refs.c: add repo_dwim_log() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 10/34] refs.c: remove the_repo from read_ref_at() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 11/34] commit.cocci: refactor code, avoid double rewrite Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 12/34] commit.c: add repo_get_commit_tree() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 13/34] sha1-name.c: remove the_repo from sort_ambiguous() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 14/34] sha1-name.c: remove the_repo from find_abbrev_len_packed() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 15/34] sha1-name.c: add repo_find_unique_abbrev_r() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 16/34] sha1-name.c: store and use repo in struct disambiguate_state Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 17/34] sha1-name.c: add repo_for_each_abbrev() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 18/34] sha1-name.c: remove the_repo from get_short_oid() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 19/34] sha1-name.c: remove the_repo from interpret_nth_prior_checkout() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 20/34] sha1-name.c: remove the_repo from interpret_branch_mark() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 21/34] sha1-name.c: add repo_interpret_branch_name() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 22/34] sha1-name.c: remove the_repo from get_oid_oneline() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 23/34] sha1-name.c: remove the_repo from get_describe_name() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 24/34] sha1-name.c: remove the_repo from get_oid_basic() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 25/34] sha1-name.c: remove the_repo from get_oid_1() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 26/34] sha1-name.c: remove the_repo from handle_one_ref() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 27/34] sha1-name.c: remove the_repo from diagnose_invalid_index_path() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 28/34] sha1-name.c: remove the_repo from resolve_relative_path() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 29/34] sha1-name.c: remove the_repo from get_oid_with_context_1() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 30/34] sha1-name.c: add repo_get_oid() Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 31/34] submodule-config.c: use repo_get_oid for reading .gitmodules Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 32/34] sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_name Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 33/34] sha1-name.c: remove the_repo from other get_oid_* Nguyễn Thái Ngọc Duy
2019-04-16  9:33       ` [PATCH v4 34/34] sha1-name.c: remove the_repo from get_oid_mb() Nguyễn Thái Ngọc Duy
  -- strict thread matches above, loose matches on Subject: below --
2019-02-17 10:08 [PATCH 00/31] Kill the_repository in sha1-name.c Nguyễn Thái Ngọc Duy
2019-02-17 10:08 ` [PATCH 16/31] sha1-name.c: remove the_repo from interpret_nth_prior_checkout() Nguyễn Thái Ngọc Duy

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).