~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
 
85
83
        basis_inv = basis.inventory
86
84
 
87
85
        if verbose:
88
 
            note('looking for changes...')
 
86
            # note('looking for changes...')
 
87
            # print 'looking for changes...'
 
88
            # disabled; should be done at a higher level
 
89
            pass
89
90
 
90
91
        pending_merges = branch.pending_merges()
91
92
 
115
116
            if work_inv.has_id(file_id):
116
117
                del work_inv[file_id]
117
118
 
118
 
 
119
119
        if rev_id is None:
120
 
            rev_id = _gen_revision_id(time.time())
 
120
            rev_id = _gen_revision_id(branch, time.time())
121
121
        inv_id = rev_id
122
122
 
123
123
        inv_tmp = tempfile.TemporaryFile()
124
 
        pack_xml(new_inv, inv_tmp)
 
124
        
 
125
        serializer_v4.write_inventory(new_inv, inv_tmp)
125
126
        inv_tmp.seek(0)
126
127
        branch.inventory_store.add(inv_tmp, inv_id)
127
128
        mutter('new inventory_id is {%s}' % inv_id)
137
138
            timestamp = time.time()
138
139
 
139
140
        if committer == None:
140
 
            committer = username()
 
141
            committer = username(branch)
141
142
 
142
143
        if timezone == None:
143
144
            timezone = local_time_offset()
144
145
 
145
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)
146
163
        rev = Revision(timestamp=timestamp,
147
164
                       timezone=timezone,
148
165
                       committer=committer,
160
177
            rev.parents.append(RevisionReference(merge_rev))            
161
178
 
162
179
        rev_tmp = tempfile.TemporaryFile()
163
 
        pack_xml(rev, rev_tmp)
 
180
        serializer_v4.write_revision(rev, rev_tmp)
164
181
        rev_tmp.seek(0)
165
182
        branch.revision_store.add(rev_tmp, rev_id)
166
183
        mutter("new revision_id is {%s}" % rev_id)
180
197
        branch.set_pending_merges([])
181
198
 
182
199
        if verbose:
183
 
            note("commited r%d" % branch.revno())
 
200
            # disabled; should go through logging
 
201
            # note("commited r%d" % branch.revno())
 
202
            # print ("commited r%d" % branch.revno())
 
203
            pass
184
204
    finally:
185
205
        branch.unlock()
186
206
 
187
207
 
188
208
 
189
 
def _gen_revision_id(when):
 
209
def _gen_revision_id(branch, when):
190
210
    """Return new revision-id."""
191
211
    from binascii import hexlify
192
 
    from osutils import rand_bytes, compact_date, user_email
 
212
    from bzrlib.osutils import rand_bytes, compact_date, user_email
193
213
 
194
 
    s = '%s-%s-' % (user_email(), compact_date(when))
 
214
    s = '%s-%s-' % (user_email(branch), compact_date(when))
195
215
    s += hexlify(rand_bytes(8))
196
216
    return s
197
217
 
244
264
        if not work_tree.has_id(file_id):
245
265
            if verbose:
246
266
                print('deleted %s%s' % (path, kind_marker(entry.kind)))
247
 
                any_changes = True
 
267
            any_changes = True
248
268
            mutter("    file is missing, removing from inventory")
249
269
            missing_ids.append(file_id)
250
270
            continue
306
326
            else:
307
327
                print 'renamed', marked
308
328
                any_changes = True
309
 
                        
 
329
        elif old_ie != entry:
 
330
            any_changes = True
 
331
 
310
332
    return missing_ids, inv, any_changes
311
333
 
312
334