Skip to content

Commit 42304da

Browse files
committed
Display file list at the top of the diff window.
1 parent 24d05af commit 42304da

File tree

7 files changed

+118
-106
lines changed

7 files changed

+118
-106
lines changed

GLFileView.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ + (NSString *)parseDiff:(NSString *)txt
317317
[res appendString:[GLFileView parseDiffBlock:[NSString stringWithFormat:@"diff --%@",block]]];
318318
}
319319

320-
return res;
320+
return [NSString stringWithFormat:@"<div id='diffs'>%@</div>",res];
321321
}
322322

323323
+ (NSString *)parseDiffBlock:(NSString *)txt

PBDiffWindowController.m

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#import "PBGitCommit.h"
1212
#import "PBGitDefaults.h"
1313
#import "GLFileView.h"
14+
#import "PBWebCommitController.h"
1415

1516

1617
@implementation PBDiffWindowController
@@ -36,28 +37,45 @@ + (void) showDiffWindowWithFiles:(NSArray *)filePaths fromCommit:(PBGitCommit *)
3637
diffCommit = [startCommit.repository headCommit];
3738

3839
NSString *commitSelector = [NSString stringWithFormat:@"%@..%@", [startCommit realSha], [diffCommit realSha]];
39-
NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"diff", @"--no-ext-diff", commitSelector, nil];
40+
NSMutableArray *args = [NSMutableArray arrayWithObjects:@"diff", @"--no-ext-diff", commitSelector, nil];
4041

4142
if (![PBGitDefaults showWhitespaceDifferences])
42-
[arguments insertObject:@"-w" atIndex:1];
43+
[args insertObject:@"-w" atIndex:1];
4344

4445
if (filePaths) {
45-
[arguments addObject:@"--"];
46-
[arguments addObjectsFromArray:filePaths];
46+
[args addObject:@"--"];
47+
[args addObjectsFromArray:filePaths];
4748
}
4849

4950
int retValue;
50-
NSString *diff = [startCommit.repository outputInWorkdirForArguments:arguments retValue:&retValue];
51+
NSString *diff = [startCommit.repository outputInWorkdirForArguments:args retValue:&retValue];
5152
if (retValue) {
52-
DLog(@"diff failed with retValue: %d for command: '%@' output: '%@'", retValue, [arguments componentsJoinedByString:@" "], diff);
53+
DLog(@"diff failed with retValue: %d for command: '%@' output: '%@'", retValue, [args componentsJoinedByString:@" "], diff);
5354
return;
5455
}
5556

56-
diff=[GLFileView parseDiff:diff];
57-
diff=[diff stringByReplacingOccurrencesOfString:@"{SHA_PREV}" withString:[startCommit realSha]];
58-
diff=[diff stringByReplacingOccurrencesOfString:@"{SHA}" withString:[diffCommit realSha]];
57+
// File Stats
58+
args = [NSMutableArray arrayWithObjects:@"show", @"--numstat", @"--summary", @"--pretty=raw", [startCommit realSha], [diffCommit realSha], nil];
59+
if (![PBGitDefaults showWhitespaceDifferences])
60+
[args insertObject:@"-w" atIndex:1];
61+
NSString *details = [startCommit.repository outputInWorkdirForArguments:args];
62+
NSMutableDictionary *stats = [PBWebCommitController parseStats:details];
63+
64+
// File list
65+
args = [NSMutableArray arrayWithObjects:@"diff-tree", @"--root", @"-r", @"-C90%", @"-M90%", nil];
66+
[args addObject:[startCommit realSha]];
67+
[args addObject:[diffCommit realSha]];
68+
NSString *dt = [startCommit.repository outputInWorkdirForArguments:args];
69+
NSString *fileList = [GLFileView parseDiffTree:dt withStats:stats];
70+
71+
// Hunk list
72+
NSString *hunks = [GLFileView parseDiff:diff];
73+
hunks=[hunks stringByReplacingOccurrencesOfString:@"{SHA_PREV}" withString:[startCommit realSha]];
74+
hunks=[hunks stringByReplacingOccurrencesOfString:@"{SHA}" withString:[diffCommit realSha]];
5975

60-
PBDiffWindowController *diffController = [[PBDiffWindowController alloc] initWithDiff:diff];
76+
NSString *html = [NSString stringWithFormat:@"%@%@",fileList,hunks];
77+
78+
PBDiffWindowController *diffController = [[PBDiffWindowController alloc] initWithDiff:html];
6179
[diffController showWindow:nil];
6280
}
6381

