Posts Tagged expand/collapse
v1.0 Release - Expand/Collapse Functionality only for Merges with >5 Pushes
Posted by Sid in DPS911, Mercurial Project, Open Source on April 21st, 2009
In my goals post I outlined that I wanted to take on a new bug. This bug outlines that only merges that have >5 pushes should be given expand/collapse functionality. Any merge that contains <5 pushes should be shown normally. I guess, when the original expand/collapse bug was fixed we all forgot about this little feature. No big deal though because I’m gonna fix it now.
The following is the current server-side code:
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | if id != lastid: lastid = id p = parity.next() entry["push"] = [{"user": user, "date": localdate(date)}] if len([c for c in ctx.parents() if c.node() != nullid]) > 1: mergehidden = "hidden" entry["mergerollup"] = [{"count": 0}] else: mergehidden = "" currentpush = entry else: entry["hidden"] = mergehidden if mergehidden: currentpush["mergerollup"][0]["count"] += 1 entry["parity"] = p l.append(entry) |
This is where the change will have to be made. Lets have a look here. On line 401 there’s an if statement that executes to true if the changeset has more than one parent, which means that it is a merge changeset. Then, the following lines setup the expand/collapse functionality. It is line 401 where I will make the change to implement this functionality.
A merge changset should have 2 parents. So, in order to find out how many pushes there are in the merge I just do a simple substraction between the rev number of parent 0 and the rev number of parent 1. The result will tell me how many pushes that merge contains. Only implement expand/collapse functionality for the merge if the result is greater than 5.
The new code:
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | if id != lastid: lastid = id p = parity.next() entry["push"] = [{"user": user, "date": localdate(date)}] if len([c for c in ctx.parents() if c.node() != nullid]) > 1 and ctx.parents()[0].rev() - ctx.parents()[1].rev() > 5: mergehidden = "hidden" entry["mergerollup"] = [{"count": 0}] else: mergehidden = "" currentpush = entry else: entry["hidden"] = mergehidden if mergehidden: currentpush["mergerollup"][0]["count"] += 1 entry["parity"] = p l.append(entry) |
As you can see above I only needed to change line 401 to implement this change. It’s always great to be able to add new functionality without needing additional lines of code. A win win!
v0.6 Release - Minor fix for bug 445560
Posted by Sid in DPS911, Mercurial Project, Open Source on February 16th, 2009
All the way back in November 2008 I had put out a patch to implement expand and collapse functionality (for merge changesets) for the pushlog. I had gotten an r+ review but I just needed to make some minor adjustments to the patch. Time went on and I totally forgot about implementing that minor fix. I was looking through some of my previous work and then I realized that I had forgotten about this.
The change is pretty simple but important. I just have to use proper naming conventions for variable names, which I wasn’t doing before. This might be the type of thing that is easily overlooked, I was guilty of that myself but it is important that we abide by naming conventions. Why? So that the code is readable when other people inevitably come along to change/read it.
In hgpoller/pushlogfeed.py I changed “Id” to “id” as all other variable names are non-capitalized:
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 }
In hg_templates/pushlog.tmpl I changed id to pushid to make it more clearer:
var pushid = $(this).attr("class"); pushid = '.' + pushid.substring(11, pushid.length); $(pushid).nextAll(pushid).toggle();
expand/collapse, hg, hgweb, JavaScript, merge Changest, Python
v0.2 Release - Fix to the Current Patch for bug 445560
Posted by Sid in Mercurial Project, Open Source on November 8th, 2008
One month ago ted put up a patch to fix bug 445560 to implement expand/collapse functionality for merge changesets for the pushlog. The patch works properly except for one issue. When a user clicks on a particular [Expand] link it should only expand the changesets belonging to it and not all merge changesets on the page. Right now all merge changesets are expanding. For example the following are 2 merge changesets that have [Expand] links:

With ted’s patch when the user clicks on the first Expand link the following happens:

Both merge changesets expand when only the first one should.
The Fix
jQuery is used to implement this expand/collapse feature which allows us to perform hide() and toggle() to hide and show the appropriate merge changesets. Each row which should be hidden is given the class name “hidden” which then allows one to go $(’.hidden’).hide() and $(’.hidden’).toggle(). But the problem is that all rows have the same class name so no matter which Expand link one clicks ALL rows with the class name “hidden” will get toggled.
Somehow each set of merge changesets have to be given their own unique identifier. In this case I decided to use the date, which is common for a set of changesets that are grouped together. To do this I made some back-end changes to changelist() in the pushlog-feed.py file. Now, it also returns a dateId:
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: 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": [], "dateId": localdate(date) }
I then passed this dateId to the map file to make it the id of each hidden row and the row which holds the expand link:
pushlogentry = '<tr id="date#dateId#" class="parity#parity# #hidden# #dateId#">
mergehidden = '<br/>← #count# hidden changesets <a id="hidedate#dateId#" class="expand" href="#">[Expand]</a>'
Now each grouped set of hidden rows has a unique id, which will allow me to hide the right set of changesets according to which Expand link the user clicks. To do this I changed some code in the pushlog.tmpl file:
1 2 3 4 5 6 7 8 9 10 11 12 13 | // hide things that should be hidden $('.hidden').hide(); // add click handler to unhide hidden things $('.expand').click(function (idDate) { if ($(this).text() == "[Expand]") $(this).text("[Collapse]"); else $(this).text("[Expand]"); //XXX: don't toggle all hidden, just the ones following this row var id = $(this).attr("id"); id = '#' + id.substring(4, id.length); $(id).nextAll(id).toggle(); return false; |
I replaced the line $(’.hidden’).toggle() with lines 10-12. Basically:
- I get the id of the Expand row that the user clicked.
- Then, I manipulate the string to get the id of the hidden rows
- Lastly, I toggle the id of the hidden rows
The above code gives the appropriate result when the first expand link is clicked:

expand/collapse, hg, hgweb, JavaScript, jQuery, Mercurial, Python
-
-
Archives
- April 2009 (15)
- March 2009 (16)
- February 2009 (14)
- January 2009 (10)
- December 2008 (10)
- November 2008 (18)
- October 2008 (7)
- September 2008 (10)
-
Meta