1
1
var commit ;
2
2
var Commit = function ( obj ) {
3
- this . raw = obj . details ;
4
- this . refs = obj . refs ;
5
3
this . object = obj ;
6
4
7
- var diffStart = this . raw . indexOf ( "\ndiff " ) ;
8
- var messageStart = this . raw . indexOf ( "\n\n" ) + 2 ;
5
+ this . refs = obj . refs ;
6
+ this . author_name = obj . author ;
7
+ this . sha = obj . sha ;
8
+ this . parents = obj . parents ;
9
+ this . subject = obj . subject ;
9
10
10
- if ( diffStart > 0 ) {
11
- this . message = this . raw . substring ( messageStart , diffStart ) . replace ( / ^ / gm, "" ) . escapeHTML ( ) ;
12
- this . diff = this . raw . substring ( diffStart ) ;
13
- } else {
14
- this . message = this . raw . substring ( messageStart ) . replace ( / ^ / gm, "" ) . escapeHTML ( ) ;
15
- this . diff = "" ;
16
- }
17
- this . header = this . raw . substring ( 0 , messageStart ) ;
11
+ // TODO:
12
+ // this.author_date instant
18
13
19
- this . sha = this . header . match ( / ^ c o m m i t ( [ 0 - 9 a - f ] { 40 , 40 } ) / ) [ 1 ] ;
14
+ // This all needs to be async
15
+ this . loadedRaw = function ( details ) {
16
+ this . raw = details ;
20
17
21
- var match = this . header . match ( / \n a u t h o r ( .* ) < ( .* @ .* ) > ( [ 0 - 9 ] .* ) / ) ;
22
- this . author_name = match [ 1 ] ;
23
- if ( ! ( match [ 2 ] . match ( / @ [ a - f 0 - 9 ] { 8 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 12 } / ) ) )
24
- this . author_email = match [ 2 ] ;
18
+ var diffStart = this . raw . indexOf ( "\ndiff " ) ;
19
+ var messageStart = this . raw . indexOf ( "\n\n" ) + 2 ;
25
20
26
- this . author_date = new Date ( parseInt ( match [ 3 ] ) * 1000 ) ;
21
+ if ( diffStart > 0 ) {
22
+ this . message = this . raw . substring ( messageStart , diffStart ) . replace ( / ^ / gm, "" ) . escapeHTML ( ) ;
23
+ this . diff = this . raw . substring ( diffStart ) ;
24
+ } else {
25
+ this . message = this . raw . substring ( messageStart ) . replace ( / ^ / gm, "" ) . escapeHTML ( ) ;
26
+ this . diff = "" ;
27
+ }
28
+ this . header = this . raw . substring ( 0 , messageStart ) ;
27
29
28
- match = this . header . match ( / \n c o m m i t t e r ( .* ) < ( .* @ .* ) > ( [ 0 - 9 ] .* ) / ) ;
29
- this . committer_name = match [ 1 ] ;
30
- this . committer_email = match [ 2 ] ;
31
- this . committer_date = new Date ( parseInt ( match [ 3 ] ) * 1000 ) ;
30
+ var match = this . header . match ( / \n a u t h o r ( .* ) < ( .* @ .* ) > ( [ 0 - 9 ] .* ) / ) ;
31
+ if ( ! ( match [ 2 ] . match ( / @ [ a - f 0 - 9 ] { 8 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 12 } / ) ) )
32
+ this . author_email = match [ 2 ] ;
32
33
33
- this . parents = obj . parents ;
34
+ this . author_date = new Date ( parseInt ( match [ 3 ] ) * 1000 ) ;
35
+
36
+ match = this . header . match ( / \n c o m m i t t e r ( .* ) < ( .* @ .* ) > ( [ 0 - 9 ] .* ) / ) ;
37
+ this . committer_name = match [ 1 ] ;
38
+ this . committer_email = match [ 2 ] ;
39
+ this . committer_date = new Date ( parseInt ( match [ 3 ] ) * 1000 ) ;
40
+ }
34
41
35
42
this . reloadRefs = function ( ) {
36
43
this . refs = CommitObject . refs ;
37
44
}
45
+
46
+ // this.loadedRaw(this.raw);
38
47
} ;
39
48
40
49
var gistie = function ( ) {
@@ -118,56 +127,67 @@ var reload = function() {
118
127
showRefs ( ) ;
119
128
}
120
129
121
- var showRefs = function ( ) {
130
+ var showRefs = function ( currentRef ) {
122
131
var refs = $ ( "refs" ) ;
123
132
if ( commit . refs ) {
124
133
refs . parentNode . style . display = "" ;
125
134
refs . innerHTML = "" ;
126
135
for ( var i = 0 ; i < commit . refs . length ; i ++ ) {
127
136
var ref = commit . refs [ i ] , curBranch = "" ;
128
- refs . innerHTML += '<span class="refs ' + ref . type ( ) + ( CurrentBranch == ref . ref ? ' currentBranch' : '' ) + '">' + ref . shortName ( ) + '</span>' ;
137
+ refs . innerHTML += '<span class="refs ' + ref . type ( ) + ( currentRef == ref . ref ? ' currentBranch' : '' ) + '">' + ref . shortName ( ) + '</span>' ;
129
138
}
130
139
} else
131
140
refs . parentNode . style . display = "none" ;
132
141
}
133
142
134
- var loadCommit = function ( ) {
135
- commit = new Commit ( CommitObject ) ;
136
- $ ( "notification" ) . style . display = "none" ;
143
+ var loadCommit = function ( commitObject , currentRef ) {
144
+ // These are only the things we can do instantly.
145
+ // Other information will be loaded later by loadExtendedCommit
146
+ commit = new Commit ( commitObject ) ;
147
+ Controller . callSelector_onObject_callBack_ ( "details" , commitObject ,
148
+ function ( data ) { commit . loadedRaw ( data ) ; loadExtendedCommit ( commit ) ; } ) ;
149
+ commit . currentRef = currentRef ;
137
150
138
- $ ( "commitID" ) . innerHTML = commit . sha ;
139
-
140
- if ( commit . author_email )
141
- $ ( "authorID" ) . innerHTML = commit . author_name + " <<a href='mailto:" + commit . author_email + "'>" + commit . author_email + "</a>>" ;
142
- else
143
- $ ( "authorID" ) . innerHTML = commit . author_name ;
151
+ notify ( "Loading commit…" , 0 ) ;
144
152
145
- $ ( "date" ) . innerHTML = commit . author_date ;
146
- $ ( "subjectID" ) . innerHTML = CommitObject . subject . escapeHTML ( ) ;
153
+ $ ( "commitID" ) . innerHTML = commit . sha ;
154
+ $ ( "authorID" ) . innerHTML = commit . author_name ;
155
+ $ ( "subjectID" ) . innerHTML = commit . subject . escapeHTML ( ) ;
156
+ $ ( "details" ) . innerHTML = ""
157
+ $ ( "message" ) . innerHTML = ""
158
+ $ ( "date" ) . innerHTML = ""
159
+ showRefs ( commit . currentRef ) ;
147
160
148
- var commitHeader = $ ( "commit_header" ) ;
149
161
for ( var i = 0 ; i < commitHeader . rows . length ; i ++ ) {
150
- var row = commitHeader . rows [ i ] ;
162
+ var row = $ ( "commit_header" ) . rows [ i ] ;
151
163
if ( row . innerHTML . match ( / P a r e n t : / ) )
152
164
row . parentNode . removeChild ( row ) ;
153
165
}
154
166
155
167
for ( var i = 0 ; i < commit . parents ; i ++ ) {
156
- var parent = commit . parents [ i ] , newRow = commitHeader . insertRow ( - 1 ) ;
157
- new_row . innerHTML = "<td class='property_name'>Parent:</td><td><a href='' onclick=\"selectCommit(this.innerHTML); return false;\">" + parent + "</a></td>" ;
168
+ var newRow = $ ( "commit_header" ) . insertRow ( - 1 ) ;
169
+ new_row . innerHTML = "<td class='property_name'>Parent:</td><td>" +
170
+ "<a href='' onclick='selectCommit(this.innerHTML); return false;'>" +
171
+ commit . parents [ i ] + "</a></td>" ;
158
172
}
159
173
160
- showRefs ( ) ;
174
+ // Scroll to top
175
+ scroll ( 0 , 0 ) ;
176
+ }
177
+
178
+ var loadExtendedCommit = function ( commit )
179
+ {
180
+ if ( commit . author_email )
181
+ $ ( "authorID" ) . innerHTML = commit . author_name + " <<a href='mailto:" + commit . author_email + "'>" + commit . author_email + "</a>>" ;
161
182
183
+ $ ( "date" ) . innerHTML = commit . author_date ;
162
184
$ ( "message" ) . innerHTML = commit . message . replace ( / \n / g, "<br>" ) ;
163
185
164
186
if ( commit . diff . length < 200000 ) {
165
187
showDiffs ( ) ;
166
188
} else {
167
189
$ ( "details" ) . innerHTML = "<a class='showdiff' href='' onclick='showDiffs(); return false;'>This is a large commit. Click here or press 'v' to view.</a>" ;
168
190
}
169
-
191
+ hideNotification ( ) ;
170
192
setGravatar ( commit . author_email , $ ( "gravatar" ) ) ;
171
-
172
- scroll ( 0 , 0 ) ;
173
- }
193
+ }
0 commit comments