65 library->runtime = MEM_new<LibraryRuntime>(__func__);
79 std::optional<Library *> owner_library,
85 BLI_assert(!owner_library || *owner_library ==
nullptr);
88 const Library *library_src =
reinterpret_cast<const Library *
>(id_src);
101 library_dst->
runtime = MEM_new<LibraryRuntime>(__func__);
114 Library *lib = id_cast<Library *>(
id);
154 Library *lib = id_cast<Library *>(
id);
172 const bool is_undo = writer->
is_undo();
202 lib->
runtime = MEM_new<LibraryRuntime>(__func__);
218 .id_code = Library::id_type,
222 .struct_size =
sizeof(
Library),
224 .name_plural =
N_(
"libraries"),
227 .asset_type_info =
nullptr,
232 .make_local =
nullptr,
234 .foreach_cache =
nullptr,
236 .foreach_working_space_color =
nullptr,
237 .foreach_asset_weak_reference =
nullptr,
238 .owner_pointer_get =
nullptr,
244 .blend_read_undo_preserve =
nullptr,
246 .lib_override_apply_post =
nullptr,
283 if (libs_in_hierarchy.
contains(lib)) {
286 libs_in_hierarchy.
add(lib);
288 Library *best_parent_lib =
nullptr;
289 bool do_break =
false;
304 ID *from_id = item->id_pointer.from;
314 if (from_id_lib == lib) {
317 if (directly_used_libs.
contains(from_id_lib)) {
320 best_parent_lib = from_id_lib;
326 bmain, directly_used_libs, libs_in_hierarchy, from_id_lib);
328 if (!best_parent_lib ||
331 best_parent_lib = from_id_lib;
334 if (!directly_used_libs.
contains(best_parent_lib)) {
339 "Library '%s' seems to be part of an archipelago of unused libraries now.",
362 if (best_parent_lib) {
369 directly_used_libs.
add(lib);
372 libs_in_hierarchy.
remove(lib);
410 directly_used_libs.
add(id_iter->
lib);
420 if (directly_used_libs.
contains(&lib_iter)) {
438 for (
Library *parent_lib_iter = &lib_iter;
440 parent_lib_iter = parent_lib_iter->runtime->parent)
442 if (parent_libraries.
contains(parent_lib_iter)) {
447 parent_libraries.
add(parent_lib_iter);
449 Library *most_remote_ancestor_library = parent_libraries.
as_span().last();
450 int parent_temp_index =
454 int(parent_libraries.
size()) - 1;
455 for (
Library *parent_lib_iter : parent_libraries) {
456 parent_lib_iter->runtime->temp_index = parent_temp_index--;
470 if (directly_used_libs.
contains(&lib_iter)) {
480 "Archived libraries are always direct parent of their owner regular library, "
481 "this should have already been ensured at the start of this function.");
494 for (
Library &lib_iter : *libraries) {
500 if (filepath_abs == lib_iter.runtime->filepath_abs) {
539 return archive_library;
548 Library *archive_library =
nullptr;
559 packed_id && packed_id->
deep_hash != id_deep_hash,
560 "An already packed ID with same deep hash as the one to be packed, should have already "
561 "be found and used (deduplication) before reaching this code-path");
566 archive_library = lib_iter;
569 if (!archive_library) {
577 return archive_library;
587 const IDHash linked_id_deep_hash = deep_hashes.
hashes.lookup(linked_id);
588 ID *packed_id = already_packed_ids.
lookup_default(linked_id_deep_hash,
nullptr);
604 auto existing_id_process = [&deep_hashes, &id_remapper](
ID *linked_id,
ID *packed_id) {
613 id_remapper.
add(linked_id, packed_id);
614 linked_id->newid = packed_id;
619 existing_id_process(linked_id, packed_id);
626 existing_id_process(&linked_key->
id, &packed_key->
id);
637 bmain, *linked_id, *linked_id->
lib, linked_id_deep_hash, is_new);
639 auto copied_id_process =
640 [&archive_lib, &deep_hashes, &ids_to_remap, &id_remapper, &already_packed_ids](
641 ID *linked_id,
ID *packed_id) {
647 if (packed_id->id_type() ==
ID_SCE) {
652 packed_id->
deep_hash = deep_hashes.hashes.lookup(linked_id);
653 id_remapper.add(linked_id, packed_id);
654 ids_to_remap.add(packed_id);
655 already_packed_ids.
add(packed_id->
deep_hash, packed_id);
666 copied_id_process(linked_id, packed_id);
673 copied_id_process(&linked_key->
id, &embedded_key->
id);
689 for (
ID *
id : ids_to_pack) {
694 "Trying to pack an already packed ID '%s' (from '%s')",
696 id->lib->runtime->filepath_abs);
700 final_ids_to_pack.
add(
id);
704 bmain, final_ids_to_pack.
as_span());
705 if (
const auto *errors = std::get_if<id_hash::DeepHashErrors>(&hash_result)) {
708 &
LOG,
"Trying to pack IDs that depend on missing linked library: %s", err_msg.
c_str());
712 &
LOG,
"Trying to pack IDs that are missing from linked library: %s", err_msg.
c_str());
715 CLOG_ERROR(&
LOG,
"Trying to pack IDs that have been modified on disk: %s", err_msg.
c_str());
719 const auto &deep_hashes = std::get<id_hash::ValidDeepHashes>(hash_result);
726 already_packed_ids.
add(
id->deep_hash,
id);
732 for (
ID *linked_id : final_ids_to_pack) {
733 pack_linked_id(bmain, linked_id, deep_hashes, already_packed_ids, ids_to_remap, id_remapper);
747 ids_to_pack.
add(&root_id);
761 if (!referenced_id) {
765 CLOG_ERROR(&
LOG,
"Linked data-block references non-linked data-block");
774 "Non-packed data-block references packed data-block from the same library, "
775 "which is not allowed");
779 if (referenced_id->id_type() ==
ID_KE) {
785 ids_to_pack.
add(referenced_id);
806 external_library->
flag = (reference_library.
flag & copy_flag) |
820 return external_library;
830 return archive_library;
841 int i_insert_curr = 0;
846 if (i_insert_curr < i_read_curr) {
853 if (i_insert_curr < i_read_curr) {
#define BKE_LIB_FOREACHID_PROCESS_IDSUPER(data_, id_super_, cb_flag_)
#define BKE_LIB_FOREACHID_PROCESS_ID(data_, id_, cb_flag_)
#define FOREACH_MAIN_ID_END
#define FOREACH_MAIN_LISTBASE_ID_END
#define FOREACH_MAIN_LISTBASE_ID_BEGIN(_lb, _id)
#define FOREACH_MAIN_LISTBASE_END
#define FOREACH_MAIN_LISTBASE_BEGIN(_bmain, _lb)
#define FOREACH_MAIN_ID_BEGIN(_bmain, _id)
#define BLT_I18NCONTEXT_ID_LIBRARY
#define CLOG_ERROR(clg_ref,...)
#define CLOG_DEBUG(clg_ref,...)
#define CLOG_INFO(clg_ref,...)
ID and Library types, which are fundamental for SDNA.
#define ID_IS_PACKED(_id)
#define ID_IS_LINKED(_id)
Object groups, one object can be in many groups at once.
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
#define BLI_assert_msg(a, msg)
bool add(const Key &key, const Value &value)
Value lookup_default(const Key &key, const Value &default_value) const
bool contains(const Key &key) const
bool remove(const Key &key)
constexpr const char * c_str() const
bool contains(const Key &key) const
Span< Key > as_span() const
void add(ID *old_id, ID *new_id)
std::variant< ValidDeepHashes, DeepHashErrors > IDHashResult
IDHashResult compute_linked_id_deep_hashes(const Main &bmain, Span< const ID * > root_ids)
Library * ensure_archive_library(Main &bmain, ID &id, Library &reference_library, const IDHash &id_deep_hash, bool &is_new)
void main_cleanup_parent_archives(Main &bmain)
Set< ID * > pack_linked_id_hierarchy(Main &bmain, ID &root_id)
Library * search_filepath_abs(ListBaseT< Library > *libraries, StringRef filepath_abs)
Library * create_external_archive_library(Main &bmain, Library &external_library)
void BKE_main_relations_free(Main *bmain)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_packedfile_blend_write(BlendWriter *writer, const PackedFile *pf)
char * STRNCPY(char(&dst)[N], const char *src)
@ LIBRARY_TAG_RESYNC_REQUIRED
@ LIBRARY_IS_ASSET_EDIT_FILE
static void library_init_data(ID *id)
PackedFile * BKE_packedfile_duplicate(const PackedFile *pf_src)
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
@ IDWALK_DO_INTERNAL_RUNTIME_POINTERS
void BKE_main_namemap_destroy(UniqueName_Map **r_name_map) ATTR_NONNULL()
static void library_blend_write_data(BlendWriter *writer, ID *id, const void *id_address)
static void library_foreach_id(ID *id, LibraryForeachIDData *data)
void BKE_packedfile_free(PackedFile *pf)
ID * BKE_libblock_find_name_and_library(Main *bmain, short type, const char *name, const char *lib_name)
static void library_copy_data(Main *bmain, std::optional< Library * > owner_library, ID *id_dst, const ID *id_src, int)
static void library_blend_read_data(BlendDataReader *reader, ID *id)
bool BKE_main_namemap_contain_name(Main &bmain, Library *lib, short id_type, StringRef name)
const char * BKE_id_name(const ID &id)
LibraryForeachIDFlag BKE_lib_query_foreachid_process_flags_get(const LibraryForeachIDData *data)
void BKE_id_blend_write(BlendWriter *writer, ID *id)
@ LIB_ID_COPY_ASSET_METADATA
static void library_runtime_reset(Library *lib)
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
bool BLO_read_data_is_undo(BlendDataReader *reader)
void BKE_library_main_rebuild_hierarchy(Main *bmain)
Key * BKE_key_from_id(ID *id)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
static void pack_linked_id(Main &bmain, ID *linked_id, const id_hash::ValidDeepHashes &deep_hashes, Map< IDHash, ID * > &already_packed_ids, VectorSet< ID * > &ids_to_remap, bke::id::IDRemapper &id_remapper)
static void library_blend_read_after_liblink(BlendLibReader *, ID *id)
static Library * add_archive_library(Main &bmain, Library &reference_library)
BMesh const char void * data
void BKE_main_ensure_invariants(Main &bmain, std::optional< Span< ID * > > modified_ids=std::nullopt)
static void library_free_data(ID *id)
static void pack_linked_ids(Main &bmain, const Set< ID * > &ids_to_pack)
static void rebuild_hierarchy_best_parent_find(Main *bmain, Set< Library * > &directly_used_libs, Set< Library * > &libs_in_hierarchy, Library *lib)
@ LIBRARY_FLAG_IS_ARCHIVE
@ LIBRARY_FLAG_IS_EXTERNAL
static void library_foreach_path(ID *id, BPathForeachPathData *bpath_data)
void BKE_main_relations_create(Main *bmain, short flag)
void BKE_library_filepath_set(Main *bmain, Library *lib, const char *filepath)
void id_us_ensure_real(ID *id)
bool BKE_bpath_foreach_path_fixed_process(BPathForeachPathData *bpath_data, char *path, size_t path_maxncpy)
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
static Library * add_external_archive_library(Main &bmain, Library &reference_library)
@ IDWALK_CB_WRITEFILE_IGNORE
@ IDWALK_CB_EMBEDDED_NOT_OWNING
@ IDWALK_CB_READFILE_IGNORE
void BKE_libblock_relink_multiple(Main *bmain, const Span< ID * > ids, eIDRemapType remap_type, bke::id::IDRemapper &id_remapper, int remap_flags)
void BKE_library_foreach_ID_link(Main *bmain, ID *id, FunctionRef< LibraryIDLinkCallback > callback, void *user_data, LibraryForeachIDFlag flag)
void * BKE_id_new(Main *bmain, short type, const char *name)
struct ID * BKE_id_copy_in_lib(Main *bmain, std::optional< Library * > owner_library, const ID *id, std::optional< const ID * > new_owner_id, ID **new_id_p, int flag)
@ IDTYPE_FLAGS_NO_ANIMDATA
@ IDTYPE_FLAGS_NO_LIBLINKING
@ IDTYPE_FLAGS_NEVER_UNUSED
void write_id_struct(const void *id_address, const T *id, BlendStructWriterTypedFn< T > fn=nullptr)
LibraryForeachIDCallbackFlag cb_flag
uint16_t undo_runtime_tag
struct Library * archive_parent_library
struct PackedFile * packedfile
bke::library::LibraryRuntime * runtime
MainIDRelationsEntryItem * next
MainIDRelationsEntryItem * from_ids
Map< const ID *, MainIDRelationsEntry * > * relations_from_pointers
MainIDRelations * relations
ListBaseT< Library > libraries
Map< const ID *, IDHash > hashes
Vector< Library * > archived_libraries
MainColorspace colorspace
UniqueName_Map * name_map