Page MenuHomeSoftware Heritage
Paste P180

swh.model.from_disk nom nom nom
ActivePublic

Authored by olasd on Sep 20 2017, 11:33 PM.
In [1]: from swh.model.from_disk import Content, Directory, ignore_named_directories
In [2]: d = Directory.from_disk(directory=b'swh-model', dir_filter=ignore_named_directories([b'.git', b'.coverage']), data=True)
In [3]: hash1 = d.hash
In [4]: d[b'.git'] = Directory.from_disk(directory=b'swh-model/.git', data=True)
In [5]: hash2 = d.hash
In [6]: d = Directory.from_disk(directory=b'swh-model', data=True)
In [7]: hash3 = d.hash
In [8]: hash2, hash3
Out[8]:
(b'2e\x179\x07i\xeb\x80d\x02\x8a\xee\xdf#\xc4\x9c*m\xda1',
b'2e\x179\x07i\xeb\x80d\x02\x8a\xee\xdf#\xc4\x9c*m\xda1')
In [9]: temp = d[b'.git/objects']
In [10]: del d[b'.git/objects']
In [11]: temp.parent
In [12]: d.hash
Out[12]: b'\xf6\xb3y\xc0\xdf\x7f\xc2\x9e#\x94B\xa8\x1d\xb1\xd2\xec\\J`\x17'
In [13]: d[b'.git/objects'] = temp
In [14]: d.hash
Out[14]: b'2e\x179\x07i\xeb\x80d\x02\x8a\xee\xdf#\xc4\x9c*m\xda1'
In [15]: d2 = Directory.from_disk(directory=b'swh-model', dir_filter=ignore_named_directories([b'objects']), data=True)
In [16]: d2.hash
Out[16]: b'\xf6\xb3y\xc0\xdf\x7f\xc2\x9e#\x94B\xa8\x1d\xb1\xd2\xec\\J`\x17'
In [17]: