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

[PATCH v2 1/3] object-file: rename variables in `check_collision()`

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 6, 2025, 09:24 UTC
Message-ID
<20250106-b4-pks-object-file-racy-collision-check-v2-1-8b3984ecbb18@pks.im>
In-Reply-To
<20250106-b4-pks-object-file-racy-collision-check-v2-0-8b3984ecbb18@pks.im>

Rename variables used in `check_collision()` to clearly identify which file is the source and which is the destination. This will make the next step easier to reason about when we start to treat those files different from one another.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 object-file.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/object-file.c b/object-file.c
index f84dcd2f2a7b88716ab47bc00ee7a605a82e8d21..e1989236ca87e565dea4d003f57882f257889ecf 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1970,56 +1970,56 @@ static void write_object_file_prepare_literally(const struct git_hash_algo *algo
 	hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen);
 }
 
-static int check_collision(const char *filename_a, const char *filename_b)
+static int check_collision(const char *source, const char *dest)
 {
-	char buf_a[4096], buf_b[4096];
-	int fd_a = -1, fd_b = -1;
+	char buf_source[4096], buf_dest[4096];
+	int fd_source = -1, fd_dest = -1;
 	int ret = 0;
 
-	fd_a = open(filename_a, O_RDONLY);
-	if (fd_a < 0) {
+	fd_source = open(source, O_RDONLY);
+	if (fd_source < 0) {
 		if (errno != ENOENT)
-			ret = error_errno(_("unable to open %s"), filename_a);
+			ret = error_errno(_("unable to open %s"), source);
 		goto out;
 	}
 
-	fd_b = open(filename_b, O_RDONLY);
-	if (fd_b < 0) {
+	fd_dest = open(dest, O_RDONLY);
+	if (fd_dest < 0) {
 		if (errno != ENOENT)
-			ret = error_errno(_("unable to open %s"), filename_b);
+			ret = error_errno(_("unable to open %s"), dest);
 		goto out;
 	}
 
 	while (1) {
 		ssize_t sz_a, sz_b;
 
-		sz_a = read_in_full(fd_a, buf_a, sizeof(buf_a));
+		sz_a = read_in_full(fd_source, buf_source, sizeof(buf_source));
 		if (sz_a < 0) {
-			ret = error_errno(_("unable to read %s"), filename_a);
+			ret = error_errno(_("unable to read %s"), source);
 			goto out;
 		}
 
-		sz_b = read_in_full(fd_b, buf_b, sizeof(buf_b));
+		sz_b = read_in_full(fd_dest, buf_dest, sizeof(buf_dest));
 		if (sz_b < 0) {
-			ret = error_errno(_("unable to read %s"), filename_b);
+			ret = error_errno(_("unable to read %s"), dest);
 			goto out;
 		}
 
-		if (sz_a != sz_b || memcmp(buf_a, buf_b, sz_a)) {
+		if (sz_a != sz_b || memcmp(buf_source, buf_dest, sz_a)) {
 			ret = error(_("files '%s' and '%s' differ in contents"),
-				    filename_a, filename_b);
+				    source, dest);
 			goto out;
 		}
 
-		if (sz_a < sizeof(buf_a))
+		if (sz_a < sizeof(buf_source))
 			break;
 	}
 
 out:
-	if (fd_a > -1)
-		close(fd_a);
-	if (fd_b > -1)
-		close(fd_b);
+	if (fd_source > -1)
+		close(fd_source);
+	if (fd_dest > -1)
+		close(fd_dest);
 	return ret;
 }
 
-- 
2.48.0.rc1.245.gb3e6e7acbc.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 14 of 16 in “object-file: retry linking file into place when occluding file vanishes”
  1. 0/2 object-file: retry linking file into place when occluding file vanishesPatrick Steinhardt, Jan 3, 2025
  2. 1/2 object-file: rename variables in `check_collision()`Patrick Steinhardt, Jan 3, 2025
  3. Jeff KingJan 3, 2025
  4. 2/2 object-file: retry linking file into place when occluding file vanishesPatrick Steinhardt, Jan 3, 2025
  5. Junio C HamanoJan 3, 2025
  6. Jeff KingJan 3, 2025
  7. Jeff KingJan 3, 2025
  8. Junio C HamanoJan 3, 2025
  9. Patrick SteinhardtJan 6, 2025
  10. Jeff KingJan 7, 2025
  11. Junio C HamanoJan 3, 2025
  12. Patrick SteinhardtJan 6, 2025
  13. 0/3 object-file: retry linking file into place when occluding file vanishesPatrick Steinhardt, Jan 6, 2025
  14. 1/3 object-file: rename variables in `check_collision()`Patrick Steinhardt, Jan 6, 2025
  15. 2/3 object-file: don't special-case missing source file in collision checkPatrick Steinhardt, Jan 6, 2025
  16. 3/3 object-file: retry linking file into place when occluding file vanishesPatrick Steinhardt, Jan 6, 2025

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.