Commit: dab1a1dd5f37d52eb7a04548094fb05ab79efbd9
Author: Bastien Montagne
Date:   Thu Dec 17 19:32:33 2015 +0100
Branches: id-remap
https://developer.blender.org/rBdab1a1dd5f37d52eb7a04548094fb05ab79efbd9

Merge main remap funcs' bool parameters into a single bitflag.

Too much bools kill bools.

===================================================================

M       source/blender/blenkernel/BKE_library.h
M       source/blender/blenkernel/intern/library.c
M       source/blender/editors/screen/screen_edit.c
M       source/blender/editors/space_outliner/outliner_tools.c
M       source/blender/makesrna/intern/rna_ID.c
M       source/blender/makesrna/intern/rna_main_api.c
M       source/blender/windowmanager/intern/wm_operators.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_library.h 
b/source/blender/blenkernel/BKE_library.h
index 9aec4b5..f66e425e 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -58,13 +58,27 @@ void *BKE_libblock_copy(struct ID *id) 
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
 void  BKE_libblock_copy_data(struct ID *id, const struct ID *id_from, const 
bool do_action);
 void  BKE_libblock_relink(struct ID *id);
 
+/* Also IDRemap->flag. */
+enum {
+       /* Do not remap indirect usages of IDs (that is, when user is some 
linked data). */
+       ID_REMAP_SKIP_INDIRECT_USAGE    = 1 << 0,
+       /* This flag should always be set, *except for 'unlink' scenarios* 
(only relevant when new_id == NULL).
+        * Basically, when unset, NEVER_NULL ID usages will keep pointing to 
old_id, but (if needed) old_id user count
+        * will still be decremented. This is mandatory for 'delete ID' case, 
but in all other situation this would lead
+        * to invalid user counts! */
+       ID_REMAP_SKIP_NEVER_NULL_USAGE  = 1 << 1,
+       /* This tells the callback func to flag with LIB_DOIT all IDs using 
target one with a 'never NULL' pointer
+        * (like e.g. Object->data). */
+       ID_REMAP_FLAG_NEVER_NULL_USAGE  = 1 << 2,
+};
+
 /* Note: Requiring new_id to be non-null, this *may* not be the case 
ultimately, but makes things simpler for now. */
 void BKE_libblock_remap_locked(
         struct Main *bmain, void *old_idv, void *new_idv,
-        const bool skip_indirect_usage, const bool us_min_never_null, const 
bool do_flag_never_null) ATTR_NONNULL(1, 2);
+        const short remap_flags) ATTR_NONNULL(1, 2);
 void BKE_libblock_remap(
         struct Main *bmain, void *old_idv, void *new_idv,
-        const bool skip_indirect_usage, const bool us_min_never_null, const 
bool do_flag_never_null) ATTR_NONNULL(1, 2);
+        const short remap_flags) ATTR_NONNULL(1, 2);
 
 void BKE_libblock_unlink(struct Main *bmain, void *idv, const bool 
do_flag_never_null) ATTR_NONNULL();
 
diff --git a/source/blender/blenkernel/intern/library.c 
b/source/blender/blenkernel/intern/library.c
index a5f6503..ba2a919 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -189,6 +189,7 @@ static void id_us_clear_real(ID *id)
                        const int limit = ID_FAKE_USERS(id);
                        id->us--;
                        BLI_assert(id->us >= limit);
+                       UNUSED_VARS_NDEBUG(limit);
                }
                id->flag2 &= ~(LIB_EXTRAUSER | LIB_EXTRAUSER_SET);
        }
@@ -1048,21 +1049,9 @@ typedef struct IDRemap {
        int skipped_refcounted;  /* Number of skipped usecases that refcount 
the datablock. */
 } IDRemap;
 
-/* IDRemp->flag */
-enum {
-       /* Do not remap indirect usages of IDs (that is, when user is some 
linked data). */
-       ID_REMAP_SKIP_INDIRECT_USAGE    = 1 << 0,
-       /* This flag should always be set, *except for 'unlink' scenarios* 
(only relevant when new_id == NULL).
-        * Basically, when unset, NEVER_NULL ID usages will keep pointing to 
old_id, but (if needed) old_id user count
-        * will still be decremented. This is mandatory for 'delete ID' case, 
but in all other situation this would lead
-        * to invalid user counts! */
-       ID_REMAP_SKIP_NEVER_NULL_USAGE  = 1 << 1,
-       /* This tells the callback func to flag with LIB_DOIT all IDs using 
target one with a 'never NULL' pointer
-        * (like e.g. Object->data). */
-       ID_REMAP_FLAG_NEVER_NULL_USAGE  = 1 << 2,
-};
+/* IDRemap->flag enums defined in BKE_library.h */
 
