~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Martin Pool
  • Date: 2005-08-12 15:28:37 UTC
  • Revision ID: mbp@sourcefrog.net-20050812152837-9f0bee4b51498c0e
- change default log format back to long
  (looks better with -v)

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):
 
27
           rev_id=None,
 
28
           allow_pointless=True):
26
29
    """Commit working copy as a new revision.
27
30
 
28
31
    The basic approach is to add all the file texts into the
39
42
    be robust against files disappearing, moving, etc.  So the
40
43
    whole thing is a bit hard.
41
44
 
 
45
    This raises PointlessCommit if there are no changes, no new merges,
 
46
    and allow_pointless  is false.
 
47
 
42
48
    timestamp -- if not None, seconds-since-epoch for a
43
49
         postdated/predated commit.
44
50
 
55
61
 
56
62
    import time, tempfile
57
63
 
58
 
    from osutils import local_time_offset, username
59
 
    
60
 
    from branch import gen_file_id
61
 
    from errors import BzrError
62
 
    from revision import Revision
63
 
    from trace import mutter, note
 
64
    from bzrlib.osutils import local_time_offset, username
 
65
    from bzrlib.branch import gen_file_id
 
66
    from bzrlib.errors import BzrError, PointlessCommit
 
67
    from bzrlib.revision import Revision, RevisionReference
 
68
    from bzrlib.trace import mutter, note
 
69
    from bzrlib.xml import pack_xml
64
70
 
65
71
    branch.lock_write()
66
72
 
81
87
        if verbose:
82
88
            note('looking for changes...')
83
89
 
84
 
        missing_ids, new_inv = _gather_commit(branch,
85
 
                                              work_tree,
86
 
                                              work_inv,
87
 
                                              basis_inv,
88
 
                                              specific_files,
89
 
                                              verbose)
 
90
        pending_merges = branch.pending_merges()
 
91
 
 
92
        missing_ids, new_inv, any_changes = \
 
93
                     _gather_commit(branch,
 
94
                                    work_tree,
 
95
                                    work_inv,
 
96
                                    basis_inv,
 
97
                                    specific_files,
 
98
                                    verbose)
 
99
 
 
100
        if not (any_changes or allow_pointless or pending_merges):
 
101
            raise PointlessCommit()
90
102
 
91
103
        for file_id in missing_ids:
92
104
            # Any files that have been deleted are now removed from the
109
121
        inv_id = rev_id
110
122
 
111
123
        inv_tmp = tempfile.TemporaryFile()
112
 
        new_inv.write_xml(inv_tmp)
 
124
        pack_xml(new_inv, inv_tmp)
113
125
        inv_tmp.seek(0)
114
126
        branch.inventory_store.add(inv_tmp, inv_id)
115
127
        mutter('new inventory_id is {%s}' % inv_id)
119
131
        # ever actually does anything special
120
132
        inv_sha1 = branch.get_inventory_sha1(inv_id)
121
133
 
122
 
        precursor = branch.last_patch()
123
 
        if precursor:
124
 
            precursor_sha1 = branch.get_revision_sha1(precursor)
125
 
        else:
126
 
            precursor_sha1 = None
127
 
 
128
134
        branch._write_inventory(work_inv)
129
135
 
130
136
        if timestamp == None:
140
146
        rev = Revision(timestamp=timestamp,
141
147
                       timezone=timezone,
142
148
                       committer=committer,
143
 
                       precursor = precursor,
144
 
                       precursor_sha1 = precursor_sha1,
145
149
                       message = message,
146
150
                       inventory_id=inv_id,
147
151
                       inventory_sha1=inv_sha1,
148
152
                       revision_id=rev_id)
149
153
 
 
154
        rev.parents = []
 
155
        precursor_id = branch.last_patch()
 
156
        if precursor_id:
 
157
            precursor_sha1 = branch.get_revision_sha1(precursor_id)
 
158
            rev.parents.append(RevisionReference(precursor_id, precursor_sha1))
 
159
        for merge_rev in pending_merges:
 
160
            rev.parents.append(RevisionReference(merge_rev))            
 
161
 
150
162
        rev_tmp = tempfile.TemporaryFile()
151
 
        rev.write_xml(rev_tmp)
 
163
        pack_xml(rev, rev_tmp)
152
164
        rev_tmp.seek(0)
153
165
        branch.revision_store.add(rev_tmp, rev_id)
154
166
        mutter("new revision_id is {%s}" % rev_id)
165
177
 
166
178
        branch.append_revision(rev_id)
167
179
 
 
180
        branch.set_pending_merges([])
 
181
 
168
182
        if verbose:
169
183
            note("commited r%d" % branch.revno())
170
184
    finally:
186
200
                   verbose):
187
201
    """Build inventory preparatory to commit.
188
202
 
 
203
    Returns missing_ids, new_inv, any_changes.
 
204
 
189
205
    This adds any changed files into the text store, and sets their
190
206
    test-id, sha and size in the returned inventory appropriately.
191
207
 
195
211
        working inventory.
196
212
    """
197
213
    from bzrlib.inventory import Inventory
198
 
    from osutils import isdir, isfile, sha_string, quotefn, \
 
214
    from bzrlib.osutils import isdir, isfile, sha_string, quotefn, \
199
215
         local_time_offset, username, kind_marker, is_inside_any
200
216
    
201
 
    from branch import gen_file_id
202
 
    from errors import BzrError
203
 
    from revision import Revision
 
217
    from bzrlib.branch import gen_file_id
 
218
    from bzrlib.errors import BzrError
 
219
    from bzrlib.revision import Revision
204
220
    from bzrlib.trace import mutter, note
205
221
 
206
 
    inv = Inventory()
 
222
    any_changes = False
 
223
    inv = Inventory(work_inv.root.file_id)
207
224
    missing_ids = []
208
225
    
209
226
    for path, entry in work_inv.iter_entries():
215
232
        mutter('commit prep file %s, id %r ' % (p, file_id))
216
233
 
217
234
        if specific_files and not is_inside_any(specific_files, path):
 
235
            mutter('  skipping file excluded from commit')
218
236
            if basis_inv.has_id(file_id):
219
237
                # carry over with previous state
220
238
                inv.add(basis_inv[file_id].copy())
226
244
        if not work_tree.has_id(file_id):
227
245
            if verbose:
228
246
                print('deleted %s%s' % (path, kind_marker(entry.kind)))
 
247
                any_changes = True
229
248
            mutter("    file is missing, removing from inventory")
230
249
            missing_ids.append(file_id)
231
250
            continue
277
296
            marked = path + kind_marker(entry.kind)
278
297
            if not old_ie:
279
298
                print 'added', marked
 
299
                any_changes = True
280
300
            elif old_ie == entry:
281
301
                pass                    # unchanged
282
302
            elif (old_ie.name == entry.name
283
303
                  and old_ie.parent_id == entry.parent_id):
284
304
                print 'modified', marked
 
305
                any_changes = True
285
306
            else:
286
307
                print 'renamed', marked
 
308
                any_changes = True
287
309
                        
288
 
    return missing_ids, inv
 
310
    return missing_ids, inv, any_changes
289
311
 
290
312