/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/upgrade.py

  • Committer: Robert Collins
  • Date: 2005-09-28 04:58:18 UTC
  • mto: (1092.2.19)
  • mto: This revision was merged to the branch mainline in revision 1391.
  • Revision ID: robertc@robertcollins.net-20050928045818-c5ce6c7cc796f6fc
patch from Rob Weir to correct bzr-man.py

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
import errno
 
19
import os
 
20
import tempfile
18
21
 
 
22
import bzrlib.errors
 
23
import bzrlib.progress
 
24
from bzrlib.xml import serializer_v4
 
25
from bzrlib.osutils import rename
19
26
 
20
27
 
21
28
def upgrade(branch):
34
41
 
35
42
    from bzrlib.trace import mutter
36
43
    from bzrlib.errors import BzrCheckError
37
 
    from bzrlib.progress import ProgressBar
 
44
    import bzrlib.ui
38
45
 
39
46
    branch.lock_write()
40
47
 
 
48
    pb = bzrlib.ui.ui_factory.progress_bar()
 
49
 
41
50
    try:
42
 
        pb = ProgressBar(show_spinner=True)
43
51
        last_rev_id = None
44
52
 
45
53
        history = branch.revision_history()
71
79
                mutter("  set inventory_sha1 on {%s}" % rev_id)
72
80
 
73
81
            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))
 
82
                try:
 
83
                    actual_sha1 = branch.get_revision_sha1(prr.revision_id)
 
84
                except bzrlib.errors.NoSuchRevision:
 
85
                    mutter("parent {%s} of {%s} not present in branch; skipped"
 
86
                           % (prr.revision_id, rev_id))
 
87
                    continue
 
88
                    
 
89
                if actual_sha1 != prr.revision_sha1:
 
90
                    mutter("parent {%s} of {%s} sha1 mismatch: "
 
91
                           "%s vs %s; fixed"
 
92
                           % (prr.revision_id, rev_id,
 
93
                              actual_sha1, prr.revision_sha1))
 
94
                    prr.revision_sha1 = actual_sha1
 
95
                    updated = True
85
96
 
86
97
            if updated:
87
98
                updated_previous_revision = True
91
102
                # revision entry. I'm not supremely happy about it, but
92
103
                # there should be *some* way of making old entries have
93
104
                # the full meta information.
94
 
                import tempfile, os, errno
95
 
                from bzrlib.xml import pack_xml
96
 
                
97
105
                rev_tmp = tempfile.TemporaryFile()
98
 
                pack_xml(rev, rev_tmp)
 
106
                serializer_v4.write_revision(rev, rev_tmp)
99
107
                rev_tmp.seek(0)
100
108
 
101
109
                tmpfd, tmp_path = tempfile.mkstemp(prefix=rev_id, suffix='.gz',
102
110
                    dir=branch.controlfilename('revision-store'))
103
111
                os.close(tmpfd)
104
 
                def special_rename(p1, p2):
105
 
                    if sys.platform == 'win32':
106
 
                        try:
107
 
                            os.remove(p2)
108
 
                        except OSError, e:
109
 
                            if e.errno != errno.ENOENT:
110
 
                                raise
111
 
                    os.rename(p1, p2)
112
112
 
113
113
                try:
114
114
                    # TODO: We may need to handle the case where the old revision
116
116
 
117
117
                    # Remove the old revision entry out of the way
118
118
                    rev_path = branch.controlfilename(['revision-store', rev_id+'.gz'])
119
 
                    special_rename(rev_path, tmp_path)
 
119
                    rename(rev_path, tmp_path)
120
120
                    branch.revision_store.add(rev_tmp, rev_id) # Add the new one
121
121
                    os.remove(tmp_path) # Remove the old name
122
122
                    mutter('    Updated revision entry {%s}' % rev_id)
123
123
                except:
124
124
                    # On any exception, restore the old entry
125
 
                    special_rename(tmp_path, rev_path)
 
125
                    rename(tmp_path, rev_path)
126
126
                    raise
127
127
                rev_tmp.close()
128
128
                updated_revisions.append(rev_id)