Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-pylib
Commits
d14761bc
Commit
d14761bc
authored
3 years ago
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
ENH: changed merge function such that it is an in-place operation
parent
472b7972
Branches
Branches containing commit
Tags
Tags containing commit
3 merge requests
!57
RELEASE 0.7.3
,
!50
F merge entities
,
!45
F copy entity
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosdb/apiutils.py
+10
-12
10 additions, 12 deletions
src/caosdb/apiutils.py
with
10 additions
and
12 deletions
src/caosdb/apiutils.py
+
10
−
12
View file @
d14761bc
...
@@ -712,19 +712,17 @@ def copy_entity(entity: Entity):
...
@@ -712,19 +712,17 @@ def copy_entity(entity: Entity):
return
new
return
new
def
merge_entities
(
entity_a
:
Entity
,
entity_b
:
Entity
):
def
merge_entities
_in_place
(
entity_a
:
Entity
,
entity_b
:
Entity
):
"""
"""
Create a new entity which is a copy of entity_a and merge it with entity_b such that
Merge entity_b into entity_a such that they have the same parents and properties.
it compare_entities would report zero differences.
"""
"""
new
=
copy_entity
(
entity_a
)
# Compare both entities:
# Compare both entities:
diff_r1
,
diff_r2
=
compare_entities
(
entity_a
,
entity_b
)
diff_r1
,
diff_r2
=
compare_entities
(
entity_a
,
entity_b
)
# Go through the comparison and try to apply changes to entity_a:
# Go through the comparison and try to apply changes to entity_a:
for
key
in
diff_r2
[
"
parents
"
]:
for
key
in
diff_r2
[
"
parents
"
]:
new
.
add_parent
(
entity_b
.
get_parent
(
key
))
entity_a
.
add_parent
(
entity_b
.
get_parent
(
key
))
for
key
in
diff_r2
[
"
properties
"
]:
for
key
in
diff_r2
[
"
properties
"
]:
if
key
in
diff_r1
[
"
properties
"
]:
if
key
in
diff_r1
[
"
properties
"
]:
...
@@ -734,24 +732,24 @@ def merge_entities(entity_a: Entity, entity_b: Entity):
...
@@ -734,24 +732,24 @@ def merge_entities(entity_a: Entity, entity_b: Entity):
for
attribute
in
(
"
datatype
"
,
"
unit
"
,
"
value
"
):
for
attribute
in
(
"
datatype
"
,
"
unit
"
,
"
value
"
):
if
diff_r1
[
"
properties
"
][
key
][
attribute
]
is
None
:
if
diff_r1
[
"
properties
"
][
key
][
attribute
]
is
None
:
setattr
(
new
.
get_property
(
key
),
attribute
,
setattr
(
entity_a
.
get_property
(
key
),
attribute
,
diff_r2
[
"
properties
"
][
key
][
attribute
])
diff_r2
[
"
properties
"
][
key
][
attribute
])
else
:
else
:
raise
RuntimeError
(
"
Merge conflict.
"
)
raise
RuntimeError
(
"
Merge conflict.
"
)
else
:
else
:
new
.
add_property
(
entity_a
.
add_property
(
entity_b
.
get_property
(
key
),
entity_b
.
get_property
(
key
),
importance
=
entity_b
.
get_importance
(
key
))
importance
=
entity_b
.
get_importance
(
key
))
for
special_attribute
in
(
"
name
"
,
"
description
"
):
for
special_attribute
in
(
"
name
"
,
"
description
"
):
sa_
new
=
getattr
(
new
,
special_attribute
)
sa_
a
=
getattr
(
entity_a
,
special_attribute
)
sa_b
=
getattr
(
entity_b
,
special_attribute
)
sa_b
=
getattr
(
entity_b
,
special_attribute
)
if
sa_
new
!=
sa_b
:
if
sa_
a
!=
sa_b
:
if
sa_
new
is
None
:
if
sa_
a
is
None
:
setattr
(
new
,
special_attribute
,
sa_b
)
setattr
(
entity_a
,
special_attribute
,
sa_b
)
else
:
else
:
raise
RuntimeError
(
"
Merge conflict.
"
)
raise
RuntimeError
(
"
Merge conflict.
"
)
return
new
return
entity_a
def
describe_diff
(
olddiff
,
newdiff
,
name
=
None
,
as_update
=
True
):
def
describe_diff
(
olddiff
,
newdiff
,
name
=
None
,
as_update
=
True
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment