Mercurial > kallithea
comparison rhodecode/controllers/changelog.py @ 3960:5293d4bbb1ea
Merged dev into stable/default/master branch
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 07 Jun 2013 00:31:11 +0200 |
parents | b95f383f428d a42bfe8a9335 |
children | 267bb347d68c |
comparison
equal
deleted
inserted
replaced
3879:51596d9ef2f8 | 3960:5293d4bbb1ea |
---|---|
35 from rhodecode.lib.base import BaseRepoController, render | 35 from rhodecode.lib.base import BaseRepoController, render |
36 from rhodecode.lib.helpers import RepoPage | 36 from rhodecode.lib.helpers import RepoPage |
37 from rhodecode.lib.compat import json | 37 from rhodecode.lib.compat import json |
38 from rhodecode.lib.graphmod import _colored, _dagwalker | 38 from rhodecode.lib.graphmod import _colored, _dagwalker |
39 from rhodecode.lib.vcs.exceptions import RepositoryError, ChangesetDoesNotExistError,\ | 39 from rhodecode.lib.vcs.exceptions import RepositoryError, ChangesetDoesNotExistError,\ |
40 EmptyRepositoryError | 40 ChangesetError, NodeDoesNotExistError, EmptyRepositoryError |
41 from rhodecode.lib.utils2 import safe_int | 41 from rhodecode.lib.utils2 import safe_int |
42 from webob.exc import HTTPNotFound | |
42 | 43 |
43 log = logging.getLogger(__name__) | 44 log = logging.getLogger(__name__) |
44 | 45 |
45 | 46 |
47 def _load_changelog_summary(): | |
48 p = safe_int(request.GET.get('page'), 1) | |
49 size = safe_int(request.GET.get('size'), 10) | |
50 | |
51 def url_generator(**kw): | |
52 return url('changelog_summary_home', | |
53 repo_name=c.rhodecode_db_repo.repo_name, size=size, **kw) | |
54 | |
55 collection = c.rhodecode_repo | |
56 | |
57 c.repo_changesets = RepoPage(collection, page=p, | |
58 items_per_page=size, | |
59 url=url_generator) | |
60 page_revisions = [x.raw_id for x in list(c.repo_changesets)] | |
61 c.comments = c.rhodecode_db_repo.get_comments(page_revisions) | |
62 c.statuses = c.rhodecode_db_repo.statuses(page_revisions) | |
63 | |
64 | |
46 class ChangelogController(BaseRepoController): | 65 class ChangelogController(BaseRepoController): |
66 | |
67 def __before__(self): | |
68 super(ChangelogController, self).__before__() | |
69 c.affected_files_cut_off = 60 | |
70 | |
71 def _graph(self, repo, revs_int, repo_size, size, p): | |
72 """ | |
73 Generates a DAG graph for repo | |
74 | |
75 :param repo: | |
76 :param revs_int: | |
77 :param repo_size: | |
78 :param size: | |
79 :param p: | |
80 """ | |
81 if not revs_int: | |
82 c.jsdata = json.dumps([]) | |
83 return | |
84 | |
85 data = [] | |
86 revs = revs_int | |
87 | |
88 dag = _dagwalker(repo, revs, repo.alias) | |
89 dag = _colored(dag) | |
90 for (id, type, ctx, vtx, edges) in dag: | |
91 data.append(['', vtx, edges]) | |
92 | |
93 c.jsdata = json.dumps(data) | |
47 | 94 |
48 @LoginRequired() | 95 @LoginRequired() |
49 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', | 96 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
50 'repository.admin') | 97 'repository.admin') |
51 def __before__(self): | 98 def index(self, repo_name, revision=None, f_path=None): |
52 super(ChangelogController, self).__before__() | |
53 c.affected_files_cut_off = 60 | |
54 | |
55 def index(self): | |
56 limit = 100 | 99 limit = 100 |
57 default = 20 | 100 default = 20 |
58 if request.GET.get('size'): | 101 if request.GET.get('size'): |
59 c.size = max(min(safe_int(request.GET.get('size')), limit), 1) | 102 c.size = max(min(safe_int(request.GET.get('size')), limit), 1) |
60 session['changelog_size'] = c.size | 103 session['changelog_size'] = c.size |
63 c.size = int(session.get('changelog_size', default)) | 106 c.size = int(session.get('changelog_size', default)) |
64 # min size must be 1 | 107 # min size must be 1 |
65 c.size = max(c.size, 1) | 108 c.size = max(c.size, 1) |
66 p = safe_int(request.GET.get('page', 1), 1) | 109 p = safe_int(request.GET.get('page', 1), 1) |
67 branch_name = request.GET.get('branch', None) | 110 branch_name = request.GET.get('branch', None) |
111 c.changelog_for_path = f_path | |
68 try: | 112 try: |
69 if branch_name: | 113 |
70 collection = [z for z in | 114 if f_path: |
71 c.rhodecode_repo.get_changesets(start=0, | 115 log.debug('generating changelog for path %s' % f_path) |
72 branch_name=branch_name)] | 116 # get the history for the file ! |
73 c.total_cs = len(collection) | 117 tip_cs = c.rhodecode_repo.get_changeset() |
118 try: | |
119 collection = tip_cs.get_file_history(f_path) | |
120 except (NodeDoesNotExistError, ChangesetError): | |
121 #this node is not present at tip ! | |
122 try: | |
123 cs = self.__get_cs_or_redirect(revision, repo_name) | |
124 collection = cs.get_file_history(f_path) | |
125 except RepositoryError, e: | |
126 h.flash(str(e), category='warning') | |
127 redirect(h.url('changelog_home', repo_name=repo_name)) | |
128 collection = list(reversed(collection)) | |
74 else: | 129 else: |
75 collection = c.rhodecode_repo | 130 collection = c.rhodecode_repo.get_changesets(start=0, |
76 c.total_cs = len(c.rhodecode_repo) | 131 branch_name=branch_name) |
132 c.total_cs = len(collection) | |
77 | 133 |
78 c.pagination = RepoPage(collection, page=p, item_count=c.total_cs, | 134 c.pagination = RepoPage(collection, page=p, item_count=c.total_cs, |
79 items_per_page=c.size, branch=branch_name) | 135 items_per_page=c.size, branch=branch_name,) |
80 collection = list(c.pagination) | 136 collection = list(c.pagination) |
81 page_revisions = [x.raw_id for x in collection] | 137 page_revisions = [x.raw_id for x in c.pagination] |
82 c.comments = c.rhodecode_db_repo.get_comments(page_revisions) | 138 c.comments = c.rhodecode_db_repo.get_comments(page_revisions) |
83 c.statuses = c.rhodecode_db_repo.statuses(page_revisions) | 139 c.statuses = c.rhodecode_db_repo.statuses(page_revisions) |
84 except (EmptyRepositoryError), e: | 140 except (EmptyRepositoryError), e: |
85 h.flash(str(e), category='warning') | 141 h.flash(str(e), category='warning') |
86 return redirect(url('summary_home', repo_name=c.repo_name)) | 142 return redirect(url('summary_home', repo_name=c.repo_name)) |
87 except (RepositoryError, ChangesetDoesNotExistError, Exception), e: | 143 except (RepositoryError, ChangesetDoesNotExistError, Exception), e: |
88 log.error(traceback.format_exc()) | 144 log.error(traceback.format_exc()) |
89 h.flash(str(e), category='error') | 145 h.flash(str(e), category='error') |
90 return redirect(url('changelog_home', repo_name=c.repo_name)) | 146 return redirect(url('changelog_home', repo_name=c.repo_name)) |
91 | 147 |
92 self._graph(c.rhodecode_repo, collection, c.total_cs, c.size, p) | |
93 | |
94 c.branch_name = branch_name | 148 c.branch_name = branch_name |
95 c.branch_filters = [('', _('All Branches'))] + \ | 149 c.branch_filters = [('', _('All Branches'))] + \ |
96 [(k, k) for k in c.rhodecode_repo.branches.keys()] | 150 [(k, k) for k in c.rhodecode_repo.branches.keys()] |
151 _revs = [] | |
152 if not f_path: | |
153 _revs = [x.revision for x in c.pagination] | |
154 self._graph(c.rhodecode_repo, _revs, c.total_cs, c.size, p) | |
97 | 155 |
98 return render('changelog/changelog.html') | 156 return render('changelog/changelog.html') |
99 | 157 |
158 @LoginRequired() | |
159 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', | |
160 'repository.admin') | |
100 def changelog_details(self, cs): | 161 def changelog_details(self, cs): |
101 if request.environ.get('HTTP_X_PARTIAL_XHR'): | 162 if request.environ.get('HTTP_X_PARTIAL_XHR'): |
102 c.cs = c.rhodecode_repo.get_changeset(cs) | 163 c.cs = c.rhodecode_repo.get_changeset(cs) |
103 return render('changelog/changelog_details.html') | 164 return render('changelog/changelog_details.html') |
165 raise HTTPNotFound() | |
104 | 166 |
105 def _graph(self, repo, collection, repo_size, size, p): | 167 @LoginRequired() |
106 """ | 168 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
107 Generates a DAG graph for mercurial | 169 'repository.admin') |
170 def changelog_summary(self, repo_name): | |
171 if request.environ.get('HTTP_X_PARTIAL_XHR'): | |
172 _load_changelog_summary() | |
108 | 173 |
109 :param repo: repo instance | 174 return render('changelog/changelog_summary_data.html') |
110 :param size: number of commits to show | 175 raise HTTPNotFound() |
111 :param p: page number | |
112 """ | |
113 if not collection: | |
114 c.jsdata = json.dumps([]) | |
115 return | |
116 | |
117 data = [] | |
118 revs = [x.revision for x in collection] | |
119 | |
120 dag = _dagwalker(repo, revs, repo.alias) | |
121 dag = _colored(dag) | |
122 for (id, type, ctx, vtx, edges) in dag: | |
123 data.append(['', vtx, edges]) | |
124 | |
125 c.jsdata = json.dumps(data) |