Add automatic object identifier computation support
Add support to automatically compute identifier in the following object models: Directory, Release, Revision, Snapshot.
If the identifier is not provided as parameter, it will be computed when the model is initialized.
This is useful when writing tests and one wants to populate the archive using models instead of raw dicts.
For instance, if we have the following directory entry model:
dir_target = ...
dir_entry = DirectoryEntry(name=b'directory', type='dir',
target=dir_target,
perms=DentryPerms.directory)
To create a valid Directory model, previously you had to proceed like this:
dir_id = hash_to_bytes(directory_identifier({
'entries': [dir_entry.to_dict()]
}))
dir = Directory(id=dir_id, entries=[dir_entry])
While after applying that diff, you can now simply write:
dir = Directory(entries=[dir_entry])
Test Plan
Tests have been added. Some raw data from test_identifiers
are reused to avoid duplication.
Migrated from D2375 (view on Phabricator)