git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 16/31] sha1-name.c: remove the_repo from interpret_nth_prior_checkout()

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Feb 17, 2019, 10:08 UTC
Message-ID
<20190217100913.4127-17-pclouds@gmail.com>
In-Reply-To
<20190217100913.4127-1-pclouds@gmail.com>
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
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 17 of 32 in “Kill the_repository in sha1-name.c”
  1. 00/31 Kill the_repository in sha1-name.cNguyễn Thái Ngọc Duy, Feb 17, 2019
  2. 01/31 packfile.c: add repo_approximate_object_count()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  3. 02/31 refs.c: add refs_ref_exists()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  4. 03/31 refs.c: add refs_shorten_unambiguous_ref()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  5. 04/31 refs.c: remove the_repo from substitute_branch_name()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  6. 05/31 refs.c: remove the_repo from expand_ref()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  7. 06/31 refs.c: add repo_dwim_ref()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  8. 07/31 refs.c: add repo_dwim_log()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  9. 08/31 refs.c: remove the_repo from read_ref_at()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  10. 09/31 commit.c: add repo_get_commit_tree()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  11. 10/31 sha1-name.c: remove the_repo from sort_ambiguous()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  12. 11/31 sha1-name.c: remove the_repo from find_abbrev_len_packed()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  13. 12/31 sha1-name.c: add repo_find_unique_abbrev_r()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  14. 13/31 sha1-name.c: store and use repo in struct disambiguate_stateNguyễn Thái Ngọc Duy, Feb 17, 2019
  15. 14/31 sha1-name.c: add repo_for_each_abbrev()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  16. 15/31 sha1-name.c: remove the_repo from get_short_oid()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  17. 16/31 sha1-name.c: remove the_repo from interpret_nth_prior_checkout()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  18. 17/31 sha1-name.c: remove the_repo from interpret_branch_mark()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  19. 18/31 sha1-name.c: add repo_interpret_branch_name()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  20. 19/31 sha1-name.c: remove the_repo from get_oid_oneline()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  21. 20/31 sha1-name.c: remove the_repo from get_describe_name()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  22. 21/31 sha1-name.c: remove the_repo from get_oid_basic()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  23. 23/31 sha1-name.c: remove the_repo from handle_one_ref()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  24. 22/31 sha1-name.c: remove the_repo from get_oid_1()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  25. 24/31 sha1-name.c: remove the_repo from diagnose_invalid_index_path()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  26. 25/31 sha1-name.c: remove the_repo from resolve_relative_path()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  27. 26/31 sha1-name.c: remove the_repo from get_oid_with_context_1()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  28. 27/31 sha1-name.c: add repo_get_oid()Nguyễn Thái Ngọc Duy, Feb 17, 2019
  29. 28/31 submodule-config.c: use repo_get_oid for reading .gitmodulesNguyễn Thái Ngọc Duy, Feb 17, 2019
  30. 29/31 sha1-name.c: remove the_repo from maybe_die_on_misspelt_object_nameNguyễn Thái Ngọc Duy, Feb 17, 2019
  31. 30/31 sha1-name.c: remove the_repo from other get_oid_*Nguyễn Thái Ngọc Duy, Feb 17, 2019
  32. 31/31 sha1-name.c: remove the_repo from get_oid_mb()Nguyễn Thái Ngọc Duy, Feb 17, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.