Patrick Steinhardt <ps@xxxxxx> writes: > 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@xxxxxx> > --- > odb.c | 37 +++++++++++++++++++++---------------- > odb.h | 4 ++-- > 2 files changed, 23 insertions(+), 18 deletions(-) > > diff --git a/odb.c b/odb.c > index 61104b7cb8..7793816f81 100644 > --- a/odb.c > +++ b/odb.c > @@ -139,23 +139,22 @@ static void read_info_alternates(struct object_database *odb, > const char *relative_base, > int depth); > > -static int link_alt_odb_entry(struct object_database *odb, > - const struct strbuf *entry, > - const char *relative_base, > - int depth, > - const char *normalized_objdir) > +static struct odb_source *link_alt_odb_entry(struct object_database *odb, > + const char *entry, > + const char *relative_base, > + int depth, > + const char *normalized_objdir) The change in return value makes sense, since we now want to return the 'odb_source' newly created. But the 'entry' argument is also changed here. > { > - struct odb_source *alternate; > + struct odb_source *alternate = NULL; > struct strbuf pathbuf = STRBUF_INIT; > struct strbuf tmp = STRBUF_INIT; > khiter_t pos; > - int ret = -1; > > - if (!is_absolute_path(entry->buf) && relative_base) { > + if (!is_absolute_path(entry) && relative_base) { > strbuf_realpath(&pathbuf, relative_base, 1); > strbuf_addch(&pathbuf, '/'); > } > - strbuf_addbuf(&pathbuf, entry); > + strbuf_addstr(&pathbuf, entry); > > if (!strbuf_realpath(&tmp, pathbuf.buf, 0)) { > error(_("unable to normalize alternate object path: %s"), > @@ -189,11 +188,11 @@ static int link_alt_odb_entry(struct object_database *odb, > > /* recursively add alternates */ > read_info_alternates(odb, alternate->path, depth + 1); > - ret = 0; > + > error: > strbuf_release(&tmp); > strbuf_release(&pathbuf); > - return ret; > + return alternate; > } > > static const char *parse_alt_odb_entry(const char *string, > @@ -246,7 +245,7 @@ static void link_alt_odb_entries(struct object_database *odb, const char *alt, > alt = parse_alt_odb_entry(alt, sep, &entry); > if (!entry.len) > continue; > - link_alt_odb_entry(odb, &entry, > + link_alt_odb_entry(odb, entry.buf, > relative_base, depth, objdirbuf.buf); I'm assuming that passing 'const char *' directly makes the function more versatile. Might be worthwhile to call this out in the commit message. [snip]
Attachment:
signature.asc
Description: PGP signature