65
65
def lookup_id(self, path):
66
"""Lookup the file id and text revision for a path.
68
:param path: Unicode path
69
:raises KeyError: raised if path was not found
70
:return: tuple with file id and text revision
66
72
return self.id_map.lookup(self.mapping, path)[:2]
68
74
def lookup_path(self, file_id):
121
127
raise errors.FileTimestampUnavailable(path)
122
128
return rev.timestamp
130
def is_executable(self, file_id, path=None):
132
path = self.id2path(file_id)
133
props = self.get_file_properties(file_id, path)
134
if props.has_key(properties.PROP_SPECIAL):
135
text = self.get_file_stream_by_path(path)
136
if text.read(5) == "link ":
138
return props.has_key(properties.PROP_EXECUTABLE)
140
def get_symlink_target(self, file_id, path=None):
142
path = self.id2path(file_id)
143
props = self.get_file_properties(file_id, path)
144
if not props.has_key(properties.PROP_SPECIAL):
146
text = self.get_file_stream_by_path(path).read()
147
if not text.startswith("link "):
149
return text[len("link "):]
151
def get_file_sha1(self, file_id, path=None, stat_value=None):
152
return osutils.sha_string(self.get_file_text(file_id, path))
154
def get_file_revision(self, file_id, path=None):
156
path = self.id2path(file_id)
157
file_id, file_revision = self.lookup_id(path)
160
def iter_files_bytes(self, file_ids):
161
for file_id, identifier in file_ids:
162
cur_file = (self.get_file_text(file_id),)
163
yield identifier, cur_file
165
def get_file_stream_by_path(self, path):
166
raise NotImplementedError(self.get_file_stream_by_path)
125
169
# This maps SVN names for eol-styles to bzr names:
205
249
self._rules_searcher = None
206
250
self.id_map = repository.get_fileid_map(self._revmeta, self.mapping)
207
251
self.file_properties = {}
208
self.transport = repository.transport.clone(self._revmeta.metarev.branch_path)
252
self.transport = repository.transport.clone(
253
self._revmeta.metarev.branch_path)
211
256
def inventory(self):
255
def get_file_revision(self, file_id, path=None):
257
path = self.id2path(file_id)
258
file_id, file_revision = self.lookup_id(path)
261
300
def get_file_size(self, file_id, path=None):
263
302
path = self.id2path(file_id)
264
303
# FIXME: More efficient implementation?
265
304
return self.inventory[file_id].text_size
267
def is_executable(self, file_id, path=None):
268
props = self.get_file_properties(file_id, path)
269
return props.has_key(properties.PROP_EXECUTABLE)
271
def get_symlink_target(self, file_id, path=None):
273
path = self.id2path(file_id)
275
(fetched_rev, props) = self.transport.get_file(path.encode("utf-8"),
276
stream, self._revmeta.metarev.revnum)
278
if props.has_key(properties.PROP_SPECIAL) and stream.read(5) == "link ":
282
def get_file_sha1(self, file_id, path=None, stat_value=None):
283
return osutils.sha_string(self.get_file_text(file_id, path))
285
306
def list_files(self, include_root=False, from_dir=None, recursive=True):
287
308
# The only files returned by this are those from the version
335
def get_file_stream_by_path(self, path):
337
(fetched_rev, props) = self.transport.get_file(path.encode("utf-8"),
338
stream, self._revmeta.metarev.revnum)
314
342
def get_file_text(self, file_id, path=None):
315
343
my_file = self.get_file(file_id, path)
450
478
ie = self.tree._bzr_inventory.add_path(self.path, 'symlink',
453
ie = self.tree._bzr_inventory.add_path(self.path, 'file', self.file_id)
481
ie = self.tree._bzr_inventory.add_path(self.path, 'file',
454
483
ie.revision = self.revision_id
456
485
actual_checksum = md5(file_data).hexdigest()
496
525
(propchanges, props) = adm.get_prop_diffs(
497
526
self.workingtree.abspath(relpath).encode("utf-8"))
498
527
if props.has_key(properties.PROP_SPECIAL):
499
is_symlink = (self.get_file_text_by_path(relpath).read(5) == "link ")
528
is_symlink = (self.get_file_stream_by_path(relpath).read(5) == "link ")
501
530
is_symlink = False
504
533
ie = self._bzr_inventory.add_path(relpath, 'symlink', id)
505
ie.symlink_target = self.get_file_text_by_path(relpath).read()[len("link "):]
534
ie.symlink_target = self.get_file_stream_by_path(relpath).read()[len("link "):]
507
536
ie = self._bzr_inventory.add_path(relpath, 'file', id)
508
data = osutils.fingerprint_file(self.get_file_text_by_path(relpath))
537
data = osutils.fingerprint_file(self.get_file_stream_by_path(relpath))
509
538
ie.text_sha1 = data['sha1']
510
539
ie.text_size = data['size']
511
540
ie.executable = props.has_key(properties.PROP_EXECUTABLE)
583
612
"""See Tree.get_revision_id()."""
584
613
return self.workingtree.last_revision()
586
def get_file_text_by_path(self, name):
587
"""See Tree.get_file_text_by_path()."""
615
def get_file_stream_by_path(self, name):
616
"""See Tree.get_file_stream_by_path()."""
588
617
assert isinstance(name, unicode)
589
618
wt_path = self.workingtree.abspath(name).encode("utf-8")
590
619
return wc.get_pristine_contents(wt_path)
592
def get_symlink_target(self, file_id, path=None):
594
path = self.id2path(file_id)
595
props = self.get_file_properties(file_id, path)
596
if not props.has_key(properties.PROP_SPECIAL):
598
text = self.get_file_text_by_path(path).read()
599
if not text.startswith("link "):
601
return text[len("link "):]
603
def get_file_sha1(self, file_id, path=None, stat_value=None):
604
return osutils.sha_string(self.get_file_text(file_id, path))
606
621
def kind(self, file_id):
608
623
return self.inventory[file_id].kind
610
def get_file_revision(self, file_id, path=None):
612
path = self.id2path(file_id)
613
(file_id, file_revision) = self.id_map.lookup(self.mapping, path)[:2]
616
def is_executable(self, file_id, path=None):
618
path = self.id2path(file_id)
619
props = self.get_file_properties(file_id, path)
620
if props.has_key(properties.PROP_SPECIAL):
621
text = self.get_file_text_by_path(path)
622
if text.read(5) == "link ":
624
return props.has_key(properties.PROP_EXECUTABLE)
626
625
def get_file_text(self, file_id, path=None):
627
626
"""See Tree.get_file_text()."""
629
628
path = self.id2path(file_id)
630
return self.get_file_text_by_path(path).read()
629
return self.get_file_stream_by_path(path).read()
632
631
def get_file_properties(self, file_id, path=None):
633
632
"""See SubversionTree.get_file_properties()."""
653
652
self.workingtree.base_revnum, file_id, self.get_revision_id(),
654
653
self.workingtree.branch.mapping)
656
def iter_files_bytes(self, file_ids):
657
for file_id, identifier in file_ids:
658
cur_file = (self.get_file_text(file_id),)
659
yield identifier, cur_file
661
655
def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
663
657
return self.inventory.iter_entries_by_dir(