Re: [PATCH v2 14/20] merge-ort: step 2 of tree writing -- function to create tree object
- From
Elijah Newren <newren@gmail.com>
- Date
- Nov 11, 2020, 21:21 UTC
- Message-ID
- <CABPp-BF+wX4nRnVNJLFKqKhjop1nL948SyhYRs2Tx3rErDa8sw@mail.gmail.com>
- In-Reply-To
- <20201111204707.3126694-1-jonathantanmy@google.com>
On Wed, Nov 11, 2020 at 12:47 PM Jonathan Tan <jonathantanmy@google.com> wrote:
Show 28 quoted lines
>
> > +static void write_tree(struct object_id *result_oid,
> > + struct string_list *versions,
> > + unsigned int offset)
> > +{
> > + size_t maxlen = 0;
> > + unsigned int nr = versions->nr - offset;
> > + struct strbuf buf = STRBUF_INIT;
> > + struct string_list relevant_entries = STRING_LIST_INIT_NODUP;
> > + int i;
> > +
> > + /*
> > + * We want to sort the last (versions->nr-offset) entries in versions.
> > + * Do so by abusing the string_list API a bit: make another string_list
> > + * that contains just those entries and then sort them.
> > + *
> > + * We won't use relevant_entries again and will let it just pop off the
> > + * stack, so there won't be allocation worries or anything.
> > + */
> > + relevant_entries.items = versions->items + offset;
> > + relevant_entries.nr = versions->nr - offset;
> > + string_list_sort(&relevant_entries);
> > +
> > + /* Pre-allocate some space in buf */
> > + for (i = 0; i < nr; i++) {
> > + maxlen += strlen(versions->items[offset+i].string) + 34;
>
> Probably should include the_hash_algo->rawsz instead of hardcoding 34.Ah, indeed. And I should submit a patch for fast-import.c to update it to not hardcode 34 either (though I'll submit the fast-import change separate from this series).