Skip to content

Commit a59d44f

Browse files
pks-tgitster
authored andcommitted
odb: return newly created in-memory sources
Callers have no trivial way to obtain the newly created object database source when adding it to the in-memory list of alternates. While not yet needed anywhere, a subsequent commit will want to obtain that pointer. Refactor the function to return the source to make it easily accessible. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 25c532f commit a59d44f

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

odb.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,16 @@ static void read_info_alternates(struct object_database *odb,
139139
const char *relative_base,
140140
int depth);
141141

142-
static int link_alt_odb_entry(struct object_database *odb,
143-
const char *dir,
144-
const char *relative_base,
145-
int depth,
146-
const char *normalized_objdir)
142+
static struct odb_source *link_alt_odb_entry(struct object_database *odb,
143+
const char *dir,
144+
const char *relative_base,
145+
int depth,
146+
const char *normalized_objdir)
147147
{
148-
struct odb_source *alternate;
148+
struct odb_source *alternate = NULL;
149149
struct strbuf pathbuf = STRBUF_INIT;
150150
struct strbuf tmp = STRBUF_INIT;
151151
khiter_t pos;
152-
int ret = -1;
153152

154153
if (!is_absolute_path(dir) && relative_base) {
155154
strbuf_realpath(&pathbuf, relative_base, 1);
@@ -189,11 +188,11 @@ static int link_alt_odb_entry(struct object_database *odb,
189188

190189
/* recursively add alternates */
191190
read_info_alternates(odb, alternate->path, depth + 1);
192-
ret = 0;
191+
193192
error:
194193
strbuf_release(&tmp);
195194
strbuf_release(&pathbuf);
196-
return ret;
195+
return alternate;
197196
}
198197

199198
static const char *parse_alt_odb_entry(const char *string,
@@ -315,16 +314,23 @@ void odb_add_to_alternates_file(struct object_database *odb,
315314
free(alts);
316315
}
317316

318-
void odb_add_to_alternates_memory(struct object_database *odb,
319-
const char *dir)
317+
struct odb_source *odb_add_to_alternates_memory(struct object_database *odb,
318+
const char *dir)
320319
{
320+
struct odb_source *alternate;
321+
char *objdir;
322+
321323
/*
322324
* Make sure alternates are initialized, or else our entry may be
323325
* overwritten when they are.
324326
*/
325327
odb_prepare_alternates(odb);
326328

327-
link_alt_odb_entries(odb, dir, '\n', NULL, 0);
329+
objdir = real_pathdup(odb->sources->path, 1);
330+
alternate = link_alt_odb_entry(odb, dir, NULL, 0, objdir);
331+
332+
free(objdir);
333+
return alternate;
328334
}
329335

330336
struct odb_source *odb_set_temporary_primary_source(struct object_database *odb,

odb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ void odb_add_to_alternates_file(struct object_database *odb,
268268
* recursive alternates it points to), but do not modify the on-disk alternates
269269
* file.
270270
*/
271-
void odb_add_to_alternates_memory(struct object_database *odb,
272-
const char *dir);
271+
struct odb_source *odb_add_to_alternates_memory(struct object_database *odb,
272+
const char *dir);
273273

274274
/*
275275
* Read an object from the database. Returns the object data and assigns object

0 commit comments

Comments
 (0)