/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: Robert Collins
  • Date: 2006-03-04 13:03:57 UTC
  • mfrom: (1505.1.30 bzr-bound-branch)
  • mto: This revision was merged to the branch mainline in revision 1590.
  • Revision ID: robertc@robertcollins.net-20060304130357-95990a95920f57bb
Update bound branch implementation to 0.8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
224
224
            raise BzrError("The message keyword parameter is required for commit().")
225
225
 
226
226
        self.weave_store = self.branch.repository.weave_store
 
227
        self.bound_branch = None
 
228
        self.master_branch = None
227
229
        self.rev_id = rev_id
228
230
        self.specific_files = specific_files
229
231
        self.allow_pointless = allow_pointless
231
233
        if revprops:
232
234
            self.revprops.update(revprops)
233
235
 
234
 
        # check for out of date working trees
235
 
        if self.work_tree.last_revision() != self.branch.last_revision():
236
 
            raise errors.OutOfDateTree(self.work_tree)
237
 
 
238
 
        if strict:
239
 
            # raise an exception as soon as we find a single unknown.
240
 
            for unknown in self.work_tree.unknowns():
241
 
                raise StrictCommitFailed()
242
 
 
243
 
        if timestamp is None:
244
 
            self.timestamp = time.time()
245
 
        else:
246
 
            self.timestamp = long(timestamp)
247
 
            
248
 
        if self.config is None:
249
 
            self.config = bzrlib.config.BranchConfig(self.branch)
250
 
 
251
 
        if rev_id is None:
252
 
            self.rev_id = _gen_revision_id(self.config, self.timestamp)
253
 
        else:
254
 
            self.rev_id = rev_id
255
 
 
256
 
        if committer is None:
257
 
            self.committer = self.config.username()
258
 
        else:
259
 
            assert isinstance(committer, basestring), type(committer)
260
 
            self.committer = committer
261
 
 
262
 
        if timezone is None:
263
 
            self.timezone = local_time_offset()
264
 
        else:
265
 
            self.timezone = int(timezone)
266
 
 
267
 
        if isinstance(message, str):
268
 
            message = message.decode(bzrlib.user_encoding)
269
 
        assert isinstance(message, unicode), type(message)
270
 
        self.message = message
271
 
        self._escape_commit_message()
272
 
 
273
 
        self.branch.lock_write()
 
236
        self.work_tree.lock_write()
274
237
        try:
 
238
            # setup the bound branch variables as needed.
 
239
            self._check_bound_branch()
 
240
 
 
241
            # check for out of date working trees
 
242
            # if we are bound, then self.branch is the master branch and this
 
243
            # test is thus all we need.
 
244
            if self.work_tree.last_revision() != self.branch.last_revision():
 
245
                raise errors.OutOfDateTree(self.work_tree)
 
246
    
 
247
            if strict:
 
248
                # raise an exception as soon as we find a single unknown.
 
249
                for unknown in self.work_tree.unknowns():
 
250
                    raise StrictCommitFailed()
 
251
    
 
252
            if timestamp is None:
 
253
                self.timestamp = time.time()
 
254
            else:
 
255
                self.timestamp = long(timestamp)
 
256
                
 
257
            if self.config is None:
 
258
                self.config = bzrlib.config.BranchConfig(self.branch)
 
259
    
 
260
            if rev_id is None:
 
261
                self.rev_id = _gen_revision_id(self.config, self.timestamp)
 
262
            else:
 
263
                self.rev_id = rev_id
 
264
    
 
265
            if committer is None:
 
266
                self.committer = self.config.username()
 
267
            else:
 
268
                assert isinstance(committer, basestring), type(committer)
 
269
                self.committer = committer
 
270
    
 
271
            if timezone is None:
 
272
                self.timezone = local_time_offset()
 
273
            else:
 
274
                self.timezone = int(timezone)
 
275
    
 
276
            if isinstance(message, str):
 
277
                message = message.decode(bzrlib.user_encoding)
 
278
            assert isinstance(message, unicode), type(message)
 
279
            self.message = message
 
280
            self._escape_commit_message()
 
281
 
275
282
            self.work_inv = self.work_tree.inventory
276
283
            self.basis_tree = self.work_tree.basis_tree()
277
284
            self.basis_inv = self.basis_tree.inventory
300
307
                self.present_parents
301
308
                )
302
309
            self._make_revision()
 
310
            # revision is in the master branch now.
 
