On Wed, Nov 11, 2020 at 12:47 PM Jonathan Tan <jonathantanmy@xxxxxxxxxx> wrote: > > > +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).