~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

merge merge tweaks from aaron, which includes latest .dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
 
18
18
 
19
 
# FIXME: "bzr commit doc/format" commits doc/format.txt!
20
 
 
21
19
def commit(branch, message,
22
20
           timestamp=None,
23
21
           timezone=None,
59
57
        If null (default), a time/random revision id is generated.
60
58
    """
61
59
 
62
 
    import time, tempfile
 
60
    import time, tempfile, re
63
61
 
64
62
    from bzrlib.osutils import local_time_offset, username
65
63
    from bzrlib.branch import gen_file_id
66
64
    from bzrlib.errors import BzrError, PointlessCommit
67
65
    from bzrlib.revision import Revision, RevisionReference
68
66
    from bzrlib.trace import mutter, note
69
 
    from bzrlib.xml import pack_xml
 
67
    from bzrlib.xml import serializer_v4
70
68
 
71
69
    branch.lock_write()
72
70
 
123
121
        inv_id = rev_id
124
122
 
125
123
        inv_tmp = tempfile.TemporaryFile()
126
 
        pack_xml(new_inv, inv_tmp)
 
124
        
 
125
        serializer_v4.write_inventory(new_inv, inv_tmp)
127
126
        inv_tmp.seek(0)
128
127
        branch.inventory_store.add(inv_tmp, inv_id)
129
128
        mutter('new inventory_id is {%s}' % inv_id)
145
144
            timezone = local_time_offset()
146
145
 
147
146
        mutter("building commit log message")
 
147
        # Python strings can include characters that can't be
 
148
        # represented in well-formed XML; escape characters that
 
149
        # aren't listed in the XML specification
 
150
        # (http://www.w3.org/TR/REC-xml/#NT-Char).
 
151
        if isinstance(message, unicode):
 
152
            char_pattern = u'[^\x09\x0A\x0D\u0020-\uD7FF\uE000-\uFFFD]'
 
153
        else:
 
154
            # Use a regular 'str' as pattern to avoid having re.subn
 
155
            # return 'unicode' results.
 
156
            char_pattern = '[^x09\x0A\x0D\x20-\xFF]'
 
157
        message, escape_count = re.subn(
 
158
            char_pattern,
 
159
            lambda match: match.group(0).encode('unicode_escape'),
 
160
            message)
 
161
        if escape_count:
 
162
            note("replaced %d control characters in message", escape_count)
148
163
        rev = Revision(timestamp=timestamp,
149
164
                       timezone=timezone,
150
165
                       committer=committer,
162
177
            rev.parents.append(RevisionReference(merge_rev))            
163
178
 
164
179
        rev_tmp = tempfile.TemporaryFile()
165
 
        pack_xml(rev, rev_tmp)
 
180
        serializer_v4.write_revision(rev, rev_tmp)
166
181
        rev_tmp.seek(0)
167
182
        branch.revision_store.add(rev_tmp, rev_id)
168
183
        mutter("new revision_id is {%s}" % rev_id)
249
264
        if not work_tree.has_id(file_id):
250
265
            if verbose:
251
266
                print('deleted %s%s' % (path, kind_marker(entry.kind)))
252
 
                any_changes = True
 
267
            any_changes = True
253
268
            mutter("    file is missing, removing from inventory")
254
269
            missing_ids.append(file_id)
255
270
            continue
311
326
            else:
312
327
                print 'renamed', marked
313
328
                any_changes = True
314
 
                        
 
329
        elif old_ie != entry:
 
330
            any_changes = True
 
331
 
315
332
    return missing_ids, inv, any_changes
316
333
 
317
334