/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 breezy/revisionspec.py

Use new context stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
708
708
 
709
709
            dt = datetime.datetime(year=year, month=month, day=day,
710
710
                    hour=hour, minute=minute, second=second)
711
 
        branch.lock_read()
712
 
        try:
 
711
        with branch.lock_read():
713
712
            rev = bisect.bisect(_RevListToTimestamps(branch), dt, 1)
714
 
        finally:
715
 
            branch.unlock()
716
713
        if rev == branch.revno():
717
714
            raise errors.InvalidRevisionSpec(self.user_spec, branch)
718
715
        return RevisionInfo(branch, rev)
758
755
    def _find_revision_id(branch, other_location):
759
756
        from .branch import Branch
760
757
 
761
 
        branch.lock_read()
762
 
        try:
 
758
        with branch.lock_read():
763
759
            revision_a = revision.ensure_null(branch.last_revision())
764
760
            if revision_a == revision.NULL_REVISION:
765
761
                raise errors.NoCommits(branch)
766
762
            if other_location == '':
767
763
                other_location = branch.get_parent()
768
764
            other_branch = Branch.open(other_location)
769
 
            other_branch.lock_read()
770
 
            try:
 
765
            with other_branch.lock_read():
771
766
                revision_b = revision.ensure_null(other_branch.last_revision())
772
767
                if revision_b == revision.NULL_REVISION:
773
768
                    raise errors.NoCommits(other_branch)
774
769
                graph = branch.repository.get_graph(other_branch.repository)
775
770
                rev_id = graph.find_unique_lca(revision_a, revision_b)
776
 
            finally:
777
 
                other_branch.unlock()
778
771
            if rev_id == revision.NULL_REVISION:
779
772
                raise errors.NoCommonAncestor(revision_a, revision_b)
780
773
            return rev_id
781
 
        finally:
782
 
            branch.unlock()
783
 
 
784
 
 
785
774
 
786
775
 
787
776
class RevisionSpec_branch(RevisionSpec):
907
896
        except ValueError:
908
897
            self._raise_invalid(numstring, context_branch)
909
898
        tree, file_path = workingtree.WorkingTree.open_containing(path)
910
 
        tree.lock_read()
911
 
        try:
 
899
        with tree.lock_read():
912
900
            file_id = tree.path2id(file_path)
913
901
            if file_id is None:
914
902
                raise errors.InvalidRevisionSpec(self.user_spec,
915
903
                    context_branch, "File '%s' is not versioned." %
916
904
                    file_path)
917
905
            revision_ids = [r for (r, l) in tree.annotate_iter(file_id)]
918
 
        finally:
919
 
            tree.unlock()
920
906
        try:
921
907
            revision_id = revision_ids[index]
922
908
        except IndexError: