Posts Tagged patch
v0.5 Release - Examining Two Patches Regarding the Hg Annotate Problem
Posted by Sid in DPS911, Mercurial Project, Open Source on February 4th, 2009
In my previous blog post I had a look at the default and coal templates for hgweb in order to find a fix to the hg annotate problem. Neither of those templates presented a viable solution so the next step I decided to take was to have a look at a couple of patches that people have attached to the bug, which apparently reduced the loading time by a bit.
Patch by Smaug
Smaug is currently the person assigned to the bug and he put up a patch back in 2008 that got an r+ rating from ted. However, it doesn’t do exactly what jorendorff wants. The patch displays a loading message until the entire page is done loading and then shows the code. Instead, jorendorff wants the first screenful to appear almost right away. Thus, I decided to remove the loading message and then test the loading time of annotate. I was able to get a time of ~12sec to ~14sec on my machine when loading this file.
Obviously this is an improvement in loading time (currently the loading time is ~20sec). However, I want it to be even faster. One great thing about this patch is that now you can select code without selecting the line numbers. Another important change is that the huge table is now gone, replaced by div and pre tags. There are some things here that I can definitely use. I will be using div tags in my implementation as well but I don’t know if I will be doing it the same way as Smaug.
Patch by Mats Palmgren
The next patch I examined also gets rid of the table and uses a pre tag to display the code. I tested it on my machine and got a loading time of ~7sec to ~8sec. Now, this is a definite improvement over the current loading time. The increase in speed over the current implementation is very noticeable. However, the problem with this patch is that it doesn’t use valid HTML. I want my implementation to use valid HTML so I can’t really use the same type of implementation as this patch. I’ll have to come up with a more conventional approach.
Looking Ahead
I think by now I’ve researched all the resources that I could acquire. Now, I can get down to actually writing the patch. I’m pretty sure I know what to do, lets see how it turns out. Stay tuned!
v0.3 Release - Problems with my Patch for bug 459727
Posted by Sid in Mercurial Project, Open Source on December 2nd, 2008
Lately there has been some activity on bug 459727 concerning the patch I had submitted to implement an OnScroll feature for the pushlog. View comments 8 and 9 to see the problems that jorendorff as identified. So far there hasn’t been an official review but it is inevitable that I will have to make changes to the patch I had submitted.
In comments 10 and 12 I underlined what steps I will be taking to fix the problems that jorendorff has identified so far. They don’t seem to be major changes although I am worried about using JSON.parse(). I don’t know if that will work or not. I guess I will have to try it out and see what I can do.
Also I don’t really understand what is wrong with using `new Function(”return ” + entries.responseText) ()` as jorendorff mentioned in comment 9. In comment 11, Justin mentioned that it may cause vulnerabilities to XSS attacks but he couldn’t explain why that was. This has me interested and I would love it if someone could tell me why.
This is the biggest patch I submitted for my v0.2 so I’m expecting to go through several iterations before the patch is accepted. Look out for a new patch soon…
v0.3 Release - Fix for my Patch for bug 445560
Posted by Sid in Mercurial Project, Open Source on November 24th, 2008
In a previous blog post I detailed problems with my previous patch for bug 445560. There were 2 problems that ted identified which need to be fixed:
- Should use ids instead of dates
- Should store unique identifiers in the class instead of the id of the tag
The Fix
I made a change to pushlog-feed.py to use ids of the changeset instead of the dates by adding the following code which passes the id to the client-side (line 270):
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | def changelist(limit=0, **map): allentries = [] lastid = None ch = None l = [] mergehidden = "" p = 0 currentpush = None for id, user, date, node in entries: ctx = web.repo.changectx(node) n = ctx.node() 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": [], "Id": id } |
Then a change needed to be made to the hg_templates\gitweb_mozilla\map file. The id needs to be stored in the class of the hidden rows and the expand row. So I made the following changes:
mergehidden = '<br/>← #count# hidden changesets <a class="expand hideidentifier#Id#" href="#">[Expand]</a>'
pushlogentry = '<tr class="parity#parity# #hidden# identifier#Id#">...
Now each expand row will have the class hideidentifier#id#, which is a unique identifier telling us which expand link is clicked. Then we can take this unique identifier and hide all the rows that have the same #Id#. To do this I needed to add some JavaScript code to hg_templates\gitweb_mozilla\pushlog.tmpl…
30 31 32 33 | var id = $(this).attr("class"); id = '.' + id.substring(11, id.length); $(id).nextAll(id).toggle(); return false; |
So line 30 gets the id of the current object (the expand row whose [Expand] link is clicked by the user). So the id might be something like “hideidentifier2434″ after line 30 is executed. Next a ‘.’ character is added on the front and the id is substringed to give us something like “.identifier2434″. Now we have the class of the rows we want to hide/unhide and we can then execute line 32. Voila! Problem fixed.
v0.3 Release - Problem with my Patch for bug 445560
Posted by Sid in Mercurial Project, Open Source on November 24th, 2008
I had a discussion with ted today relating to my patch for bug 445560 for the pushlog. There seems to be a slight problem with it. When there are 2 merges on one page, if one clicks the second expand link, it shows those changesets, but the row with the [Expand] link disappears (example of the problem). This is a problem that we don’t want happening.
Problem
Currently I’m using the date as a unique identifier (view here for full details) but if somehow (very unlikely, but possible) two rows have the same date then there will be a problem, which is the case with the example linked above.
Fix
This problem can be solved by using the id as the unique identifier instead of the date. This will work because each changeset has a different id and each set merge changesets have the same id so it will allow one to identify all the merge changesets to hide on a page and not hide the ones that shouldn’t be hidden.
I will be putting up a new patch to fix this issue.
Edit: I didn’t read the comments (comment #6) that ted put on bug 445560 for my patch before I made this post. There is another problem that he identified, which I need to fix. Apparently I’m not allowed to have multiple elements with the same id so I can’t be putting my unique identifiers in the id of the tag. ted recommended putting them in the class of the tag which is what I will be doing. Look out for a new blog post explaining the code.
Applying a patch to a Repo using Mercurial
Posted by Sid in Mercurial Project, Open Source on October 14th, 2008
As I mentioned in a previous blog post, one of the features for my v0.1 release will be implementing a expand/collapse feature for pushloghtml. Well, turns out that ted has already started working on that. He’s already filed a bug and released a patch for it. According to him its not quite done and a couple of things need to be changed.
So, my first job was to download the patch and apply it to my repo. So I headed over to Bugzilla and looked up the bug. There were 2 patches that I needed to download…
- One for pushlog-feed.py
- Another for gitweb_mozilla
Before you read the following take into account that I’ve never applied any kind of a patch before so this is purely from the point of a beginner. So I was looking for a way to download the patch so that I could apply it. But apparently there is no download link available on BugZIlla (it took me almost 20 mins to realize that). They should really look to put in some sort of download link/button. In the end I just ended up using the crude method of “Save Page As” to download the patch file.
Now onto applying the patch. I had no idea how to do that so I tried using tortoiseMerge since I already had that installed. It is apparently capable of applying a patch. I added the path of the diff file and the directory where I wanted it to apply the patch in the two text boxes below and then clicked the OK button. Nothing happened at all. Nothing got loaded, no error message, no nothing. This had me a bit bewildered and frustrated. tortoiseMerge was basically useless.

Now onto the next option which was hg itself. I knew that there was a way since I had read about it in some documentation when I was getting know hg at the start of my project. So I headed over to google to perform a search. I tried various things such as “apply a patch hg”, “patch hg”, “install patch hg” and “mercurial apply patch”. The last one gave me a couple of good results. One was at hgbook and another was documentation about hg queues but neither of them was a straight up guide of how to install patches. I tried many different google searches but I just couldn’t find any simple and easy guide explaining how one would install a patch using hg. Well, here I am to the rescue. The following is a simple guide that gives instructions on installing a simple patch using hg…
- Download the .patch or .diff file onto your machine
- Navigate to the repo that you want to install the patch to i.e. testRepo (I will using repo name for this example, substitute it with your repo name when you are trying to apply a patch yourself)
- Open testRepo\.hg\hgrc (the config file)
- Add the following to hgrc and save (This enables queues for hg so that we can use commands that we need, qimport and qpush)
[extensions]
hgext.mq = - Now open up a command prompt and navigate to your repo directory
- Type in hg qimport <full-path-of-patch-file> and press enter
- The above command should create a patch folder within testRepo\.hg\patches\
- Next navigate to testRepo\.hg\patches\
- Type in hg qpush <patch-file-name>
- Done! The patch should have been applied (if you get an error such as “abort: local changes found, refresh first” then that means you have made changes to the original files and the patch won’t work)
In my trials and tribulations while trying to apply a patch I had to first figure out what hg queues did and how to use them. I tried to just type in hg qimport but I just got a “command does not exist” error. I didn’t realize that I had to import something until ted gave me a push in the right direction. A simple guide would have really helped.