~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Martin Pool
  • Date: 2005-07-11 22:20:04 UTC
  • Revision ID: mbp@sourcefrog.net-20050711222004-4130f49c487f0bb8
patch from John

On Mac OSX /tmp is actually a symlink to /private/tmp
so _relpath() fails because the real full path is different.

The attached path just makes dtmp be expanded to it's real path, which
makes the tests pass.

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
 
57
63
 
58
64
    from bzrlib.osutils import local_time_offset, username
59
65
    from bzrlib.branch import gen_file_id
60
 
    from bzrlib.errors import BzrError
 
66
    from bzrlib.errors import BzrError, PointlessCommit
61
67
    from bzrlib.revision import Revision, RevisionReference
62
68
    from bzrlib.trace import mutter, note
63
69
    from bzrlib.xml import pack_xml
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
139
151
                       inventory_sha1=inv_sha1,
140
152
                       revision_id=rev_id)
141
153
 
 
154
        rev.parents = []
142
155
        precursor_id = branch.last_patch()
143
156
        if precursor_id:
144
157
            precursor_sha1 = branch.get_revision_sha1(precursor_id)
145
 
            rev.parents = [RevisionReference(precursor_id, precursor_sha1)]
 
158
            rev.parents.append(RevisionReference(precursor_id, precursor_sha1))
 
159
        for merge_rev in pending_merges:
 
160
            rev.parents.append(RevisionReference(merge_rev))            
146
161
 
147
162
        rev_tmp = tempfile.TemporaryFile()
148
163
        pack_xml(rev, rev_tmp)
162
177
 
163
178
        branch.append_revision(rev_id)
164
179
 
 
180
        branch.set_pending_merges([])
 
181
 
165
182
        if verbose:
166
183
            note("commited r%d" % branch.revno())
167
184
    finally:
183
200
                   verbose):
184
201
    """Build inventory preparatory to commit.
185
202
 
 
203
    Returns missing_ids, new_inv, any_changes.
 
204
 
186
205
    This adds any changed files into the text store, and sets their
187
206
    test-id, sha and size in the returned inventory appropriately.
188
207
 
200
219
    from revision import Revision
201
220
    from bzrlib.trace import mutter, note
202
221
 
203
 
    inv = Inventory()
 
222
    any_changes = False
 
223
    inv = Inventory(work_inv.root.file_id)
204
224
    missing_ids = []
205
225
    
206
226
    for path, entry in work_inv.iter_entries():
212
232
        mutter('commit prep file %s, id %r ' % (p, file_id))
213
233
 
214
234
        if specific_files and not is_inside_any(specific_files, path):
 
235
            mutter('  skipping file excluded from commit')
215
236
            if basis_inv.has_id(file_id):
216
237
                # carry over with previous state
217
238
                inv.add(basis_inv[file_id].copy())
223
244
        if not work_tree.has_id(file_id):
224
245
            if verbose:
225
246
                print('deleted %s%s' % (path, kind_marker(entry.kind)))
 
247
                any_changes = True
226
248
            mutter("    file is missing, removing from inventory")
227
249
            missing_ids.append(file_id)
228
250
            continue
274
296
            marked = path + kind_marker(entry.kind)
275
297
            if not old_ie:
276
298
                print 'added', marked
 
299
                any_changes = True
277
300
            elif old_ie == entry:
278
301
                pass                    # unchanged
279
302
            elif (old_ie.name == entry.name
280
303
                  and old_ie.parent_id == entry.parent_id):
281
304
                print 'modified', marked
 
305
                any_changes = True
282
306
            else:
283
307
                print 'renamed', marked
 
308
                any_changes = True
284
309
                        
285
 
    return missing_ids, inv
 
310
    return missing_ids, inv, any_changes
286
311
 
287
312