~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Martin Pool
  • Date: 2005-07-04 12:26:02 UTC
  • Revision ID: mbp@sourcefrog.net-20050704122602-69901910521e62c3
- check command checks that all inventory-ids are the same as in the revision.

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
 
19
21
def commit(branch, message,
20
22
           timestamp=None,
21
23
           timezone=None,
22
24
           committer=None,
23
25
           verbose=True,
24
26
           specific_files=None,
25
 
           rev_id=None,
26
 
           allow_pointless=True):
 
27
           rev_id=None):
27
28
    """Commit working copy as a new revision.
28
29
 
29
30
    The basic approach is to add all the file texts into the
40
41
    be robust against files disappearing, moving, etc.  So the
41
42
    whole thing is a bit hard.
42
43
 
43
 
    This raises PointlessCommit if there are no changes, no new merges,
44
 
    and allow_pointless  is false.
45
 
 
46
44
    timestamp -- if not None, seconds-since-epoch for a
47
45
         postdated/predated commit.
48
46
 
61
59
 
62
60
    from bzrlib.osutils import local_time_offset, username
63
61
    from bzrlib.branch import gen_file_id
64
 
    from bzrlib.errors import BzrError, PointlessCommit
 
62
    from bzrlib.errors import BzrError
65
63
    from bzrlib.revision import Revision, RevisionReference
66
64
    from bzrlib.trace import mutter, note
67
 
    from bzrlib.xml import serializer_v4
 
65
    from bzrlib.xml import pack_xml
68
66
 
69
67
    branch.lock_write()
70
68
 
83
81
        basis_inv = basis.inventory
84
82
 
85
83
        if verbose:
86
 
            # note('looking for changes...')
87
 
            # print 'looking for changes...'
88
 
            # disabled; should be done at a higher level
89
 
            pass
 
84
            note('looking for changes...')
90
85
 
91
86
        pending_merges = branch.pending_merges()
92
87
 
93
 
        missing_ids, new_inv, any_changes = \
94
 
                     _gather_commit(branch,
95
 
                                    work_tree,
96
 
                                    work_inv,
97
 
                                    basis_inv,
98
 
                                    specific_files,
99
 
                                    verbose)
100
 
 
101
 
        if not (any_changes or allow_pointless or pending_merges):
102
 
            raise PointlessCommit()
 
88
        missing_ids, new_inv = _gather_commit(branch,
 
89
                                              work_tree,
 
90
                                              work_inv,
 
91
                                              basis_inv,
 
92
                                              specific_files,
 
93
                                              verbose)
103
94
 
104
95
        for file_id in missing_ids:
105
96
            # Any files that have been deleted are now removed from the
116
107
            if work_inv.has_id(file_id):
117
108
                del work_inv[file_id]
118
109
 
 
110
 
119
111
        if rev_id is None:
120
 
            rev_id = _gen_revision_id(branch, time.time())
 
112
            rev_id = _gen_revision_id(time.time())
121
113
        inv_id = rev_id
122
114
 
123
115
        inv_tmp = tempfile.TemporaryFile()
124
 
        
125
 
        serializer_v4.write_inventory(new_inv, inv_tmp)
 
116
        pack_xml(new_inv, inv_tmp)
126
117
        inv_tmp.seek(0)
127
118
        branch.inventory_store.add(inv_tmp, inv_id)
128
119
        mutter('new inventory_id is {%s}' % inv_id)
138
129
            timestamp = time.time()
139
130
 
140
131
        if committer == None:
141
 
            committer = username(branch)
 
132
            committer = username()
142
133
 
143
134
        if timezone == None:
144
135
            timezone = local_time_offset()
161
152
            rev.parents.append(RevisionReference(merge_rev))            
162
153
 
163
154
        rev_tmp = tempfile.TemporaryFile()
164
 
        serializer_v4.write_revision(rev, rev_tmp)
 
155
        pack_xml(rev, rev_tmp)
165
156
        rev_tmp.seek(0)
166
157
        branch.revision_store.add(rev_tmp, rev_id)
167
158
        mutter("new revision_id is {%s}" % rev_id)
181
172
        branch.set_pending_merges([])
182
173
 
183
174
        if verbose:
184
 
            # disabled; should go through logging
185
 
            # note("commited r%d" % branch.revno())
186
 
            # print ("commited r%d" % branch.revno())
187
 
            pass
 
175
            note("commited r%d" % branch.revno())
188
176
    finally:
189
177
        branch.unlock()
190
178
 
191
179
 
192
180
 
193
 
def _gen_revision_id(branch, when):
 
181
def _gen_revision_id(when):
194
182
    """Return new revision-id."""
195
183
    from binascii import hexlify
196
 
    from bzrlib.osutils import rand_bytes, compact_date, user_email
 
184
    from osutils import rand_bytes, compact_date, user_email
197
185
 
198
 
    s = '%s-%s-' % (user_email(branch), compact_date(when))
 
186
    s = '%s-%s-' % (user_email(), compact_date(when))
199
187
    s += hexlify(rand_bytes(8))
200
188
    return s
201
189
 
204
192
                   verbose):
205
193
    """Build inventory preparatory to commit.
206
194
 
207
 
    Returns missing_ids, new_inv, any_changes.
208
 
 
209
195
    This adds any changed files into the text store, and sets their
210
196
    test-id, sha and size in the returned inventory appropriately.
211
197
 
215
201
        working inventory.
216
202
    """
217
203
    from bzrlib.inventory import Inventory
218
 
    from bzrlib.osutils import isdir, isfile, sha_string, quotefn, \
 
204
    from osutils import isdir, isfile, sha_string, quotefn, \
219
205
         local_time_offset, username, kind_marker, is_inside_any
220
206
    
221
 
    from bzrlib.branch import gen_file_id
222
 
    from bzrlib.errors import BzrError
223
 
    from bzrlib.revision import Revision
 
207
    from branch import gen_file_id
 
208
    from errors import BzrError
 
209
    from revision import Revision
224
210
    from bzrlib.trace import mutter, note
225
211
 
226
 
    any_changes = False
227
 
    inv = Inventory(work_inv.root.file_id)
 
212
    inv = Inventory()
228
213
    missing_ids = []
229
214
    
230
215
    for path, entry in work_inv.iter_entries():
236
221
        mutter('commit prep file %s, id %r ' % (p, file_id))
237
222
 
238
223
        if specific_files and not is_inside_any(specific_files, path):
239
 
            mutter('  skipping file excluded from commit')
240
224
            if basis_inv.has_id(file_id):
241
225
                # carry over with previous state
242
226
                inv.add(basis_inv[file_id].copy())
248
232
        if not work_tree.has_id(file_id):
249
233
            if verbose:
250
234
                print('deleted %s%s' % (path, kind_marker(entry.kind)))
251
 
                any_changes = True
252
235
            mutter("    file is missing, removing from inventory")
253
236
            missing_ids.append(file_id)
254
237
            continue
300
283
            marked = path + kind_marker(entry.kind)
301
284
            if not old_ie:
302
285
                print 'added', marked
303
 
                any_changes = True
304
286
            elif old_ie == entry:
305
287
                pass                    # unchanged
306
288
            elif (old_ie.name == entry.name
307
289
                  and old_ie.parent_id == entry.parent_id):
308
290
                print 'modified', marked
309
 
                any_changes = True
310
291
            else:
311
292
                print 'renamed', marked
312
 
                any_changes = True
313
293
                        
314
 
    return missing_ids, inv, any_changes
 
294
    return missing_ids, inv
315
295
 
316
296