[Bf-blender-cvs] [1870e16] master: Cleanup: factorize the 'ensure local' part of datablock copy into a single BKE_id_copy_ensure_local function.

Bastien Montagne noreply at git.blender.org
Mon Jul 25 16:16:49 CEST 2016


Commit: 1870e166deaa4ced1bb5226e97e037db10dbd06c
Author: Bastien Montagne
Date:   Mon Jul 25 16:15:37 2016 +0200
Branches: master
https://developer.blender.org/rB1870e166deaa4ced1bb5226e97e037db10dbd06c

Cleanup: factorize the 'ensure local' part of datablock copy into a single BKE_id_copy_ensure_local function.

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

M	source/blender/blenkernel/BKE_library.h
M	source/blender/blenkernel/intern/action.c
M	source/blender/blenkernel/intern/armature.c
M	source/blender/blenkernel/intern/brush.c
M	source/blender/blenkernel/intern/camera.c
M	source/blender/blenkernel/intern/curve.c
M	source/blender/blenkernel/intern/group.c
M	source/blender/blenkernel/intern/image.c
M	source/blender/blenkernel/intern/key.c
M	source/blender/blenkernel/intern/lamp.c
M	source/blender/blenkernel/intern/lattice.c
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/linestyle.c
M	source/blender/blenkernel/intern/mask.c
M	source/blender/blenkernel/intern/material.c
M	source/blender/blenkernel/intern/mball.c
M	source/blender/blenkernel/intern/mesh.c
M	source/blender/blenkernel/intern/node.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenkernel/intern/speaker.c
M	source/blender/blenkernel/intern/text.c
M	source/blender/blenkernel/intern/texture.c
M	source/blender/blenkernel/intern/world.c

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

diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index 2ac7e3c..e32bc2f 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -86,6 +86,7 @@ bool id_single_user(struct bContext *C, struct ID *id, struct PointerRNA *ptr, s
 bool id_copy(struct Main *bmain, struct ID *id, struct ID **newid, bool test);
 void id_sort_by_name(struct ListBase *lb, struct ID *id);
 void BKE_id_expand_local(struct ID *id);
+void BKE_id_copy_ensure_local(struct Main *bmain, struct ID *old_id, struct ID *new_id);
 
 bool new_id(struct ListBase *lb, struct ID *id, const char *name);
 void id_clear_lib_data(struct Main *bmain, struct ID *id);
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index 8f82610..470098f 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -156,10 +156,7 @@ bAction *BKE_action_copy(Main *bmain, bAction *src)
 		}
 	}
 	
-	if (ID_IS_LINKED_DATABLOCK(src)) {
-		BKE_id_expand_local(&dst->id);
-		BKE_id_lib_local_paths(bmain, src->id.lib, &dst->id);
-	}
+	BKE_id_copy_ensure_local(bmain, &src->id, &dst->id);
 
 	return dst;
 }
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 790272c..c644fe0 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -194,10 +194,7 @@ bArmature *BKE_armature_copy(Main *bmain, bArmature *arm)
 	newArm->act_edbone = NULL;
 	newArm->sketch = NULL;
 
-	if (ID_IS_LINKED_DATABLOCK(arm)) {
-		BKE_id_expand_local(&newArm->id);
-		BKE_id_lib_local_paths(bmain, arm->id.lib, &newArm->id);
-	}
+	BKE_id_copy_ensure_local(bmain, &arm->id, &newArm->id);
 
 	return newArm;
 }
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 9027287..8ef1fae 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -197,10 +197,7 @@ Brush *BKE_brush_copy(Main *bmain, Brush *brush)
 	/* enable fake user by default */
 	id_fake_user_set(&brush->id);
 
-	if (ID_IS_LINKED_DATABLOCK(brush)) {
-		BKE_id_expand_local(&brushn->id);
-		BKE_id_lib_local_paths(bmain, brush->id.lib, &brushn->id);
-	}
+	BKE_id_copy_ensure_local(bmain, &brush->id, &brushn->id);
 
 	return brushn;
 }
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index 4229b2a..85ce399 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -99,10 +99,7 @@ Camera *BKE_camera_copy(Main *bmain, Camera *cam)
 	
 	camn = BKE_libblock_copy(bmain, &cam->id);
 
