Skip to content

Commit 5c7e052

Browse files
committed
Merge pull request brotherbard#101 from barrywardell/master
Improvements to commit view
2 parents a33c1c8 + 03e69f8 commit 5c7e052

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

PBWebCommitController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919

2020
NSString* currentSha;
2121
NSString* diff;
22+
BOOL showLongDiffs;
2223
}
2324

2425
- (void) changeContentTo: (PBGitCommit *) content;
2526
- (void) sendKey: (NSString*) key;
2627
- (void) openFileMerge:(NSString*)file sha:(NSString *)sha sha2:(NSString *)sha2;
28+
- (void) showLongDiff;
2729

2830
- (void) didLoad;
2931
// Called when a commit or parent link is clicked.

PBWebCommitController.m

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,14 @@ @implementation PBWebCommitController
3232

3333
@synthesize diff;
3434

35+
- (void) showLongDiff
36+
{
37+
showLongDiffs = TRUE;
38+
}
39+
3540
- (void) awakeFromNib
3641
{
42+
showLongDiffs = FALSE;
3743
startFile = @"history";
3844
[super awakeFromNib];
3945
}
@@ -118,10 +124,16 @@ - (void)commitDetailsLoaded:(NSNotification *)notification
118124
[args addObjectsFromArray:parents];
119125
[args addObject:currentSha];
120126
NSString *d = [repository outputInWorkdirForArguments:args];
121-
NSString *diffs = [GLFileView parseDiff:d];
122-
123-
NSString *html = [NSString stringWithFormat:@"%@%@<div id='diffs'>%@</div>",header,fileList,diffs];
124-
127+
NSString *html;
128+
if(showLongDiffs || [d length] < 200000)
129+
{
130+
showLongDiffs = FALSE;
131+
NSString *diffs = [GLFileView parseDiff:d];
132+
html = [NSString stringWithFormat:@"%@%@<div id='diffs'>%@</div>",header,fileList,diffs];
133+
} else {
134+
html = [NSString stringWithFormat:@"%@%@<div id='diffs'><p>This is a very large commit. It may take a long time to load the diff. Click <a href='' onclick='showFullDiff(); return false;'>here</a> to show anyway.</p></div>",header,fileList,currentSha];
135+
}
136+
125137
html = [html stringByReplacingOccurrencesOfString:@"{SHA_PREV}" withString:[NSString stringWithFormat:@"%@^",currentSha]];
126138
html = [html stringByReplacingOccurrencesOfString:@"{SHA}" withString:currentSha];
127139

@@ -216,13 +228,20 @@ - (NSArray *)parseHeader:(NSString *)text
216228
- (NSString *)htmlForHeader:(NSArray *)header withRefs:(NSString *)badges
217229
{
218230
NSString *last_mail = @"";
231+
NSMutableString *subjectFirst = [NSMutableString string];
219232
NSMutableString *auths=[NSMutableString string];
220233
NSMutableString *refs=[NSMutableString string];
221234
NSMutableString *subject=[NSMutableString string];
235+
NSMutableString *all=[NSMutableString string];
222236

223237
for (NSDictionary *item in header) {
224238
if ([[item objectForKey:kHeaderKeyName] isEqualToString:@"subject"]) {
225-
[subject appendString:[NSString stringWithFormat:@"%@<br/>",[GLFileView escapeHTML:[item objectForKey:kHeaderKeyContent]]]];
239+
if ([subjectFirst isEqualToString:@""]) {
240+
[subjectFirst appendString:[NSString stringWithFormat:@"%@",[GLFileView escapeHTML:[item objectForKey:kHeaderKeyContent]]]];
241+
} else {
242+
[subject appendString:[NSString stringWithFormat:@"%@<br/>",[GLFileView escapeHTML:[item objectForKey:kHeaderKeyContent]]]];
243+
}
244+
226245
}else{
227246
if([[item objectForKey:kHeaderKeyContent] isKindOfClass:[NSString class]]){
228247
[refs appendString:[NSString stringWithFormat:@"<tr><td>%@</td><td><a href='' onclick='selectCommit(this.innerHTML); return false;'>%@</a></td></tr>",[item objectForKey:kHeaderKeyName],[item objectForKey:kHeaderKeyContent]]];
@@ -251,7 +270,17 @@ - (NSString *)htmlForHeader:(NSArray *)header withRefs:(NSString *)badges
251270
}
252271
}
253272

254-
return [NSString stringWithFormat:@"<div id='header' class='clearfix'><table class='references'>%@</table><p class='subject'>%@</p>%@<div id='badges'>%@</div></div>",refs,subject,auths,badges];
273+
[all appendString:[NSString stringWithFormat:@"<div id='header' class='clearfix'><table class='references'>%@</table><p class='subject'>%@</p>%@",refs,subjectFirst,auths]];
274+
275+
if (![badges isEqualToString:@""])
276+
[all appendString:[NSString stringWithFormat:@"<div id='badges'>%@</div>",badges]];
277+
278+
[all appendString:@"</div>"];
279+
280+
if (![subject isEqualToString:@""])
281+
[all appendString:[NSString stringWithFormat:@"<p class='subjectDetail'>%@</p>",subject]];
282+
283+
return all;
255284
}
256285

257286
- (NSString *) arbitraryHashForString:(NSString*)concat {

html/views/history/history.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ a.servicebutton {
102102
font-size: 13px;
103103
padding: 5px;
104104
float: none;
105+
font-weight: bold;
106+
}
107+
108+
p.subjectDetail {
109+
padding: 5px;
105110
}
106111

107112
#files {
@@ -198,6 +203,7 @@ a.showdiff {
198203

199204
#filelist tr td {
200205
border-bottom: 1px solid #ccc;
206+
border-top: 1px solid #ccc;
201207
}
202208

203209
#filelist a {
@@ -308,7 +314,6 @@ a.showdiff {
308314
}
309315

310316
#diffs {
311-
-webkit-box-shadow: inset 0px 5px 5px #ccc;
312317
width: 100%;
313318
display: block;
314319
padding-top: 10px;

html/views/history/history.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ var showCommit = function(data){
2121
$("commit").innerHTML=data;
2222
}
2323

24+
var showFullDiff = function() {
25+
Controller.showLongDiff();
26+
Controller.updateView();
27+
}

0 commit comments

Comments
 (0)