~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:18:24 UTC
  • Revision ID: mbp@sourcefrog.net-20050922051824-263a54b20d3c54a4
- store control weaves in .bzr/, not mixed in with file weaves

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
# the moment saves us having to worry about when files need new
68
68
# versions.
69
69
 
 
70
# TODO: Check that the working directory is clean before converting
 
71
 
70
72
 
71
73
if False:
72
74
    try:
76
78
        pass
77
79
 
78
80
 
 
81
import os
79
82
import tempfile
80
83
import hotshot, hotshot.stats
81
84
import sys
82
85
import logging
 
86
import shutil
83
87
 
84
88
from bzrlib.branch import Branch, find_branch
85
89
from bzrlib.revfile import Revfile
105
109
        
106
110
 
107
111
 
108
 
 
109
112
    def convert(self):
110
113
        enable_default_logging()
 
114
        self._backup_control_dir()
111
115
        self.pb = ProgressBar()
 
116
        if not os.path.isdir('.bzr/weaves'):
 
117
            os.mkdir('.bzr/weaves')
112
118
        self.inv_weave = Weave('__inventory')
113
119
        self.anc_weave = Weave('__ancestry')
114
120
        self.ancestries = {}
115
121
        # holds in-memory weaves for all files
116
122
        self.text_weaves = {}
117
123
        self.branch = Branch('.', relax_version_check=True)
118
 
        rev_history = self.branch.revision_history()
 
124
        self._convert_working_inv()
 
125
        rev_history = self.branch.revision_history()[:300]
119
126
        # to_read is a stack holding the revisions we still need to process;
120
127
        # appending to it adds new highest-priority revisions
121
128
        self.known_revisions = set(rev_history)
131
138
            self.pb.update('converting revision', i, len(to_import))
132
139
            self._convert_one_rev(rev_id)
133
140
        self.pb.clear()
134
 
        print 'upgraded to weaves:'
135
 
        print '  %6d revisions and inventories' % len(self.revisions)
136
 
        print '  %6d absent revisions removed' % len(self.absent_revisions)
137
 
        print '  %6d texts' % self.text_count
 
141
        note('upgraded to weaves:')
 
142
        note('  %6d revisions and inventories' % len(self.revisions))
 
143
        note('  %6d absent revisions removed' % len(self.absent_revisions))
 
144
        note('  %6d texts' % self.text_count)
138
145
        self._write_all_weaves()
139
146
        self._write_all_revs()
140
147
 
141
148
 
 
149
    def _backup_control_dir(self):
 
150
        shutil.copytree('.bzr', '.bzr.backup')
 
151
        note('.bzr has been backed up to .bzr.backup')
 
152
        note('if conversion fails, you can move this directory back to .bzr')
 
153
        note('if it succeeds, you can remove this directory if you wish')
 
154
 
 
155
 
 
156
    def _convert_working_inv(self):
 
157
        branch = self.branch
 
158
        inv = serializer_v4.read_inventory(branch.controlfile('inventory', 'rb'))
 
159
        serializer_v5.write_inventory(inv, branch.controlfile('new-inventory', 'wb'))
 
160
 
 
161
 
 
162
 
142
163
    def _write_all_weaves(self):
143
 
        write_a_weave(self.inv_weave, 'weaves/inventory.weave')
144
 
        write_a_weave(self.anc_weave, 'weaves/ancestry.weave')
 
164
        write_a_weave(self.inv_weave, '.bzr/inventory.weave')
 
165
        write_a_weave(self.anc_weave, '.bzr/ancestry.weave')
145
166
        i = 0
146
167
        try:
147
168
            for file_id, file_weave in self.text_weaves.items():
148
169
                self.pb.update('writing weave', i, len(self.text_weaves))
149
 
                write_a_weave(file_weave, 'weaves/%s.weave' % file_id)
 
170
                write_a_weave(file_weave, '.bzr/weaves/%s.weave' % file_id)
150
171
                i += 1
151
172
        finally:
152
173
            self.pb.clear()