/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Andrew Bennetts
  • Date: 2008-10-27 06:14:45 UTC
  • mfrom: (3793 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3795.
  • Revision ID: andrew.bennetts@canonical.com-20081027061445-eqt9lz6uw1mbvq4g
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
from cStringIO import StringIO
18
 
 
19
17
from bzrlib.lazy_import import lazy_import
20
18
lazy_import(globals(), """
 
19
import cStringIO
21
20
import re
22
21
import time
23
22
 
34
33
    lockdir,
35
34
    lru_cache,
36
35
    osutils,
37
 
    registry,
38
36
    remote,
39
37
    revision as _mod_revision,
40
38
    symbol_versioning,
41
 
    transactions,
42
39
    tsort,
43
40
    ui,
44
41
    )
45
42
from bzrlib.bundle import serializer
46
43
from bzrlib.revisiontree import RevisionTree
47
44
from bzrlib.store.versioned import VersionedFileStore
48
 
from bzrlib.store.text import TextStore
49
45
from bzrlib.testament import Testament
50
 
from bzrlib.util import bencode
51
46
""")
52
47
 
 
48
from bzrlib import registry
53
49
from bzrlib.decorators import needs_read_lock, needs_write_lock
54
50
from bzrlib.inter import InterObject
55
51
from bzrlib.inventory import Inventory, InventoryDirectory, ROOT_ID
57
53
        deprecated_method,
58
54
        one_one,
59
55
        one_two,
60
 
        one_three,
61
56
        one_six,
62
57
        )
63
 
from bzrlib.trace import mutter, mutter_callsite, note, warning
 
58
from bzrlib.trace import mutter, mutter_callsite, warning
64
59
 
65
60
 
66
61
# Old formats display a warning, but only once
241
236
            content - stat, length, exec, sha/link target. This is only
242
237
            accessed when the entry has a revision of None - that is when it is
243
238
            a candidate to commit.
244
 
        :return: A tuple (change_delta, version_recorded). change_delta is 
245
 
            an inventory_delta change for this entry against the basis tree of
246
 
            the commit, or None if no change occured against the basis tree.
 
239
        :return: A tuple (change_delta, version_recorded, fs_hash).
 
240
            change_delta is an inventory_delta change for this entry against
 
241
            the basis tree of the commit, or None if no change occured against
 
242
            the basis tree.
247
243
            version_recorded is True if a new version of the entry has been
248
244
            recorded. For instance, committing a merge where a file was only
249
245
            changed on the other side will return (delta, False).
 
246
            fs_hash is either None, or the hash details for the path (currently
 
247
            a tuple of the contents sha1 and the statvalue returned by
 
248
            tree.get_file_with_stat()).
