@@ -95,141 +95,147 @@ - (void) updateCommits:(NSDictionary *)update
95
95
96
96
- (void ) walkRevisionListWithSpecifier : (PBGitRevSpecifier*)rev
97
97
{
98
- NSDate *start = [NSDate date ];
99
- NSDate *lastUpdate = [NSDate date ];
100
- NSMutableArray *revisions = [NSMutableArray array ];
101
- PBGitGrapher *g = [[PBGitGrapher alloc ] initWithRepository: repository];
102
- std::map<string, NSStringEncoding > encodingMap;
103
- NSThread *currentThread = [NSThread currentThread ];
104
-
105
- NSString *formatString = @" --pretty=format:%H\01 %e \01 %a N\01 %c N\01 %s \01 %P\01 %a t" ;
106
- BOOL showSign = [rev hasLeftRight ];
107
-
108
- if (showSign)
109
- formatString = [formatString stringByAppendingString: @" \01 %m" ];
110
-
111
- NSMutableArray *arguments = [NSMutableArray arrayWithObjects: @" log" , @" -z" , @" --topo-order" , @" --children" , formatString, nil ];
112
-
113
- if (!rev)
114
- [arguments addObject: @" HEAD" ];
115
- else
116
- [arguments addObjectsFromArray: [rev parameters ]];
117
-
118
- NSString *directory = rev.workingDirectory ? rev.workingDirectory .path : repository.fileURL .path ;
119
- NSTask *task = [PBEasyPipe taskForCommand: [PBGitBinary path ] withArgs: arguments inDir: directory];
120
- [task launch ];
121
- NSFileHandle *handle = [task.standardOutput fileHandleForReading ];
122
-
123
- int fd = [handle fileDescriptor ];
124
- __gnu_cxx::stdio_filebuf<char > buf (fd, std::ios::in);
125
- std::istream stream (&buf);
126
-
127
- int num = 0 ;
128
- while (true ) {
129
- if ([currentThread isCancelled ])
130
- break ;
131
-
132
- string sha;
133
- if (!getline (stream, sha, ' \1 ' ))
134
- break ;
135
-
136
- // From now on, 1.2 seconds
137
- string encoding_str;
138
- getline (stream, encoding_str, ' \1 ' );
139
- NSStringEncoding encoding = NSUTF8StringEncoding;
140
- if (encoding_str.length ())
141
- {
142
- if (encodingMap.find (encoding_str) != encodingMap.end ()) {
143
- encoding = encodingMap[encoding_str];
144
- } else {
145
- encoding = CFStringConvertEncodingToNSStringEncoding (CFStringConvertIANACharSetNameToEncoding ((__bridge CFStringRef )[NSString stringWithUTF8String: encoding_str.c_str ()]));
146
- encodingMap[encoding_str] = encoding;
147
- }
148
- }
149
-
150
- git_oid oid;
151
- git_oid_fromstr (&oid, sha.c_str ());
152
- PBGitCommit *newCommit = [PBGitCommit commitWithRepository: repository andSha: [PBGitSHA shaWithOID: oid]];
153
-
154
- string author;
155
- getline (stream, author, ' \1 ' );
156
-
157
- string committer;
158
- getline (stream, committer, ' \1 ' );
159
-
160
- string subject;
161
- getline (stream, subject, ' \1 ' );
162
-
163
- string parentString;
164
- getline (stream, parentString, ' \1 ' );
165
- if (parentString.size () != 0 )
166
- {
167
- if (((parentString.size () + 1 ) % 41 ) != 0 ) {
168
- NSLog (@" invalid parents: %zu " , parentString.size());
169
- continue ;
170
- }
171
- int nParents = (parentString.size () + 1 ) / 41 ;
172
- NSMutableArray *parents = [NSMutableArray arrayWithCapacity: nParents];
173
- int parentIndex;
174
- for (parentIndex = 0 ; parentIndex < nParents; ++parentIndex)
175
- [parents addObject: [PBGitSHA shaWithCString: parentString.substr (parentIndex * 41 , 40 ).c_str ()]];
176
-
177
- [newCommit setParents: parents];
178
- }
179
-
180
- int time ;
181
- stream >> time ;
182
-
183
- [newCommit setSubject: [NSString stringWithCString: subject.c_str () encoding: encoding]];
184
- [newCommit setAuthor: [NSString stringWithCString: author.c_str () encoding: encoding]];
185
- [newCommit setCommitter: [NSString stringWithCString: committer.c_str () encoding: encoding]];
186
- [newCommit setTimestamp: time ];
98
+ @autoreleasepool {
99
+ NSDate *start = [NSDate date ];
100
+ NSDate *lastUpdate = [NSDate date ];
101
+ NSMutableArray *revisions = [NSMutableArray array ];
102
+ PBGitGrapher *g = [[PBGitGrapher alloc ] initWithRepository: repository];
103
+ std::map<string, NSStringEncoding > encodingMap;
104
+ NSThread *currentThread = [NSThread currentThread ];
105
+
106
+ NSString *formatString = @" --pretty=format:%H\01 %e \01 %a N\01 %c N\01 %s \01 %P\01 %a t" ;
107
+ BOOL showSign = [rev hasLeftRight ];
187
108
188
109
if (showSign)
189
- {
110
+ formatString = [formatString stringByAppendingString: @" \01 %m" ];
111
+
112
+ NSMutableArray *arguments = [NSMutableArray arrayWithObjects: @" log" ,
113
+ @" -z" ,
114
+ @" --topo-order" ,
115
+ @" --children" ,
116
+ formatString, nil ];
117
+
118
+ if (!rev)
119
+ [arguments addObject: @" HEAD" ];
120
+ else
121
+ [arguments addObjectsFromArray: [rev parameters ]];
122
+
123
+ NSString *directory = rev.workingDirectory ? rev.workingDirectory .path : repository.fileURL .path ;
124
+ NSTask *task = [PBEasyPipe taskForCommand: [PBGitBinary path ] withArgs: arguments inDir: directory];
125
+ [task launch ];
126
+ NSFileHandle *handle = [task.standardOutput fileHandleForReading ];
127
+
128
+ int fd = [handle fileDescriptor ];
129
+ __gnu_cxx::stdio_filebuf<char > buf (fd, std::ios::in);
130
+ std::istream stream (&buf);
131
+
132
+ int num = 0 ;
133
+ while (true ) {
134
+ if ([currentThread isCancelled ])
135
+ break ;
136
+
137
+ string sha;
138
+ if (!getline (stream, sha, ' \1 ' ))
139
+ break ;
140
+
141
+ // From now on, 1.2 seconds
142
+ string encoding_str;
143
+ getline (stream, encoding_str, ' \1 ' );
144
+ NSStringEncoding encoding = NSUTF8StringEncoding;
145
+ if (encoding_str.length ())
146
+ {
147
+ if (encodingMap.find (encoding_str) != encodingMap.end ()) {
148
+ encoding = encodingMap[encoding_str];
149
+ } else {
150
+ encoding = CFStringConvertEncodingToNSStringEncoding (CFStringConvertIANACharSetNameToEncoding ((__bridge CFStringRef )[NSString stringWithUTF8String: encoding_str.c_str ()]));
151
+ encodingMap[encoding_str] = encoding;
152
+ }
153
+ }
154
+
155
+ git_oid oid;
156
+ git_oid_fromstr (&oid, sha.c_str ());
157
+ PBGitCommit *newCommit = [PBGitCommit commitWithRepository: repository andSha: [PBGitSHA shaWithOID: oid]];
158
+
159
+ string author;
160
+ getline (stream, author, ' \1 ' );
161
+
162
+ string committer;
163
+ getline (stream, committer, ' \1 ' );
164
+
165
+ string subject;
166
+ getline (stream, subject, ' \1 ' );
167
+
168
+ string parentString;
169
+ getline (stream, parentString, ' \1 ' );
170
+ if (parentString.size () != 0 )
171
+ {
172
+ if (((parentString.size () + 1 ) % 41 ) != 0 ) {
173
+ NSLog (@" invalid parents: %zu " , parentString.size());
174
+ continue ;
175
+ }
176
+ int nParents = (parentString.size () + 1 ) / 41 ;
177
+ NSMutableArray *parents = [NSMutableArray arrayWithCapacity: nParents];
178
+ int parentIndex;
179
+ for (parentIndex = 0 ; parentIndex < nParents; ++parentIndex)
180
+ [parents addObject: [PBGitSHA shaWithCString: parentString.substr (parentIndex * 41 , 40 ).c_str ()]];
181
+
182
+ [newCommit setParents: parents];
183
+ }
184
+
185
+ int time ;
186
+ stream >> time ;
187
+
188
+ [newCommit setSubject: [NSString stringWithCString: subject.c_str () encoding: encoding]];
189
+ [newCommit setAuthor: [NSString stringWithCString: author.c_str () encoding: encoding]];
190
+ [newCommit setCommitter: [NSString stringWithCString: committer.c_str () encoding: encoding]];
191
+ [newCommit setTimestamp: time ];
192
+
193
+ if (showSign)
194
+ {
195
+ char c;
196
+ stream >> c; // Remove separator
197
+ stream >> c;
198
+ if (c != ' >' && c != ' <' && c != ' ^' && c != ' -' )
199
+ NSLog (@" Error loading commits: sign not correct" );
200
+ [newCommit setSign: c];
201
+ }
202
+
190
203
char c;
191
- stream >> c; // Remove separator
192
204
stream >> c;
193
- if (c != ' >' && c != ' <' && c != ' ^' && c != ' -' )
194
- NSLog (@" Error loading commits: sign not correct" );
195
- [newCommit setSign: c];
196
- }
197
-
198
- char c;
199
- stream >> c;
200
- if (c != ' \0 ' )
201
- cout << " Error" << endl;
202
-
203
- [revisions addObject: newCommit];
204
- if (isGraphing)
205
- [g decorateCommit: newCommit];
206
-
207
- if (++num % 100 == 0 ) {
208
- if ([[NSDate date ] timeIntervalSinceDate: lastUpdate] > 0.1 ) {
209
- NSDictionary *update = [NSDictionary dictionaryWithObjectsAndKeys: currentThread, kRevListThreadKey , revisions, kRevListRevisionsKey , nil ];
210
- [self performSelectorOnMainThread: @selector (updateCommits: ) withObject: update waitUntilDone: NO ];
211
- revisions = [NSMutableArray array ];
212
- lastUpdate = [NSDate date ];
205
+ if (c != ' \0 ' )
206
+ cout << " Error" << endl;
207
+
208
+ [revisions addObject: newCommit];
209
+ if (isGraphing)
210
+ [g decorateCommit: newCommit];
211
+
212
+ if (++num % 100 == 0 ) {
213
+ if ([[NSDate date ] timeIntervalSinceDate: lastUpdate] > 0.1 ) {
214
+ NSDictionary *update = [NSDictionary dictionaryWithObjectsAndKeys: currentThread, kRevListThreadKey , revisions, kRevListRevisionsKey , nil ];
215
+ [self performSelectorOnMainThread: @selector (updateCommits: ) withObject: update waitUntilDone: NO ];
216
+ revisions = [NSMutableArray array ];
217
+ lastUpdate = [NSDate date ];
218
+ }
213
219
}
214
220
}
221
+
222
+ if (![currentThread isCancelled ]) {
223
+ NSTimeInterval duration = [[NSDate date ] timeIntervalSinceDate: start];
224
+ NSLog (@" Loaded %i commits in %f seconds (%f /sec)" , num, duration, num/duration);
225
+
226
+ // Make sure the commits are stored before exiting.
227
+ NSDictionary *update = [NSDictionary dictionaryWithObjectsAndKeys: currentThread, kRevListThreadKey , revisions, kRevListRevisionsKey , nil ];
228
+ [self performSelectorOnMainThread: @selector (updateCommits: ) withObject: update waitUntilDone: YES ];
229
+
230
+ [self performSelectorOnMainThread: @selector (finishedParsing ) withObject: nil waitUntilDone: NO ];
231
+ }
232
+ else {
233
+ NSLog (@" [%@ %@ ] thread has been canceled" , [self class ], NSStringFromSelector (_cmd));
234
+ }
235
+
236
+ [task terminate ];
237
+ [task waitUntilExit ];
215
238
}
216
-
217
- if (![currentThread isCancelled ]) {
218
- NSTimeInterval duration = [[NSDate date ] timeIntervalSinceDate: start];
219
- NSLog (@" Loaded %i commits in %f seconds (%f /sec)" , num, duration, num/duration);
220
-
221
- // Make sure the commits are stored before exiting.
222
- NSDictionary *update = [NSDictionary dictionaryWithObjectsAndKeys: currentThread, kRevListThreadKey , revisions, kRevListRevisionsKey , nil ];
223
- [self performSelectorOnMainThread: @selector (updateCommits: ) withObject: update waitUntilDone: YES ];
224
-
225
- [self performSelectorOnMainThread: @selector (finishedParsing ) withObject: nil waitUntilDone: NO ];
226
- }
227
- else {
228
- NSLog (@" [%@ %@ ] thread has been canceled" , [self class ], NSStringFromSelector (_cmd));
229
- }
230
-
231
- [task terminate ];
232
- [task waitUntilExit ];
233
239
}
234
240
235
241
@end
0 commit comments