def test_get_info_refs(self): self._environ['QUERY_STRING'] = '' blob1 = make_object(Blob, data='1') blob2 = make_object(Blob, data='2') blob3 = make_object(Blob, data='3') tag1 = make_object(Tag, name='tag-tag', tagger='Test <*****@*****.**>', tag_time=12345, tag_timezone=0, message='message', object=(Blob, blob2.id)) objects = [blob1, blob2, blob3, tag1] refs = { 'HEAD': '000', 'refs/heads/master': blob1.id, 'refs/tags/tag-tag': tag1.id, 'refs/tags/blob-tag': blob3.id, } backend = _test_backend(objects, refs=refs) mat = re.search('.*', '//info/refs') self.assertEquals(['%s\trefs/heads/master\n' % blob1.id, '%s\trefs/tags/blob-tag\n' % blob3.id, '%s\trefs/tags/tag-tag\n' % tag1.id, '%s\trefs/tags/tag-tag^{}\n' % blob2.id], list(get_info_refs(self._req, backend, mat))) self.assertEquals(HTTP_OK, self._status) self.assertContentTypeEquals('text/plain') self.assertFalse(self._req.cached)
def test_filter_with_merge(self): blob_a = make_object(Blob, data=b'a') blob_a2 = make_object(Blob, data=b'a2') blob_b = make_object(Blob, data=b'b') blob_b2 = make_object(Blob, data=b'b2') x1, y2, m3 = self.make_commits( [[1], [2], [3, 1, 2]], trees={1: [(b'x/a', blob_a)], 2: [(b'y/b', blob_b)], 3: [(b'x/a', blob_a2), (b'y/b', blob_b2)]}) # Get the WalkEntry for the merge commit. walker = Walker(self.store, m3.id) entries = list(walker) walker_entry = entries[0] self.assertEqual(walker_entry.commit.id, m3.id) changes = walker_entry.changes(b'x') self.assertEqual(1, len(changes)) entry_a = (b'a', F, blob_a.id) entry_a2 = (b'a', F, blob_a2.id) self.assertEqual( [[TreeChange(CHANGE_MODIFY, entry_a, entry_a2)]], changes, )
def test_get_info_refs(self): self._environ['QUERY_STRING'] = '' blob1 = make_object(Blob, data=b'1') blob2 = make_object(Blob, data=b'2') blob3 = make_object(Blob, data=b'3') tag1 = make_tag(blob2, name=b'tag-tag') objects = [blob1, blob2, blob3, tag1] refs = { b'HEAD': b'000', b'refs/heads/master': blob1.id, b'refs/tags/tag-tag': tag1.id, b'refs/tags/blob-tag': blob3.id, } backend = _test_backend(objects, refs=refs) mat = re.search('.*', '//info/refs') self.assertEqual([blob1.id + b'\trefs/heads/master\n', blob3.id + b'\trefs/tags/blob-tag\n', tag1.id + b'\trefs/tags/tag-tag\n', blob2.id + b'\trefs/tags/tag-tag^{}\n'], list(get_info_refs(self._req, backend, mat))) self.assertEqual(HTTP_OK, self._status) self.assertContentTypeEquals('text/plain') self.assertFalse(self._req.cached)
def setUp(self): super(MOFLinearRepoTest, self).setUp() # present in 1, removed in 3 f1_1 = make_object(Blob, data=b'f1') # present in all revisions, changed in 2 and 3 f2_1 = make_object(Blob, data=b'f2') f2_2 = make_object(Blob, data=b'f2-changed') f2_3 = make_object(Blob, data=b'f2-changed-again') # added in 2, left unmodified in 3 f3_2 = make_object(Blob, data=b'f3') commit_spec = [[1], [2, 1], [3, 2]] trees = {1: [(b'f1', f1_1), (b'f2', f2_1)], 2: [(b'f1', f1_1), (b'f2', f2_2), (b'f3', f3_2)], 3: [(b'f2', f2_3), (b'f3', f3_2)]} # commit 1: f1 and f2 # commit 2: f3 added, f2 changed. Missing shall report commit id and a # tree referenced by commit # commit 3: f1 removed, f2 changed. Commit sha and root tree sha shall # be reported as modified self.commits = build_commit_graph(self.store, commit_spec, trees) self.missing_1_2 = [self.cmt(2).id, self.cmt(2).tree, f2_2.id, f3_2.id] self.missing_2_3 = [self.cmt(3).id, self.cmt(3).tree, f2_3.id] self.missing_1_3 = [ self.cmt(2).id, self.cmt(3).id, self.cmt(2).tree, self.cmt(3).tree, f2_2.id, f3_2.id, f2_3.id]
def _do_test_merge_entries(self, merge_entries): blob_a1 = make_object(Blob, data='a1') blob_a2 = make_object(Blob, data='a2') blob_b1 = make_object(Blob, data='b1') blob_c2 = make_object(Blob, data='c2') tree1 = self.commit_tree([('a', blob_a1, 0100644), ('b', blob_b1, 0100755)])
def test_iter_tree_contents_include_trees(self): blob_a = make_object(Blob, data='a') blob_b = make_object(Blob, data='b') blob_c = make_object(Blob, data='c') for blob in [blob_a, blob_b, blob_c]: self.store.add_object(blob) blobs = [ ('a', blob_a.id, 0100644), ('ad/b', blob_b.id, 0100644), ('ad/bd/c', blob_c.id, 0100755), ] tree_id = commit_tree(self.store, blobs) tree = self.store[tree_id] tree_ad = self.store[tree['ad'][1]] tree_bd = self.store[tree_ad['bd'][1]] expected = [ TreeEntry('', 0040000, tree_id), TreeEntry('a', 0100644, blob_a.id), TreeEntry('ad', 0040000, tree_ad.id), TreeEntry('ad/b', 0100644, blob_b.id), TreeEntry('ad/bd', 0040000, tree_bd.id), TreeEntry('ad/bd/c', 0100755, blob_c.id), ] actual = self.store.iter_tree_contents(tree_id, include_trees=True) self.assertEquals(expected, list(actual))
def test_tree_changes_rename_detector(self): blob_a1 = make_object(Blob, data='a\nb\nc\nd\n') blob_a2 = make_object(Blob, data='a\nb\nc\ne\n') blob_b = make_object(Blob, data='b') tree1 = self.commit_tree([('a', blob_a1), ('b', blob_b)]) tree2 = self.commit_tree([('c', blob_a2), ('b', blob_b)]) detector = RenameDetector(self.store) self.assertChangesEqual( [TreeChange.delete(('a', F, blob_a1.id)), TreeChange.add(('c', F, blob_a2.id))], tree1, tree2) self.assertChangesEqual( [TreeChange.delete(('a', F, blob_a1.id)), TreeChange(CHANGE_UNCHANGED, ('b', F, blob_b.id), ('b', F, blob_b.id)), TreeChange.add(('c', F, blob_a2.id))], tree1, tree2, want_unchanged=True) self.assertChangesEqual( [TreeChange(CHANGE_RENAME, ('a', F, blob_a1.id), ('c', F, blob_a2.id))], tree1, tree2, rename_detector=detector) self.assertChangesEqual( [TreeChange(CHANGE_RENAME, ('a', F, blob_a1.id), ('c', F, blob_a2.id)), TreeChange(CHANGE_UNCHANGED, ('b', F, blob_b.id), ('b', F, blob_b.id))], tree1, tree2, rename_detector=detector, want_unchanged=True)
def test_trees(self): a1 = make_object(Blob, data=b'aaa1') a2 = make_object(Blob, data=b'aaa2') c1, c2 = build_commit_graph(self.store, [[1], [2, 1]], trees={1: [(b'a', a1)], 2: [(b'a', a2, 0o100644)]}) self.assertEqual((0o100644, a1.id), self.store[c1.tree][b'a']) self.assertEqual((0o100644, a2.id), self.store[c2.tree][b'a'])
def test_tree_changes_to_tree(self): blob_a = make_object(Blob, data=b"a") blob_x = make_object(Blob, data=b"x") tree1 = self.commit_tree([("a", blob_a)]) tree2 = self.commit_tree([("a/x", blob_x)]) self.assertChangesEqual( [TreeChange.delete((b"a", F, blob_a.id)), TreeChange.add((b"a/x", F, blob_x.id))], tree1, tree2 )
def test_paths_max_entries(self): blob_a = make_object(Blob, data='a') blob_b = make_object(Blob, data='b') c1, c2 = self.make_linear_commits( 2, trees={1: [('a', blob_a)], 2: [('a', blob_a), ('b', blob_b)]}) self.assertWalkYields([c2], [c2.id], paths=['b'], max_entries=1) self.assertWalkYields([c1], [c1.id], paths=['a'], max_entries=1)
def test_tree_changes_modify_contents(self): blob_a1 = make_object(Blob, data='a1') blob_a2 = make_object(Blob, data='a2') tree1 = self.commit_tree([('a', blob_a1)]) tree2 = self.commit_tree([('a', blob_a2)]) self.assertChangesEqual( [TreeChange(CHANGE_MODIFY, ('a', F, blob_a1.id), ('a', F, blob_a2.id))], tree1, tree2)
def test_tree_changes_change_type_same(self): blob_a1 = make_object(Blob, data=b'a') blob_a2 = make_object(Blob, data=b'/foo/bar') tree1 = self.commit_tree([(b'a', blob_a1, 0o100644)]) tree2 = self.commit_tree([(b'a', blob_a2, 0o120000)]) self.assertChangesEqual( [TreeChange(CHANGE_MODIFY, (b'a', 0o100644, blob_a1.id), (b'a', 0o120000, blob_a2.id))], tree1, tree2, change_type_same=True)
def test_exact_rename_and_different_type(self): blob1 = make_object(Blob, data='1') blob2 = make_object(Blob, data='2') tree1 = self.commit_tree([('a', blob1)]) tree2 = self.commit_tree([('a', blob2, 0o120000), ('b', blob1)]) self.assertEqual( [TreeChange.add(('a', 0o120000, blob2.id)), TreeChange(CHANGE_RENAME, ('a', F, blob1.id), ('b', F, blob1.id))], self.detect_renames(tree1, tree2))
def test_no_renames(self): blob1 = make_object(Blob, data='a\nb\nc\nd\n') blob2 = make_object(Blob, data='a\nb\ne\nf\n') blob3 = make_object(Blob, data='a\nb\ng\nh\n') tree1 = self.commit_tree([('a', blob1), ('b', blob2)]) tree2 = self.commit_tree([('a', blob1), ('b', blob3)]) self.assertEqual( [TreeChange(CHANGE_MODIFY, ('b', F, blob2.id), ('b', F, blob3.id))], self.detect_renames(tree1, tree2))
def test_exact_copy_modify(self): blob1 = make_object(Blob, data='a\nb\nc\nd\n') blob2 = make_object(Blob, data='a\nb\nc\ne\n') tree1 = self.commit_tree([('a', blob1)]) tree2 = self.commit_tree([('a', blob2), ('b', blob1)]) self.assertEqual( [TreeChange(CHANGE_MODIFY, ('a', F, blob1.id), ('a', F, blob2.id)), TreeChange(CHANGE_COPY, ('a', F, blob1.id), ('b', F, blob1.id))], self.detect_renames(tree1, tree2))
def test_exact_rename_one_to_one(self): blob1 = make_object(Blob, data='1') blob2 = make_object(Blob, data='2') tree1 = self.commit_tree([('a', blob1), ('b', blob2)]) tree2 = self.commit_tree([('c', blob1), ('d', blob2)]) self.assertEqual( [TreeChange(CHANGE_RENAME, ('a', F, blob1.id), ('c', F, blob1.id)), TreeChange(CHANGE_RENAME, ('b', F, blob2.id), ('d', F, blob2.id))], self.detect_renames(tree1, tree2))
def test_tree_changes_change_type(self): blob_a1 = make_object(Blob, data='a') blob_a2 = make_object(Blob, data='/foo/bar') tree1 = self.commit_tree([('a', blob_a1, 0o100644)]) tree2 = self.commit_tree([('a', blob_a2, 0o120000)]) self.assertChangesEqual( [TreeChange.delete(('a', 0o100644, blob_a1.id)), TreeChange.add(('a', 0o120000, blob_a2.id))], tree1, tree2)
def test_pack_loose_objects(self): b1 = make_object(Blob, data="yummy data") self.store.add_object(b1) b2 = make_object(Blob, data="more yummy data") self.store.add_object(b2) self.assertEquals([], self.store.packs) self.assertEquals(2, self.store.pack_loose_objects()) self.assertNotEquals([], self.store.packs) self.assertEquals(0, self.store.pack_loose_objects())
def test_paths_subtree(self): blob_a = make_object(Blob, data='a') blob_b = make_object(Blob, data='b') c1, c2, c3 = self.make_linear_commits( 3, trees={1: [('x/a', blob_a)], 2: [('b', blob_b), ('x/a', blob_a)], 3: [('b', blob_b), ('x/a', blob_a), ('x/b', blob_b)]}) self.assertWalkYields([c2], [c3.id], paths=['b']) self.assertWalkYields([c3, c1], [c3.id], paths=['x'])
def test_tree_changes_to_tree(self): blob_a = make_object(Blob, data='a') blob_x = make_object(Blob, data='x') tree1 = self.commit_tree([('a', blob_a)]) tree2 = self.commit_tree([('a/x', blob_x)]) self.assertChangesEqual( [TreeChange.delete(('a', F, blob_a.id)), TreeChange.add(('a/x', F, blob_x.id))], tree1, tree2)
def test_content_rename_many_to_one(self): blob1 = make_object(Blob, data='a\nb\nc\nd\n') blob2 = make_object(Blob, data='a\nb\nc\ne\n') blob3 = make_object(Blob, data='a\nb\nc\nf\n') tree1 = self.commit_tree([('a', blob1), ('b', blob2)]) tree2 = self.commit_tree([('c', blob3)]) self.assertEqual( [TreeChange(CHANGE_RENAME, ('a', F, blob1.id), ('c', F, blob3.id)), TreeChange.delete(('b', F, blob2.id))], self.detect_renames(tree1, tree2))
def test_content_rename_one_to_many(self): blob1 = make_object(Blob, data='aa\nb\nc\nd\ne\n') blob2 = make_object(Blob, data='ab\nb\nc\nd\ne\n') # 8/11 match blob3 = make_object(Blob, data='aa\nb\nc\nd\nf\n') # 9/11 match tree1 = self.commit_tree([('a', blob1)]) tree2 = self.commit_tree([('b', blob2), ('c', blob3)]) self.assertEqual( [TreeChange(CHANGE_COPY, ('a', F, blob1.id), ('b', F, blob2.id)), TreeChange(CHANGE_RENAME, ('a', F, blob1.id), ('c', F, blob3.id))], self.detect_renames(tree1, tree2))
def test_tree_changes_for_merge_add_modify_conflict(self): blob1 = make_object(Blob, data='1') blob2 = make_object(Blob, data='2') parent1 = self.commit_tree([]) parent2 = self.commit_tree([('a', blob1)]) merge = self.commit_tree([('a', blob2)]) self.assertChangesForMergeEqual( [[TreeChange.add(('a', F, blob2.id)), TreeChange(CHANGE_MODIFY, ('a', F, blob1.id), ('a', F, blob2.id))]], [parent1, parent2], merge)
def test_tree_changes_for_merge_modify_rename_conflict(self): blob1 = make_object(Blob, data='a\nb\nc\nd\n') blob2 = make_object(Blob, data='a\nb\nc\ne\n') parent1 = self.commit_tree([('a', blob1)]) parent2 = self.commit_tree([('b', blob1)]) merge = self.commit_tree([('b', blob2)]) self.assertChangesForMergeEqual( [[TreeChange(CHANGE_RENAME, ('a', F, blob1.id), ('b', F, blob2.id)), TreeChange(CHANGE_MODIFY, ('b', F, blob1.id), ('b', F, blob2.id))]], [parent1, parent2], merge, rename_detector=self.detector)
def test_tree_changes_for_merge_delete_delete_conflict(self): blob1 = make_object(Blob, data='1') blob2 = make_object(Blob, data='2') parent1 = self.commit_tree([('a', blob1)]) parent2 = self.commit_tree([('a', blob2)]) merge = self.commit_tree([]) self.assertChangesForMergeEqual( [[TreeChange.delete(('a', F, blob1.id)), TreeChange.delete(('a', F, blob2.id))]], [parent1, parent2], merge)
def test_find_copies_harder_content(self): blob1 = make_object(Blob, data='a\nb\nc\nd\n') blob2 = make_object(Blob, data='a\nb\nc\ne\n') tree1 = self.commit_tree([('a', blob1)]) tree2 = self.commit_tree([('a', blob1), ('b', blob2)]) self.assertEqual([TreeChange.add(('b', F, blob2.id))], self.detect_renames(tree1, tree2)) self.assertEqual( [TreeChange(CHANGE_COPY, ('a', F, blob1.id), ('b', F, blob2.id))], self.detect_renames(tree1, tree2, find_copies_harder=True))
def test_content_rename_one_to_one(self): b11 = make_object(Blob, data='a\nb\nc\nd\n') b12 = make_object(Blob, data='a\nb\nc\ne\n') b21 = make_object(Blob, data='e\nf\ng\n\h') b22 = make_object(Blob, data='e\nf\ng\n\i') tree1 = self.commit_tree([('a', b11), ('b', b21)]) tree2 = self.commit_tree([('c', b12), ('d', b22)]) self.assertEqual( [TreeChange(CHANGE_RENAME, ('a', F, b11.id), ('c', F, b12.id)), TreeChange(CHANGE_RENAME, ('b', F, b21.id), ('d', F, b22.id))], self.detect_renames(tree1, tree2))
def test_tree_changes_for_merge_octopus_modify_conflict(self): # Because the octopus merge strategy is limited, I doubt it's possible # to create this with the git command line. But the output is well- # defined, so test it anyway. r = list(range(5)) parent_blobs = [make_object(Blob, data=str(i).encode("utf-8")) for i in r] merge_blob = make_object(Blob, data=b"merge") parents = [self.commit_tree([("a", parent_blobs[i])]) for i in r] merge = self.commit_tree([("a", merge_blob)]) expected = [[TreeChange(CHANGE_MODIFY, (b"a", F, parent_blobs[i].id), (b"a", F, merge_blob.id)) for i in r]] self.assertChangesForMergeEqual(expected, parents, merge)
def test_content_rename_swap(self): blob1 = make_object(Blob, data='a\nb\nc\nd\n') blob2 = make_object(Blob, data='e\nf\ng\nh\n') blob3 = make_object(Blob, data='a\nb\nc\ne\n') blob4 = make_object(Blob, data='e\nf\ng\ni\n') tree1 = self.commit_tree([('a', blob1), ('b', blob2)]) tree2 = self.commit_tree([('a', blob4), ('b', blob3)]) self.assertEqual( [TreeChange(CHANGE_RENAME, ('a', F, blob1.id), ('b', F, blob3.id)), TreeChange(CHANGE_RENAME, ('b', F, blob2.id), ('a', F, blob4.id))], self.detect_renames(tree1, tree2, rewrite_threshold=60))
def test_paths_merge(self): blob_a1 = make_object(Blob, data='a1') blob_a2 = make_object(Blob, data='a2') blob_a3 = make_object(Blob, data='a3') x1, y2, m3, m4 = self.make_commits( [[1], [2], [3, 1, 2], [4, 1, 2]], trees={1: [('a', blob_a1)], 2: [('a', blob_a2)], 3: [('a', blob_a3)], 4: [('a', blob_a1)]}) # Non-conflicting self.assertWalkYields([m3, y2, x1], [m3.id], paths=['a']) self.assertWalkYields([y2, x1], [m4.id], paths=['a'])
def test_tree_changes(self): blob_a1 = make_object(Blob, data='a1') blob_a2 = make_object(Blob, data='a2') blob_b = make_object(Blob, data='b') for blob in [blob_a1, blob_a2, blob_b]: self.store.add_object(blob) blobs_1 = [('a', blob_a1.id, 0o100644), ('b', blob_b.id, 0o100644)] tree1_id = commit_tree(self.store, blobs_1) blobs_2 = [('a', blob_a2.id, 0o100644), ('b', blob_b.id, 0o100644)] tree2_id = commit_tree(self.store, blobs_2) change_a = (('a', 'a'), (0o100644, 0o100644), (blob_a1.id, blob_a2.id)) self.assertEqual([change_a], list(self.store.tree_changes(tree1_id, tree2_id))) self.assertEqual([ change_a, (('b', 'b'), (0o100644, 0o100644), (blob_b.id, blob_b.id)) ], list( self.store.tree_changes(tree1_id, tree2_id, want_unchanged=True)))
def test_rewrite_threshold(self): blob1 = make_object(Blob, data=b'a\nb\nc\nd\n') blob2 = make_object(Blob, data=b'a\nb\nc\ne\n') blob3 = make_object(Blob, data=b'a\nb\nf\ng\n') tree1 = self.commit_tree([(b'a', blob1)]) tree2 = self.commit_tree([(b'a', blob3), (b'b', blob2)]) no_renames = [ TreeChange(CHANGE_MODIFY, (b'a', F, blob1.id), (b'a', F, blob3.id)), TreeChange(CHANGE_COPY, (b'a', F, blob1.id), (b'b', F, blob2.id))] self.assertEqual( no_renames, self.detect_renames(tree1, tree2)) self.assertEqual( no_renames, self.detect_renames( tree1, tree2, rewrite_threshold=40)) self.assertEqual( [TreeChange.add((b'a', F, blob3.id)), TreeChange(CHANGE_RENAME, (b'a', F, blob1.id), (b'b', F, blob2.id))], self.detect_renames(tree1, tree2, rewrite_threshold=80))
def test_tree_changes_no_changes(self): blob = make_object(Blob, data='blob') tree = self.commit_tree([('a', blob), ('b/c', blob)]) self.assertChangesEqual([], self.empty_tree, self.empty_tree) self.assertChangesEqual([], tree, tree) self.assertChangesEqual([ TreeChange(CHANGE_UNCHANGED, ('a', F, blob.id), ('a', F, blob.id)), TreeChange(CHANGE_UNCHANGED, ('b/c', F, blob.id), ('b/c', F, blob.id)) ], tree, tree, want_unchanged=True)
def test_tag(self): c1, c2 = self.make_linear_commits(2) tag = make_object(Tag, name='tag', message='', tagger='Tagger <*****@*****.**>', tag_time=12345, tag_timezone=0, object=(Commit, c2.id)) self._store.add_object(tag) self.assertEqual((set([c1.id]), set([c2.id])), _find_shallow(self._store, [tag.id], 1))
def test_tree_changes_name_order(self): blob = make_object(Blob, data=b'a') tree1 = self.commit_tree([(b'a', blob), (b'a.', blob), (b'a..', blob)]) # Tree order is the reverse of this, so if we used tree order, 'a..' # would not be merged. tree2 = self.commit_tree([(b'a/x', blob), (b'a./x', blob), (b'a..', blob)]) self.assertChangesEqual( [TreeChange.delete((b'a', F, blob.id)), TreeChange.add((b'a/x', F, blob.id)), TreeChange.delete((b'a.', F, blob.id)), TreeChange.add((b'a./x', F, blob.id))], tree1, tree2)
def test_alternates(self): alternate_dir = tempfile.mkdtemp() if not isinstance(alternate_dir, bytes): alternate_dir = alternate_dir.encode(sys.getfilesystemencoding()) self.addCleanup(shutil.rmtree, alternate_dir) alternate_store = DiskObjectStore(alternate_dir) b2 = make_object(Blob, data=b"yummy data") alternate_store.add_object(b2) store = DiskObjectStore(self.store_dir) self.assertRaises(KeyError, store.__getitem__, b2.id) store.add_alternate_path(alternate_dir) self.assertIn(b2.id, store) self.assertEqual(b2, store[b2.id])
def test_store_resilience(self): """Test if updating an existing stored object doesn't erase the object from the store. """ test_object = make_object(Blob, data=b'data') self.store.add_object(test_object) test_object_id = test_object.id test_object.data = test_object.data + b'update' stored_test_object = self.store[test_object_id] self.assertNotEqual(test_object.id, stored_test_object.id) self.assertEqual(stored_test_object.id, test_object_id)
def test_no_head_no_checkout(self): f1_1 = make_object(Blob, data=b'f1') commit_spec = [[1]] trees = {1: [(b'f1', f1_1), (b'f2', f1_1)]} (c1, ) = build_commit_graph(self.repo.object_store, commit_spec, trees) self.repo.refs[b"refs/heads/master"] = c1.id target_path = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, target_path) errstream = BytesIO() r = porcelain.clone( self.repo.path, target_path, checkout=True, errstream=errstream) r.close()
def test_get_loose_object_error(self): blob = make_object(Blob, data=b'foo') backend = _test_backend([blob]) mat = re.search('^(..)(.{38})$', blob.id.decode('ascii')) def as_legacy_object_error(self): raise IOError self.addCleanup(setattr, Blob, 'as_legacy_object', Blob.as_legacy_object) Blob.as_legacy_object = as_legacy_object_error list(get_loose_object(self._req, backend, mat)) self.assertEqual(HTTP_ERROR, self._status)
def test_all_changes(self): # Construct a commit with 2 files in different subdirectories. blob_a = make_object(Blob, data=b'a') blob_b = make_object(Blob, data=b'b') c1 = self.make_linear_commits( 1, trees={1: [(b'x/a', blob_a), (b'y/b', blob_b)]}, )[0] # Get the WalkEntry for the commit. walker = Walker(self.store, c1.id) walker_entry = list(walker)[0] changes = walker_entry.changes() # Compare the changes with the expected values. entry_a = (b'x/a', F, blob_a.id) entry_b = (b'y/b', F, blob_b.id) self.assertEqual( [TreeChange.add(entry_a), TreeChange.add(entry_b)], changes, )
def test_serialize_none_message(self): x = make_object(Tag, tagger=b'Jelmer Vernooij <*****@*****.**>', name=b'0.1', message=None, object=(Blob, b'd80c186a03f423a81b39df39dc87fd269736ca86'), tag_time=423423423, tag_timezone=0) self.assertEqual((b'object d80c186a03f423a81b39df39dc87fd269736ca86\n' b'type blob\n' b'tag 0.1\n' b'tagger Jelmer Vernooij <*****@*****.**> ' b'423423423 +0000\n'), x.as_raw_string())
def test_all_with_merge(self): blob_a = make_object(Blob, data=b"a") blob_a2 = make_object(Blob, data=b"a2") blob_b = make_object(Blob, data=b"b") blob_b2 = make_object(Blob, data=b"b2") x1, y2, m3 = self.make_commits( [[1], [2], [3, 1, 2]], trees={ 1: [(b"x/a", blob_a)], 2: [(b"y/b", blob_b)], 3: [(b"x/a", blob_a2), (b"y/b", blob_b2)], }, ) # Get the WalkEntry for the merge commit. walker = Walker(self.store, m3.id) entries = list(walker) walker_entry = entries[0] self.assertEqual(walker_entry.commit.id, m3.id) changes = walker_entry.changes() self.assertEqual(2, len(changes)) entry_a = (b"x/a", F, blob_a.id) entry_a2 = (b"x/a", F, blob_a2.id) entry_b = (b"y/b", F, blob_b.id) entry_b2 = (b"y/b", F, blob_b2.id) self.assertEqual( [ [ TreeChange(CHANGE_MODIFY, entry_a, entry_a2), TreeChange.add(entry_a2), ], [ TreeChange.add(entry_b2), TreeChange(CHANGE_MODIFY, entry_b, entry_b2), ], ], changes, )
def test_rel_alternative_path(self): alternate_dir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, alternate_dir) alternate_store = DiskObjectStore(alternate_dir) b2 = make_object(Blob, data="yummy data") alternate_store.add_object(b2) store = DiskObjectStore(self.store_dir) self.assertRaises(KeyError, store.__getitem__, b2.id) store.add_alternate_path(os.path.relpath(alternate_dir, self.store_dir)) self.assertEqual(list(alternate_store), list(store.alternates[0])) self.assertIn(b2.id, store) self.assertEqual(b2, store[b2.id])
def test_add_thin_pack(self): o = MemoryObjectStore() blob = make_object(Blob, data=b'yummy data') o.add_object(blob) f = BytesIO() entries = build_pack(f, [ (REF_DELTA, (blob.id, b'more yummy data')), ], store=o) o.add_thin_pack(f.read, None) packed_blob_sha = sha_to_hex(entries[0][3]) self.assertEqual((Blob.type_num, b'more yummy data'), o.get_raw(packed_blob_sha))
def test_tree_changes_rename_detector(self): blob_a1 = make_object(Blob, data='a\nb\nc\nd\n') blob_a2 = make_object(Blob, data='a\nb\nc\ne\n') blob_b = make_object(Blob, data='b') tree1 = self.commit_tree([('a', blob_a1), ('b', blob_b)]) tree2 = self.commit_tree([('c', blob_a2), ('b', blob_b)]) detector = RenameDetector(self.store) self.assertChangesEqual([ TreeChange.delete(('a', F, blob_a1.id)), TreeChange.add(('c', F, blob_a2.id)) ], tree1, tree2) self.assertChangesEqual([ TreeChange.delete(('a', F, blob_a1.id)), TreeChange(CHANGE_UNCHANGED, ('b', F, blob_b.id), ('b', F, blob_b.id)), TreeChange.add(('c', F, blob_a2.id)) ], tree1, tree2, want_unchanged=True) self.assertChangesEqual([ TreeChange(CHANGE_RENAME, ('a', F, blob_a1.id), ('c', F, blob_a2.id)) ], tree1, tree2, rename_detector=detector) self.assertChangesEqual([ TreeChange(CHANGE_RENAME, ('a', F, blob_a1.id), ('c', F, blob_a2.id)), TreeChange(CHANGE_UNCHANGED, ('b', F, blob_b.id), ('b', F, blob_b.id)) ], tree1, tree2, rename_detector=detector, want_unchanged=True)
def test_follow_rename(self): blob = make_object(Blob, data=b'blob') names = [b'a', b'a', b'b', b'b', b'c', b'c'] trees = dict((i + 1, [(n, blob, F)]) for i, n in enumerate(names)) c1, c2, c3, c4, c5, c6 = self.make_linear_commits(6, trees=trees) self.assertWalkYields([c5], [c6.id], paths=[b'c']) e = lambda n: (n, F, blob.id) self.assertWalkYields( [TestWalkEntry(c5, [TreeChange(CHANGE_RENAME, e(b'b'), e(b'c'))]), TestWalkEntry(c3, [TreeChange(CHANGE_RENAME, e(b'a'), e(b'b'))]), TestWalkEntry(c1, [TreeChange.add(e(b'a'))])], [c6.id], paths=[b'c'], follow=True)
def test_deserialize_mergetags(self): tag = make_object( Tag, object=(Commit, "a38d6181ff27824c79fc7df825164a212eff6a3f"), object_type_name="commit", name="v2.6.22-rc7", tag_time=1183319674, tag_timezone=0, tagger="Linus Torvalds <*****@*****.**>", message=default_message) commit = self.make_commit(mergetag=[tag, tag]) d = Commit() d._deserialize(commit.as_raw_chunks()) self.assertEqual(commit, d)
def test_exact_rename_swap(self): blob1 = make_object(Blob, data=b"1") blob2 = make_object(Blob, data=b"2") tree1 = self.commit_tree([(b"a", blob1), (b"b", blob2)]) tree2 = self.commit_tree([(b"a", blob2), (b"b", blob1)]) self.assertEqual( [ TreeChange(CHANGE_MODIFY, (b"a", F, blob1.id), (b"a", F, blob2.id)), TreeChange(CHANGE_MODIFY, (b"b", F, blob2.id), (b"b", F, blob1.id)), ], self.detect_renames(tree1, tree2), ) self.assertEqual( [ TreeChange(CHANGE_RENAME, (b"a", F, blob1.id), (b"b", F, blob1.id)), TreeChange(CHANGE_RENAME, (b"b", F, blob2.id), (b"a", F, blob2.id)), ], self.detect_renames(tree1, tree2, rewrite_threshold=50), )
def test_paths(self): blob_a1 = make_object(Blob, data=b'a1') blob_b2 = make_object(Blob, data=b'b2') blob_a3 = make_object(Blob, data=b'a3') blob_b3 = make_object(Blob, data=b'b3') c1, c2, c3 = self.make_linear_commits( 3, trees={1: [(b'a', blob_a1)], 2: [(b'a', blob_a1), (b'x/b', blob_b2)], 3: [(b'a', blob_a3), (b'x/b', blob_b3)]}) self.assertWalkYields([c3, c2, c1], [c3.id]) self.assertWalkYields([c3, c1], [c3.id], paths=[b'a']) self.assertWalkYields([c3, c2], [c3.id], paths=[b'x/b']) # All changes are included, not just for requested paths. changes = [ TreeChange(CHANGE_MODIFY, (b'a', F, blob_a1.id), (b'a', F, blob_a3.id)), TreeChange(CHANGE_MODIFY, (b'x/b', F, blob_b2.id), (b'x/b', F, blob_b3.id)), ] self.assertWalkYields([TestWalkEntry(c3, changes)], [c3.id], max_entries=1, paths=[b'a'])
def test_no_checkout_with_bare(self): f1_1 = make_object(Blob, data=b'f1') commit_spec = [[1]] trees = {1: [(b'f1', f1_1), (b'f2', f1_1)]} (c1, ) = build_commit_graph(self.repo.object_store, commit_spec, trees) self.repo.refs[b"refs/heads/master"] = c1.id self.repo.refs[b"HEAD"] = c1.id target_path = tempfile.mkdtemp() errstream = BytesIO() self.addCleanup(shutil.rmtree, target_path) self.assertRaises( ValueError, porcelain.clone, self.repo.path, target_path, checkout=True, bare=True, errstream=errstream)
def test_exact_rename_many_to_many(self): blob = make_object(Blob, data=b"1") tree1 = self.commit_tree([(b"a", blob), (b"b", blob)]) tree2 = self.commit_tree([(b"c", blob), (b"d", blob), (b"e", blob)]) self.assertEqual( [ TreeChange(CHANGE_RENAME, (b"a", F, blob.id), (b"c", F, blob.id)), TreeChange(CHANGE_COPY, (b"a", F, blob.id), (b"e", F, blob.id)), TreeChange(CHANGE_RENAME, (b"b", F, blob.id), (b"d", F, blob.id)), ], self.detect_renames(tree1, tree2), )
def setUp(self): super(MOFLinearRepoTest, self).setUp() f1_1 = make_object(Blob, data='f1') # present in 1, removed in 3 f2_1 = make_object(Blob, data='f2') # present in all revisions, changed in 2 and 3 f2_2 = make_object(Blob, data='f2-changed') f2_3 = make_object(Blob, data='f2-changed-again') f3_2 = make_object(Blob, data='f3') # added in 2, left unmodified in 3 commit_spec = [[1], [2, 1], [3, 2]] trees = {1: [('f1', f1_1), ('f2', f2_1)], 2: [('f1', f1_1), ('f2', f2_2), ('f3', f3_2)], 3: [('f2', f2_3), ('f3', f3_2)] } # commit 1: f1 and f2 # commit 2: f3 added, f2 changed. Missing shall report commit id and a # tree referenced by commit # commit 3: f1 removed, f2 changed. Commit sha and root tree sha shall # be reported as modified self.commits = build_commit_graph(self.store, commit_spec, trees) self.missing_1_2 = [self.cmt(2).id, self.cmt(2).tree, f2_2.id, f3_2.id] self.missing_2_3 = [self.cmt(3).id, self.cmt(3).tree, f2_3.id] self.missing_1_3 = [ self.cmt(2).id, self.cmt(3).id, self.cmt(2).tree, self.cmt(3).tree, f2_2.id, f3_2.id, f2_3.id]
def test_tree_changes(self): blob_a1 = make_object(Blob, data=b"a1") blob_a2 = make_object(Blob, data=b"a2") blob_b = make_object(Blob, data=b"b") for blob in [blob_a1, blob_a2, blob_b]: self.store.add_object(blob) blobs_1 = [(b"a", blob_a1.id, 0o100644), (b"b", blob_b.id, 0o100644)] tree1_id = commit_tree(self.store, blobs_1) blobs_2 = [(b"a", blob_a2.id, 0o100644), (b"b", blob_b.id, 0o100644)] tree2_id = commit_tree(self.store, blobs_2) change_a = ( (b"a", b"a"), (0o100644, 0o100644), (blob_a1.id, blob_a2.id), ) self.assertEqual([change_a], list(self.store.tree_changes(tree1_id, tree2_id))) self.assertEqual( [ change_a, ((b"b", b"b"), (0o100644, 0o100644), (blob_b.id, blob_b.id)), ], list(self.store.tree_changes(tree1_id, tree2_id, want_unchanged=True)), )
def test_tree_changes_modify_mode(self): blob_a = make_object(Blob, data=b"a") tree1 = self.commit_tree([(b"a", blob_a, 0o100644)]) tree2 = self.commit_tree([(b"a", blob_a, 0o100755)]) self.assertChangesEqual( [ TreeChange( CHANGE_MODIFY, (b"a", 0o100644, blob_a.id), (b"a", 0o100755, blob_a.id), ) ], tree1, tree2, )
def test_tree_changes_for_merge_add_exact_rename_conflict(self): blob = make_object(Blob, data=b"a\nb\nc\nd\n") parent1 = self.commit_tree([(b"a", blob)]) parent2 = self.commit_tree([]) merge = self.commit_tree([(b"b", blob)]) self.assertChangesForMergeEqual( [[ TreeChange(CHANGE_RENAME, (b"a", F, blob.id), (b"b", F, blob.id)), TreeChange.add((b"b", F, blob.id)), ]], [parent1, parent2], merge, rename_detector=self.detector, )
def test_content_rename_with_more_deletions(self): blob1 = make_object(Blob, data=b'') tree1 = self.commit_tree([(b'a', blob1), (b'b', blob1), (b'c', blob1), (b'd', blob1)]) tree2 = self.commit_tree([(b'e', blob1), (b'f', blob1), (b'g', blob1)]) self.maxDiff = None self.assertEqual([ TreeChange(CHANGE_RENAME, (b'a', F, blob1.id), (b'e', F, blob1.id)), TreeChange(CHANGE_RENAME, (b'b', F, blob1.id), (b'f', F, blob1.id)), TreeChange(CHANGE_RENAME, (b'c', F, blob1.id), (b'g', F, blob1.id)), TreeChange.delete((b'd', F, blob1.id)) ], self.detect_renames(tree1, tree2))
def test_changes_with_renames(self): blob = make_object(Blob, data=b'blob') c1, c2 = self.make_linear_commits( 2, trees={1: [(b'a', blob)], 2: [(b'b', blob)]}) entry_a = (b'a', F, blob.id) entry_b = (b'b', F, blob.id) changes_without_renames = [TreeChange.delete(entry_a), TreeChange.add(entry_b)] changes_with_renames = [TreeChange(CHANGE_RENAME, entry_a, entry_b)] self.assertWalkYields( [TestWalkEntry(c2, changes_without_renames)], [c2.id], max_entries=1) detector = RenameDetector(self.store) self.assertWalkYields( [TestWalkEntry(c2, changes_with_renames)], [c2.id], max_entries=1, rename_detector=detector)
def test_exact_copy_change_mode(self): blob = make_object(Blob, data=b"a\nb\nc\nd\n") tree1 = self.commit_tree([(b"a", blob)]) tree2 = self.commit_tree([(b"a", blob, 0o100755), (b"b", blob)]) self.assertEqual( [ TreeChange( CHANGE_MODIFY, (b"a", F, blob.id), (b"a", 0o100755, blob.id), ), TreeChange(CHANGE_COPY, (b"a", F, blob.id), (b"b", F, blob.id)), ], self.detect_renames(tree1, tree2), )
def test_get_depth(self): self.assertEqual(0, self.store._get_depth(testobject.id)) self.store.add_object(testobject) self.assertEqual( 1, self.store._get_depth(testobject.id, get_parents=lambda x: [])) parent = make_object(Blob, data=b"parent data") self.store.add_object(parent) self.assertEqual( 2, self.store._get_depth( testobject.id, get_parents=lambda x: [parent.id] if x == testobject else [], ), )
def test_add_blob_in_dir(self): blob_d = make_object(Blob, data=b"d") new_tree = commit_tree_changes( self.store, self.store[self.tree_id], [(b"e/f/d", 0o100644, blob_d.id)], ) self.assertEqual( new_tree.items(), [ TreeEntry(path=b"a", mode=stat.S_IFREG | 0o100644, sha=self.blob_a.id), TreeEntry( path=b"ad", mode=stat.S_IFDIR, sha=b"0e2ce2cd7725ff4817791be31ccd6e627e801f4a", ), TreeEntry(path=b"c", mode=stat.S_IFREG | 0o100644, sha=self.blob_c.id), TreeEntry( path=b"e", mode=stat.S_IFDIR, sha=b"6ab344e288724ac2fb38704728b8896e367ed108", ), ], ) e_tree = self.store[new_tree[b"e"][1]] self.assertEqual( e_tree.items(), [ TreeEntry( path=b"f", mode=stat.S_IFDIR, sha=b"24d2c94d8af232b15a0978c006bf61ef4479a0a5", ) ], ) f_tree = self.store[e_tree[b"f"][1]] self.assertEqual( f_tree.items(), [ TreeEntry( path=b"d", mode=stat.S_IFREG | 0o100644, sha=blob_d.id) ], )