comparison mercurial/hgweb/hgweb_mod.py @ 2684:783220e5d2d1

[hgweb] Implemented shortlog (gitweb templates only)
author Josef "Jeff" Sipek <jeffpc@josefsipek.net>
date Mon, 24 Jul 2006 20:56:30 -0400
parents 8a798185809d
children 2edfd6644a9f
comparison
equal deleted inserted replaced
2683:8a798185809d 2684:783220e5d2d1
44 mtime = get_mtime(self.repo.root) 44 mtime = get_mtime(self.repo.root)
45 if mtime != self.mtime: 45 if mtime != self.mtime:
46 self.mtime = mtime 46 self.mtime = mtime
47 self.repo = hg.repository(self.repo.ui, self.repo.root) 47 self.repo = hg.repository(self.repo.ui, self.repo.root)
48 self.maxchanges = int(self.repo.ui.config("web", "maxchanges", 10)) 48 self.maxchanges = int(self.repo.ui.config("web", "maxchanges", 10))
49 self.maxshortchanges = int(self.repo.ui.config("web", "maxshortchanges", 60))
49 self.maxfiles = int(self.repo.ui.config("web", "maxfiles", 10)) 50 self.maxfiles = int(self.repo.ui.config("web", "maxfiles", 10))
50 self.allowpull = self.repo.ui.configbool("web", "allowpull", True) 51 self.allowpull = self.repo.ui.configbool("web", "allowpull", True)
51 52
52 def archivelist(self, nodeid): 53 def archivelist(self, nodeid):
53 allowed = self.repo.ui.configlist("web", "allow_archive") 54 allowed = self.repo.ui.configlist("web", "allow_archive")
156 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f, 157 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f,
157 showfunc=showfunc, ignorews=ignorews, 158 showfunc=showfunc, ignorews=ignorews,
158 ignorewsamount=ignorewsamount, 159 ignorewsamount=ignorewsamount,
159 ignoreblanklines=ignoreblanklines), f, tn) 160 ignoreblanklines=ignoreblanklines), f, tn)
160 161
161 def changelog(self, pos): 162 def changelog(self, pos, shortlog=False):
162 def changenav(**map): 163 def changenav(**map):
163 def seq(factor, maxchanges=None): 164 def seq(factor, maxchanges=None):
164 if maxchanges: 165 if maxchanges:
165 yield maxchanges 166 yield maxchanges
166 if maxchanges >= 20 and maxchanges <= 40: 167 if maxchanges >= 20 and maxchanges <= 40:
171 for f in seq(factor * 10): 172 for f in seq(factor * 10):
172 yield f 173 yield f
173 174
174 l = [] 175 l = []
175 last = 0 176 last = 0
176 for f in seq(1, self.maxchanges): 177 maxchanges = shortlog and self.maxshortchanges or self.maxchanges
177 if f < self.maxchanges or f <= last: 178 for f in seq(1, maxchanges):
179 if f < maxchanges or f <= last:
178 continue 180 continue
179 if f > count: 181 if f > count:
180 break 182 break
181 last = f 183 last = f
182 r = "%d" % f 184 r = "%d" % f
217 parity = 1 - parity 219 parity = 1 - parity
218 220
219 for e in l: 221 for e in l:
220 yield e 222 yield e
221 223
224 maxchanges = shortlog and self.maxshortchanges or self.maxchanges
222 cl = self.repo.changelog 225 cl = self.repo.changelog
223 mf = cl.read(cl.tip())[0] 226 mf = cl.read(cl.tip())[0]
224 count = cl.count() 227 count = cl.count()
225 start = max(0, pos - self.maxchanges + 1) 228 start = max(0, pos - maxchanges + 1)
226 end = min(count, start + self.maxchanges) 229 end = min(count, start + maxchanges)
227 pos = end - 1 230 pos = end - 1
228 231
229 yield self.t('changelog', 232 yield self.t(shortlog and 'shortlog' or 'changelog',
230 changenav=changenav, 233 changenav=changenav,
231 manifest=hex(mf), 234 manifest=hex(mf),
232 rev=pos, changesets=count, entries=changelist, 235 rev=pos, changesets=count, entries=changelist,
233 archives=self.archivelist("tip")) 236 archives=self.archivelist("tip"))
234 237
688 **map) 691 **map)
689 692
690 def expand_form(form): 693 def expand_form(form):
691 shortcuts = { 694 shortcuts = {
692 'cl': [('cmd', ['changelog']), ('rev', None)], 695 'cl': [('cmd', ['changelog']), ('rev', None)],
696 'sl': [('cmd', ['shortlog']), ('rev', None)],
693 'cs': [('cmd', ['changeset']), ('node', None)], 697 'cs': [('cmd', ['changeset']), ('node', None)],
694 'f': [('cmd', ['file']), ('filenode', None)], 698 'f': [('cmd', ['file']), ('filenode', None)],
695 'fl': [('cmd', ['filelog']), ('filenode', None)], 699 'fl': [('cmd', ['filelog']), ('filenode', None)],
696 'fd': [('cmd', ['filediff']), ('node', None)], 700 'fd': [('cmd', ['filediff']), ('node', None)],
697 'fa': [('cmd', ['annotate']), ('filenode', None)], 701 'fa': [('cmd', ['annotate']), ('filenode', None)],
762 except hg.RepoError: 766 except hg.RepoError:
763 req.write(self.search(hi)) # XXX redirect to 404 page? 767 req.write(self.search(hi)) # XXX redirect to 404 page?
764 return 768 return
765 769
766 req.write(self.changelog(hi)) 770 req.write(self.changelog(hi))
771
772 def do_shortlog(self, req):
773 hi = self.repo.changelog.count() - 1
774 if req.form.has_key('rev'):
775 hi = req.form['rev'][0]
776 try:
777 hi = self.repo.changelog.rev(self.repo.lookup(hi))
778 except hg.RepoError:
779 req.write(self.search(hi)) # XXX redirect to 404 page?
780 return
781
782 req.write(self.changelog(hi, shortlog = True))
767 783
768 def do_changeset(self, req): 784 def do_changeset(self, req):
769 req.write(self.changeset(req.form['node'][0])) 785 req.write(self.changeset(req.form['node'][0]))
770 786
771 def do_manifest(self, req): 787 def do_manifest(self, req):