annotate rhodecode/model/hg.py @ 685:87943675813a beta

fixed whoosh indexing from admin panel
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 13 Nov 2010 02:39:03 +0100
parents 070f32743632
children 4685f3eafd35
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
58
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
1 #!/usr/bin/env python
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
2 # encoding: utf-8
569
000b675e7c1d bumped version, some spelling fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
3 # Model for RhodeCode
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
373
3171614c0067 Added permissions check on repo switcher,
Marcin Kuzminski <marcin@python-works.com>
parents: 368
diff changeset
5 #
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
6 # This program is free software; you can redistribute it and/or
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
7 # modify it under the terms of the GNU General Public License
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
8 # as published by the Free Software Foundation; version 2
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
9 # of the License or (at your opinion) any later version of the license.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
10 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
11 # This program is distributed in the hope that it will be useful,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
14 # GNU General Public License for more details.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
15 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
16 # You should have received a copy of the GNU General Public License
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
17 # along with this program; if not, write to the Free Software
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
19 # MA 02110-1301, USA.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
20 """
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
21 Created on April 9, 2010
569
000b675e7c1d bumped version, some spelling fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
22 Model for RhodeCode
58
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
23 @author: marcink
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
24 """
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
25 from beaker.cache import cache_region, region_invalidate
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
26 from mercurial import ui
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 535
diff changeset
27 from rhodecode.lib import helpers as h
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 535
diff changeset
28 from rhodecode.lib.auth import HasRepoPermissionAny
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
29 from rhodecode.lib.utils import get_repos
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 535
diff changeset
30 from rhodecode.model import meta
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
31 from rhodecode.model.caching_query import FromCache
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
32 from rhodecode.model.db import Repository, User, RhodeCodeUi
535
72778dda34cf some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents: 531
diff changeset
33 from sqlalchemy.orm import joinedload
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
34 from vcs import get_repo as vcs_get_repo, get_backend
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
35 from vcs.backends.hg import MercurialRepository
373
3171614c0067 Added permissions check on repo switcher,
Marcin Kuzminski <marcin@python-works.com>
parents: 368
diff changeset
36 from vcs.exceptions import RepositoryError, VCSError
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
37 from vcs.utils.lazy import LazyProperty
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
38 import logging
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
39 import os
633
fcf599cd3404 Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 631
diff changeset
40 import time
fcf599cd3404 Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 631
diff changeset
41
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
42 log = logging.getLogger(__name__)
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
43
58
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
44 class HgModel(object):
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
45 """
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
46 Mercurial Model
58
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
47 """
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
48
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
49 def __init__(self, sa=None):
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
50 if not sa:
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
51 self.sa = meta.Session()
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
52 else:
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
53 self.sa = sa
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
54
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
55
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
56 @LazyProperty
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
57 def repos_path(self):
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
58 """
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
59 Get's the repositories root path from database
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
60 """
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
61 q = self.sa.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/').one()
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
62
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
63 return q.ui_value
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
64
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
65 def repo_scan(self, repos_path, baseui, initial=False):
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
66 """
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
67 Listing of repositories in given path. This path should not be a
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
68 repository itself. Return a dictionary of repository objects
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
69
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
70 :param repos_path: path to directory containing repositories
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
71 :param baseui
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
72 :param initial: initial scan
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
73 """
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
74 log.info('scanning for repositories in %s', repos_path)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
75
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
76 if not isinstance(baseui, ui.ui):
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
77 baseui = ui.ui()
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
78 repos_list = {}
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
79 for name, path in get_repos(repos_path):
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
80 try:
248
fb7f066126cc Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
81 if repos_list.has_key(name):
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
82 raise RepositoryError('Duplicate repository name %s '
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
83 'found in %s' % (name, path))
248
fb7f066126cc Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
84 else:
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
85
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
86 klass = get_backend(path[0])
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
87
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
88 if path[0] == 'hg':
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
89 repos_list[name] = klass(path[1], baseui=baseui)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
90
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
91 if path[0] == 'git':
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
92 repos_list[name] = klass(path[1])
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
93 except OSError:
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
94 continue
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
95
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 222
diff changeset
96 return repos_list
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
97
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
98 def get_repos(self, all_repos=None):
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
99 """
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
100 Get all repos from db and for each such repo make backend and
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
101 fetch dependent data from db
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
102 """
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
103 if not all_repos:
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
104 all_repos = self.sa.query(Repository).all()
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
105
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
106 for r in all_repos:
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
107
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
108 repo = self.get(r.repo_name)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
109
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
110 if repo is not None:
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
111 last_change = repo.last_change
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
112 tip = h.get_changeset_safe(repo, 'tip')
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
113
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
114 tmp_d = {}
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
115 tmp_d['name'] = repo.name
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
116 tmp_d['name_sort'] = tmp_d['name'].lower()
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
117 tmp_d['description'] = repo.dbrepo.description
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
118 tmp_d['description_sort'] = tmp_d['description']
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
119 tmp_d['last_change'] = last_change
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
120 tmp_d['last_change_sort'] = time.mktime(last_change.timetuple())
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
121 tmp_d['tip'] = tip.raw_id
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
122 tmp_d['tip_sort'] = tip.revision
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
123 tmp_d['rev'] = tip.revision
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
124 tmp_d['contact'] = repo.dbrepo.user.full_contact
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
125 tmp_d['contact_sort'] = tmp_d['contact']
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
126 tmp_d['repo_archives'] = list(repo._get_archives())
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
127 tmp_d['last_msg'] = tip.message
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
128 tmp_d['repo'] = repo
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
129 yield tmp_d
74
cdf4fda66dd9 Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents: 73
diff changeset
130
cdf4fda66dd9 Started summary page. Added filters to templates. used by n,self.f.filtername prefixed by n to disable other filters. Few other fixes found
Marcin Kuzminski <marcin@python-blog.com>
parents: 73
diff changeset
131 def get_repo(self, repo_name):
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
132 return self.get(repo_name)
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
133
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
134 def get(self, repo_name):
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
135 """
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
136 Get's repository from given name, creates BackendInstance and
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
137 propagates it's data from database with all additional information
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
138 :param repo_name:
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
139 """
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
140 if not HasRepoPermissionAny('repository.read', 'repository.write',
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
141 'repository.admin')(repo_name, 'get repo check'):
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
142 return
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
143
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
144 @cache_region('long_term', 'get_repo_cached_%s' % repo_name)
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
145 def _get_repo(repo_name):
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
146
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
147 repo = vcs_get_repo(os.path.join(self.repos_path, repo_name),
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
148 alias=None, create=False)
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
149
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
150 #skip hidden web repository
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
151 if isinstance(repo, MercurialRepository) and repo._get_hidden():
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
152 return
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
153
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
154 dbrepo = self.sa.query(Repository)\
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
155 .options(joinedload(Repository.fork))\
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
156 .options(joinedload(Repository.user))\
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
157 .filter(Repository.repo_name == repo_name)\
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
158 .scalar()
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
159 repo.dbrepo = dbrepo
535
72778dda34cf some fixups in cache, added fallback and cache invalidation when key not found in cached repos list,
Marcin Kuzminski <marcin@python-works.com>
parents: 531
diff changeset
160 return repo
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
161
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
162 invalidate = False
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
163 if invalidate:
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
164 log.info('INVALIDATING CACHE FOR %s', repo_name)
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
165 region_invalidate(_get_repo, None, repo_name)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
166
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
167 return _get_repo(repo_name)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
168