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

Re: [PATCH][RFC] read-cache: read_index_from() accepts repo as arg

From
Duy Nguyen <pclouds@gmail.com>
Date
Apr 7, 2019, 10:19 UTC
Message-ID
<20190407101938.GA24126@ash>
In-Reply-To
<20190407100010.GA23427@ash>
On Sun, Apr 07, 2019 at 05:00:11PM +0700, Duy Nguyen wrote:
Show 9 quoted lines
> So, with something like a patch below (not tested), you should be able
> to write
> 
> 	worktrees = repo_get_worktrees(revs->repo, 0);
> 	...
> 		struct repository *r = repo_worktree_init(wt);
> 		if (read_index_from(&istate, r->index_file, r) > 0)
> 			do_add_index_objects_to_pending(revs, &istate, flags);
> 		repo_clear(r);
Actually it gets better. You can just use repo_read_index()
diff --git a/revision.c b/revision.c
index eb8e51bc63..93fe8bbbfe 100644
--- a/revision.c
+++ b/revision.c
@@ -1546,19 +1546,18 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
 	if (revs->single_worktree)
 		return;
 
-	worktrees = get_worktrees(0);
+	worktrees = repo_get_worktrees(revs->repo);
 	for (p = worktrees; *p; p++) {
+		struct repository repo;
 		struct worktree *wt = *p;
-		struct index_state istate = { NULL };
 
 		if (wt->is_current)
 			continue; /* current index already taken care of */
 
-		if (read_index_from(&istate,
-				    worktree_git_path(wt, "index"),
-				    get_worktree_git_dir(wt)) > 0)
-			do_add_index_objects_to_pending(revs, &istate, flags);
-		discard_index(&istate);
+		repo_worktree_init(repo, revs->repo, wt);
+		if (repo_read_index(repo) > 0)
+			do_add_index_objects_to_pending(revs, repo->index, flags);
+		repo_clear(&repo);
 	}
 	free_worktrees(worktrees);
 }
--
Duy
Previous: Duy NguyenNext: Taylor Blau
Message 3 of 4 in “[RFC] read-cache: read_index_from() accepts repo as arg”
  1. [RFC] read-cache: read_index_from() accepts repo as argKapil Jain, Apr 7, 2019
  2. Duy NguyenApr 7, 2019
  3. Duy NguyenApr 7, 2019
  4. Taylor BlauApr 9, 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.