-	if (ID_IS_LINKED_DATABLOCK(cam)) {
-		BKE_id_expand_local(&camn->id);
-		BKE_id_lib_local_paths(bmain, cam->id.lib, &camn->id);
-	}
+	BKE_id_copy_ensure_local(bmain, &cam->id, &camn->id);
 
 	return camn;
 }
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 07f4e4f..90a5147 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -207,10 +207,7 @@ Curve *BKE_curve_copy(Main *bmain, Curve *cu)
 	id_us_plus((ID *)cun->vfonti);
 	id_us_plus((ID *)cun->vfontbi);
 
-	if (ID_IS_LINKED_DATABLOCK(cu)) {
-		BKE_id_expand_local(&cun->id);
-		BKE_id_lib_local_paths(bmain, cu->id.lib, &cun->id);
-	}
+	BKE_id_copy_ensure_local(bmain, &cu->id, &cun->id);
 
 	return cun;
 }
diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c
index f58d26f..9b011db 100644
--- a/source/blender/blenkernel/intern/group.c
+++ b/source/blender/blenkernel/intern/group.c
@@ -97,10 +97,7 @@ Group *BKE_group_copy(Main *bmain, Group *group)
 	/* Do not copy group's preview (same behavior as for objects). */
 	groupn->preview = NULL;
 
-	if (ID_IS_LINKED_DATABLOCK(group)) {
-		BKE_id_expand_local(&groupn->id);
-		BKE_id_lib_local_paths(bmain, group->id.lib, &groupn->id);
-	}
+	BKE_id_copy_ensure_local(bmain, &group->id, &groupn->id);
 
 	return groupn;
 }
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 017eb41..ea28dab 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -462,10 +462,7 @@ Image *BKE_image_copy(Main *bmain, Image *ima)
 
 	BKE_previewimg_id_copy(&nima->id, &ima->id);
 
-	if (ID_IS_LINKED_DATABLOCK(ima)) {
-		BKE_id_expand_local(&nima->id);
-		BKE_id_lib_local_paths(bmain, ima->id.lib, &nima->id);
-	}
+	BKE_id_copy_ensure_local(bmain, &ima->id, &nima->id);
 
 	return nima;
 }
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index a524f92..6cdeaf5 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -170,10 +170,7 @@ Key *BKE_key_copy(Main *bmain, Key *key)
 		kb = kb->next;
 	}
 
-	if (ID_IS_LINKED_DATABLOCK(key)) {
-		BKE_id_expand_local(&keyn->id);
-		BKE_id_lib_local_paths(bmain, key->id.lib, &keyn->id);
-	}
+	BKE_id_copy_ensure_local(bmain, &key->id, &keyn->id);
 
 	return keyn;
 }
diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c
index 35fcf21..e9d039a 100644
--- a/source/blender/blenkernel/intern/lamp.c
+++ b/source/blender/blenkernel/intern/lamp.c
@@ -138,10 +138,7 @@ Lamp *BKE_lamp_copy(Main *bmain, Lamp *la)
 
 	BKE_previewimg_id_copy(&lan->id, &la->id);
 
-	if (ID_IS_LINKED_DATABLOCK(la)) {
-		BKE_id_expand_local(&lan->id);
-		BKE_id_lib_local_paths(bmain, la->id.lib, &lan->id);
-	}
+	BKE_id_copy_ensure_local(bmain, &la->id, &lan->id);
 
 	return lan;
 }
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index 82b179d..b0671f3 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -297,10 +297,7 @@ Lattice *BKE_lattice_copy(Main *bmain, Lattice *lt)
 
 	ltn->editlatt = NULL;
 
