Mercurial > kallithea
comparison rhodecode/controllers/changelog.py @ 3747:600ffde2634c beta
changelog pagination with branch filtering now uses
common logic that non branch filtered version.
- introduced CollectionGenerator object as a helper for
achieving abstraction layer on top of filtered results
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 13 Apr 2013 14:36:02 +0200 |
parents | 881ae12b3c7d |
children | 9d743ca9cede |
comparison
equal
deleted
inserted
replaced
3746:76b935e7427d | 3747:600ffde2634c |
---|---|
67 # min size must be 1 | 67 # min size must be 1 |
68 c.size = max(c.size, 1) | 68 c.size = max(c.size, 1) |
69 p = safe_int(request.params.get('page', 1), 1) | 69 p = safe_int(request.params.get('page', 1), 1) |
70 branch_name = request.params.get('branch', None) | 70 branch_name = request.params.get('branch', None) |
71 try: | 71 try: |
72 if branch_name: | 72 collection = c.rhodecode_repo.get_changesets(start=0, |
73 collection = [z for z in | 73 branch_name=branch_name) |
74 c.rhodecode_repo.get_changesets(start=0, | 74 c.total_cs = len(collection) |
75 branch_name=branch_name)] | |
76 c.total_cs = len(collection) | |
77 else: | |
78 collection = c.rhodecode_repo | |
79 c.total_cs = len(c.rhodecode_repo) | |
80 | 75 |
81 c.pagination = RepoPage(collection, page=p, item_count=c.total_cs, | 76 c.pagination = RepoPage(collection, page=p, item_count=c.total_cs, |
82 items_per_page=c.size, branch=branch_name) | 77 items_per_page=c.size, branch=branch_name) |
83 collection = list(c.pagination) | 78 collection = list(c.pagination) |
84 page_revisions = [x.raw_id for x in collection] | 79 page_revisions = [x.raw_id for x in c.pagination] |
85 c.comments = c.rhodecode_db_repo.get_comments(page_revisions) | 80 c.comments = c.rhodecode_db_repo.get_comments(page_revisions) |
86 c.statuses = c.rhodecode_db_repo.statuses(page_revisions) | 81 c.statuses = c.rhodecode_db_repo.statuses(page_revisions) |
87 except (RepositoryError, ChangesetDoesNotExistError, Exception), e: | 82 except (RepositoryError, ChangesetDoesNotExistError, Exception), e: |
88 log.error(traceback.format_exc()) | 83 log.error(traceback.format_exc()) |
89 h.flash(str(e), category='error') | 84 h.flash(str(e), category='error') |
90 return redirect(url('changelog_home', repo_name=c.repo_name)) | 85 return redirect(url('changelog_home', repo_name=c.repo_name)) |
91 | 86 |
92 self._graph(c.rhodecode_repo, collection, c.total_cs, c.size, p) | |
93 | |
94 c.branch_name = branch_name | 87 c.branch_name = branch_name |
95 c.branch_filters = [('', _('All Branches'))] + \ | 88 c.branch_filters = [('', _('All Branches'))] + \ |
96 [(k, k) for k in c.rhodecode_repo.branches.keys()] | 89 [(k, k) for k in c.rhodecode_repo.branches.keys()] |
90 | |
91 self._graph(c.rhodecode_repo, [x.revision for x in c.pagination], | |
92 c.total_cs, c.size, p) | |
97 | 93 |
98 return render('changelog/changelog.html') | 94 return render('changelog/changelog.html') |
99 | 95 |
100 def changelog_details(self, cs): | 96 def changelog_details(self, cs): |
101 if request.environ.get('HTTP_X_PARTIAL_XHR'): | 97 if request.environ.get('HTTP_X_PARTIAL_XHR'): |
102 c.cs = c.rhodecode_repo.get_changeset(cs) | 98 c.cs = c.rhodecode_repo.get_changeset(cs) |
103 return render('changelog/changelog_details.html') | 99 return render('changelog/changelog_details.html') |
104 | 100 |
105 def _graph(self, repo, collection, repo_size, size, p): | 101 def _graph(self, repo, revs_int, repo_size, size, p): |
106 """ | 102 """ |
107 Generates a DAG graph for mercurial | 103 Generates a DAG graph for repo |
108 | 104 |
109 :param repo: repo instance | 105 :param repo: |
110 :param size: number of commits to show | 106 :param revs_int: |
111 :param p: page number | 107 :param repo_size: |
108 :param size: | |
109 :param p: | |
112 """ | 110 """ |
113 if not collection: | 111 if not revs_int: |
114 c.jsdata = json.dumps([]) | 112 c.jsdata = json.dumps([]) |
115 return | 113 return |
116 | 114 |
117 data = [] | 115 data = [] |
118 revs = [x.revision for x in collection] | 116 revs = revs_int |
119 | 117 |
120 dag = _dagwalker(repo, revs, repo.alias) | 118 dag = _dagwalker(repo, revs, repo.alias) |
121 dag = _colored(dag) | 119 dag = _colored(dag) |
122 for (id, type, ctx, vtx, edges) in dag: | 120 for (id, type, ctx, vtx, edges) in dag: |
123 data.append(['', vtx, edges]) | 121 data.append(['', vtx, edges]) |