annotate rhodecode/model/scm.py @ 3234:21cccfea18bf beta

Return a list of invlidated keys on mark_for_invalidation func - log.debug list of invalidated keys
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 26 Jan 2013 23:11:40 +0100
parents ba2e2514a01a
children 85f69bf84d95
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
757
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
1 # -*- coding: utf-8 -*-
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
2 """
811
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
3 rhodecode.model.scm
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
4 ~~~~~~~~~~~~~~~~~~~
757
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
5
811
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
6 Scm model for RhodeCode
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
7
757
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
8 :created_on: Apr 9, 2010
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
9 :author: marcink
1824
89efedac4e6c 2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents: 1810
diff changeset
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
757
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
11 :license: GPLv3, see COPYING for more details.
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
12 """
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
13 # This program is free software: you can redistribute it and/or modify
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
14 # it under the terms of the GNU General Public License as published by
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
15 # the Free Software Foundation, either version 3 of the License, or
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
16 # (at your option) any later version.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1193
diff changeset
17 #
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
18 # 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
19 # 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
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
21 # GNU General Public License for more details.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1193
diff changeset
22 #
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
23 # You should have received a copy of the GNU General Public License
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
2620
cd207411cf22 fixed python2.5 compat and repo mapper issue
Marcin Kuzminski <marcin@python-works.com>
parents: 2618
diff changeset
25 from __future__ import with_statement
1554
e7c6341ad3cb fixes #245 Rescan of the repositories on Windows
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
26 import os
2618
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
27 import re
757
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
28 import time
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
29 import traceback
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
30 import logging
1801
b6d23aa3754c fixed problem with uploading files into rhodecode that wasn't detected as streams
Marcin Kuzminski <marcin@python-works.com>
parents: 1755
diff changeset
31 import cStringIO
2618
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
32 import pkg_resources
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
33 from os.path import dirname as dn, join as jn
757
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
34
2354
f3417f0d54b5 fixed default sorting on main page with sorting using wrapped lower() call on database level
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
35 from sqlalchemy import func
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
36 from pylons.i18n.translation import _
2354
f3417f0d54b5 fixed default sorting on main page with sorting using wrapped lower() call on database level
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
37
2618
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
38 import rhodecode
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
39 from rhodecode.lib.vcs import get_backend
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
40 from rhodecode.lib.vcs.exceptions import RepositoryError
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
41 from rhodecode.lib.vcs.utils.lazy import LazyProperty
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
42 from rhodecode.lib.vcs.nodes import FileNode
2684
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2672
diff changeset
43 from rhodecode.lib.vcs.backends.base import EmptyChangeset
757
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
44
710
e2f3c8e6939d Disable git support due to large problems with dulwich.
Marcin Kuzminski <marcin@python-works.com>
parents: 693
diff changeset
45 from rhodecode import BACKENDS
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 535
diff changeset
46 from rhodecode.lib import helpers as h
2199
31ebf7010566 various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
47 from rhodecode.lib.utils2 import safe_str, safe_unicode
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
48 from rhodecode.lib.auth import HasRepoPermissionAny, HasReposGroupPermissionAny
3228
ba2e2514a01a reposcann should skip directories with starting with '.'
Marcin Kuzminski <marcin@python-works.com>
parents: 3222
diff changeset
49 from rhodecode.lib.utils import get_filesystem_repos, make_ui, \
2684
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2672
diff changeset
50 action_logger, REMOVED_REPO_PAT
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 747
diff changeset
51 from rhodecode.model import BaseModel
758
6a31e64acabd code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 757
diff changeset
52 from rhodecode.model.db import Repository, RhodeCodeUi, CacheInvalidation, \
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
53 UserFollowing, UserLog, User, RepoGroup, PullRequest
757
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
54
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
55 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
56
757
c52e88b57bf4 rolled back to make transient since got some exceptions on expunge
Marcin Kuzminski <marcin@python-works.com>
parents: 753
diff changeset
57
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
58 class UserTemp(object):
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
59 def __init__(self, user_id):
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
60 self.user_id = user_id
901
765c2125e4d9 Fixed repo of Temp user and repo for better logging
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
61
765c2125e4d9 Fixed repo of Temp user and repo for better logging
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
62 def __repr__(self):
765c2125e4d9 Fixed repo of Temp user and repo for better logging
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
63 return "<%s('id:%s')>" % (self.__class__.__name__, self.user_id)
765c2125e4d9 Fixed repo of Temp user and repo for better logging
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
64
1213
68e34f5cf122 #150 fixes for errors on repositories mapped in db but corrupted in filesystem
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
65
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
66 class RepoTemp(object):
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
67 def __init__(self, repo_id):
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
68 self.repo_id = repo_id
747
2f89beda06a1 Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
69
901
765c2125e4d9 Fixed repo of Temp user and repo for better logging
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
70 def __repr__(self):
765c2125e4d9 Fixed repo of Temp user and repo for better logging
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
71 return "<%s('id:%s')>" % (self.__class__.__name__, self.repo_id)
765c2125e4d9 Fixed repo of Temp user and repo for better logging
Marcin Kuzminski <marcin@python-works.com>
parents: 878
diff changeset
72
1801
b6d23aa3754c fixed problem with uploading files into rhodecode that wasn't detected as streams
Marcin Kuzminski <marcin@python-works.com>
parents: 1755
diff changeset
73
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
74 class CachedRepoList(object):
2604
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
75 """
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
76 Cached repo list, uses in-memory cache after initialization, that is
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
77 super fast
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
78 """
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
79
3222
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
80 def __init__(self, db_repo_list, repos_path, order_by=None, perm_set=None):
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
81 self.db_repo_list = db_repo_list
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
82 self.repos_path = repos_path
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
83 self.order_by = order_by
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
84 self.reversed = (order_by or '').startswith('-')
3222
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
85 if not perm_set:
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
86 perm_set = ['repository.read', 'repository.write',
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
87 'repository.admin']
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
88 self.perm_set = perm_set
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
89
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
90 def __len__(self):
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
91 return len(self.db_repo_list)
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
92
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
93 def __repr__(self):
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
94 return '<%s (%s)>' % (self.__class__.__name__, self.__len__())
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
95
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
96 def __iter__(self):
2352
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2209
diff changeset
97 # pre-propagated cache_map to save executing select statements
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2209
diff changeset
98 # for each repo
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2209
diff changeset
99 cache_map = CacheInvalidation.get_cache_map()
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2209
diff changeset
100
1428
e5467730682b fixed some issues with cache invalidation, and simplified invalidation codes
Marcin Kuzminski <marcin@python-works.com>
parents: 1401
diff changeset
101 for dbr in self.db_repo_list:
2352
90e06f53af8c Implemented cache-map on main page to save executing select
Marcin Kuzminski <marcin@python-works.com>
parents: 2209
diff changeset
102 scmr = dbr.scm_instance_cached(cache_map)
1437
7a46d67c263c added welcome message if no repositories are present in current view
Marcin Kuzminski <marcin@python-works.com>
parents: 1428
diff changeset
103 # check permission at this level
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
104 if not HasRepoPermissionAny(
3222
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
105 *self.perm_set
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
106 )(dbr.repo_name, 'get repo check'):
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
107 continue
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
108
1380
39ae0f0972b9 Fixed problem with new repos, and visibility on the main list.
Marcin Kuzminski <marcin@python-works.com>
parents: 1373
diff changeset
109 if scmr is None:
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
110 log.error(
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
111 '%s this repository is present in database but it '
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
112 'cannot be created as an scm instance' % dbr.repo_name
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
113 )
1373
66f03a87141c Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents: 1370
diff changeset
114 continue
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
115
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
116 last_change = scmr.last_change
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
117 tip = h.get_changeset_safe(scmr, 'tip')
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
118
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
119 tmp_d = {}
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
120 tmp_d['name'] = dbr.repo_name
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
121 tmp_d['name_sort'] = tmp_d['name'].lower()
2936
62e493c7f436 Added lightweight dashboard option. ref #500
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
122 tmp_d['raw_name'] = tmp_d['name'].lower()
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
123 tmp_d['description'] = dbr.description
2604
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
124 tmp_d['description_sort'] = tmp_d['description'].lower()
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
125 tmp_d['last_change'] = last_change
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
126 tmp_d['last_change_sort'] = time.mktime(last_change.timetuple())
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
127 tmp_d['tip'] = tip.raw_id
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
128 tmp_d['tip_sort'] = tip.revision
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
129 tmp_d['rev'] = tip.revision
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
130 tmp_d['contact'] = dbr.user.full_contact
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
131 tmp_d['contact_sort'] = tmp_d['contact']
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
132 tmp_d['owner_sort'] = tmp_d['contact']
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
133 tmp_d['repo_archives'] = list(scmr._get_archives())
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
134 tmp_d['last_msg'] = tip.message
1459
6691d4097344 added author to main page tooltip
Marcin Kuzminski <marcin@python-works.com>
parents: 1437
diff changeset
135 tmp_d['author'] = tip.author
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
136 tmp_d['dbrepo'] = dbr.get_dict()
1728
07e56179633e - fixes celery sqlalchemy session issues for async forking
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
137 tmp_d['dbrepo_fork'] = dbr.fork.get_dict() if dbr.fork else {}
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
138 yield tmp_d
1213
68e34f5cf122 #150 fixes for errors on repositories mapped in db but corrupted in filesystem
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
139
1801
b6d23aa3754c fixed problem with uploading files into rhodecode that wasn't detected as streams
Marcin Kuzminski <marcin@python-works.com>
parents: 1755
diff changeset
140
2604
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
141 class SimpleCachedRepoList(CachedRepoList):
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
142 """
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
143 Lighter version of CachedRepoList without the scm initialisation
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
144 """
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
145
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
146 def __iter__(self):
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
147 for dbr in self.db_repo_list:
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
148 # check permission at this level
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
149 if not HasRepoPermissionAny(
3222
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
150 *self.perm_set
2604
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
151 )(dbr.repo_name, 'get repo check'):
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
152 continue
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
153
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
154 tmp_d = {}
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
155 tmp_d['name'] = dbr.repo_name
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
156 tmp_d['name_sort'] = tmp_d['name'].lower()
2936
62e493c7f436 Added lightweight dashboard option. ref #500
Marcin Kuzminski <marcin@python-works.com>
parents: 2726
diff changeset
157 tmp_d['raw_name'] = tmp_d['name'].lower()
2604
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
158 tmp_d['description'] = dbr.description
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
159 tmp_d['description_sort'] = tmp_d['description'].lower()
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
160 tmp_d['dbrepo'] = dbr.get_dict()
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
161 tmp_d['dbrepo_fork'] = dbr.fork.get_dict() if dbr.fork else {}
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
162 yield tmp_d
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
163
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
164
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
165 class GroupList(object):
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
166
3222
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
167 def __init__(self, db_repo_group_list, perm_set=None):
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
168 """
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
169 Creates iterator from given list of group objects, additionally
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
170 checking permission for them from perm_set var
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
171
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
172 :param db_repo_group_list:
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
173 :param perm_set: list of permissons to check
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
174 """
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
175 self.db_repo_group_list = db_repo_group_list
3222
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
176 if not perm_set:
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
177 perm_set = ['group.read', 'group.write', 'group.admin']
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
178 self.perm_set = perm_set
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
179
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
180 def __len__(self):
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
181 return len(self.db_repo_group_list)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
182
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
183 def __repr__(self):
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
184 return '<%s (%s)>' % (self.__class__.__name__, self.__len__())
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
185
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
186 def __iter__(self):
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
187 for dbgr in self.db_repo_group_list:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
188 # check permission at this level
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
189 if not HasReposGroupPermissionAny(
3222
b4daef4cc26d Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents: 3152
diff changeset
190 *self.perm_set
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
191 )(dbgr.group_name, 'get group repo check'):
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
192 continue
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
193
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
194 yield dbgr
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
195
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
196
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 747
diff changeset
197 class ScmModel(BaseModel):
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
198 """
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
199 Generic Scm 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
200 """
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
201
1755
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
202 def __get_repo(self, instance):
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
203 cls = Repository
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
204 if isinstance(instance, cls):
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
205 return instance
2672
169807710db2 fixed possible unicode errors on repo get function
Marcin Kuzminski <marcin@python-works.com>
parents: 2655
diff changeset
206 elif isinstance(instance, int) or safe_str(instance).isdigit():
1755
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
207 return cls.get(instance)
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
208 elif isinstance(instance, basestring):
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
209 return cls.get_by_repo_name(instance)
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
210 elif instance:
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
211 raise Exception('given object must be int, basestr or Instance'
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
212 ' of %s got %s' % (type(cls), type(instance)))
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
213
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
214 @LazyProperty
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
215 def repos_path(self):
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
216 """
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
217 Get's the repositories root path from database
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
218 """
811
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
219
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
220 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
221
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
222 return q.ui_value
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
223
1038
5554aa9c2480 another major code rafactor, reimplemented (almost from scratch)
Marcin Kuzminski <marcin@python-works.com>
parents: 1033
diff changeset
224 def repo_scan(self, repos_path=None):
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
225 """
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
226 Listing of repositories in given path. This path should not be a
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
227 repository itself. Return a dictionary of repository objects
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1193
diff changeset
228
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
229 :param repos_path: path to directory containing repositories
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
230 """
811
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 792
diff changeset
231
1038
5554aa9c2480 another major code rafactor, reimplemented (almost from scratch)
Marcin Kuzminski <marcin@python-works.com>
parents: 1033
diff changeset
232 if repos_path is None:
5554aa9c2480 another major code rafactor, reimplemented (almost from scratch)
Marcin Kuzminski <marcin@python-works.com>
parents: 1033
diff changeset
233 repos_path = self.repos_path
5554aa9c2480 another major code rafactor, reimplemented (almost from scratch)
Marcin Kuzminski <marcin@python-works.com>
parents: 1033
diff changeset
234
1925
9d400b585c24 fixes issue #341, logger outputed invalid path name
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
235 log.info('scanning for repositories in %s' % repos_path)
9d400b585c24 fixes issue #341, logger outputed invalid path name
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
236
1038
5554aa9c2480 another major code rafactor, reimplemented (almost from scratch)
Marcin Kuzminski <marcin@python-works.com>
parents: 1033
diff changeset
237 baseui = make_ui('db')
1751
47c2a006d43b Summary page downloads limited to zip.
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
238 repos = {}
690
4685f3eafd35 Fixed sumamry page description bug
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
239
877
bc9a73adc216 Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents: 851
diff changeset
240 for name, path in get_filesystem_repos(repos_path, recursive=True):
1554
e7c6341ad3cb fixes #245 Rescan of the repositories on Windows
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
241 # name need to be decomposed and put back together using the /
e7c6341ad3cb fixes #245 Rescan of the repositories on Windows
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
242 # since this is internal storage separator for rhodecode
3152
46234d2d388f fixed issues with getting repos by path on windows
Marcin Kuzminski <marcin@python-works.com>
parents: 3150
diff changeset
243 name = Repository.normalize_repo_name(name)
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1607
diff changeset
244
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
245 try:
1751
47c2a006d43b Summary page downloads limited to zip.
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
246 if name in repos:
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
247 raise RepositoryError('Duplicate repository name %s '
1554
e7c6341ad3cb fixes #245 Rescan of the repositories on Windows
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
248 'found in %s' % (name, path))
248
fb7f066126cc Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
249 else:
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
250
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
251 klass = get_backend(path[0])
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
252
710
e2f3c8e6939d Disable git support due to large problems with dulwich.
Marcin Kuzminski <marcin@python-works.com>
parents: 693
diff changeset
253 if path[0] == 'hg' and path[0] in BACKENDS.keys():
1753
1d1ccb873d00 moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 1751
diff changeset
254 repos[name] = klass(safe_str(path[1]), baseui=baseui)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
255
710
e2f3c8e6939d Disable git support due to large problems with dulwich.
Marcin Kuzminski <marcin@python-works.com>
parents: 693
diff changeset
256 if path[0] == 'git' and path[0] in BACKENDS.keys():
1751
47c2a006d43b Summary page downloads limited to zip.
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
257 repos[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
258 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
259 continue
3228
ba2e2514a01a reposcann should skip directories with starting with '.'
Marcin Kuzminski <marcin@python-works.com>
parents: 3222
diff changeset
260 log.debug('found %s paths with repositories' % (len(repos)))
1751
47c2a006d43b Summary page downloads limited to zip.
Marcin Kuzminski <marcin@python-works.com>
parents: 1728
diff changeset
261 return repos
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
262
2604
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
263 def get_repos(self, all_repos=None, sort_key=None, simple=False):
1343
a04fe5986109 #47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1312
diff changeset
264 """
a04fe5986109 #47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1312
diff changeset
265 Get all repos from db and for each repo create it's
1213
68e34f5cf122 #150 fixes for errors on repositories mapped in db but corrupted in filesystem
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
266 backend instance and fill that backed with information from database
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1193
diff changeset
267
1343
a04fe5986109 #47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1312
diff changeset
268 :param all_repos: list of repository names as strings
a04fe5986109 #47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1312
diff changeset
269 give specific repositories list, good for filtering
2604
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
270
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
271 :param sort_key: initial sorting of repos
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
272 :param simple: use SimpleCachedList - one without the SCM info
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
273 """
767
632b0761e617 bugfix, when user had no repos he would see all repos in my account, (correct commit)
Marcin Kuzminski <marcin@python-works.com>
parents: 758
diff changeset
274 if all_repos is None:
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
275 all_repos = self.sa.query(Repository)\
1343
a04fe5986109 #47 implemented basic gui for browsing repo groups
Marcin Kuzminski <marcin@python-works.com>
parents: 1312
diff changeset
276 .filter(Repository.group_id == None)\
2354
f3417f0d54b5 fixed default sorting on main page with sorting using wrapped lower() call on database level
Marcin Kuzminski <marcin@python-works.com>
parents: 2352
diff changeset
277 .order_by(func.lower(Repository.repo_name)).all()
2604
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
278 if simple:
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
279 repo_iter = SimpleCachedRepoList(all_repos,
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
280 repos_path=self.repos_path,
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
281 order_by=sort_key)
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
282 else:
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
283 repo_iter = CachedRepoList(all_repos,
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
284 repos_path=self.repos_path,
dfa5180cf02f Use simplified cached repos list for quick repo switcher, in some cases it can have 2-3x speed-up since it doesn't need to init the scms
Marcin Kuzminski <marcin@python-works.com>
parents: 2520
diff changeset
285 order_by=sort_key)
665
070f32743632 Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents: 636
diff changeset
286
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1343
diff changeset
287 return repo_iter
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
288
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
289 def get_repos_groups(self, all_groups=None):
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
290 if all_groups is None:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
291 all_groups = RepoGroup.query()\
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
292 .filter(RepoGroup.group_parent_id == None).all()
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
293 group_iter = GroupList(all_groups)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
294
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
295 return group_iter
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1925
diff changeset
296
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
297 def mark_for_invalidation(self, repo_name):
2147
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
298 """
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
299 Puts cache invalidation task into db for
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
300 further global cache invalidation
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1193
diff changeset
301
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
302 :param repo_name: this repo that should invalidation take place
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
303 """
3234
21cccfea18bf Return a list of invlidated keys on mark_for_invalidation func
Marcin Kuzminski <marcin@python-works.com>
parents: 3228
diff changeset
304 invalidated_keys = CacheInvalidation.set_invalidate(repo_name=repo_name)
3150
80abc924a38c always update changeset cache after invalidation signal
Marcin Kuzminski <marcin@python-works.com>
parents: 3090
diff changeset
305 repo = Repository.get_by_repo_name(repo_name)
80abc924a38c always update changeset cache after invalidation signal
Marcin Kuzminski <marcin@python-works.com>
parents: 3090
diff changeset
306 if repo:
80abc924a38c always update changeset cache after invalidation signal
Marcin Kuzminski <marcin@python-works.com>
parents: 3090
diff changeset
307 repo.update_changeset_cache()
3234
21cccfea18bf Return a list of invlidated keys on mark_for_invalidation func
Marcin Kuzminski <marcin@python-works.com>
parents: 3228
diff changeset
308 return invalidated_keys
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
309
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
310 def toggle_following_repo(self, follow_repo_id, user_id):
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
311
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
312 f = self.sa.query(UserFollowing)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
313 .filter(UserFollowing.follows_repo_id == follow_repo_id)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
314 .filter(UserFollowing.user_id == user_id).scalar()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
315
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
316 if f is not None:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
317 try:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
318 self.sa.delete(f)
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
319 action_logger(UserTemp(user_id),
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
320 'stopped_following_repo',
747
2f89beda06a1 Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
321 RepoTemp(follow_repo_id))
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
322 return
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
323 except:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
324 log.error(traceback.format_exc())
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
325 raise
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
326
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
327 try:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
328 f = UserFollowing()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
329 f.user_id = user_id
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
330 f.follows_repo_id = follow_repo_id
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
331 self.sa.add(f)
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
332
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
333 action_logger(UserTemp(user_id),
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 734
diff changeset
334 'started_following_repo',
747
2f89beda06a1 Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
335 RepoTemp(follow_repo_id))
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
336 except:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
337 log.error(traceback.format_exc())
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
338 raise
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
339
1213
68e34f5cf122 #150 fixes for errors on repositories mapped in db but corrupted in filesystem
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
340 def toggle_following_user(self, follow_user_id, user_id):
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
341 f = self.sa.query(UserFollowing)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
342 .filter(UserFollowing.follows_user_id == follow_user_id)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
343 .filter(UserFollowing.user_id == user_id).scalar()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
344
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
345 if f is not None:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
346 try:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
347 self.sa.delete(f)
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
348 return
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
349 except:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
350 log.error(traceback.format_exc())
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
351 raise
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
352
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
353 try:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
354 f = UserFollowing()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
355 f.user_id = user_id
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
356 f.follows_user_id = follow_user_id
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
357 self.sa.add(f)
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
358 except:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
359 log.error(traceback.format_exc())
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
360 raise
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
361
999
1951c35483ab fixed following js snipet. It' can be called multiple times now next to each repository
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
362 def is_following_repo(self, repo_name, user_id, cache=False):
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
363 r = self.sa.query(Repository)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
364 .filter(Repository.repo_name == repo_name).scalar()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
365
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
366 f = self.sa.query(UserFollowing)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
367 .filter(UserFollowing.follows_repository == r)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
368 .filter(UserFollowing.user_id == user_id).scalar()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
369
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
370 return f is not None
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
371
999
1951c35483ab fixed following js snipet. It' can be called multiple times now next to each repository
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
372 def is_following_user(self, username, user_id, cache=False):
1530
04027bdb876c Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1508
diff changeset
373 u = User.get_by_username(username)
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
374
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
375 f = self.sa.query(UserFollowing)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
376 .filter(UserFollowing.follows_user == u)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
377 .filter(UserFollowing.user_id == user_id).scalar()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
378
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents: 726
diff changeset
379 return f is not None
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
380
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
381 def get_followers(self, repo):
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
382 repo = self._get_repo(repo)
1282
faaadfc3c359 fixed condition evaluated for gitrepo that returned null, simplified scm functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1265
diff changeset
383
faaadfc3c359 fixed condition evaluated for gitrepo that returned null, simplified scm functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1265
diff changeset
384 return self.sa.query(UserFollowing)\
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
385 .filter(UserFollowing.follows_repository == repo).count()
747
2f89beda06a1 Added icons with numbers of followers and number of forks
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
386
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
387 def get_forks(self, repo):
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
388 repo = self._get_repo(repo)
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
389 return self.sa.query(Repository)\
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
390 .filter(Repository.fork == repo).count()
1282
faaadfc3c359 fixed condition evaluated for gitrepo that returned null, simplified scm functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1265
diff changeset
391
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
392 def get_pull_requests(self, repo):
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
393 repo = self._get_repo(repo)
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
394 return self.sa.query(PullRequest)\
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
395 .filter(PullRequest.other_repo == repo).count()
692
cb0d9ce6ac5c #50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents: 691
diff changeset
396
1755
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
397 def mark_as_fork(self, repo, fork, user):
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
398 repo = self.__get_repo(repo)
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
399 fork = self.__get_repo(fork)
2629
d2901d906ef3 Fixed issue #501 error on setting set_as_fork to same repo
Marcin Kuzminski <marcin@python-works.com>
parents: 2620
diff changeset
400 if fork and repo.repo_id == fork.repo_id:
d2901d906ef3 Fixed issue #501 error on setting set_as_fork to same repo
Marcin Kuzminski <marcin@python-works.com>
parents: 2620
diff changeset
401 raise Exception("Cannot set repository as fork of itself")
1755
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
402 repo.fork = fork
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
403 self.sa.add(repo)
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
404 return repo
1088ded6e602 implements #239 manual marking of repos as forks for admins
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
405
2514
9b734e9530c2 fixed pull method repo lookup
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
406 def pull_changes(self, repo, username):
9b734e9530c2 fixed pull method repo lookup
Marcin Kuzminski <marcin@python-works.com>
parents: 2462
diff changeset
407 dbrepo = self.__get_repo(repo)
1508
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1485
diff changeset
408 clone_uri = dbrepo.clone_uri
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1485
diff changeset
409 if not clone_uri:
4aba7be311e8 API added checks for a valid repository on pull command
Marcin Kuzminski <marcin@python-works.com>
parents: 1485
diff changeset
410 raise Exception("This repository doesn't have a clone uri")
1530
04027bdb876c Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1508
diff changeset
411
1370
ef9a30e22ea6 Fixed remote pull command from todays code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
412 repo = dbrepo.scm_instance
2984
5e1dadbc6f46 fixed extras params from remote pull action
Marcin Kuzminski <marcin@python-works.com>
parents: 2936
diff changeset
413 from rhodecode import CONFIG
1114
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
414 try:
2208
954d8952ff2a fixed mising scm key for remote-pulls execution
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
415 extras = {
954d8952ff2a fixed mising scm key for remote-pulls execution
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
416 'ip': '',
954d8952ff2a fixed mising scm key for remote-pulls execution
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
417 'username': username,
954d8952ff2a fixed mising scm key for remote-pulls execution
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
418 'action': 'push_remote',
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2514
diff changeset
419 'repository': dbrepo.repo_name,
2208
954d8952ff2a fixed mising scm key for remote-pulls execution
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
420 'scm': repo.alias,
2984
5e1dadbc6f46 fixed extras params from remote pull action
Marcin Kuzminski <marcin@python-works.com>
parents: 2936
diff changeset
421 'config': CONFIG['__file__'],
5e1dadbc6f46 fixed extras params from remote pull action
Marcin Kuzminski <marcin@python-works.com>
parents: 2936
diff changeset
422 'make_lock': None,
5e1dadbc6f46 fixed extras params from remote pull action
Marcin Kuzminski <marcin@python-works.com>
parents: 2936
diff changeset
423 'locked_by': [None, None]
2208
954d8952ff2a fixed mising scm key for remote-pulls execution
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
424 }
2984
5e1dadbc6f46 fixed extras params from remote pull action
Marcin Kuzminski <marcin@python-works.com>
parents: 2936
diff changeset
425
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2514
diff changeset
426 Repository.inject_ui(repo, extras=extras)
1114
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
427
2383
e576410f911d Don't do git pull on remote repos since they are bare now, we need to use git fetch on them
Marcin Kuzminski <marcin@python-works.com>
parents: 2354
diff changeset
428 if repo.alias == 'git':
e576410f911d Don't do git pull on remote repos since they are bare now, we need to use git fetch on them
Marcin Kuzminski <marcin@python-works.com>
parents: 2354
diff changeset
429 repo.fetch(clone_uri)
e576410f911d Don't do git pull on remote repos since they are bare now, we need to use git fetch on them
Marcin Kuzminski <marcin@python-works.com>
parents: 2354
diff changeset
430 else:
e576410f911d Don't do git pull on remote repos since they are bare now, we need to use git fetch on them
Marcin Kuzminski <marcin@python-works.com>
parents: 2354
diff changeset
431 repo.pull(clone_uri)
2520
a1e156503afe Fixed calls to Session in db model
Marcin Kuzminski <marcin@python-works.com>
parents: 2514
diff changeset
432 self.mark_for_invalidation(dbrepo.repo_name)
1114
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
433 except:
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
434 log.error(traceback.format_exc())
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
435 raise
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
436
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
437 def commit_change(self, repo, repo_name, cs, user, author, message,
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
438 content, f_path):
2684
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2672
diff changeset
439 """
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2672
diff changeset
440 Commits changes
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2672
diff changeset
441
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2672
diff changeset
442 :param repo: SCM instance
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2672
diff changeset
443
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2672
diff changeset
444 """
1311
6705eeebc41b moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents: 1282
diff changeset
445
6705eeebc41b moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents: 1282
diff changeset
446 if repo.alias == 'hg':
2208
954d8952ff2a fixed mising scm key for remote-pulls execution
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
447 from rhodecode.lib.vcs.backends.hg import \
954d8952ff2a fixed mising scm key for remote-pulls execution
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
448 MercurialInMemoryChangeset as IMC
1311
6705eeebc41b moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents: 1282
diff changeset
449 elif repo.alias == 'git':
2208
954d8952ff2a fixed mising scm key for remote-pulls execution
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
450 from rhodecode.lib.vcs.backends.git import \
954d8952ff2a fixed mising scm key for remote-pulls execution
Marcin Kuzminski <marcin@python-works.com>
parents: 2199
diff changeset
451 GitInMemoryChangeset as IMC
1311
6705eeebc41b moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents: 1282
diff changeset
452
6705eeebc41b moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents: 1282
diff changeset
453 # decoding here will force that we have proper encoded values
6705eeebc41b moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents: 1282
diff changeset
454 # in any other case this will throw exceptions and deny commit
1401
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1380
diff changeset
455 content = safe_str(content)
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1380
diff changeset
456 path = safe_str(f_path)
2199
31ebf7010566 various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
457 # message and author needs to be unicode
31ebf7010566 various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
458 # proper backend should then translate that into required type
31ebf7010566 various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
459 message = safe_unicode(message)
31ebf7010566 various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
460 author = safe_unicode(author)
1311
6705eeebc41b moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents: 1282
diff changeset
461 m = IMC(repo)
6705eeebc41b moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents: 1282
diff changeset
462 m.change(FileNode(path, content))
1312
70a5a9a57864 logged local commit with special action via action_logger,
Marcin Kuzminski <marcin@python-works.com>
parents: 1311
diff changeset
463 tip = m.commit(message=message,
2199
31ebf7010566 various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
464 author=author,
31ebf7010566 various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
465 parents=[cs], branch=cs.branch)
1311
6705eeebc41b moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents: 1282
diff changeset
466
2655
5a39eb37edfa use raw_id in push_local action
Marcin Kuzminski <marcin@python-works.com>
parents: 2629
diff changeset
467 action = 'push_local:%s' % tip.raw_id
1312
70a5a9a57864 logged local commit with special action via action_logger,
Marcin Kuzminski <marcin@python-works.com>
parents: 1311
diff changeset
468 action_logger(user, action, repo_name)
1311
6705eeebc41b moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents: 1282
diff changeset
469 self.mark_for_invalidation(repo_name)
2684
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2672
diff changeset
470 return tip
1311
6705eeebc41b moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents: 1282
diff changeset
471
1483
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
472 def create_node(self, repo, repo_name, cs, user, author, message, content,
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
473 f_path):
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
474 if repo.alias == 'hg':
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
475 from rhodecode.lib.vcs.backends.hg import MercurialInMemoryChangeset as IMC
1483
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
476 elif repo.alias == 'git':
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
477 from rhodecode.lib.vcs.backends.git import GitInMemoryChangeset as IMC
1483
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
478 # decoding here will force that we have proper encoded values
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
479 # in any other case this will throw exceptions and deny commit
1530
04027bdb876c Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1508
diff changeset
480
04027bdb876c Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1508
diff changeset
481 if isinstance(content, (basestring,)):
1485
269905fac50a added uploading of files from web interface directly into repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1483
diff changeset
482 content = safe_str(content)
1801
b6d23aa3754c fixed problem with uploading files into rhodecode that wasn't detected as streams
Marcin Kuzminski <marcin@python-works.com>
parents: 1755
diff changeset
483 elif isinstance(content, (file, cStringIO.OutputType,)):
1485
269905fac50a added uploading of files from web interface directly into repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1483
diff changeset
484 content = content.read()
1801
b6d23aa3754c fixed problem with uploading files into rhodecode that wasn't detected as streams
Marcin Kuzminski <marcin@python-works.com>
parents: 1755
diff changeset
485 else:
b6d23aa3754c fixed problem with uploading files into rhodecode that wasn't detected as streams
Marcin Kuzminski <marcin@python-works.com>
parents: 1755
diff changeset
486 raise Exception('Content is of unrecognized type %s' % (
b6d23aa3754c fixed problem with uploading files into rhodecode that wasn't detected as streams
Marcin Kuzminski <marcin@python-works.com>
parents: 1755
diff changeset
487 type(content)
b6d23aa3754c fixed problem with uploading files into rhodecode that wasn't detected as streams
Marcin Kuzminski <marcin@python-works.com>
parents: 1755
diff changeset
488 ))
1530
04027bdb876c Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1508
diff changeset
489
2199
31ebf7010566 various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
490 message = safe_unicode(message)
31ebf7010566 various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
491 author = safe_unicode(author)
1483
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
492 path = safe_str(f_path)
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
493 m = IMC(repo)
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
494
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
495 if isinstance(cs, EmptyChangeset):
2199
31ebf7010566 various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
496 # EmptyChangeset means we we're editing empty repository
1483
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
497 parents = None
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
498 else:
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
499 parents = [cs]
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
500
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
501 m.add(FileNode(path, content=content))
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
502 tip = m.commit(message=message,
2199
31ebf7010566 various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
503 author=author,
31ebf7010566 various fixes for git and mercurial with InMemoryCommit backend and non-ascii files
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
504 parents=parents, branch=cs.branch)
1483
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
505
2655
5a39eb37edfa use raw_id in push_local action
Marcin Kuzminski <marcin@python-works.com>
parents: 2629
diff changeset
506 action = 'push_local:%s' % tip.raw_id
1483
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
507 action_logger(user, action, repo_name)
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
508 self.mark_for_invalidation(repo_name)
2684
2b6939a77052 Bumped mercurial version to 2.3
Marcin Kuzminski <marcin@python-works.com>
parents: 2672
diff changeset
509 return tip
1483
7b67b0dcad6d Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents: 1459
diff changeset
510
1810
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
511 def get_nodes(self, repo_name, revision, root_path='/', flat=True):
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
512 """
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
513 recursive walk in root dir and return a set of all path in that dir
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
514 based on repository walk function
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
515
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
516 :param repo_name: name of repository
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
517 :param revision: revision for which to list nodes
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
518 :param root_path: root path to list
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
519 :param flat: return as a list, if False returns a dict with decription
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
520
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
521 """
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
522 _files = list()
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
523 _dirs = list()
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
524 try:
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
525 _repo = self.__get_repo(repo_name)
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
526 changeset = _repo.scm_instance.get_changeset(revision)
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
527 root_path = root_path.lstrip('/')
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
528 for topnode, dirs, files in changeset.walk(root_path):
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
529 for f in files:
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
530 _files.append(f.path if flat else {"name": f.path,
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
531 "type": "file"})
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
532 for d in dirs:
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
533 _dirs.append(d.path if flat else {"name": d.path,
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
534 "type": "dir"})
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
535 except RepositoryError:
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
536 log.debug(traceback.format_exc())
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
537 raise
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
538
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
539 return _dirs, _files
203af05539e0 implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents: 1801
diff changeset
540
784
30d3161c6683 Implemented fancier top menu for logged and anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 767
diff changeset
541 def get_unread_journal(self):
30d3161c6683 Implemented fancier top menu for logged and anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 767
diff changeset
542 return self.sa.query(UserLog).count()
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
543
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
544 def get_repo_landing_revs(self, repo=None):
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
545 """
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
546 Generates select option with tags branches and bookmarks (for hg only)
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
547 grouped by type
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
548
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
549 :param repo:
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
550 :type repo:
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
551 """
2460
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
552
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
553 hist_l = []
2460
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
554 choices = []
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
555 repo = self.__get_repo(repo)
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
556 hist_l.append(['tip', _('latest tip')])
2460
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
557 choices.append('tip')
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
558 if not repo:
2460
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
559 return choices, hist_l
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
560
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
561 repo = repo.scm_instance
2460
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
562
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
563 branches_group = ([(k, k) for k, v in
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
564 repo.branches.iteritems()], _("Branches"))
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
565 hist_l.append(branches_group)
2460
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
566 choices.extend([x[0] for x in branches_group[0]])
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
567
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
568 if repo.alias == 'hg':
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
569 bookmarks_group = ([(k, k) for k, v in
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
570 repo.bookmarks.iteritems()], _("Bookmarks"))
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
571 hist_l.append(bookmarks_group)
2460
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
572 choices.extend([x[0] for x in bookmarks_group[0]])
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
573
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
574 tags_group = ([(k, k) for k, v in
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
575 repo.tags.iteritems()], _("Tags"))
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
576 hist_l.append(tags_group)
2460
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
577 choices.extend([x[0] for x in tags_group[0]])
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2383
diff changeset
578
2460
12fa0c19c42f validating choices for landing_rev
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
579 return choices, hist_l
2618
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
580
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
581 def install_git_hook(self, repo, force_create=False):
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
582 """
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
583 Creates a rhodecode hook inside a git repository
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
584
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
585 :param repo: Instance of VCS repo
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
586 :param force_create: Create even if same name hook exists
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
587 """
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
588
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
589 loc = jn(repo.path, 'hooks')
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
590 if not repo.bare:
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
591 loc = jn(repo.path, '.git', 'hooks')
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
592 if not os.path.isdir(loc):
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
593 os.makedirs(loc)
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
594
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
595 tmpl_post = pkg_resources.resource_string(
2618
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
596 'rhodecode', jn('config', 'post_receive_tmpl.py')
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
597 )
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
598 tmpl_pre = pkg_resources.resource_string(
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
599 'rhodecode', jn('config', 'pre_receive_tmpl.py')
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
600 )
2618
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
601
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
602 for h_type, tmpl in [('pre', tmpl_pre), ('post', tmpl_post)]:
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
603 _hook_file = jn(loc, '%s-receive' % h_type)
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
604 _rhodecode_hook = False
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
605 log.debug('Installing git hook in repo %s' % repo)
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
606 if os.path.exists(_hook_file):
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
607 # let's take a look at this hook, maybe it's rhodecode ?
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
608 log.debug('hook exists, checking if it is from rhodecode')
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
609 _HOOK_VER_PAT = re.compile(r'^RC_HOOK_VER')
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
610 with open(_hook_file, 'rb') as f:
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
611 data = f.read()
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
612 matches = re.compile(r'(?:%s)\s*=\s*(.*)'
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
613 % 'RC_HOOK_VER').search(data)
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
614 if matches:
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
615 try:
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
616 ver = matches.groups()[0]
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
617 log.debug('got %s it is rhodecode' % (ver))
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
618 _rhodecode_hook = True
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
619 except:
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
620 log.error(traceback.format_exc())
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
621 else:
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
622 # there is no hook in this dir, so we want to create one
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
623 _rhodecode_hook = True
2618
e1370dcb9908 Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents: 2604
diff changeset
624
2726
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
625 if _rhodecode_hook or force_create:
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
626 log.debug('writing %s hook file !' % h_type)
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
627 with open(_hook_file, 'wb') as f:
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
628 tmpl = tmpl.replace('_TMPL_', rhodecode.__version__)
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
629 f.write(tmpl)
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
630 os.chmod(_hook_file, 0755)
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
631 else:
aa17c7a1b8a5 Implemented basic locking functionality.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
632 log.debug('skipping writing hook file')