~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/upgrade.py

  • Committer: Martin Pool
  • Date: 2006-01-13 08:12:22 UTC
  • mfrom: (1185.63.5 bzr.patches)
  • Revision ID: mbp@sourcefrog.net-20060113081222-6b572004a2ade0cc
[merge] test_hashcache_raise from Denys

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/python
2
 
#
3
1
# Copyright (C) 2005 Canonical Ltd
4
2
#
5
3
# This program is free software; you can redistribute it and/or modify
68
66
# versions.
69
67
 
70
68
 
71
 
# TODO: Don't create a progress bar here, have it passed by the caller.  
72
 
# At least do it from the UI factory.
73
 
 
74
 
if False:
75
 
    try:
76
 
        import psyco
77
 
        psyco.full()
78
 
    except ImportError:
79
 
        pass
80
 
 
81
 
 
82
69
import os
83
70
import tempfile
84
71
import sys
85
 
import logging
86
72
import shutil
87
73
 
88
74
from bzrlib.branch import Branch, find_branch
89
75
from bzrlib.branch import BZR_BRANCH_FORMAT_5, BZR_BRANCH_FORMAT_6
90
76
import bzrlib.hashcache as hashcache
91
 
from bzrlib.revfile import Revfile
92
77
from bzrlib.weave import Weave
93
78
from bzrlib.weavefile import read_weave, write_weave
94
79
from bzrlib.ui import ui_factory
95
80
from bzrlib.atomicfile import AtomicFile
96
81
from bzrlib.xml4 import serializer_v4
97
82
from bzrlib.xml5 import serializer_v5
98
 
from bzrlib.trace import mutter, note, warning, enable_default_logging
99
 
from bzrlib.osutils import sha_strings, sha_string
 
83
from bzrlib.trace import mutter, note, warning
 
84
from bzrlib.osutils import sha_strings, sha_string, pathjoin, abspath
100
85
 
101
86
 
102
87
class Convert(object):
123
108
            note('starting upgrade from format 5 to 6')
124
109
            self._convert_to_prefixed()
125
110
            self._open_branch()
126
 
        cache = hashcache.HashCache(os.path.abspath(self.base))
 
111
        cache = hashcache.HashCache(abspath(self.base))
127
112
        cache.clear()
128
113
        cache.write()
129
114
        note("finished")
133
118
        from bzrlib.store import hash_prefix
134
119
        for store_name in ["weaves", "revision-store"]:
135
120
            note("adding prefixes to %s" % store_name) 
136
 
            store_dir = os.path.join(self.base, ".bzr", store_name)
 
121
            store_dir = pathjoin(self.base, ".bzr", store_name)
137
122
            for filename in os.listdir(store_dir):
138
123
                if filename.endswith(".weave") or filename.endswith(".gz"):
139
124
                    file_id = os.path.splitext(filename)[0]
140
125
                else:
141
126
                    file_id = filename
142
 
                prefix_dir = os.path.join(store_dir, hash_prefix(file_id))
 
127
                prefix_dir = pathjoin(store_dir, hash_prefix(file_id))
143
128
                if not os.path.isdir(prefix_dir):
144
129
                    os.mkdir(prefix_dir)
145
 
                os.rename(os.path.join(store_dir, filename),
146
 
                          os.path.join(prefix_dir, filename))
 
130
                os.rename(pathjoin(store_dir, filename),
 
131
                          pathjoin(prefix_dir, filename))
147
132
        self._set_new_format(BZR_BRANCH_FORMAT_6)
148
133
 
149
134
 
160
145
        # to_read is a stack holding the revisions we still need to process;
161
146
        # appending to it adds new highest-priority revisions
162
147
        self.known_revisions = set(rev_history)
163
 
        self.to_read = [rev_history[-1]]
 
148
        self.to_read = rev_history[-1:]
164
149
        while self.to_read:
165
150
            rev_id = self.to_read.pop()
166
151
            if (rev_id not in self.revisions
263
248
        self.pb.update('loading revision',
264
249
                       len(self.revisions),
265
250
                       len(self.known_revisions))
266
 
        if rev_id not in self.branch.revision_store:
 
251
        if not self.branch.revision_store.has_id(rev_id):
267
252
            self.pb.clear()
268
253
            note('revision {%s} not present in branch; '
269
254
                 'will be converted as a ghost',
270
255
                 rev_id)
271
256
            self.absent_revisions.add(rev_id)
272
257
        else:
273
 
            rev_xml = self.branch.revision_store[rev_id].read()
 
258
            rev_xml = self.branch.revision_store.get(rev_id).read()
274
259
            rev = serializer_v4.read_revision_from_string(rev_xml)
275
260
            for parent_id in rev.parent_ids:
276
261
                self.known_revisions.add(parent_id)
280
265
 
281
266
    def _load_old_inventory(self, rev_id):
282
267
        assert rev_id not in self.converted_revs
283
 
        old_inv_xml = self.branch.inventory_store[rev_id].read()
 
268
        old_inv_xml = self.branch.inventory_store.get(rev_id).read()
284
269
        inv = serializer_v4.read_inventory_from_string(old_inv_xml)
285
270
        rev = self.revisions[rev_id]
286
271
        if rev.inventory_sha1:
375
360
                return
376
361
        parent_indexes = map(w.lookup, previous_revisions)
377
362
        if ie.has_text():
378
 
            file_lines = self.branch.text_store[ie.text_id].readlines()
 
363
            file_lines = self.branch.text_store.get(ie.text_id).readlines()
379
364
            assert sha_strings(file_lines) == ie.text_sha1
380
365
            assert sum(map(len, file_lines)) == ie.text_size
381
366
            w.add(rev_id, parent_indexes, file_lines, ie.text_sha1)