~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/upgrade.py

  • Committer: Martin Pool
  • Date: 2005-09-16 09:56:24 UTC
  • Revision ID: mbp@sourcefrog.net-20050916095623-ca0dff452934f21f
- make progress bar more tolerant of out-of-range values

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
 
 
 
18
import tempfile, os, errno
 
19
                
 
20
import bzrlib.errors
 
21
import bzrlib.progress
 
22
from bzrlib.xml4 import serializer_v4
19
23
 
20
24
 
21
25
def upgrade(branch):
34
38
 
35
39
    from bzrlib.trace import mutter
36
40
    from bzrlib.errors import BzrCheckError
37
 
    from bzrlib.progress import ProgressBar
 
41
    import bzrlib.ui
38
42
 
39
43
    branch.lock_write()
40
44
 
 
45
    pb = bzrlib.ui.ui_factory.progress_bar()
 
46
 
41
47
    try:
42
 
        pb = ProgressBar(show_spinner=True)
43
48
        last_rev_id = None
44
49
 
45
50
        history = branch.revision_history()
66
71
            updated = False
67
72
 
68
73
            if rev.inventory_sha1 is None:
69
 
                rev.inventory_sha1 = branch.get_inventory_sha1(rev.inventory_id)
 
74
                rev.inventory_sha1 = branch.get_inventory_sha1(rev_id)
70
75
                updated = True
71
76
                mutter("  set inventory_sha1 on {%s}" % rev_id)
72
77
 
73
78
            for prr in rev.parents:
74
 
                actual_sha1 = branch.get_revision_sha1(prr.revision_id)
75
 
                if (updated_previous_revision
76
 
                    or prr.revision_sha1 is None):
77
 
                    if prr.revision_sha1 != actual_sha1:
78
 
                        prr.revision_sha1 = actual_sha1
79
 
                        updated = True
80
 
                elif actual_sha1 != prr.revision_sha1:
81
 
                    raise BzrCheckError("parent {%s} of {%s} sha1 mismatch: "
82
 
                                        "%s vs %s"
83
 
                                        % (prr.revision_id, rev_id,
84
 
                                           actual_sha1, prr.revision_sha1))
 
79
                try:
 
80
                    actual_sha1 = branch.get_revision_sha1(prr.revision_id)
 
81
                except bzrlib.errors.NoSuchRevision:
 
82
                    mutter("parent {%s} of {%s} not present in branch; skipped"
 
83
                           % (prr.revision_id, rev_id))
 
84
                    continue
 
85
                    
 
86
                if actual_sha1 != prr.revision_sha1:
 
87
                    mutter("parent {%s} of {%s} sha1 mismatch: "
 
88
                           "%s vs %s; fixed"
 
89
                           % (prr.revision_id, rev_id,
 
90
                              actual_sha1, prr.revision_sha1))
 
91
                    prr.revision_sha1 = actual_sha1
 
92
                    updated = True
85
93
 
86
94
            if updated:
87
95
                updated_previous_revision = True
91
99
                # revision entry. I'm not supremely happy about it, but
92
100
                # there should be *some* way of making old entries have
93
101
                # the full meta information.
94
 
                import tempfile, os, errno
95
 
                from bzrlib.xml import pack_xml
96
 
                
97
102
                rev_tmp = tempfile.TemporaryFile()
98
 
                pack_xml(rev, rev_tmp)
 
103
                serializer_v4.write_revision(rev, rev_tmp)
99
104
                rev_tmp.seek(0)
100
105
 
101
106
                tmpfd, tmp_path = tempfile.mkstemp(prefix=rev_id, suffix='.gz',