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

[PATCH 1/3] read-cache.c: change type of "temp" in write_shared_index()

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jan 24, 2018, 09:38 UTC
Message-ID
<20180124093829.12966-2-pclouds@gmail.com>
In-Reply-To
<20180124093829.12966-1-pclouds@gmail.com>

This local variable 'temp' will be passed in from the caller in the next patch. To reduce patch noise, let's change its type now while it's still a local variable and get all the trival conversion out of the next patch.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 read-cache.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index 2eb81a66b9..536086e1fe 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2474,30 +2474,32 @@ static int clean_shared_index_files(const char *current_hex)
 static int write_shared_index(struct index_state *istate,
 			      struct lock_file *lock, unsigned flags)
 {
-	struct tempfile *temp;
+	struct tempfile *real_temp;
+	struct tempfile **temp = &real_temp;
 	struct split_index *si = istate->split_index;
 	int ret;
 
-	temp = mks_tempfile(git_path("sharedindex_XXXXXX"));
-	if (!temp) {
+	real_temp = mks_tempfile(git_path("sharedindex_XXXXXX"));
+	if (!real_temp) {
 		hashclr(si->base_sha1);
 		return do_write_locked_index(istate, lock, flags);
 	}
+	temp = &real_temp;
 	move_cache_to_base_index(istate);
-	ret = do_write_index(si->base, temp, 1);
+	ret = do_write_index(si->base, *temp, 1);
 	if (ret) {
-		delete_tempfile(&temp);
+		delete_tempfile(temp);
 		return ret;
 	}
-	ret = adjust_shared_perm(get_tempfile_path(temp));
+	ret = adjust_shared_perm(get_tempfile_path(*temp));
 	if (ret) {
 		int save_errno = errno;
-		error("cannot fix permission bits on %s", get_tempfile_path(temp));
-		delete_tempfile(&temp);
+		error("cannot fix permission bits on %s", get_tempfile_path(*temp));
+		delete_tempfile(temp);
 		errno = save_errno;
 		return ret;
 	}
-	ret = rename_tempfile(&temp,
+	ret = rename_tempfile(temp,
 			      git_path("sharedindex.%s", sha1_to_hex(si->base->sha1)));
 	if (!ret) {
 		hashcpy(si->base_sha1, si->base->sha1);
-- 
2.16.0.47.g3d9b0fac3a
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 8 of 11 in “nd/shared-index-fix update”
  1. 0/3 nd/shared-index-fix updateNguyễn Thái Ngọc Duy, Jan 22, 2018
  2. 1/3 read-cache.c: change type of "temp" in write_shared_index()Nguyễn Thái Ngọc Duy, Jan 22, 2018
  3. 2/3 read-cache.c: move tempfile creation/cleanup out of write_shared_indexNguyễn Thái Ngọc Duy, Jan 22, 2018
  4. 3/3 read-cache: don't write index twice if we can't write shared indexNguyễn Thái Ngọc Duy, Jan 22, 2018
  5. Junio C HamanoJan 22, 2018
  6. Duy NguyenJan 23, 2018
  7. 0/3 nd/shared-index-fix updatesNguyễn Thái Ngọc Duy, Jan 24, 2018
  8. 1/3 read-cache.c: change type of "temp" in write_shared_index()Nguyễn Thái Ngọc Duy, Jan 24, 2018
  9. 2/3 read-cache.c: move tempfile creation/cleanup out of write_shared_indexNguyễn Thái Ngọc Duy, Jan 24, 2018
  10. 3/3 read-cache: don't write index twice if we can't write shared indexNguyễn Thái Ngọc Duy, Jan 24, 2018
  11. Junio C HamanoJan 24, 2018

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.