@@ -115,73 +115,100 @@ - (NSString*) contents
115
115
return [repository outputForArguments: [NSArray arrayWithObjects: @" show" , [self refSpec ], nil ]];
116
116
}
117
117
118
- - (NSString *) blame
118
+ - (NSString *) blame : ( NSError **) anError
119
119
{
120
+ NSString *error=nil ;
121
+ NSString *res=nil ;
120
122
if (!leaf)
121
- return [NSString stringWithFormat: @" This is a tree with path %@ " , [self fullPath ]];
123
+ error= [NSString stringWithFormat: @" This is a tree with path %@ " , [self fullPath ]];
122
124
123
125
if ([self hasBinaryAttributes ])
124
- return [NSString stringWithFormat: @" %@ appears to be a binary file of %d bytes" , [self fullPath ], [self fileSize ]];
126
+ error= [NSString stringWithFormat: @" %@ appears to be a binary file of %d bytes" , [self fullPath ], [self fileSize ]];
125
127
126
128
if ([self fileSize ] > 52428800 ) // ~50MB
127
- return [NSString stringWithFormat: @" %@ is too big to be displayed (%d bytes)" , [self fullPath ], [self fileSize ]];
129
+ error= [NSString stringWithFormat: @" %@ is too big to be displayed (%d bytes)" , [self fullPath ], [self fileSize ]];
128
130
129
- NSString *contents=[repository outputInWorkdirForArguments: [NSArray arrayWithObjects: @" blame" , @" -p" , sha, @" --" , [self fullPath ], nil ]];
131
+ if (error==nil ){
132
+ res=[repository outputInWorkdirForArguments: [NSArray arrayWithObjects: @" blame" , @" -p" , sha, @" --" , [self fullPath ], nil ]];
133
+ }else {
134
+ *anError = [NSError errorWithDomain: @" blame" code: 1 userInfo: [NSDictionary dictionaryWithObjectsAndKeys: error,NSLocalizedDescriptionKey ,nil ]];
135
+ }
130
136
131
- if ([self hasBinaryHeader: contents])
132
- return [NSString stringWithFormat: @" %@ appears to be a binary file of %d bytes" , [self fullPath ], [self fileSize ]];
137
+ return res;
138
+ }
139
+
140
+ - (NSString *) log : (NSString *)format error : (NSError **)anError
141
+ {
142
+ NSString *error=nil ;
143
+ NSString *res=nil ;
144
+ if (!leaf)
145
+ error=[NSString stringWithFormat: @" This is a tree with path %@ " , [self fullPath ]];
133
146
147
+ if (error==nil ){
148
+ res=[repository outputInWorkdirForArguments: [NSArray arrayWithObjects: @" log" , [NSString stringWithFormat: @" --pretty=format:%@ " ,format], @" --" , [self fullPath ], nil ]];
149
+ }else {
150
+ *anError = [NSError errorWithDomain: @" log" code: 1 userInfo: [NSDictionary dictionaryWithObjectsAndKeys: error,NSLocalizedDescriptionKey ,nil ]];
151
+ }
134
152
135
- return contents ;
153
+ return res ;
136
154
}
137
155
138
- - (NSString *) log : (NSString *)format
156
+ - (NSString *) diff : (NSString *)format error : ( NSError **) anError
139
157
{
158
+ NSString *error=nil ;
159
+ NSString *res=nil ;
140
160
if (!leaf)
141
- return [NSString stringWithFormat: @" This is a tree with path %@ " , [self fullPath ]];
161
+ error= [NSString stringWithFormat: @" This is a tree with path %@ " , [self fullPath ]];
142
162
143
163
if ([self hasBinaryAttributes ])
144
- return [NSString stringWithFormat: @" %@ appears to be a binary file of %d bytes" , [self fullPath ], [self fileSize ]];
164
+ error= [NSString stringWithFormat: @" %@ appears to be a binary file of %d bytes" , [self fullPath ], [self fileSize ]];
145
165
146
166
if ([self fileSize ] > 52428800 ) // ~50MB
147
- return [NSString stringWithFormat: @" %@ is too big to be displayed (%d bytes)" , [self fullPath ], [self fileSize ]];
167
+ error= [NSString stringWithFormat: @" %@ is too big to be displayed (%d bytes)" , [self fullPath ], [self fileSize ]];
148
168
149
- NSString *contents=[repository outputInWorkdirForArguments: [NSArray arrayWithObjects: @" log" , [NSString stringWithFormat: @" --pretty=format:%@ " ,format], @" --" , [self fullPath ], nil ]];
150
-
151
- if ([self hasBinaryHeader: contents])
152
- return [NSString stringWithFormat: @" %@ appears to be a binary file of %d bytes" , [self fullPath ], [self fileSize ]];
153
-
154
-
155
- return contents;
169
+ if (error==nil ){
170
+ NSString *des=@" " ;
171
+ if (format==@" p" ) {
172
+ des=[NSString stringWithFormat: @" %@ ^" ,sha];
173
+ }else if (format==@" h" ) {
174
+ des=@" HEAD" ;
175
+ }else {
176
+ des=@" --" ;
177
+ }
178
+ res=[repository outputInWorkdirForArguments: [NSArray arrayWithObjects: @" diff" , sha, des,[self fullPath ], nil ]];
179
+ if ([res length ]==0 ) {
180
+ NSLog (@" --%d " ,[res length ]);
181
+ *anError = [NSError errorWithDomain: @" diff" code: 1 userInfo: [NSDictionary dictionaryWithObjectsAndKeys: @" No Diff" ,NSLocalizedDescriptionKey ,nil ]];
182
+ }else {
183
+ NSLog (@" --%@ " ,[res substringToIndex: 80 ]);
184
+ }
185
+ }else {
186
+ *anError = [NSError errorWithDomain: @" diff" code: 1 userInfo: [NSDictionary dictionaryWithObjectsAndKeys: error,NSLocalizedDescriptionKey ,nil ]];
187
+ }
188
+
189
+ return res;
156
190
}
157
191
158
- - (NSString *) diff : ( NSString *) format
192
+ - (NSString *)textContents : ( NSError **) anError
159
193
{
194
+ NSString *error=nil ;
195
+ NSString *res=nil ;
160
196
if (!leaf)
161
- return [NSString stringWithFormat: @" This is a tree with path %@ " , [self fullPath ]];
197
+ error= [NSString stringWithFormat: @" This is a tree with path %@ " , [self fullPath ]];
162
198
163
199
if ([self hasBinaryAttributes ])
164
- return [NSString stringWithFormat: @" %@ appears to be a binary file of %d bytes" , [self fullPath ], [self fileSize ]];
200
+ error= [NSString stringWithFormat: @" %@ appears to be a binary file of %d bytes" , [self fullPath ], [self fileSize ]];
165
201
166
202
if ([self fileSize ] > 52428800 ) // ~50MB
167
- return [NSString stringWithFormat: @" %@ is too big to be displayed (%d bytes)" , [self fullPath ], [self fileSize ]];
203
+ error= [NSString stringWithFormat: @" %@ is too big to be displayed (%d bytes)" , [self fullPath ], [self fileSize ]];
168
204
169
- NSString *contents=@" " ;
170
- if (format==@" p" ) {
171
- contents=[repository outputInWorkdirForArguments: [NSArray arrayWithObjects: @" diff" , sha, [NSString stringWithFormat: @" %@ ^" ,sha],[self fullPath ], nil ]];
172
- }else if (format==@" h" ) {
173
- contents=[repository outputInWorkdirForArguments: [NSArray arrayWithObjects: @" diff" , sha, @" HEAD" ,[self fullPath ], nil ]];
174
- }else if (format==@" l" ) {
175
- contents=[repository outputInWorkdirForArguments: [NSArray arrayWithObjects: @" diff" , sha, @" --" ,[self fullPath ], nil ]];
205
+ if (error==nil ){
206
+ res = [self contents ];
207
+ }else {
208
+ *anError = [NSError errorWithDomain: @" show" code: 1 userInfo: [NSDictionary dictionaryWithObjectsAndKeys: error,NSLocalizedDescriptionKey ,nil ]];
176
209
}
177
-
178
-
179
-
180
- if ([self hasBinaryHeader: contents])
181
- return [NSString stringWithFormat: @" %@ appears to be a binary file of %d bytes" , [self fullPath ], [self fileSize ]];
182
-
183
-
184
- return contents;
210
+
211
+ return res;
185
212
}
186
213
187
214
- (long long )fileSize
@@ -200,25 +227,6 @@ - (long long)fileSize
200
227
return _fileSize;
201
228
}
202
229
203
- - (NSString *)textContents
204
- {
205
- if (!leaf)
206
- return [NSString stringWithFormat: @" This is a tree with path %@ " , [self fullPath ]];
207
-
208
- if ([self hasBinaryAttributes ])
209
- return [NSString stringWithFormat: @" %@ appears to be a binary file of %d bytes" , [self fullPath ], [self fileSize ]];
210
-
211
- if ([self fileSize ] > 52428800 ) // ~50MB
212
- return [NSString stringWithFormat: @" %@ is too big to be displayed (%d bytes)" , [self fullPath ], [self fileSize ]];
213
-
214
- NSString * contents = [self contents ];
215
-
216
- if ([self hasBinaryHeader: contents])
217
- return [NSString stringWithFormat: @" %@ appears to be a binary file of %d bytes" , [self fullPath ], [self fileSize ]];
218
-
219
- return contents;
220
- }
221
-
222
230
- (void ) saveToFolder : (NSString *) dir
223
231
{
224
232
NSString * newName = [dir stringByAppendingPathComponent: path];
0 commit comments