object-file: rename variables in `check_collision()`

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jan 6, 2025 at 10:24 UTC c1acf1a31761d0cfddc3ea6d39c92a6528cd9c5c
1 file changed +20 -20
object-file.c
+20 -20
@@ -1974,56 +1974,56 @@ static void write_object_file_prepare_literally(const struct git_hash_algo *algo
1974 hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen);
1975 }
1976
1977 -static int check_collision(const char *filename_a, const char *filename_b)
1977 +static int check_collision(const char *source, const char *dest)
1978 {
1979 - char buf_a[4096], buf_b[4096];
1980 - int fd_a = -1, fd_b = -1;
1979 + char buf_source[4096], buf_dest[4096];
1980 + int fd_source = -1, fd_dest = -1;
1981 int ret = 0;
1982
1983 - fd_a = open(filename_a, O_RDONLY);
1984 - if (fd_a < 0) {
1983 + fd_source = open(source, O_RDONLY);
1984 + if (fd_source < 0) {
1985 if (errno != ENOENT)
1986 - ret = error_errno(_("unable to open %s"), filename_a);
1986 + ret = error_errno(_("unable to open %s"), source);
1987 goto out;
1988 }
1989
1990 - fd_b = open(filename_b, O_RDONLY);
1991 - if (fd_b < 0) {
1990 + fd_dest = open(dest, O_RDONLY);
1991 + if (fd_dest < 0) {
1992 if (errno != ENOENT)
1993 - ret = error_errno(_("unable to open %s"), filename_b);
1993 + ret = error_errno(_("unable to open %s"), dest);
1994 goto out;
1995 }
1996
1997 while (1) {
1998 ssize_t sz_a, sz_b;
1999
2000 - sz_a = read_in_full(fd_a, buf_a, sizeof(buf_a));
2000 + sz_a = read_in_full(fd_source, buf_source, sizeof(buf_source));
2001 if (sz_a < 0) {
2002 - ret = error_errno(_("unable to read %s"), filename_a);
2002 + ret = error_errno(_("unable to read %s"), source);
2003 goto out;
2004 }
2005
2006 - sz_b = read_in_full(fd_b, buf_b, sizeof(buf_b));
2006 + sz_b = read_in_full(fd_dest, buf_dest, sizeof(buf_dest));
2007 if (sz_b < 0) {
2008 - ret = error_errno(_("unable to read %s"), filename_b);
2008 + ret = error_errno(_("unable to read %s"), dest);
2009 goto out;
2010 }
2011
2012 - if (sz_a != sz_b || memcmp(buf_a, buf_b, sz_a)) {
2012 + if (sz_a != sz_b || memcmp(buf_source, buf_dest, sz_a)) {
2013 ret = error(_("files '%s' and '%s' differ in contents"),
2014 - filename_a, filename_b);
2014 + source, dest);
2015 goto out;
2016 }
2017
2018 - if (sz_a < sizeof(buf_a))
2018 + if (sz_a < sizeof(buf_source))
2019 break;
2020 }
2021
2022 out:
2023 - if (fd_a > -1)
2024 - close(fd_a);
2025 - if (fd_b > -1)
2026 - close(fd_b);
2023 + if (fd_source > -1)
2024 + close(fd_source);
2025 + if (fd_dest > -1)
2026 + close(fd_dest);
2027 return ret;
2028 }
2029