Posts Tagged HTML
v0.5 Release - Examining How Other Templates Implement Hg Annotate
Posted by Sid in DPS911, Mercurial Project, Open Source on February 3rd, 2009
In order to complete the goals for my v0.5 release I examined how other templates implement hg annotate. I wanted to find out whether these other implementations had the ability to load 10,000 line cpp files quickly or not.
Default Template
Hgweb comes with a default template, which is quite ugly if you ask me but maybe it is efficient. I put together my local hgweb environment to use the default template and I was able to get a time of ~12secs. However, there was a major problem with this template. I noticed that after about 2000 lines the rest of the lines stopped showing up. The page kept loading new content but as I scrolled down the rest of the page was completely blank. None of the other 8000 or so lines of code were visible. This problem means that this template is of no use to me.
Coal Template
The next step was to try the coal template, which strangely doesn’t look very different from the default template. I configured my local hgweb environment to use the coal template and I got a time of ~14secs. This is not a significant improvement over Mozilla’s template which was clocking in at ~20secs but it is definitely better. Any reduction in loading time is a good thing. The problem is that gitweb_mozilla (the template that Mozilla uses) and the Coal template both use the same type of implementation. They both use one HUGE table to display the file, which obviously is not the correct method to employ (see below).
gitweb_mozilla
<div class="page_body">
<table border="0">
#annotate%annotateline#</table>
</div>coal
<div class="overflow">
<table class="bigtable" border="0">
<tr>
<th class="annotate">rev</th>
<th class="lineno">line</th>
<th class="line">source</th>
</tr>
{annotate%annotateline}
</table>
</div>Neither of these templates have been able to help me to solve my problem. Next I’ll be having a look at some of the patches that people put up on the bug page. Lets see if they improve annotate’s loading time or not.
v0.2 Release - Show Files Touched by a Changeset in the Pushlog
Posted by Sid in Mercurial Project, Open Source on November 11th, 2008
As part of my v0.2 release I wanted to fix bug 448707. It is aparently a very desired feature by the community. Adding this featue definitely makes it easier to immediately find out which files were touched while right now one has to click the changset link to do that.
Initial Thoughts
I talked to ted and jorendorff about how they thought I should go about implementing this feature. ted recommended using the http://hg.mozilla.org/mozilla-central/pushlog feed which returns the files touched. I thought I could use an XMLHttpRequest to get the data to the front-end and then format it. But after looking at the code I decided that that wasn’t the way to go. I decided to format the data on the back-end and then just print it through the map file exactly how everything else in the pushlog is rendered
Implementation
So, as I mentioned before I had to make some back-end changes (changelist function in pushlog-feed.py and map). The following is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | def changelist(limit=0, **map): #pdb.set_trace() allentries = [] lastid = None ch = None l = [] mergehidden = "" p = 0 currentpush = None for id, user, date, node in entries: filesTouched = '' ctx = web.repo.changectx(node) n = ctx.node() if len(ctx.files()) > 1: for f in ctx.files(): filesTouched += f + '<br/>' else: for f in ctx.files(): filesTouched += f entry = {"author": ctx.user(), "desc": ctx.description(), "files": web.listfilediffs(tmpl, ctx.files(), n), "rev": ctx.rev(), "node": hex(n), "tags": nodetagsdict(web.repo, n), "branches": nodebranchdict(web.repo, ctx), "inbranch": nodeinbranch(web.repo, ctx), "hidden": "", "push": [], "mergerollup": [], "dateId": localdate(date), "filesTouched": filesTouched } |
So basically, there is a function that gives me all the files touched by a changeset, ctx.files(). I just call the function append each file touched by a changeset into a string (filesTouched, in this case). Once I add it to the entry array I can then perform the following in the map file:
1 | pushlogentry = '<tr id="date#dateId#" class="parity#parity# #hidden# #dateId#"><td>#push%pushinfo#</td><td class="age"><a href="{url}rev/#node|short#{sessionvars%urlparameter}">#node|short#</a></td><td id="#dateId#"><strong>#author|person# — #desc|strip|escape|buglink#</strong> <span class="logtags">{inbranch%inbranchtag}{branches%branchtag}{tags%tagtag}</span>#mergerollup%mergehidden#<br/><span style="font-size: x-small; color: #FF902B; font-weight: bold">#filesTouched#</span></td></tr>\n' |
I added:
1 | <br/><span style="font-size: x-small; color: #FF902B; font-weight: bold">#filesTouched#</span> |
The above line of code gets the filesTouched variable from the back-end and formats it using CSS styles to display within on the page.
The following is the result of the obove code: http://sidkalra.com/files/mercurial/filesTouched1.png
This way it is easy to tell which files a changeset touched. A users knows it right away, no need to click on any other links to find out. Only thing I am unsure about is the text color of the files touched. At first I had gone with red but that was a bit too bold, so I decided to go with orange but I don’t know if it fits the theme well. As far as I can tell it seems like an OK choice but I might (or might not) change it in the future.
EDIT: I’ve changed the color of the text to a dark brown so that it is easier to read. I felt that the previous orange color was a bit too harsh on the eyes. Have a look: http://sidkalra.com/files/mercurial/filesTouched2.png