13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
"""WorkingTree object and friends.
230
231
wt_trans = self.bzrdir.get_workingtree_transport(None)
231
232
cache_filename = wt_trans.local_abspath('stat-cache')
232
233
self._hashcache = hashcache.HashCache(basedir, cache_filename,
233
self.bzrdir._get_file_mode())
234
self.bzrdir._get_file_mode(),
235
self._content_filter_stack_provider())
234
236
hc = self._hashcache
236
238
# is this scan needed ? it makes things kinda slow.
435
437
def has_filename(self, filename):
436
438
return osutils.lexists(self.abspath(filename))
438
def get_file(self, file_id, path=None):
439
return self.get_file_with_stat(file_id, path)[0]
440
def get_file(self, file_id, path=None, filtered=True):
441
return self.get_file_with_stat(file_id, path, filtered=filtered)[0]
441
def get_file_with_stat(self, file_id, path=None, _fstat=os.fstat):
443
def get_file_with_stat(self, file_id, path=None, filtered=True,
442
445
"""See MutableTree.get_file_with_stat."""
444
447
path = self.id2path(file_id)
445
file_obj = self.get_file_byname(path)
446
return (file_obj, _fstat(file_obj.fileno()))
448
def get_file_byname(self, filename):
449
return file(self.abspath(filename), 'rb')
451
def get_file_lines(self, file_id, path=None):
448
file_obj = self.get_file_byname(path, filtered=False)
449
stat_value = _fstat(file_obj.fileno())
450
if self.supports_content_filtering() and filtered:
451
filters = self._content_filter_stack(path)
452
file_obj = filtered_input_file(file_obj, filters)
453
return (file_obj, stat_value)
455
def get_file_text(self, file_id, path=None, filtered=True):
456
return self.get_file(file_id, path=path, filtered=filtered).read()
458
def get_file_byname(self, filename, filtered=True):
459
path = self.abspath(filename)
461
if self.supports_content_filtering() and filtered:
462
filters = self._content_filter_stack(filename)
463
return filtered_input_file(f, filters)
467
def get_file_lines(self, file_id, path=None, filtered=True):
452
468
"""See Tree.get_file_lines()"""
453
file = self.get_file(file_id, path)
469
file = self.get_file(file_id, path, filtered=filtered)
455
471
return file.readlines()
750
766
def _set_merges_from_parent_ids(self, parent_ids):
751
767
merges = parent_ids[1:]
752
768
self._transport.put_bytes('pending-merges', '\n'.join(merges),
753
mode=self._control_files._file_mode)
769
mode=self.bzrdir._get_file_mode())
755
771
def _filter_parent_ids_by_ancestry(self, revision_ids):
756
772
"""Check that all merged revisions are proper 'heads'.
856
872
self._must_be_locked()
857
873
my_file = rio_file(stanzas, header)
858
874
self._transport.put_file(filename, my_file,
859
mode=self._control_files._file_mode)
875
mode=self.bzrdir._get_file_mode())
861
877
@needs_write_lock # because merge pulls data into the branch.
862
878
def merge_from_branch(self, branch, to_revision=None, from_revision=None,
1088
1104
self._serialize(self._inventory, sio)
1090
1106
self._transport.put_file('inventory', sio,
1091
mode=self._control_files._file_mode)
1107
mode=self.bzrdir._get_file_mode())
1092
1108
self._inventory_is_modified = False
1094
1110
def _kind(self, relpath):
1811
1827
path = self._basis_inventory_name()
1812
1828
sio = StringIO(xml)
1813
1829
self._transport.put_file(path, sio,
1814
mode=self._control_files._file_mode)
1830
mode=self.bzrdir._get_file_mode())
1816
1832
def _create_basis_xml_from_inventory(self, revision_id, inventory):
1817
1833
"""Create the text that will be saved in basis-inventory"""
2888
2904
control_files.create_lock()
2889
2905
control_files.lock_write()
2890
2906
transport.put_bytes('format', self.get_format_string(),
2891
mode=control_files._file_mode)
2907
mode=a_bzrdir._get_file_mode())
2892
2908
if from_branch is not None:
2893
2909
branch = from_branch