250
249
        """
251
250
        if self.new_inventory.root is None:
252
251
            if ie.parent_id is not None:
287
286
                else:
288
287
                    # add
289
288
                    delta = (None, path, ie.file_id, ie)
290
 
                return delta, False
 
289
                return delta, False, None
291
290
            else:
292
291
                # we don't need to commit this, because the caller already
293
292
                # determined that an existing revision of this file is
298
297
                    raise AssertionError("Impossible situation, a skipped "
299
298
                        "inventory entry (%r) claims to be modified in this "
300
299
                        "commit (%r).", (ie, self._new_revision_id))
301
 
                return None, False
 
300
                return None, False, None
302
301
        # XXX: Friction: parent_candidates should return a list not a dict
303
302
        #      so that we don't have to walk the inventories again.
304
303
        parent_candiate_entries = ie.parent_candidates(parent_invs)
334
333
            # if the kind changed the content obviously has
335
334
            if kind != parent_entry.kind:
336
335
                store = True
 
336
        # Stat cache fingerprint feedback for the caller - None as we usually
 
337
        # don't generate one.
 
338
        fingerprint = None
337
339
        if kind == 'file':
338
340
            if content_summary[2] is None:
339
341
                raise ValueError("Files must not have executable = None")
350
352
                    ie.text_size = parent_entry.text_size
351
353
                    ie.text_sha1 = parent_entry.text_sha1
352
354
                    ie.executable = parent_entry.executable
353
 
                    return self._get_delta(ie, basis_inv, path), False
 
355
                    return self._get_delta(ie, basis_inv, path), False, None
354
356
                else:
355
357
                    # Either there is only a hash change(no hash cache entry,
356
358
                    # or same size content change), or there is no change on
363
365
                # absence of a content change in the file.
364
366
                nostore_sha = None
365
367
            ie.executable = content_summary[2]
366
 
            lines = tree.get_file(ie.file_id, path).readlines()
 
368
            file_obj, stat_value = tree.get_file_with_stat(ie.file_id, path)
 
369
            try:
 
370
                lines = file_obj.readlines()
 
371
            finally:
 
372
                file_obj.close()
367
373
            try:
368
374
                ie.text_sha1, ie.text_size = self._add_text_to_weave(
369
375
                    ie.file_id, lines, heads, nostore_sha)
 
376
                # Let the caller know we generated a stat fingerprint.
 
377
                fingerprint = (ie.text_sha1, stat_value)
370
378
            except errors.ExistingContent:
371
379
                # Turns out that the file content was unchanged, and we were
372
380
                # only going to store a new node if it was changed. Carry over
375
383
                ie.text_size = parent_entry.text_size
376
384
                ie.text_sha1 = parent_entry.text_sha1
377
385
                ie.executable = parent_entry.executable
378
 
                return self._get_delta(ie, basis_inv, path), False
 
386
                return self._get_delta(ie, basis_inv, path), False, None
379
387
        elif kind == 'directory':
380
388
            if not store:
381
389
                # all data is meta here, nothing specific to directory, so
382
390
                # carry over:
383
391
                ie.revision = parent_entry.revision
384
 
                return self._get_delta(ie, basis_inv, path), False
 
392
                return self._get_delta(ie, basis_inv, path), False, None
385
393
            lines = []
386
394
            self._add_text_to_weave(ie.file_id, lines, heads, None)
387
395
        elif kind == 'symlink':
395
403
                # unchanged, carry over.
396
404
                ie.revision = parent_entry.revision
397
405
                ie.symlink_target = parent_entry.symlink_target
398
 
                return self._get_delta(ie, basis_inv, path), False
 
406
                return self._get_delta(ie, basis_inv, path), False, None
399
407
            ie.symlink_target = current_link_target
400
408
            lines = []
401
409
            self._add_text_to_weave(ie.file_id, lines, heads, None)
407
415
                # unchanged, carry over.
408
416
                ie.reference_revision = parent_entry.reference_revision
409
417
                ie.revision = parent_entry.revision
410
 
                return self._get_delta(ie, basis_inv, path), False
 
418
                return self._get_delta(ie, basis_inv, path), False, None
411
419
            ie.reference_revision = content_summary[3]
412
420
            lines = []
413
421
            self._add_text_to_weave(ie.file_id, lines, heads, None)
414
422
        else:
415
423
            raise NotImplementedError('unknown kind')
416
424
        ie.revision = self._new_revision_id
417
 
        return self._get_delta(ie, basis_inv, path), True
 
425
        return self._get_delta(ie, basis_inv, path), True, fingerprint
418
426
 
419
427
    def _add_text_to_weave(self, file_id, new_lines, parents, nostore_sha):
420
428
        # Note: as we read the content directly from the tree, we know its not
1145
1153
        #       would have already do it.
1146
1154
        # TODO: jam 20070210 Just use _serializer.write_revision_to_string()
1147
1155
        rev = self.get_revision(revision_id)
1148
 
        rev_tmp = StringIO()
 
1156
        rev_tmp = cStringIO.StringIO()
1149
1157
        # the current serializer..
1150
1158
        self._serializer.write_revision(rev, rev_tmp)
1151
1159
        rev_tmp.seek(0)
2319
2327
    )
2320
2328
 
2321
2329
# Development formats. 
2322
 
# 1.5->1.6
2323
 
format_registry.register_lazy(
2324
 
    "Bazaar development format 1 (needs bzr.dev from before 1.6)\n",
2325
 
    'bzrlib.repofmt.pack_repo',
2326
 
    'RepositoryFormatPackDevelopment1',
2327
 
    )
2328
 
format_registry.register_lazy(
2329
 
    ("Bazaar development format 1 with subtree support "
2330
 
        "(needs bzr.dev from before 1.6)\n"),
2331
 
    'bzrlib.repofmt.pack_repo',
2332
 
    'RepositoryFormatPackDevelopment1Subtree',
2333
 
    )
2334
 
# 1.6->1.7 go below here
 
2330
# 1.7->1.8 go below here
 
2331
format_registry.register_lazy(
 
2332
    "Bazaar development format 2 (needs bzr.dev from before 1.8)\n",
 
2333
    'bzrlib.repofmt.pack_repo',
 
2334
    'RepositoryFormatPackDevelopment2',
 
2335
    )
 
2336
format_registry.register_lazy(
 
2337
    ("Bazaar development format 2 with subtree support "
 
2338
        "(needs bzr.dev from before 1.8)\n"),
 
2339
    'bzrlib.repofmt.pack_repo',
 
2340
    'RepositoryFormatPackDevelopment2Subtree',
 
2341
    )
2335
2342
 
2336
2343
 
2337
2344
class InterRepository(InterObject):
2922
2929
                RepositoryFormatKnitPack4,
2923
2930
                RepositoryFormatKnitPack5,
2924
2931
                RepositoryFormatKnitPack5RichRoot,
2925
 
                RepositoryFormatPackDevelopment1,
2926
 
                RepositoryFormatPackDevelopment1Subtree,
 
2932
                RepositoryFormatPackDevelopment2,
 
2933
                RepositoryFormatPackDevelopment2Subtree,
2927
2934
                )
2928
2935
            norichroot = (
2929
2936
                RepositoryFormatKnit1,            # no rr, no subtree
2930
2937
                RepositoryFormatKnitPack1,        # no rr, no subtree
2931
 
                RepositoryFormatPackDevelopment1, # no rr, no subtree
 
2938
                RepositoryFormatPackDevelopment2, # no rr, no subtree
2932
2939
                RepositoryFormatKnitPack5,        # no rr, no subtree
2933
2940
                )
2934
2941
            richroot = (
2936
2943
                RepositoryFormatKnitPack3,        # rr, subtree
2937
2944
                RepositoryFormatKnitPack4,        # rr, no subtree
2938
2945
                RepositoryFormatKnitPack5RichRoot,# rr, no subtree
2939
 
                RepositoryFormatPackDevelopment1Subtree, # rr, subtree
 
2946
                RepositoryFormatPackDevelopment2Subtree, # rr, subtree
2940
2947
                )
2941
2948
            for format in norichroot:
2942
2949
                if format.rich_root_data: