comparison rhodecode/controllers/changelog.py @ 3760:6302a1423a4e beta

Use changelog controller for displaying history of files. step 1 for removing obsolete shortlog
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 15 Apr 2013 21:58:40 +0200
parents b950b884ab87
children c7970889c5c0
comparison
equal deleted inserted replaced
3759:12ca667b69b6 3760:6302a1423a4e
34 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator 34 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
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 ChangesetError, NodeDoesNotExistError
40 from rhodecode.lib.utils2 import safe_int 41 from rhodecode.lib.utils2 import safe_int
41 42
42 log = logging.getLogger(__name__) 43 log = logging.getLogger(__name__)
43 44
44 45
73 c.jsdata = json.dumps(data) 74 c.jsdata = json.dumps(data)
74 75
75 @LoginRequired() 76 @LoginRequired()
76 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 77 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
77 'repository.admin') 78 'repository.admin')
78 def index(self): 79 def index(self, repo_name, revision=None, f_path=None):
79 limit = 100 80 limit = 100
80 default = 20 81 default = 20
81 if request.GET.get('size'): 82 if request.GET.get('size'):
82 c.size = max(min(safe_int(request.GET.get('size')), limit), 1) 83 c.size = max(min(safe_int(request.GET.get('size')), limit), 1)
83 session['changelog_size'] = c.size 84 session['changelog_size'] = c.size
86 c.size = int(session.get('changelog_size', default)) 87 c.size = int(session.get('changelog_size', default))
87 # min size must be 1 88 # min size must be 1
88 c.size = max(c.size, 1) 89 c.size = max(c.size, 1)
89 p = safe_int(request.GET.get('page', 1), 1) 90 p = safe_int(request.GET.get('page', 1), 1)
90 branch_name = request.GET.get('branch', None) 91 branch_name = request.GET.get('branch', None)
92 c.changelog_for_path = f_path
91 try: 93 try:
92 collection = c.rhodecode_repo.get_changesets(start=0, 94
93 branch_name=branch_name) 95 if f_path:
96 log.debug('generating changelog for path %s' % f_path)
97 # get the history for the file !
98 tip_cs = c.rhodecode_repo.get_changeset()
99 try:
100 collection = tip_cs.get_file_history(f_path)
101 except (NodeDoesNotExistError, ChangesetError):
102 #this node is not present at tip !
103 try:
104 cs = self.__get_cs_or_redirect(revision, repo_name)
105 collection = cs.get_file_history(f_path)
106 except RepositoryError, e:
107 h.flash(str(e), category='warning')
108 redirect(h.url('changelog_home', repo_name=repo_name))
109 collection = list(reversed(collection))
110 else:
111 collection = c.rhodecode_repo.get_changesets(start=0,
112 branch_name=branch_name)
94 c.total_cs = len(collection) 113 c.total_cs = len(collection)
95 114
96 c.pagination = RepoPage(collection, page=p, item_count=c.total_cs, 115 c.pagination = RepoPage(collection, page=p, item_count=c.total_cs,
97 items_per_page=c.size, branch=branch_name) 116 items_per_page=c.size, branch=branch_name)
98 collection = list(c.pagination) 117 collection = list(c.pagination)
105 return redirect(url('changelog_home', repo_name=c.repo_name)) 124 return redirect(url('changelog_home', repo_name=c.repo_name))
106 125
107 c.branch_name = branch_name 126 c.branch_name = branch_name
108 c.branch_filters = [('', _('All Branches'))] + \ 127 c.branch_filters = [('', _('All Branches'))] + \
109 [(k, k) for k in c.rhodecode_repo.branches.keys()] 128 [(k, k) for k in c.rhodecode_repo.branches.keys()]
110 129 _revs = []
111 self._graph(c.rhodecode_repo, [x.revision for x in c.pagination], 130 if not f_path:
112 c.total_cs, c.size, p) 131 _revs = [x.revision for x in c.pagination]
132 self._graph(c.rhodecode_repo, _revs, c.total_cs, c.size, p)
113 133
114 return render('changelog/changelog.html') 134 return render('changelog/changelog.html')
115 135
116 @LoginRequired() 136 @LoginRequired()
117 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 137 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',