PBWebCommitController.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
- (void) openFileMerge:(NSString*)file sha:(NSString *)sha sha2:(NSString *)sha2;
2828
- (void) showLongDiff;
2929

30+
+ (NSArray *)parseHeader:(NSString *)text;
31+
+ (NSMutableDictionary *)parseStats:(NSString *)txt;
32+
3033
- (void) didLoad;
3134
// Called when a commit or parent link is clicked.
3235
- (void)selectCommit:(NSString *)sha;

PBWebCommitController.m

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313
@interface PBWebCommitController (Private)
1414

15-
- (NSArray *)parseHeader:(NSString *)text;
1615
- (NSString *)htmlForHeader:(NSArray *)header withRefs:(NSString *)badges;
17-
- (NSMutableDictionary *)parseStats:(NSString *)txt;
1816
- (NSString *) arbitraryHashForString:(NSString*)concat;
1917

2018
@end
@@ -96,7 +94,7 @@ - (void)commitDetailsLoaded:(NSNotification *)notification
9694
return;
9795

9896
// Header
99-
NSArray *headerItems = [self parseHeader:details];
97+
NSArray *headerItems = [PBWebCommitController parseHeader:details];
10098
NSString *header = [self htmlForHeader:headerItems withRefs:[self refsForCurrentCommit]];
10199

102100
// In case the commit is a merge, we need to explicity give diff-tree the
@@ -111,7 +109,7 @@ - (void)commitDetailsLoaded:(NSNotification *)notification
111109
NSArray *parents = [self chooseDiffParents:allParents];
112110

113111
// File Stats
114-
NSMutableDictionary *stats = [self parseStats:details];
112+
NSMutableDictionary *stats = [PBWebCommitController parseStats:details];
115113

116114
// File list
117115
NSMutableArray *args = [NSMutableArray arrayWithObjects:@"diff-tree", @"--root", @"-r", @"-C90%", @"-M90%", nil];
@@ -132,7 +130,7 @@ - (void)commitDetailsLoaded:(NSNotification *)notification
132130
{
133131
showLongDiffs = FALSE;
134132
NSString *diffs = [GLFileView parseDiff:d];
135-
html = [NSString stringWithFormat:@"%@%@<div id='diffs'>%@</div>",header,fileList,diffs];
133+
html = [NSString stringWithFormat:@"%@%@%@",header,fileList,diffs];
136134
} else {
137135
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];
138136
}
@@ -165,7 +163,7 @@ - (NSArray*) chooseDiffParents:(NSArray *)parents
165163
return parents;
166164
}
167165

168-
- (NSMutableDictionary *)parseStats:(NSString *)txt
166+
+ (NSMutableDictionary *)parseStats:(NSString *)txt
169167
{
170168
NSArray *lines = [txt componentsSeparatedByString:@"\n"];
171169
NSMutableDictionary *stats=[NSMutableDictionary dictionary];
@@ -183,7 +181,7 @@ - (NSMutableDictionary *)parseStats:(NSString *)txt
183181
return stats;
184182
}
185183

186-
- (NSArray *)parseHeader:(NSString *)text
184+
+ (NSArray *)parseHeader:(NSString *)text
187185
{
188186
NSMutableArray *result = [NSMutableArray array];
189187
NSArray *lines = [text componentsSeparatedByString:@"\n"];

html/views/diff/diffWindow.css

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1+
body {
2+
margin: 0;
3+
padding: 0;
4+
}
5+
6+
#diffs {
7+
width: 100%;
8+
display: block;
9+
overflow: auto;
10+
}
11+
12+
#diff {
13+
display: block;
14+
overflow: auto;
15+
}
16+
117
table.diff {
218
font-family: Menlo, Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;
319
border: 1px solid #8f8f8f;
4-
width: 100%;
520
border-collapse: collapse;
6-
margin-bottom: 10px;
7-
-webkit-box-shadow: 5px 5px 5px #ccc;
21+
-webkit-box-shadow:3px 3px 3px #ccc;
22+
width: 98%;
23+
margin: auto auto 20px 1%;
824
}
925

