~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 08:06:51 UTC
  • Revision ID: mbp@sourcefrog.net-20050704080651-6ecec49164359e48
- track pending-merges

- unit tests for this

Show diffs side-by-side

added added

removed removed

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