-	if (ID_IS_LINKED_DATABLOCK(lt)) {
-		BKE_id_expand_local(&ltn->id);
-		BKE_id_lib_local_paths(bmain, lt->id.lib, &ltn->id);
-	}
+	BKE_id_copy_ensure_local(bmain, &lt->id, &ltn->id);
 
 	return ltn;
 }
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index c31df68..ce70e5d 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -272,6 +272,17 @@ void BKE_id_expand_local(ID *id)
 }
 
 /**
+ * Ensure new (copied) ID is fully made local.
+ */
+void BKE_id_copy_ensure_local(Main *bmain, ID *old_id, ID *new_id)
+{
+	if (ID_IS_LINKED_DATABLOCK(old_id)) {
+		BKE_id_expand_local(new_id);
+		BKE_id_lib_local_paths(bmain, old_id->lib, new_id);
+	}
+}
+
+/**
  * Generic 'make local' function, works for most of datablock types...
  */
 void BKE_id_make_local_generic(Main *bmain, ID *id, const bool id_in_mainlist, const bool lib_local)
diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c
index 1aff5d5..430935a 100644
--- a/source/blender/blenkernel/intern/linestyle.c
+++ b/source/blender/blenkernel/intern/linestyle.c
@@ -218,10 +218,7 @@ FreestyleLineStyle *BKE_linestyle_copy(struct Main *bmain, FreestyleLineStyle *l
 	for (m = (LineStyleModifier *)linestyle->geometry_modifiers.first; m; m = m->next)
 		BKE_linestyle_geometry_modifier_copy(new_linestyle, m);
 
-	if (ID_IS_LINKED_DATABLOCK(linestyle)) {
-		BKE_id_expand_local(&new_linestyle->id);
-		BKE_id_lib_local_paths(bmain, linestyle->id.lib, &new_linestyle->id);
-	}
+	BKE_id_copy_ensure_local(bmain, &linestyle->id, &new_linestyle->id);
 
 	return new_linestyle;
 }
diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c
index 014461e..21023d9 100644
--- a/source/blender/blenkernel/intern/mask.c
+++ b/source/blender/blenkernel/intern/mask.c
@@ -853,10 +853,7 @@ Mask *BKE_mask_copy(Main *bmain, Mask *mask)
 	/* enable fake user by default */
 	id_fake_user_set(&mask->id);
 
-	if (ID_IS_LINKED_DATABLOCK(mask)) {
-		BKE_id_expand_local(&mask_new->id);
-		BKE_id_lib_local_paths(bmain, mask->id.lib, &mask_new->id);
-	}
+	BKE_id_copy_ensure_local(bmain, &mask->id, &mask_new->id);
 
 	return mask_new;
 }
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 62aba1a..0be32c9 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -247,10 +247,7 @@ Material *BKE_material_copy(Main *bmain, Material *ma)
 
 	BLI_listbase_clear(&man->gpumaterial);
 
-	if (ID_IS_LINKED_DATABLOCK(ma)) {
-		BKE_id_expand_local(&man->id);
-		BKE_id_lib_local_paths(bmain, ma->id.lib, &man->id);
-	}
+	BKE_id_copy_ensure_local(bmain, &ma->id, &man->id);
 
 	return man;
 }
diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c
index 7e363e5..8d024ea 100644
--- a/source/blender/blenkernel/intern/mball.c
+++ b/source/blender/blenkernel/intern/mball.c
@@ -119,10 +119,7 @@ MetaBall *BKE_mball_copy(Main *bmain, MetaBall *mb)
 	mbn->editelems = NULL;
 	mbn->lastelem = NULL;
 	
-	if (ID_IS_LINKED_DATABLOCK(mb)) {
-		BKE_id_expand_local(&mbn->id);
-		BKE_id_lib_local_paths(bmain, mb->id.lib, &mbn->id);
-	}
+	BKE_id_copy_ensure_local(bmain, &mb->id, &mbn->id);
 
 	return mbn;
 }
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 2b35cdc..733e903 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -531,10 +531,7 @@ Mesh *BKE_mesh_copy(Main *bmain, Mesh *me)
 		men->key->from = (ID *)men;
 	}
 
-	if (ID_IS_LINKED_DATABLOCK(me)) {
-		BKE_id_expand_local(&men->id);
-		BKE_id_lib_local_paths(bmain, me->id.lib, &men->id);
-	}
+	BKE_id_copy_ensure_local(bmain, &me->id, &men->id);
 
 	return men;
 }
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index 8bae048..2b88ae4 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -1290,10 +1290,7 @@ static bNodeTree *ntreeCopyTree_internal(bNodeTree *nt

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list