-/* IDRemp->status */
+/* IDRemap->status */
 enum {
        /* *** Set by callback. *** */
        ID_REMAP_IS_LINKED_DIRECT       = 1 << 0,  /* new_id is directly linked 
in current .blend. */
@@ -1245,14 +1234,11 @@ static void libblock_remap_data(
  */
 void BKE_libblock_remap_locked(
         Main *bmain, void *old_idv, void *new_idv,
-        const bool skip_indirect_usage, const bool us_min_never_null, const 
bool do_flag_never_null)
+        const short remap_flags)
 {
        IDRemap id_remap_data;
        ID *old_id = old_idv;
        ID *new_id = new_idv;
-       int remap_flags = ((skip_indirect_usage ? ID_REMAP_SKIP_INDIRECT_USAGE 
: 0) |
-                          (do_flag_never_null ? ID_REMAP_FLAG_NEVER_NULL_USAGE 
: 0) |
-                          (us_min_never_null ? 0 : 
ID_REMAP_SKIP_NEVER_NULL_USAGE));
        int skipped_direct, skipped_refcounted;
 
        BLI_assert(old_id != NULL);
@@ -1357,23 +1343,29 @@ void BKE_libblock_remap_locked(
        DAG_relations_tag_update(bmain);
 }
 
-void BKE_libblock_remap(
-        Main *bmain, void *old_idv, void *new_idv,
-        const bool skip_indirect_usage, const bool us_min_never_null, const 
bool do_flag_never_null)
+void BKE_libblock_remap(Main *bmain, void *old_idv, void *new_idv, const short 
remap_flags)
 {
        BKE_main_lock(bmain);
 
-       BKE_libblock_remap_locked(bmain, old_idv, new_idv, skip_indirect_usage, 
us_min_never_null, do_flag_never_null);
+       BKE_libblock_remap_locked(bmain, old_idv, new_idv, remap_flags);
 
        BKE_main_unlock(bmain);
 }
 
-/** Unlink given \a id from given \a bmain (does not touch to indirect, i.e. 
library, usages of the ID). */
+/**
+ * Unlink given \a id from given \a bmain (does not touch to indirect, i.e. 
library, usages of the ID).
+ *
+ * \param do_flag_never_null If true, all IDs using \a idv in a 'non-NULL' way 
are flagged by \a LIB_DOIT flag
+ *                           (quite obviously, 'non-NULL' usages can never be 
unlinked by this function...).
+ */
 void BKE_libblock_unlink(Main *bmain, void *idv, const bool do_flag_never_null)
 {
+       const short remap_flags = ID_REMAP_SKIP_INDIRECT_USAGE | 
ID_REMAP_SKIP_INDIRECT_USAGE |
+                                 (do_flag_never_null ? 
ID_REMAP_FLAG_NEVER_NULL_USAGE : 0);
+
        BKE_main_lock(bmain);
 
-       BKE_libblock_remap_locked(bmain, idv, NULL, true, false, 
do_flag_never_null);
+       BKE_libblock_remap_locked(bmain, idv, NULL, remap_flags);
 
        BKE_main_unlock(bmain);
 }
diff --git a/source/blender/editors/screen/screen_edit.c 
b/source/blender/editors/screen/screen_edit.c
index d491dfe..16e5d12 100644
--- a/source/blender/editors/screen/screen_edit.c
+++ b/source/blender/editors/screen/screen_edit.c
@@ -1747,7 +1747,7 @@ bool ED_screen_delete_scene(bContext *C, Scene *scene)
 
        ED_screen_set_scene(C, CTX_wm_screen(C), newscene);
 
-       BKE_libblock_remap(bmain, scene, newscene, true, false, false);
+       BKE_libblock_remap(bmain, scene, newscene, ID_REMAP_SKIP_INDIRECT_USAGE 
| ID_REMAP_SKIP_NEVER_NULL_USAGE);
 
        BKE_libblock_free(bmain, scene);
 
diff --git a/source/blender/editors/space_outliner/outliner_tools.c 
b/source/blender/editors/space_outliner/outliner_tools.c
index 92ddbd4..e854f4f 100644
--- a/source/blender/editors/space_outliner/outliner_tools.c
+++ b/source/blender/editors/space_outliner/outliner_tools.c
@@ -1388,7 +1388,8 @@ static void remap_action_cb(bContext *C, Scene 
*UNUSED(scene), TreeElement *UNUS
        ID *new_id = user_data;
 
        if (tselem->id && (tselem->id != new_id) && (GS(tselem->id->name) == 
GS(new_id->name))) {
-               BKE_libblock_remap(CTX_data_main(C), tselem->id, new_id, true, 
false, false);
+               BKE_libblock_remap(CTX_data_main(C), tselem->id, new_id,
+                                  ID_REMAP_SKIP_INDIRECT_USAGE | 
ID_REMAP_SKIP_NEVER_NULL_USAGE);
        }
 }
 
diff --git a/source/blender/makesrna/intern/rna_ID.c 
b/source/blender/makesrna/intern/rna_ID.c
index 8ec673e..9be9cee 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -342,7 +342,8 @@ static void rna_ID_delete(ID *id, Main *bmain)
 static void rna_ID_user_remap(ID *id, Main *bmain, ID *new_id)
 {
        if (GS(id->name) == GS(new_id->name)) {
-               BKE_libblock_remap(bmain, id, new_id, true, false, false);  /* 
Now, do not allow remapping data in linked data from here... */
+               /* For now, do not allow remapping data in linked data from 
here... */
+               BKE_libblock_remap(bmain, id, new_id, 
ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_NEVER_NULL_USAGE);
        }
 }
 
diff --git a/source/blender/makesrna/intern/rna_main_api.c 
b/source/blender/makesrna/intern/rna_main_api.c
index afb2875..25d448c 100644
--- a/source/blender/makesrna/intern/rna_main_api.c
+++ b/source/blender/makesrna/intern/rna_main_api.c
@@ -160,7 +160,7 @@ static void rna_Main_scenes_remove(Main *bmain, bContext 
*C, ReportList *reports
 
                }
 
-               BKE_libblock_remap(bmain, scene, scene_new, true, false, false);
+               BKE_libblock_remap(bmain, scene, scene_new, 
ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_NEVER_NULL_USAGE);
                BKE_libblock_free(bmain, scene);
                RNA_POINTER_INVALIDATE(scene_ptr);
        }
diff --git a/source/blender/windowmanager/intern/wm_operators.c 
b/source/blender/windowmanager/intern/wm_operators.c
index cbd902c..a9793a5 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -3126,7 +3126,7 @@ static int wm_lib_relocate_exec_do(bContext *C, 
wmOperator *op, const bool reloa
                                if (new_id) {
 //                                     printf("before remap, old_id users: %d 
(%p), new_id users: %d (%p)\n", old_id->us, old_id, new_id->us, new_id);
                                        /* Note that here, we also want to 
replace indirect usages. */
-                                       BKE_libblock_remap_locked(bmain, 
old_id, new_id, false, false, false);
+                                       BKE_libblock_remap_locked(bmain, 
old_id, new_id, ID_REMAP_SKIP_NEVER_NULL_USAGE);
 
 //                                     printf("after remap, old_id users: %d, 
new_id users: %d\n", old_id->us, new_id->us);
 
@@ -3255,7 +3255,8 @@ static int wm_lib_relocate_exec_do(bContext *C, 
wmOperator *op, const bool reloa
                                BLI_assert(old_id);
                                if (new_id) {
 //                                     printf("before remap, old_id users: %d, 
new_id users: %d\n", old_id->us, new_id->us);
-                                       BKE_libblock_remap_locked(bmain, 
old_id, new_id, true, false, false);
+                                       BKE_libblock_remap_locked(bmain, 
old_id, new_id,
+                                                                 
ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_NEVER_NULL_USAGE);
 
                                        if (old_id->flag & LIB_FAKEUSER) {
                                                id_fake_user_clear(old_id);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to