~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge_directive.py

  • Committer: Aaron Bentley
  • Date: 2007-06-22 22:19:13 UTC
  • mto: (2520.5.2 bzr.mpbundle)
  • mto: This revision was merged to the branch mainline in revision 2631.
  • Revision ID: abentley@panoramicfeedback.com-20070622221913-mcjioqruw8rhgnd8
Improve locking in _BaseMergeDirective.from_object

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
        used for the commit.
104
104
        """
105
105
        t_revision_id = revision_id
106
 
        if revision_id == 'null:':
 
106
        if revision_id == _mod_revision.NULL_REVISION:
107
107
            t_revision_id = None
108
108
        t = testament.StrictTestament3.from_revision(repository, t_revision_id)
109
109
        submit_branch = _mod_branch.Branch.open(target_branch)
421
421
        If the message is not supplied, the message from revision_id will be
422
422
        used for the commit.
423
423
        """
424
 
        t_revision_id = revision_id
425
 
        if revision_id == 'null:':
426
 
            t_revision_id = None
427
 
        t = testament.StrictTestament3.from_revision(repository, t_revision_id)
428
 
        submit_branch = _mod_branch.Branch.open(target_branch)
429
 
        if submit_branch.get_public_branch() is not None:
430
 
            target_branch = submit_branch.get_public_branch()
431
 
        if patch_type is None:
432
 
            patch = None
433
 
            bundle = None
434
 
        else:
435
 
            submit_revision_id = submit_branch.last_revision()
436
 
            submit_revision_id = _mod_revision.ensure_null(submit_revision_id)
437
 
            repository.fetch(submit_branch.repository, submit_revision_id)
438
 
            graph = repository.get_graph()
439
 
            ancestor_id = graph.find_unique_lca(revision_id,
440
 
                                                submit_revision_id)
441
 
            if patch_type in ('bundle', 'diff'):
442
 
                patch = klass._generate_diff(repository, revision_id,
443
 
                                             ancestor_id)
444
 
            if patch_type == 'bundle':
445
 
                bundle = klass._generate_bundle(repository, revision_id,
446
 
                                               ancestor_id).encode('base-64')
447
 
            else:
 
424
        locked = []
 
425
        try:
 
426
            repository.lock_write()
 
427
            locked.append(repository)
 
428
            t_revision_id = revision_id
 
429
            if revision_id == 'null:':
 
430
                t_revision_id = None
 
431
            t = testament.StrictTestament3.from_revision(repository,
 
432
                t_revision_id)
 
433
            submit_branch = _mod_branch.Branch.open(target_branch)
 
434
            submit_branch.lock_read()
 
435
            locked.append(submit_branch)
 
436
            if submit_branch.get_public_branch() is not None:
 
437
                target_branch = submit_branch.get_public_branch()
 
438
            if patch_type is None:
 
439
                patch = None
448
440
                bundle = None
449
 
 
450
 
            if public_branch is not None and patch_type != 'bundle':
451
 
                public_branch_obj = _mod_branch.Branch.open(public_branch)
452
 
                if not public_branch_obj.repository.has_revision(revision_id):
453
 
                    raise errors.PublicBranchOutOfDate(public_branch,
454
 
                                                       revision_id)
455
 
 
 
441
            else:
 
442
                submit_revision_id = submit_branch.last_revision()
 
443
                submit_revision_id = _mod_revision.ensure_null(
 
444
                    submit_revision_id)
 
445
                repository.fetch(submit_branch.repository, submit_revision_id)
 
446
                graph = repository.get_graph()
 
447
                ancestor_id = graph.find_unique_lca(revision_id,
 
448
                                                    submit_revision_id)
 
449
                if patch_type in ('bundle', 'diff'):
 
450
                    patch = klass._generate_diff(repository, revision_id,
 
451
                                                 ancestor_id)
 
452
                if patch_type == 'bundle':
 
453
                    bundle = klass._generate_bundle(repository, revision_id,
 
454
                        ancestor_id).encode('base-64')
 
455
                else:
 
456
                    bundle = None
 
457
 
 
458
                if public_branch is not None and patch_type != 'bundle':
 
459
                    public_branch_obj = _mod_branch.Branch.open(public_branch)
 
460
                    public_branch_obj.lock_read
 
461
                    locked.append(public_branch_obj)
 
462
                    if not public_branch_obj.repository.has_revision(
 
463
                        revision_id):
 
464
                        raise errors.PublicBranchOutOfDate(public_branch,
 
465
                                                           revision_id)
 
466
        finally:
 
467
            for entry in reversed(locked):
 
468
                entry.unlock()
456
469
        return klass(revision_id, t.as_sha1(), time, timezone, target_branch,
457
470
            patch, public_branch, message, bundle)
458
471