~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/upgrade.py

  • Committer: Martin Pool
  • Date: 2005-08-25 07:46:11 UTC
  • Revision ID: mbp@sourcefrog.net-20050825074611-98130ea6d05d9d2a
- add functions to enable and disable default logging, so that we can
  turn it off while running the tests

- default logging gets turned on from the bzr main function so that
  other applications using the library can make their own decisions

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 bzrlib.errors
 
19
import bzrlib.progress
19
20
 
20
21
 
21
22
def upgrade(branch):
34
35
 
35
36
    from bzrlib.trace import mutter
36
37
    from bzrlib.errors import BzrCheckError
37
 
    from bzrlib.progress import ProgressBar
 
38
    import bzrlib.ui
38
39
 
39
40
    branch.lock_write()
40
41
 
 
42
    pb = bzrlib.ui.progress_bar()
 
43
 
41
44
    try:
42
 
        pb = ProgressBar(show_spinner=True)
43
45
        last_rev_id = None
44
46
 
45
47
        history = branch.revision_history()
71
73
                mutter("  set inventory_sha1 on {%s}" % rev_id)
72
74
 
73
75
            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))
 
76
                try:
 
77
                    actual_sha1 = branch.get_revision_sha1(prr.revision_id)
 
78
                except bzrlib.errors.NoSuchRevision:
 
79
                    mutter("parent {%s} of {%s} not present in branch; skipped"
 
80
                           % (prr.revision_id, rev_id))
 
81
                    continue
 
82
                    
 
83
                if actual_sha1 != prr.revision_sha1:
 
84
                    mutter("parent {%s} of {%s} sha1 mismatch: "
 
85
                           "%s vs %s; fixed"
 
86
                           % (prr.revision_id, rev_id,
 
87
                              actual_sha1, prr.revision_sha1))
 
88
                    prr.revision_sha1 = actual_sha1
 
89
                    updated = True
85
90
 
86
91
            if updated:
87
92
                updated_previous_revision = True
92
97
                # there should be *some* way of making old entries have
93
98
                # the full meta information.
94
99
                import tempfile, os, errno
 
100
                from bzrlib.xml import pack_xml
 
101
                
95
102
                rev_tmp = tempfile.TemporaryFile()
96
 
                rev.write_xml(rev_tmp)
 
103
                pack_xml(rev, rev_tmp)
97
104
                rev_tmp.seek(0)
98
105
 
99
106
                tmpfd, tmp_path = tempfile.mkstemp(prefix=rev_id, suffix='.gz',