Guest User

Untitled

a guest
Feb 21st, 2018
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. Index: trac/env.py
  2. ===================================================================
  3. --- trac/env.py (revision 3975)
  4. +++ trac/env.py (working copy)
  5. @@ -188,6 +188,7 @@
  6.  
  7. def shutdown(self, tid=None):
  8. """Close the environment."""
  9. + RepositoryManager(self).shutdown(tid)
  10. DatabaseManager(self).shutdown(tid)
  11.  
  12. def get_repository(self, authname=None):
  13. Index: trac/versioncontrol/api.py
  14. ===================================================================
  15. --- trac/versioncontrol/api.py (revision 3975)
  16. +++ trac/versioncontrol/api.py (working copy)
  17. @@ -15,6 +15,11 @@
  18. # Author: Christopher Lenz <cmlenz@gmx.de>
  19.  
  20. from heapq import heappop, heappush
  21. +try:
  22. + import threading
  23. +except ImportError:
  24. + import dummy_threading as threading
  25. + threading._get_ident = lambda: 0
  26.  
  27. from trac.config import Option
  28. from trac.core import *
  29. @@ -53,6 +58,8 @@
  30. """Path to local repository""")
  31.  
  32. def __init__(self):
  33. + self._cache = {}
  34. + self._lock = threading.Lock()
  35. self._connector = None
  36.  
  37. # Public API methods
  38. @@ -69,10 +76,29 @@
  39. raise TracError('Unsupported version control system "%s"'
  40. % self.repository_type)
  41. self._connector = heappop(candidates)[1]
  42. - return self._connector.get_repository(self.repository_type,
  43. - self.repository_dir, authname)
  44. + try:
  45. + self._lock.acquire()
  46. + tid = threading._get_ident()
  47. + if tid in self._cache:
  48. + repos = self._cache[tid]
  49. + else:
  50. + rtype, rdir = self.repository_type, self.repository_dir
  51. + repos = self._connector.get_repository(rtype, rdir, authname)
  52. + self._cache[tid] = repos
  53. + return repos
  54. + finally:
  55. + self._lock.release()
  56.  
  57. + def shutdown(self, tid=None):
  58. + assert tid == threading._get_ident()
  59. + if tid:
  60. + try:
  61. + self._lock.acquire()
  62. + self._cache.pop(tid, None)
  63. + finally:
  64. + self._lock.release()
  65.  
  66. +
  67. class NoSuchChangeset(TracError):
  68. def __init__(self, rev):
  69. TracError.__init__(self, "No changeset %s in the repository" % rev)
Add Comment
Please, Sign In to add comment