/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/commit.py

  • Committer: Martin Pool
  • Date: 2005-06-29 04:11:40 UTC
  • Revision ID: mbp@sourcefrog.net-20050629041140-6b17e65a23ffdf47
Merge John's log patch:

implements bzr log --forward --verbose
optimizes so that only logs to be printed are read (rather than reading
all and filtering out unwanted).

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,
24
22
           committer=None,
25
23
           verbose=True,
26
24
           specific_files=None,
27
 
           rev_id=None,
28
 
           allow_pointless=True):
 
25
           rev_id=None):
29
26
    """Commit working copy as a new revision.
30
27
 
31
28
    The basic approach is to add all the file texts into the
42
39
    be robust against files disappearing, moving, etc.  So the
43
40
    whole thing is a bit hard.
44
41
 
45
 
    This raises PointlessCommit if there are no changes, no new merges,
46
 
    and allow_pointless  is false.
47
 
 
48
42
    timestamp -- if not None, seconds-since-epoch for a
49
43
         postdated/predated commit.
50
44
 
63
57
 
64
58
    from bzrlib.osutils import local_time_offset, username
65
59
    from bzrlib.branch import gen_file_id
66
 
    from bzrlib.errors import BzrError, PointlessCommit
 
60
    from bzrlib.errors import BzrError
67
61
    from bzrlib.revision import Revision, RevisionReference
68
62
    from bzrlib.trace import mutter, note
69
63
    from bzrlib.xml import pack_xml
87
81
        if verbose:
88
82
            note('looking for changes...')
89
83
 
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()
 
84
        missing_ids, new_inv = _gather_commit(branch,
 
85
                                              work_tree,
 
86
                                              work_inv,
 
87
                                              basis_inv,
 
88
                                              specific_files,
 
89
                                              verbose)
102
90
 
103
91
        for file_id in missing_ids:
104
92
            # Any files that have been deleted are now removed from the
151
139
                       inventory_sha1=inv_sha1,
152
140
                       revision_id=rev_id)
153
141
 
154
 
        rev.parents = []
155
142
        precursor_id = branch.last_patch()
156
143
        if precursor_id:
157
144
            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))            
 
145
            rev.parents = [RevisionReference(precursor_id, precursor_sha1)]
161
146
 
162
147
        rev_tmp = tempfile.TemporaryFile()
163
148
        pack_xml(rev, rev_tmp)
177
162
 
178
163
        branch.append_revision(rev_id)
179
164
 
180
 
        branch.set_pending_merges([])
181
 
 
182
165
        if verbose:
183
166
            note("commited r%d" % branch.revno())
184
167
    finally:
200
183
                   verbose):
201
184
    """Build inventory preparatory to commit.
202
185
 
203
 
    Returns missing_ids, new_inv, any_changes.
204
 
 
205
186
    This adds any changed files into the text store, and sets their
206
187
    test-id, sha and size in the returned inventory appropriately.
207
188
 
211
192
        working inventory.
212
193
    """
213
194
    from bzrlib.inventory import Inventory
214
 
    from bzrlib.osutils import isdir, isfile, sha_string, quotefn, \
 
195
    from osutils import isdir, isfile, sha_string, quotefn, \
215
196
         local_time_offset, username, kind_marker, is_inside_any
216
197
    
217
 
    from bzrlib.branch import gen_file_id
218
 
    from bzrlib.errors import BzrError
219
 
    from bzrlib.revision import Revision
 
198
    from branch import gen_file_id
 
199
    from errors import BzrError
 
200
    from revision import Revision
220
201
    from bzrlib.trace import mutter, note
221
202
 
222
 
    any_changes = False
223
 
    inv = Inventory(work_inv.root.file_id)
 
203
    inv = Inventory()
224
204
    missing_ids = []
225
205
    
226
206
    for path, entry in work_inv.iter_entries():
232
212
        mutter('commit prep file %s, id %r ' % (p, file_id))
233
213
 
234
214
        if specific_files and not is_inside_any(specific_files, path):
235
 
            mutter('  skipping file excluded from commit')
236
215
            if basis_inv.has_id(file_id):
237
216
                # carry over with previous state
238
217
                inv.add(basis_inv[file_id].copy())
244
223
        if not work_tree.has_id(file_id):
245
224
            if verbose:
246
225
                print('deleted %s%s' % (path, kind_marker(entry.kind)))
247
 
                any_changes = True
248
226
            mutter("    file is missing, removing from inventory")
249
227
            missing_ids.append(file_id)
250
228
            continue
296
274
            marked = path + kind_marker(entry.kind)
297
275
            if not old_ie:
298
276
                print 'added', marked
299
 
                any_changes = True
300
277
            elif old_ie == entry:
301
278
                pass                    # unchanged
302
279
            elif (old_ie.name == entry.name
303
280
                  and old_ie.parent_id == entry.parent_id):
304
281
                print 'modified', marked
305
 
                any_changes = True
306
282
            else:
307
283
                print 'renamed', marked
308
 
                any_changes = True
309
284
                        
310
 
    return missing_ids, inv, any_changes
 
285
    return missing_ids, inv
311
286
 
312
287