~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lock.py

  • Committer: John Arbash Meinel
  • Date: 2008-07-11 21:41:24 UTC
  • mto: This revision was merged to the branch mainline in revision 3543.
  • Revision ID: john@arbash-meinel.com-20080711214124-qi09irlj7pd5cuzg
Shortcut the case when one revision is in the ancestry of the other.

At the cost of a heads() check, when one parent supersedes, we don't have to extract
the text for the other. Changes merge time from 3m37s => 3m21s. Using a
CachingParentsProvider would drop the time down to 3m11s.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
42
42
    osutils,
43
43
    trace,
44
44
    )
45
 
from bzrlib.hooks import Hooks
46
 
 
47
 
 
48
 
class LockHooks(Hooks):
49
 
 
50
 
    def __init__(self):
51
 
        Hooks.__init__(self)
52
 
 
53
 
        # added in 1.8; called with a LockResult when a physical lock is
54
 
        # acquired
55
 
        self['lock_acquired'] = []
56
 
 
57
 
        # added in 1.8; called with a LockResult when a physical lock is
58
 
        # acquired
59
 
        self['lock_released'] = []
60
 
 
61
 
 
62
 
class Lock(object):
63
 
    """Base class for locks.
64
 
 
65
 
    :cvar hooks: Hook dictionary for operations on locks.
66
 
    """
67
 
 
68
 
    hooks = LockHooks()
69
 
 
70
 
 
71
 
class LockResult(object):
72
 
    """Result of an operation on a lock; passed to a hook"""
73
 
 
74
 
    def __init__(self, lock_url, details=None):
75
 
        """Create a lock result for lock with optional details about the lock."""
76
 
        self.lock_url = lock_url
77
 
        self.details = details
78
 
 
79
 
    def __eq__(self, other):
80
 
        return self.lock_url == other.lock_url and self.details == other.details
81
 
 
82
 
 
83
 
try:
84
 
    import fcntl
85
 
    have_fcntl = True
86
 
except ImportError:
87
 
    have_fcntl = False
88
 
 
89
 
have_pywin32 = False
90
 
have_ctypes_win32 = False
91
 
if sys.platform == 'win32':
92
 
    import msvcrt
93
 
    try:
94
 
        import win32con, win32file, pywintypes, winerror
95
 
        have_pywin32 = True
96
 
    except ImportError:
97
 
        pass
98
 
 
99
 
    try:
100
 
        import ctypes
101
 
        have_ctypes_win32 = True
102
 
    except ImportError:
103
 
        pass
104
45
 
105
46
 
106
47
class _OSLock(object):
142
83
        raise NotImplementedError()
143
84
 
144
85
 
 
86
try:
 
87
    import fcntl
 
88
    have_fcntl = True
 
89
except ImportError:
 
90
    have_fcntl = False
 
91
try:
 
92
    import win32con, win32file, pywintypes, winerror, msvcrt
 
93
    have_pywin32 = True
 
94
except ImportError:
 
95
    have_pywin32 = False
 
96
try:
 
97
    import ctypes, msvcrt
 
98
    have_ctypes = True
 
99
except ImportError:
 
100
    have_ctypes = False
 
101
 
 
102
 
145
103
_lock_classes = []
146
104
 
147
105
 
374
332
    _lock_classes.append(('pywin32', _w32c_WriteLock, _w32c_ReadLock))
375
333
 
376
334
 
377
 
if have_ctypes_win32:
 
335
if have_ctypes and sys.platform == 'win32':
378
336
    # These constants were copied from the win32con.py module.
379
337
    LOCKFILE_FAIL_IMMEDIATELY = 1
380
338
    LOCKFILE_EXCLUSIVE_LOCK = 2