~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: John Arbash Meinel
  • Date: 2005-12-31 00:23:03 UTC
  • mto: (1587.1.6 bound-branches)
  • mto: This revision was merged to the branch mainline in revision 1590.
  • Revision ID: john@arbash-meinel.com-20051231002303-fbc5cf80469ef0cf
Updated commit to handle bound branches. Included test to handle commit after merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
                           ConflictsInTree,
85
85
                           StrictCommitFailed
86
86
                           )
 
87
import bzrlib.errors as errors
87
88
import bzrlib.gpg as gpg
88
89
from bzrlib.revision import Revision
89
90
from bzrlib.testament import Testament
202
203
        mutter('preparing to commit')
203
204
 
204
205
        self.branch = branch
 
206
        self.bound_branch = None
 
207
        self.master_branch = None
205
208
        self.weave_store = branch.weave_store
206
209
        self.rev_id = rev_id
207
210
        self.specific_files = specific_files
209
212
        self.revprops = {'branch-nick': branch.nick}
210
213
        if revprops:
211
214
            self.revprops.update(revprops)
212
 
        self.work_tree = WorkingTree(branch.base, branch)
 
215
        self.work_tree = branch.working_tree()
213
216
 
214
217
        if strict:
215
218
            # raise an exception as soon as we find a single unknown.
248
251
 
249
252
        self.branch.lock_write()
250
253
        try:
 
254
            self._check_bound_branch()
 
255
 
251
256
            self.work_inv = self.work_tree.inventory
252
257
            self.basis_tree = self.branch.basis_tree()
253
258
            self.basis_inv = self.basis_tree.inventory
274
279
            self._make_revision()
275
280
            self.work_tree.set_pending_merges([])
276
281
            self.branch.append_revision(self.rev_id)
 
282
            self._update_bound_branch()
277
283
            self.reporter.completed(self.branch.revno()+1, self.rev_id)
278
284
            if self.config.post_commit() is not None:
279
285
                hooks = self.config.post_commit().split(' ')
284
290
                                   'bzrlib':bzrlib,
285
291
                                   'rev_id':self.rev_id})
286
292
        finally:
 
293
            self._cleanup_bound_branch()
287
294
            self.branch.unlock()
288
295
 
 
296
    def _check_bound_branch(self):
 
297
        """Check to see if the local branch is bound.
 
298
 
 
299
        If it is bound, then most of the commit will actually be
 
300
        done using the remote branch as the target branch.
 
301
        Only at the end will the local branch be updated.
 
302
        """
 
303
        # TODO: jam 20051230 Consider a special error for the case
 
304
        #       where the local branch is bound, and can't access the
 
305
        #       master branch
 
306
        self.master_branch = self.branch.get_bound_branch()
 
307
        if not self.master_branch:
 
308
            return
 
309
 
 
310
        # If the master branch is bound, we must fail
 
311
        master_bound_location = self.master_branch.get_bound_location()
 
312
        if master_bound_location:
 
313
            raise CommitToDoubleBoundBranch(self.branch,
 
314
                    self.master_branch, master_bound_location)
 
315
 
 
316
        # TODO: jam 20051230 We could automatically push local
 
317
        #       commits to the remote branch if they would fit.
 
318
        #       But for now, just require remote to be identical
 
319
        #       to local.
 
320
        
 
321
        # Make sure the local branch is identical to the master
 
322
        master_rh = self.master_branch.revision_history()
 
323
        local_rh = self.branch.revision_history()
 
324
        if local_rh != master_rh:
 
325
            raise errors.BoundBranchOutOfDate(self.branch,
 
326
                    self.master_branch)
 
327
 
 
328
        # Now things are ready to change the master branch
 
329
        # so grab the lock
 
330
        self.bound_branch = self.branch
 
331
        self.master_branch.lock_write()
 
332
        self.branch = self.master_branch
 
333
 
 
334
        # Check to see if we have any pending merges. If we do
 
335
        # those need to be pushed into the master branch
 
336
        pending_merges = self.work_tree.pending_merges()
 
337
        if pending_merges:
 
338
            from bzrlib.fetch import fetch
 
339
            for revision_id in pending_merges:
 
340
                fetch(self.master_branch, self.bound_branch, revision_id)
 
341
 
 
342
    def _cleanup_bound_branch(self):
 
343
        """Executed at the end of a try/finally to cleanup a bound branch.
 
344
 
 
345
        If the branch wasn't bound, this is a no-op.
 
346
        If it was, it resents self.branch to the local branch, instead
 
347
        of being the master.
 
348
        """
 
349
        if not self.bound_branch:
 
350
            return
 
351
        self.branch = self.bound_branch
 
352
        self.master_branch.unlock()
 
353
 
 
354
    def _update_bound_branch(self):
 
355
        """Update the local bound branch, after commit.
 
356
 
 
357
        This only runs if the commit to the remote branch succeeds.
 
358
        """
 
359
        if not self.bound_branch:
 
360
            return
 
361
        # We always want the local branch to look like the remote one
 
362
        self.bound_branch.pull(self.master_branch)
 
363
 
289
364
    def _record_inventory(self):
290
365
        """Store the inventory for the new revision."""
291
366
        inv_text = serializer_v5.write_inventory_to_string(self.new_inv)