1026
table.diff tr td {
@@ -65,13 +81,69 @@ table.diff .filemerge {
6581
text-align: center;
6682
}
6783

68-
#diff {
84+
#filelist {
85+
font-size: 13px;
86+
white-space: nowrap;
6987
width: 100%;
88+
padding: 0 20px;
89+
border-collapse: collapse;
90+
margin-bottom: 10px;
91+
}
92+
93+
#filelist tr td {
94+
border-bottom: 1px solid #ccc;
95+
border-top: 1px solid #ccc;
96+
}
97+
98+
#filelist a {
99+
margin-left: 10px;
100+
padding-left: 20px;
101+
text-decoration: none;
102+
}
103+
104+
#filelist a:hover {
105+
text-decoration: underline;
106+
}
107+
108+
#filelist a.A {
109+
background: url(../../images/added.png) no-repeat 0 center;
110+
}
111+
112+
#filelist a.D {
113+
background: url(../../images/removed.png) no-repeat 0 center;
114+
}
115+
116+
#filelist a.M {
117+
background: url(../../images/modified.png) no-repeat 0 center;
118+
}
119+
120+
#filelist a.R,#filelist a.C {
121+
background: url(../../images/renamed.png) no-repeat 0 center;
122+
}
123+
124+
#filelist span.add,#filelist span.rem {
70125
display: block;
71-
overflow: auto;
126+
height: 10px;
127+
border-top-left-radius: 5px;
128+
border-bottom-left-radius: 5px;
129+
float: right;
130+
clear: both;
72131
}
73132

74-
#diff table.diff {
75-
width: 98%;
76-
margin: auto auto 20px 1%;
133+
#filelist span.add {
134+
background-color: rgba(0, 255, 0, 0.199219);
135+
}
136+
137+
#filelist span.rem {
138+
background-color: rgba(255, 0, 0, 0.199219);
139+
}
140+
141+
#filelist td.bar {
142+
width: 50%;
143+
display: block;
144+
}
145+
146+
#filelist td.add,#filelist td.rem {
147+
width: 1%;
148+
text-align: right;
77149
}

html/views/diff/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<script src="../../lib/keyboardNavigation.js"></script>
77
<script src="diffWindow.js"></script>
88

9+
<link rel="stylesheet" href="../../css/GitX.css">
910
<link rel="stylesheet" href="diffWindow.css">
10-
<link rel="stylesheet" href="../../css/GitX.css">
1111
</head>
1212

1313
<body>

html/views/history/history.css

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -193,72 +193,6 @@ a.showdiff {
193193
background-color: #fca64f;
194194
}
195195

196-
#filelist {
197-
font-size: 13px;
198-
white-space: nowrap;
199-
width: 100%;
200-
padding: 10px 20px;
201-
border-collapse: collapse;
202-
}
203-
204-
#filelist tr td {
205-
border-bottom: 1px solid #ccc;
206-
border-top: 1px solid #ccc;
207-
}
208-
209-
#filelist a {
210-
margin-left: 10px;
211-
padding-left: 20px;
212-
text-decoration: none;
213-
}
214-
215-
#filelist a:hover {
216-
text-decoration: underline;
217-
}
218-
219-
#filelist a.A {
220-
background: url(../../images/added.png) no-repeat 0 center;
221-
}
222-
223-
#filelist a.D {
224-
background: url(../../images/removed.png) no-repeat 0 center;
225-
}
226-
227-
#filelist a.M {
228-
background: url(../../images/modified.png) no-repeat 0 center;
229-
}
230-
231-
#filelist a.R,#filelist a.C {
232-
background: url(../../images/renamed.png) no-repeat 0 center;
233-
}
234-
235-
#filelist span.add,#filelist span.rem {
236-
display: block;
237-
height: 10px;
238-
border-top-left-radius: 5px;
239-
border-bottom-left-radius: 5px;
240-
float: right;
241-
clear: both;
242-
}
243-
244-
#filelist span.add {
245-
background-color: rgba(0, 255, 0, 0.199219);
246-
}
247-
248-
#filelist span.rem {
249-
background-color: rgba(255, 0, 0, 0.199219);
250-
}
251-
252-
#filelist td.bar {
253-
width: 50%;
254-
display: block;
255-
}
256-
257-
#filelist td.add,#filelist td.rem {
258-
width: 1%;
259-
text-align: right;
260-
}
261-
262196
#header {
263197
font-size: 13px;
264198
background-image: -webkit-gradient(linear,left top,left bottom, color-stop(.7, #EAF2f6), color-stop(1, #e3ebf3));
@@ -318,19 +252,6 @@ a.showdiff {
318252
padding-bottom: 5px;
319253
}
320254

321-
#diffs {
322-
width: 100%;
323-
display: block;
324-
padding-top: 10px;
325-
overflow: auto;
326-
}
327-
328-
#diffs table.diff {
329-
-webkit-box-shadow:3px 3px 3px #ccc;
330-
width: 98%;
331-
margin: auto auto 20px 1%;
332-
}
333-
334255
.filemerge {
335256
float: right;
336257
text-align: center;

0 commit comments

Comments
 (0)