odb: consistently use "dir" to refer to alternate's directory

The functions that add an alternate object directory to the object database are somewhat inconsistent in how they call the paramater that refers to the directory path: in our headers we refer to it as "dir", whereas in the implementation we often call it "reference" or "entry". Unify this and consistently call the parameter "dir". While at it, refactor `link_alt_odb_entry()` to accept a C string instead of a `struct strbuf` as parameter to clarify that we really only need the path and nothing else. Suggested-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Aug 11, 2025 at 15:46 UTC 25c532f6e0797ef501ce43835fb4af4bd9c33de5
1 file changed +14 -16
odb.c
+14 -16
@@ -140,7 +140,7 @@ static void read_info_alternates(struct object_database *odb,
140 int depth);
141
142 static int link_alt_odb_entry(struct object_database *odb,
143 - const struct strbuf *entry,
143 + const char *dir,
144 const char *relative_base,
145 int depth,
146 const char *normalized_objdir)
@@ -151,11 +151,11 @@ static int link_alt_odb_entry(struct object_database *odb,
151 khiter_t pos;
152 int ret = -1;
153
154 - if (!is_absolute_path(entry->buf) && relative_base) {
154 + if (!is_absolute_path(dir) && relative_base) {
155 strbuf_realpath(&pathbuf, relative_base, 1);
156 strbuf_addch(&pathbuf, '/');
157 }
158 - strbuf_addbuf(&pathbuf, entry);
158 + strbuf_addstr(&pathbuf, dir);
159
160 if (!strbuf_realpath(&tmp, pathbuf.buf, 0)) {
161 error(_("unable to normalize alternate object path: %s"),
@@ -229,7 +229,7 @@ static void link_alt_odb_entries(struct object_database *odb, const char *alt,
229 int sep, const char *relative_base, int depth)
230 {
231 struct strbuf objdirbuf = STRBUF_INIT;
232 - struct strbuf entry = STRBUF_INIT;
232 + struct strbuf dir = STRBUF_INIT;
233
234 if (!alt || !*alt)
235 return;
@@ -243,13 +243,13 @@ static void link_alt_odb_entries(struct object_database *odb, const char *alt,
243 strbuf_realpath(&objdirbuf, odb->sources->path, 1);
244
245 while (*alt) {
246 - alt = parse_alt_odb_entry(alt, sep, &entry);
247 - if (!entry.len)
246 + alt = parse_alt_odb_entry(alt, sep, &dir);
247 + if (!dir.len)
248 continue;
249 - link_alt_odb_entry(odb, &entry,
249 + link_alt_odb_entry(odb, dir.buf,
250 relative_base, depth, objdirbuf.buf);
251 }
252 - strbuf_release(&entry);
252 + strbuf_release(&dir);
253 strbuf_release(&objdirbuf);
254 }
255
@@ -273,7 +273,7 @@ static void read_info_alternates(struct object_database *odb,
273 }
274
275 void odb_add_to_alternates_file(struct object_database *odb,
276 - const char *reference)
276 + const char *dir)
277 {
278 struct lock_file lock = LOCK_INIT;
279 char *alts = repo_git_path(odb->repo, "objects/info/alternates");
@@ -290,7 +290,7 @@ void odb_add_to_alternates_file(struct object_database *odb,
290 struct strbuf line = STRBUF_INIT;
291
292 while (strbuf_getline(&line, in) != EOF) {
293 - if (!strcmp(reference, line.buf)) {
293 + if (!strcmp(dir, line.buf)) {
294 found = 1;
295 break;
296 }
@@ -306,18 +306,17 @@ void odb_add_to_alternates_file(struct object_database *odb,
306 if (found) {
307 rollback_lock_file(&lock);
308 } else {
309 - fprintf_or_die(out, "%s\n", reference);
309 + fprintf_or_die(out, "%s\n", dir);
310 if (commit_lock_file(&lock))
311 die_errno(_("unable to move new alternates file into place"));
312 if (odb->loaded_alternates)
313 - link_alt_odb_entries(odb, reference,
314 - '\n', NULL, 0);
313 + link_alt_odb_entries(odb, dir, '\n', NULL, 0);
314 }
315 free(alts);
316 }
317
318 void odb_add_to_alternates_memory(struct object_database *odb,
320 - const char *reference)
319 + const char *dir)
320 {
321 /*
322 * Make sure alternates are initialized, or else our entry may be
@@ -325,8 +324,7 @@ void odb_add_to_alternates_memory(struct object_database *odb,
324 */
325 odb_prepare_alternates(odb);
326
328 - link_alt_odb_entries(odb, reference,
329 - '\n', NULL, 0);
327 + link_alt_odb_entries(odb, dir, '\n', NULL, 0);
328 }
329
330 struct odb_source *odb_set_temporary_primary_source(struct object_database *odb,