g_sorcery/package_db: split generate_tree function