v1.0 Release – Expand/Collapse Functionality only for Merges with >5 Pushes

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!

This entry was posted in DPS911, Mercurial Project, Open Source and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>