74
75
self.root = InventoryDirectory(ROOT_ID, '', None)
76
77
inventory = property(lambda x:x)
79
return self.paths.iterkeys()
78
root_inventory = property(lambda x:x)
80
def get_root_id(self):
81
return self.root.file_id
83
def all_file_ids(self):
84
return set(self.paths.keys())
86
def is_executable(self, file_id):
87
# Not all the files are executable.
81
90
def __getitem__(self, file_id):
82
91
if file_id == self.root.file_id:
94
103
for path, file_id in self.ids.iteritems():
95
104
yield path, self[file_id]
97
def get_file_kind(self, file_id):
106
def kind(self, file_id):
98
107
if file_id in self.contents:
104
113
def make_entry(self, file_id, path):
105
from bzrlib.inventory import (InventoryEntry, InventoryFile
106
, InventoryDirectory, InventoryLink)
114
from bzrlib.inventory import (InventoryFile , InventoryDirectory,
107
116
name = os.path.basename(path)
108
kind = self.get_file_kind(file_id)
117
kind = self.kind(file_id)
109
118
parent_id = self.parent_id(file_id)
110
119
text_sha_1, text_size = self.contents_stats(file_id)
111
120
if kind == 'directory':
146
155
def get_file_revision(self, file_id):
147
156
return self.inventory[file_id].revision
158
def get_file_size(self, file_id):
159
return self.inventory[file_id].text_size
161
def get_file_sha1(self, file_id):
162
return self.inventory[file_id].text_sha1
149
164
def contents_stats(self, file_id):
150
165
if file_id not in self.contents:
151
166
return None, None
508
523
if not _mod_revision.is_null(rev_id):
509
rh = self.b1.revision_history()
510
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
511
tree.branch.set_revision_history, rh[:rh.index(rev_id)+1])
524
tree.branch.generate_revision_history(rev_id)
513
526
delta = tree.changes_from(self.b1.repository.revision_tree(rev_id))
514
527
self.assertFalse(delta.has_changed(),
650
663
bundle = self.get_valid_bundle('null:', 'a@cset-0-4')
653
open('b1/sub/dir/WithCaps.txt', 'ab').write('\nAdding some text\n')
654
open('b1/sub/dir/ pre space', 'ab').write(
666
with open('b1/sub/dir/WithCaps.txt', 'ab') as f: f.write('\nAdding some text\n')
667
with open('b1/sub/dir/ pre space', 'ab') as f: f.write(
655
668
'\r\nAdding some\r\nDOS format lines\r\n')
656
open('b1/sub/dir/nolastnewline.txt', 'ab').write('\n')
669
with open('b1/sub/dir/nolastnewline.txt', 'ab') as f: f.write('\n')
657
670
self.tree1.rename_one('sub/dir/ pre space',
658
671
'sub/ start space')
659
672
self.tree1.commit('Modified files', rev_id='a@cset-0-5')
681
694
def _test_symlink_bundle(self, link_name, link_target, new_link_target):
682
695
link_id = 'link-1'
684
self.requireFeature(tests.SymlinkFeature)
697
self.requireFeature(features.SymlinkFeature)
685
698
self.tree1 = self.make_branch_and_tree('b1')
686
699
self.b1 = self.tree1.branch
728
741
self._test_symlink_bundle('link', 'bar/foo', 'mars')
730
743
def test_unicode_symlink_bundle(self):
731
self.requireFeature(tests.UnicodeFilenameFeature)
744
self.requireFeature(features.UnicodeFilenameFeature)
732
745
self._test_symlink_bundle(u'\N{Euro Sign}link',
733
746
u'bar/\N{Euro Sign}foo',
734
747
u'mars\N{Euro Sign}')
808
821
self.tree1 = self.make_branch_and_tree('b1')
809
822
self.b1 = self.tree1.branch
811
open('b1/one', 'wb').write('one\n')
824
with open('b1/one', 'wb') as f: f.write('one\n')
812
825
self.tree1.add('one')
813
826
self.tree1.commit('add file', rev_id='a@cset-0-1')
814
open('b1/one', 'wb').write('two\n')
827
with open('b1/one', 'wb') as f: f.write('two\n')
815
828
self.tree1.commit('modify', rev_id='a@cset-0-2')
816
open('b1/one', 'wb').write('three\n')
829
with open('b1/one', 'wb') as f: f.write('three\n')
817
830
self.tree1.commit('modify', rev_id='a@cset-0-3')
818
831
bundle_file = StringIO()
819
832
rev_ids = write_bundle(self.tree1.branch.repository, 'a@cset-0-3',
835
848
return bundle_file.getvalue()
837
850
def test_unicode_bundle(self):
838
self.requireFeature(tests.UnicodeFilenameFeature)
851
self.requireFeature(features.UnicodeFilenameFeature)
839
852
# Handle international characters
841
854
f = open(u'b1/with Dod\N{Euro Sign}', 'wb')
898
911
bundle = self.get_valid_bundle('null:', 'white-1')
901
open('b1/trailing space ', 'ab').write('add some text\n')
914
with open('b1/trailing space ', 'ab') as f: f.write('add some text\n')
902
915
self.tree1.commit('add text', rev_id='white-2')
904
917
bundle = self.get_valid_bundle('white-1', 'white-2')
946
959
self.tree1.commit('message', rev_id='revid1')
947
960
bundle = self.get_valid_bundle('null:', 'revid1')
948
961
tree = self.get_bundle_tree(bundle, 'revid1')
949
self.assertEqual('revid1', tree.inventory.root.revision)
962
root_revision = tree.get_file_revision(tree.get_root_id())
963
self.assertEqual('revid1', root_revision)
951
965
def test_install_revisions(self):
952
966
self.tree1 = self.make_branch_and_tree('b1')
1419
1433
from bzrlib.testament import Testament
1420
1434
# monkey patch gpg signing mechanism
1421
1435
bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
1422
new_config = test_commit.MustSignConfig(branch)
1423
commit.Commit(config=new_config).commit(message="base",
1436
new_config = test_commit.MustSignConfig()
1437
commit.Commit(config_stack=new_config).commit(message="base",
1424
1438
allow_pointless=True,
1426
1440
working_tree=tree_a)
1835
1849
bundle, then the ConnectionReset error should be propagated.
1837
1851
# Instantiate a server that will provoke a ConnectionReset
1838
sock_server = _DisconnectingTCPServer()
1852
sock_server = DisconnectingServer()
1839
1853
self.start_server(sock_server)
1840
1854
# We don't really care what the url is since the server will close the
1841
1855
# connection without interpreting it
1843
1857
self.assertRaises(errors.ConnectionReset, read_mergeable_from_url, url)
1846
class _DisconnectingTCPServer(object):
1847
"""A TCP server that immediately closes any connection made to it."""
1849
def start_server(self):
1850
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1851
self.sock.bind(('127.0.0.1', 0))
1853
self.port = self.sock.getsockname()[1]
1854
self.thread = threading.Thread(
1855
name='%s (port %d)' % (self.__class__.__name__, self.port),
1856
target=self.accept_and_close)
1859
def accept_and_close(self):
1860
conn, addr = self.sock.accept()
1861
conn.shutdown(socket.SHUT_RDWR)
1860
class DisconnectingHandler(SocketServer.BaseRequestHandler):
1861
"""A request handler that immediately closes any connection made to it."""
1864
self.request.close()
1867
class DisconnectingServer(test_server.TestingTCPServerInAThread):
1870
super(DisconnectingServer, self).__init__(
1872
test_server.TestingTCPServer,
1873
DisconnectingHandler)
1864
1875
def get_url(self):
1865
return 'bzr://127.0.0.1:%d/' % (self.port,)
1867
def stop_server(self):
1869
# make sure the thread dies by connecting to the listening socket,
1870
# just in case the test failed to do so.
1871
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1872
conn.connect(self.sock.getsockname())
1874
except socket.error:
1876
"""Return the url of the server"""
1877
return "bzr://%s:%d/" % self.server.server_address