sync
[gitlive] / old_seed_version / Scm / Git / Event.js
1 var XObject = imports.XObject.XObject;
2
3
4 Event = XObject.define( 
5     function (cfg) {
6         // do nothing?? universal ctr ?
7         XObject.extend(this,cfg);
8         if (this.commit.length) {
9             this.parseCommit();
10         }
11         //print(JSON.stringify(this, null,4)); Seed.quit();
12     },
13     Object,
14     {
15         
16          
17         
18         repo : false,
19         /** Revision or changeset identifier for this particular file */
20         rev : false,
21     
22         /** commit message associated with this revision */
23         changelog : false,
24     
25         /** who committed this revision */
26         changeby : false,
27     
28         /** when this revision was committed */
29         ctime : false,
30     
31         /** files affected in this event; may be null, but otherwise
32         * will be an array of MTrackSCMFileEvent */
33         files : false,
34     
35         commit : false,
36         
37         
38         
39         
40         parseCommit  : function()
41         {
42             
43             var ent = this;
44             
45             this.branches    = []; // FIXME
46             this.tags        = []; // FIXME
47             this.files       = {};
48         
49          
50              
51             var lines = this.commit.split("\n");
52             
53             // print ('--->'+ lines.join("\n"));
54
55             var line = lines.shift();
56             if (!line.match(/^commit\s+(\S+)/)) {
57                 throw "Invalid commit line";
58             }
59             this.rev = line.replace(/^commit\s+/,'');
60             
61             while (lines.length) {
62                 line = lines.shift();
63                 if (!line.length) {
64                     break; //  empty line = STOP?
65                 }
66                 if (line.match(/^(\S+):\s+(.*)\s*/)) {
67                     var k,v
68                     line.replace(/^(\S+):\s+(.*)\s*/, function(m,ma,mb) {
69                         k = ma;
70                         v = mb;
71                     }) 
72                    
73                     switch (k) {
74                         case 'Author':
75                           this.changeby = v;
76                           break;
77                         
78                         case 'Date':
79                           //var ts = strtotime(v);
80                           
81                             var Date = imports.Date.Date;
82                             //var pd = imports.Date.Date.pqqqarseDate;
83                             this.changed_raw =  v;
84                             this.changed  =  Date.parseDate(v, "Y-m-d h:i:s O");
85                             this.cday = this.changed.format("Y-m-d");
86                             this.ctime  = this.changed.format("H:i:s");
87                           break;
88                     }
89                 }1
90             }
91         
92             this.changelog = "";
93         
94             if (lines[0] == '') {
95                 lines.shift();
96             }
97         
98             while ( lines.length ) {
99                 line = lines.shift();
100                 if (!line.match(/^    /)) { 
101                     lines.unshift( line );
102                     break;
103                 }
104                 line = line.substring( 4);
105                 this.changelog += line + "\n";
106             }
107         
108             if (lines[0] == '') {
109                 lines.shift();
110             }
111             var info;
112             
113             
114             // this should only be the last set of lines..
115             lines.forEach(function(line) { 
116                 if (!line.length) {
117                     return;
118                 }
119                   
120                 if (line.match(/^:/)) {
121                     // it's our stat line..:
122                     // :100755 100755 fde93abd1a71accd3aa7e97b29c1eecfb43095d7 
123                     // 3d71edf6512035846d8164c3b28818de0062335a M      web/MTrackWeb/DataObjects/Changes.php
124                     var lr = line.split(/\t/);
125                     var info = lr[0].substring(1).split(/\s+/);
126                     
127                       
128                    // print_r(info);
129                     var f = {}; //new MTrackSCMFileEvent; //generic..
130                    
131                     f.oldperm = info.shift();
132                     f.newperm = info.shift();
133                     f.oldver  = info.shift();
134                     f.newver  = info.shift();;
135                     f.status  = info.shift();
136                     f.name = lr[1]; // not the right way to do this!!! - does not handle names correclty.
137                     ent.files[f.name] = f;
138                      
139                     return;
140                 }
141              
142                 var info = line.substring(1).split(/\t/); // 3 only..
143                 //print_r(info);
144                 var added = info.shift();
145                 var removed = info.shift();
146                 
147                 var name = info.join("\t");
148                 
149                 ent.files[name] = XObject.extend(
150                     typeof(ent.files[name]) == 'undefined' ? {}  : ent.files[name],
151                     {
152                          added   : added,
153                          removed : removed
154                     }
155                 );                
156             });
157             // fixme..
158             if (!this.branches.length) {
159                 this.branches.push(  'master' );
160             }
161         
162          }
163     }
164 );
165
166