311
            
 
312
            self.branch.append_revision(self.rev_id)
 
313
            # now its in the master branch history.
 
314
 
 
315
            self._update_bound_branch()
 
316
            # now the local branch is up to date
 
317
 
303
318
            self.work_tree.set_pending_merges([])
304
 
            self.branch.append_revision(self.rev_id)
305
319
            if len(self.parents):
306
320
                precursor = self.parents[0]
307
321
            else:
308
322
                precursor = None
309
323
            self.work_tree.set_last_revision(self.rev_id, precursor)
 
324
            # now the work tree is up to date with the branch
 
325
            
310
326
            self.reporter.completed(self.branch.revno()+1, self.rev_id)
311
327
            if self.config.post_commit() is not None:
312
328
                hooks = self.config.post_commit().split(' ')
317
333
                                   'bzrlib':bzrlib,
318
334
                                   'rev_id':self.rev_id})
319
335
        finally:
320
 
            self.branch.unlock()
321
 
 
 
336
            self._cleanup_bound_branch()
 
337
            self.work_tree.unlock()
 
338
 
 
339
    def _check_bound_branch(self):
 
340
        """Check to see if the local branch is bound.
 
341
 
 
342
        If it is bound, then most of the commit will actually be
 
343
        done using the remote branch as the target branch.
 
344
        Only at the end will the local branch be updated.
 
345
        """
 
346
        # TODO: jam 20051230 Consider a special error for the case
 
347
        #       where the local branch is bound, and can't access the
 
348
        #       master branch
 
349
        self.master_branch = self.branch.get_master_branch()
 
350
        if not self.master_branch:
 
351
            return
 
352
 
 
353
        # If the master branch is bound, we must fail
 
354
        master_bound_location = self.master_branch.get_bound_location()
 
355
        if master_bound_location:
 
356
            raise errors.CommitToDoubleBoundBranch(self.branch,
 
357
                    self.master_branch, master_bound_location)
 
358
 
 
359
        # TODO: jam 20051230 We could automatically push local
 
360
        #       commits to the remote branch if they would fit.
 
361
        #       But for now, just require remote to be identical
 
362
        #       to local.
 
363
        
 
364
        # Make sure the local branch is identical to the master
 
365
        master_rh = self.master_branch.revision_history()
 
366
        local_rh = self.branch.revision_history()
 
367
        if local_rh != master_rh:
 
368
            raise errors.BoundBranchOutOfDate(self.branch,
 
369
                    self.master_branch)
 
370
 
 
371
        # Now things are ready to change the master branch
 
372
        # so grab the lock
 
373
        self.bound_branch = self.branch
 
374
        self.master_branch.lock_write()
 
375
        self.branch = self.master_branch
 
376
        
 
377
        # Check to see if we have any pending merges. If we do
 
378
        # those need to be pushed into the master branch
 
379
        pending_merges = self.work_tree.pending_merges()
 
380
        if pending_merges:
 
381
            for revision_id in pending_merges:
 
382
                self.master_branch.repository.fetch(self.bound_branch.repository,
 
383
                                                    revision_id=revision_id)
 
384
 
 
385
    def _cleanup_bound_branch(self):
 
386
        """Executed at the end of a try/finally to cleanup a bound branch.
 
387
 
 
388
        If the branch wasn't bound, this is a no-op.
 
389
        If it was, it resents self.branch to the local branch, instead
 
390
        of being the master.
 
391
        """
 
392
        if not self.bound_branch:
 
393
            return
 
394
        self.branch = self.bound_branch
 
395
        self.master_branch.unlock()
 
396
 
 
397
    def _update_bound_branch(self):
 
398
        """Update the local bound branch, after commit.
 
399
 
 
400
        This only runs if the commit to the master branch succeeds.
 
401
        """
 
402
        if not self.bound_branch:
 
403
            return
 
404
        # We always want the local branch to look like the remote one
 
405
        # TODO: jam 20051231 We might want overwrite=True here, but
 
406
        #       the local branch should be a prefix of master anyway
 
407
        self.bound_branch.pull(self.master_branch)
 
408
 
 
409
        # TODO: jam 20051231 At this point we probably 
 
410
        #       want to merge any changes into master branch's
 
411
        #       working tree.
 
412
        
322
413
    def _escape_commit_message(self):
323
414
        """Replace xml-incompatible control characters."""
324
415
        # Python strings can include characters that can't be