~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to tools/history2weaves.py

  • Committer: Martin Pool
  • Date: 2005-09-22 05:29:31 UTC
  • Revision ID: mbp@sourcefrog.net-20050922052931-b8afc00ea792942c
- write working inventory into final location

- set branch format indicator after upgrade

- cleanup unused files

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
import logging
86
86
import shutil
87
87
 
88
 
from bzrlib.branch import Branch, find_branch
 
88
from bzrlib.branch import Branch, find_branch, BZR_BRANCH_FORMAT_5
89
89
from bzrlib.revfile import Revfile
90
90
from bzrlib.weave import Weave
91
91
from bzrlib.weavefile import read_weave, write_weave
110
110
 
111
111
 
112
112
    def convert(self):
113
 
        enable_default_logging()
114
113
        self._backup_control_dir()
115
114
        self.pb = ProgressBar()
116
115
        if not os.path.isdir('.bzr/weaves'):
121
120
        # holds in-memory weaves for all files
122
121
        self.text_weaves = {}
123
122
        self.branch = Branch('.', relax_version_check=True)
 
123
        os.remove(self.branch.controlfilename('branch-format'))
124
124
        self._convert_working_inv()
 
125
        self._cleanup_spare_files()
125
126
        rev_history = self.branch.revision_history()[:300]
126
127
        # to_read is a stack holding the revisions we still need to process;
127
128
        # appending to it adds new highest-priority revisions
144
145
        note('  %6d texts' % self.text_count)
145
146
        self._write_all_weaves()
146
147
        self._write_all_revs()
 
148
        f = self.branch.controlfile('branch-format', 'wb')
 
149
        try:
 
150
            f.write(BZR_BRANCH_FORMAT_5)
 
151
        finally:
 
152
            f.close()
 
153
 
 
154
 
 
155
    def _cleanup_spare_files(self):
 
156
        for n in 'merged-patches', 'pending-merged-patches':
 
157
            p = self.branch.controlfilename(n)
 
158
            if not os.path.exists(p):
 
159
                continue
 
160
            assert os.path.getsize(p) == 0
 
161
            os.remove(p)
147
162
 
148
163
 
149
164
    def _backup_control_dir(self):
156
171
    def _convert_working_inv(self):
157
172
        branch = self.branch
158
173
        inv = serializer_v4.read_inventory(branch.controlfile('inventory', 'rb'))
159
 
        serializer_v5.write_inventory(inv, branch.controlfile('new-inventory', 'wb'))
 
174
        serializer_v5.write_inventory(inv, branch.controlfile('inventory', 'wb'))
160
175
 
161
176
 
162
177