v0.2 Release Getting Merge Changesets to Display Properly for bug 459727

I’ve been working hard to make merge changesets display properly OnScrollDown for bug 459727. They weren’t appearing at all before since I didn’t implement any code for them. I started to work on doing so but I ran into a puzzling problem that jorendorff helped solve. I’ve managed to get merge changesets to display properly now. It wasn’t as hard as I had expected but the amount of code I had to write was quite long. There are probably ways to shrink it down a bit but I just don’t see how right now. Lets go over it…

The Code

The server side code can is explained here. The following is the client side 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
function renderMorePushLogResults() {
  //start += 20;
  //end = start + 19;
  var end = start;
  start = start - 20
  var pushCheckins = new XMLHttpRequest();
  pushCheckins.open('GET', '/json-pushes?startID=' + start + '&endID=' + end, true);
  pushCheckins.onreadystatechange = function() {
  if(pushCheckins.readyState == 4)  {
    if(pushCheckins.status != 404) {
      var loader = document.getElementById("loader");
      loader.innerHTML = '<img src="{url}static/ajax-loader.gif" align="right" />';
 
      var pushData = new Function("return " + pushCheckins.responseText) ();
      var counter = 0;
      for(var i = end; i > start; i--) {
        var trScroll = document.createElement("tr");
 
        if(counter == 0) {
          counter = 1;
        } else {
            trScroll.style.backgroundColor = "#f6f6f0";
            counter = 0;
        }      
 
        var tdScrollUser = document.createElement("td");
        tdScrollUser.width = "184px";
        tdScrollUser.innerHTML += '<i>' + pushData[i].user + '<br />' + pushData[i].formattedDate + '</i>';
 
        //Create changset link
        var tdScrollChangeset = document.createElement("td");
        tdScrollChangeset.innerHTML += 
         '<a href="/rev/' + 
         pushData[i].individualChangeset.substring(0, 12) + 
         '">' + 
         pushData[i].individualChangeset.substring(0, 12) + 
         '</a>';
 
        //Create buglink
        var bugInDesc = (pushData[i].desc).toLowerCase().indexOf("bug");
 
        if(bugInDesc != -1) {
          var bugLinkName = (pushData[i].desc).substring(bugInDesc, bugInDesc + 10);
          var bugNumber = bugLinkName.substring(4, 10);
          var bugLink = 
           (pushData[i].desc).substring(0, bugInDesc) + 
           '<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=' + 
           bugNumber + 
           '">' + 
           bugLinkName + 
           '</a>' + 
           (pushData[i].desc).substring(bugInDesc + 10, (pushData[i].desc).length);
        } else { //No bug provided
            var bugLink = pushData[i].desc;
        }
        var tdScrollAuthorDesc = document.createElement("td");
        tdScrollAuthorDesc.innerHTML += '<b>' + pushData[i].author + ' — ' + bugLink + '</b>';
 
        trScroll.appendChild(tdScrollUser);
        trScroll.appendChild(tdScrollChangeset);
        trScroll.appendChild(tdScrollAuthorDesc);
 
        loader.innerHTML = "";
        document.getElementById("titlePush").appendChild(trScroll);
 
        //Check whether it is a merge changeset or not
        if(pushData[i].MergeData != []) {
          for(var j = 0; j < pushData[i].mergeData.length; j++) {
            if(pushData[i].mergeData[j] != "") {
              var mergeStr = pushData[i].mergeData[j];
              for(var k = 0; k < pushData[i].mergeData[j].length; k++) {
                var actualMergeStr = mergeStr[k].split('|-|');
 
                var mergeC = actualMergeStr[0];
                var mergeUser = actualMergeStr[1];
                var mergeDesc = actualMergeStr[2];
 
                if(mergeDesc != pushData[i].desc) {
 
                  var trScrollMerge = document.createElement("tr");
                  trScrollMerge.style.backgroundColor = trScroll.style.backgroundColor;
 
                  var tdScroll_MergeUser = document.createElement("td");
                  tdScroll_MergeUser.width = "184px";
 
                  //Create changset link
                  var tdScroll_MergeC = document.createElement("td");
                  tdScroll_MergeC.innerHTML +=
                   '<a href="/rev/' +
                   mergeC.substring(0, 12) + 
                   '">' + 
                   mergeC.substring(0, 12) +
                   '</a>';    
 
                  //Create buglink
                  var merge_bugInDesc = mergeDesc.toLowerCase().indexOf("bug");
                  if(merge_bugInDesc != -1) {
                    var merge_bugLinkName = mergeDesc.substring(merge_bugInDesc, merge_bugInDesc + 10);
                    var merge_bugNumber = merge_bugLinkName.substring(4, 10);
                    var merge_bugLink =
                    mergeDesc.substring(0, merge_bugInDesc) + 
                     '<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=' + 
                     merge_bugNumber + 
                     '">' + 
                     merge_bugLinkName + 
                     '</a>' + 
                     mergeDesc.substring(merge_bugInDesc + 10, mergeDesc.length);
                  } else { //No bug provided
                      var merge_bugLink = mergeDesc;
                  }
                  var tdScroll_MergeAuthorDesc = document.createElement("td");
                  tdScroll_MergeAuthorDesc.innerHTML += '<b>' + mergeUser + ' — ' + merge_bugLink + '</b>';
 
                  trScrollMerge.appendChild(tdScroll_MergeUser);
                  trScrollMerge.appendChild(tdScroll_MergeC);
                  trScrollMerge.appendChild(tdScroll_MergeAuthorDesc);
 
                  document.getElementById("titlePush").appendChild(trScrollMerge);
                }
              }
            }
          }
        }
 
      }    
    } 
   }
  }
  pushCheckins.send(null);
}

Everything before line 68 is for normal changesets that don’t have any merge changesets (in which case the whole section encapsulated within the if statement is skipped). Everything afterwords sets up the merge changesets.

Line 69 is a for loop that goes through pushData[i].mergeData which contains all the data for the merge changesets (changeset, user and description). Then on line 73 a split() is performed (the data is received as a string in the format: changeset|-|user|-|description) to get the values of the changeset, user and description. Instead of putting the data within a character delimited string I could have created a class but this implementation meant writing less lines of code which is almost always better.

On line 81 the row is created and the background color is set. The first column is then created (it will be empty) and the width is set to get the right alignment. Lines 87-95 the changeset link is created. Lines 97-114 the buglink is created via some cumbersome string manipulation. Lines 116-118 all three tds are added to the row and then on line 120 the row is added to the table.

The Result

The above code gives me the following result: http://sidkalra.com/files/mercurial/mergeChangsets.png

This entry was posted in 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>