Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-model
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
Renaud Boyer
swh-model
Commits
363b1659
Verified
Commit
363b1659
authored
4 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
Unify object_type some more within the merkle and from_disk modules
parent
40a40f50
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
swh/model/from_disk.py
+5
-5
5 additions, 5 deletions
swh/model/from_disk.py
swh/model/merkle.py
+3
-4
3 additions, 4 deletions
swh/model/merkle.py
swh/model/tests/test_merkle.py
+10
-6
10 additions, 6 deletions
swh/model/tests/test_merkle.py
with
18 additions
and
15 deletions
swh/model/from_disk.py
+
5
−
5
View file @
363b1659
...
...
@@ -121,7 +121,7 @@ class Content(MerkleLeaf):
"""
__slots__
=
[]
# type: List[str]
type
=
"
content
"
object_type
:
Final
=
"
content
"
@classmethod
def
from_bytes
(
cls
,
*
,
mode
,
data
):
...
...
@@ -300,7 +300,7 @@ class Directory(MerkleNode):
"""
__slots__
=
[
"
__entries
"
]
type
=
"
directory
"
object_type
:
Final
=
"
directory
"
@classmethod
def
from_disk
(
...
...
@@ -352,14 +352,14 @@ class Directory(MerkleNode):
@staticmethod
def
child_to_directory_entry
(
name
,
child
):
if
isinstance
(
child
,
D
irectory
)
:
if
child
.
object_type
==
"
d
irectory
"
:
return
{
"
type
"
:
"
dir
"
,
"
perms
"
:
DentryPerms
.
directory
,
"
target
"
:
child
.
hash
,
"
name
"
:
name
,
}
elif
isinstance
(
child
,
C
ontent
)
:
elif
child
.
object_type
==
"
c
ontent
"
:
return
{
"
type
"
:
"
file
"
,
"
perms
"
:
child
.
data
[
"
perms
"
],
...
...
@@ -367,7 +367,7 @@ class Directory(MerkleNode):
"
name
"
:
name
,
}
else
:
raise
ValueError
(
"
unknown child
"
)
raise
ValueError
(
f
"
unknown child
{
child
}
"
)
def
get_data
(
self
,
**
kwargs
):
return
{
...
...
This diff is collapsed.
Click to expand it.
swh/model/merkle.py
+
3
−
4
View file @
363b1659
# Copyright (C) 2017 The Software Heritage developers
# Copyright (C) 2017
-2020
The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
...
...
@@ -8,7 +8,7 @@
import
abc
import
collections
from
typing
import
Iterator
,
List
,
Optional
,
Set
from
typing
import
Iterator
,
List
,
Set
def
deep_update
(
left
,
right
):
...
...
@@ -111,7 +111,6 @@ class MerkleNode(dict, metaclass=abc.ABCMeta):
__slots__
=
[
"
parents
"
,
"
data
"
,
"
__hash
"
,
"
collected
"
]
type
=
None
# type: Optional[str] # TODO: make this an enum
"""
Type of the current node (used as a classifier for :func:`collect`)
"""
def
__init__
(
self
,
data
=
None
):
...
...
@@ -234,7 +233,7 @@ class MerkleNode(dict, metaclass=abc.ABCMeta):
"""
if
not
self
.
collected
:
self
.
collected
=
True
return
{
self
.
type
:
{
self
.
hash
:
self
.
get_data
(
**
kwargs
)}}
return
{
self
.
object_
type
:
{
self
.
hash
:
self
.
get_data
(
**
kwargs
)}}
else
:
return
{}
...
...
This diff is collapsed.
Click to expand it.
swh/model/tests/test_merkle.py
+
10
−
6
View file @
363b1659
# Copyright (C) 2017 The Software Heritage developers
# Copyright (C) 2017
-2020
The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
...
...
@@ -9,7 +9,7 @@ from swh.model import merkle
class
MerkleTestNode
(
merkle
.
MerkleNode
):
type
=
"
tested_merkle_node_type
"
object_
type
=
"
tested_merkle_node_type
"
def
__init__
(
self
,
data
):
super
().
__init__
(
data
)
...
...
@@ -23,7 +23,7 @@ class MerkleTestNode(merkle.MerkleNode):
class
MerkleTestLeaf
(
merkle
.
MerkleLeaf
):
type
=
"
tested_merkle_leaf_type
"
object_
type
=
"
tested_merkle_leaf_type
"
def
__init__
(
self
,
data
):
super
().
__init__
(
data
)
...
...
@@ -62,7 +62,11 @@ class TestMerkleLeaf(unittest.TestCase):
collected
=
self
.
instance
.
collect
()
self
.
assertEqual
(
collected
,
{
self
.
instance
.
type
:
{
self
.
instance
.
hash
:
self
.
instance
.
get_data
(),},},
{
self
.
instance
.
object_type
:
{
self
.
instance
.
hash
:
self
.
instance
.
get_data
(),
},
},
)
collected2
=
self
.
instance
.
collect
()
self
.
assertEqual
(
collected2
,
{})
...
...
@@ -162,7 +166,7 @@ class TestMerkleNode(unittest.TestCase):
def
test_collect
(
self
):
collected
=
self
.
root
.
collect
()
self
.
assertEqual
(
len
(
collected
[
self
.
root
.
type
]),
len
(
self
.
nodes
))
self
.
assertEqual
(
len
(
collected
[
self
.
root
.
object_
type
]),
len
(
self
.
nodes
))
for
node
in
self
.
nodes
.
values
():
self
.
assertTrue
(
node
.
collected
)
collected2
=
self
.
root
.
collect
()
...
...
@@ -229,7 +233,7 @@ class TestMerkleNode(unittest.TestCase):
# Ensure we collected root, root/b, and both new children
collected_after_update
=
self
.
root
.
collect
()
self
.
assertCountEqual
(
collected_after_update
[
MerkleTestNode
.
type
],
collected_after_update
[
MerkleTestNode
.
object_
type
],
[
self
.
nodes
[
b
"
root
"
].
hash
,
self
.
nodes
[
b
"
root/b
"
].
hash
,
...
...
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