Skip to content

Commit 25c532f

Browse files
pks-tgitster
authored andcommitted
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>
1 parent 0d61933 commit 25c532f

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

odb.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static void read_info_alternates(struct object_database *odb,
140140
int depth);
141141

142142
static int link_alt_odb_entry(struct object_database *odb,
143-
const struct strbuf *entry,
143+
const char *dir,
144144
const char *relative_base,
145145
int depth,
146146
const char *normalized_objdir)
@@ -151,11 +151,11 @@ static int link_alt_odb_entry(struct object_database *odb,
151151
khiter_t pos;
152152
int ret = -1;
153153

154-
if (!is_absolute_path(entry->buf) && relative_base) {
154+
if (!is_absolute_path(dir) && relative_base) {
155155
strbuf_realpath(&pathbuf, relative_base, 1);
156156
strbuf_addch(&pathbuf, '/');
157157
}
158-
strbuf_addbuf(&pathbuf, entry);
158+
strbuf_addstr(&pathbuf, dir);
159159

160160
if (!strbuf_realpath(&tmp, pathbuf.buf, 0)) {
161161
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,
229229
int sep, const char *relative_base, int depth)
230230
{
231231
struct strbuf objdirbuf = STRBUF_INIT;
232-
struct strbuf entry = STRBUF_INIT;
232+
struct strbuf dir = STRBUF_INIT;
233233

234234
if (!alt || !*alt)
235235
return;
@@ -243,13 +243,13 @@ static void link_alt_odb_entries(struct object_database *odb, const char *alt,
243243
strbuf_realpath(&objdirbuf, odb->sources->path, 1);
244244

245245
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)
248248
continue;
249-
link_alt_odb_entry(odb, &entry,
249+
link_alt_odb_entry(odb, dir.buf,
250250
relative_base, depth, objdirbuf.buf);
251251
}
252-
strbuf_release(&entry);
252+
strbuf_release(&dir);
253253
strbuf_release(&objdirbuf);
254254
}
255255

@@ -273,7 +273,7 @@ static void read_info_alternates(struct object_database *odb,
273273
}
274274

275275
void odb_add_to_alternates_file(struct object_database *odb,
276-
const char *reference)
276+
const char *dir)
277277
{
278278
struct lock_file lock = LOCK_INIT;
279279
char *alts = repo_git_path(odb->repo, "objects/info/alternates");
@@ -290,7 +290,7 @@ void odb_add_to_alternates_file(struct object_database *odb,
290290
struct strbuf line = STRBUF_INIT;
291291

292292
while (strbuf_getline(&line, in) != EOF) {
293-
if (!strcmp(reference, line.buf)) {
293+
if (!strcmp(dir, line.buf)) {
294294
found = 1;
295295
break;
296296
}
@@ -306,27 +306,25 @@ void odb_add_to_alternates_file(struct object_database *odb,
306306
if (found) {
307307
rollback_lock_file(&lock);
308308
} else {
309-
fprintf_or_die(out, "%s\n", reference);
309+
fprintf_or_die(out, "%s\n", dir);
310310
if (commit_lock_file(&lock))
311311
die_errno(_("unable to move new alternates file into place"));
312312
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);
315314
}
316315
free(alts);
317316
}
318317

319318
void odb_add_to_alternates_memory(struct object_database *odb,
320-
const char *reference)
319+
const char *dir)
321320
{
322321
/*
323322
* Make sure alternates are initialized, or else our entry may be
324323
* overwritten when they are.
325324
*/
326325
odb_prepare_alternates(odb);
327326

328-
link_alt_odb_entries(odb, reference,
329-
'\n', NULL, 0);
327+
link_alt_odb_entries(odb, dir, '\n', NULL, 0);
330328
}
331329

332330
struct odb_source *odb_set_temporary_primary_source(struct object_database *odb,

0 commit comments

Comments
 (0)