~ubuntu-branches/ubuntu/oneiric/bzr-svn/oneiric

« back to all changes in this revision

Viewing changes to tree.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2011-08-26 19:47:18 UTC
  • mfrom: (1.1.31 upstream) (3.3.8 sid)
  • Revision ID: james.westby@ubuntu.com-20110826194718-iefslmdqyftcjyxx
Tags: 1.1.0-1
* New upstream release.
 + Fixes problems with sparse revision caches. LP: #795700, LP: #664085
 + Fixes test run against bzr 2.4.0. LP: #828381

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
        return True
64
64
 
65
65
    def lookup_id(self, path):
 
66
        """Lookup the file id and text revision for a path.
 
67
 
 
68
        :param path: Unicode path
 
69
        :raises KeyError: raised if path was not found
 
70
        :return: tuple with file id and text revision
 
71
        """
66
72
        return self.id_map.lookup(self.mapping, path)[:2]
67
73
 
68
74
    def lookup_path(self, file_id):
121
127
            raise errors.FileTimestampUnavailable(path)
122
128
        return rev.timestamp
123
129
 
 
130
    def is_executable(self, file_id, path=None):
 
131
        if path is 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 ":
 
137
                return False
 
138
        return props.has_key(properties.PROP_EXECUTABLE)
 
139
 
 
140
    def get_symlink_target(self, file_id, path=None):
 
141
        if path is 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):
 
145
            return None
 
146
        text = self.get_file_stream_by_path(path).read()
 
147
        if not text.startswith("link "):
 
148
            return None
 
149
        return text[len("link "):]
 
150
 
 
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))
 
153
 
 
154
    def get_file_revision(self, file_id, path=None):
 
155
        if path is None:
 
156
            path = self.id2path(file_id)
 
157
        file_id, file_revision = self.lookup_id(path)
 
158
        return file_revision
 
159
 
 
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
 
164
 
 
165
    def get_file_stream_by_path(self, path):
 
166
        raise NotImplementedError(self.get_file_stream_by_path)
 
167
 
124
168
 
125
169
# This maps SVN names for eol-styles to bzr names:
126
170
eol_style = {
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)
209
254
 
210
255
    @property
211
256
    def inventory(self):
252
297
            return "symlink"
253
298
        return "file"
254
299
 
255
 
    def get_file_revision(self, file_id, path=None):
256
 
        if path is None:
257
 
            path = self.id2path(file_id)
258
 
        file_id, file_revision = self.lookup_id(path)
259
 
        return file_revision
260
 
 
261
300
    def get_file_size(self, file_id, path=None):
262
 
        if not path:
 
301
        if path is None:
263
302
            path = self.id2path(file_id)
264
303
        # FIXME: More efficient implementation?
265
304
        return self.inventory[file_id].text_size
266
305
 
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)
270
 
 
271
 
    def get_symlink_target(self, file_id, path=None):
272
 
        if path is None:
273
 
            path = self.id2path(file_id)
274
 
        stream = StringIO()
275
 
        (fetched_rev, props) = self.transport.get_file(path.encode("utf-8"),
276
 
                stream, self._revmeta.metarev.revnum)
277
 
        stream.seek(0)
278
 
        if props.has_key(properties.PROP_SPECIAL) and stream.read(5) == "link ":
279
 
            return stream.read()
280
 
        return None
281
 
 
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))
284
 
 
285
306
    def list_files(self, include_root=False, from_dir=None, recursive=True):
286
307
        # FIXME
287
308
        # The only files returned by this are those from the version
311
332
        stream.seek(0)
312
333
        return stream
313
334
 
 
335
    def get_file_stream_by_path(self, path):
 
336
        stream = StringIO()
 
337
        (fetched_rev, props) = self.transport.get_file(path.encode("utf-8"),
 
338
                stream, self._revmeta.metarev.revnum)
 
339
        stream.seek(0)
 
340
        return stream
 
341
 
314
342
    def get_file_text(self, file_id, path=None):
315
343
        my_file = self.get_file(file_id, path)
316
344
        try:
450
478
            ie = self.tree._bzr_inventory.add_path(self.path, 'symlink',
451
479
                self.file_id)
452
480
        else:
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',
 
482
                self.file_id)
454
483
        ie.revision = self.revision_id
455
484
 
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 ")
500
529
            else:
501
530
                is_symlink = False
502
531
 
503
532
            if is_symlink:
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 "):]
506
535
            else:
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)
528
557
            entries = adm.entries_read(False)
529
558
            entry = entries[""]
530
559
            (id, revid) = find_ids(entry)
531
 
            if id == None:
 
560
            if id is None:
532
561
                return
533
562
 
534
563
            # First handle directory itself
583
612
        """See Tree.get_revision_id()."""
584
613
        return self.workingtree.last_revision()
585
614
 
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)
591
620
 
592
 
    def get_symlink_target(self, file_id, path=None):
593
 
        if path is 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):
597
 
            return None
598
 
        text = self.get_file_text_by_path(path).read()
599
 
        if not text.startswith("link "):
600
 
            return None
601
 
        return text[len("link "):]
602
 
 
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))
605
 
 
606
621
    def kind(self, file_id):
607
622
        # FIXME
608
623
        return self.inventory[file_id].kind
609
624
 
610
 
    def get_file_revision(self, file_id, path=None):
611
 
        if path is None:
612
 
            path = self.id2path(file_id)
613
 
        (file_id, file_revision) = self.id_map.lookup(self.mapping, path)[:2]
614
 
        return file_revision
615
 
 
616
 
    def is_executable(self, file_id, path=None):
617
 
        if path is 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 ":
623
 
                return False
624
 
        return props.has_key(properties.PROP_EXECUTABLE)
625
 
 
626
625
    def get_file_text(self, file_id, path=None):
627
626
        """See Tree.get_file_text()."""
628
627
        if path is None:
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()
631
630
 
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)
655
654
 
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
660
 
 
661
655
    def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
662
656
        # FIXME
663
657
        return self.inventory.iter_entries_by_dir(