@@ -42,17 +42,7 @@ - (void)readStagedFiles:(NSNotification *)notification;
4242
4343@end
4444
45- @interface PBGitIndex () {
46-
47- @private
48- __weak PBGitRepository *repository;
49- NSURL *workingDirectory;
50- NSMutableArray *files;
51-
52- NSUInteger refreshStatus;
53- NSDictionary *amendEnvironment;
54- BOOL amend;
55- }
45+ @interface PBGitIndex ()
5646
5747// Returns the tree to compare the index to, based
5848// on whether amend is set or not.
@@ -62,11 +52,16 @@ - (void)postCommitFailure:(NSString *)reason;
6252- (void )postCommitHookFailure : (NSString *)reason ;
6353- (void )postIndexChange ;
6454- (void )postOperationFailed : (NSString *)description ;
55+
56+ @property (retain ) NSDictionary *amendEnvironment;
57+ @property (retain ) NSMutableArray *files;
58+ @property (assign ) NSUInteger refreshStatus;
59+
6560@end
6661
6762@implementation PBGitIndex
6863
69- @synthesize repository=repository; /* WIP: Switch to automatic synthesize */
64+ @synthesize amend=_amend;
7065
7166- (id )initWithRepository : (PBGitRepository *)theRepository
7267{
@@ -75,26 +70,25 @@ - (id)initWithRepository:(PBGitRepository *)theRepository
7570
7671 NSAssert (theRepository, @" PBGitIndex requires a repository" );
7772
78- repository = theRepository;
79- workingDirectory = repository.workingDirectoryURL ;
73+ _repository = theRepository;
8074
81- files = [NSMutableArray array ];
75+ _files = [NSMutableArray array ];
8276
8377 return self;
8478}
8579
8680- (NSArray *)indexChanges
8781{
88- return files;
82+ return self. files ;
8983}
9084
9185- (void )setAmend : (BOOL )newAmend
9286{
93- if (newAmend == amend )
87+ if (newAmend == _amend )
9488 return ;
9589
96- amend = newAmend;
97- amendEnvironment = nil ;
90+ _amend = newAmend;
91+ self. amendEnvironment = nil ;
9892
9993 [self refresh ];
10094
@@ -104,13 +98,13 @@ - (void)setAmend:(BOOL)newAmend
10498 // If we amend, we want to keep the author information for the previous commit
10599 // We do this by reading in the previous commit, and storing the information
106100 // in a dictionary. This dictionary will then later be read by [self commit:]
107- NSString *message = [repository outputForCommand: @" cat-file commit HEAD" ];
101+ NSString *message = [self . repository outputForCommand: @" cat-file commit HEAD" ];
108102 NSArray *match = [message substringsMatchingRegularExpression: @" \n author ([^\n ]*) <([^\n >]*)> ([0-9]+[^\n ]*)\n " count: 3 options: 0 ranges: nil error: nil ];
109103 if (match)
110- amendEnvironment = [NSDictionary dictionaryWithObjectsAndKeys: [match objectAtIndex: 1 ], @" GIT_AUTHOR_NAME" ,
111- [match objectAtIndex: 2 ], @" GIT_AUTHOR_EMAIL" ,
112- [match objectAtIndex: 3 ], @" GIT_AUTHOR_DATE" ,
113- nil ];
104+ self. amendEnvironment = [NSDictionary dictionaryWithObjectsAndKeys: [match objectAtIndex: 1 ], @" GIT_AUTHOR_NAME" ,
105+ [match objectAtIndex: 2 ], @" GIT_AUTHOR_EMAIL" ,
106+ [match objectAtIndex: 3 ], @" GIT_AUTHOR_DATE" ,
107+ nil ];
114108
115109 // Find the commit message
116110 NSRange r = [message rangeOfString: @" \n\n " ];
@@ -123,24 +117,24 @@ - (void)setAmend:(BOOL)newAmend
123117
124118}
125119
126- - (BOOL ) amend
120+ - (BOOL )isAmend
127121{
128- return amend ;
122+ return _amend ;
129123}
130124
131125- (void )refresh
132126{
133127 // If we were already refreshing the index, we don't want
134128 // double notifications. As we can't stop the tasks anymore,
135129 // just cancel the notifications
136- refreshStatus = 0 ;
130+ self. refreshStatus = 0 ;
137131 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter ];
138132 [nc removeObserver: self ];
139133
140134 // Ask Git to refresh the index
141135 NSFileHandle *updateHandle = [PBEasyPipe handleForCommand: [PBGitBinary path ]
142136 withArgs: [NSArray arrayWithObjects: @" update-index" , @" -q" , @" --unmerged" , @" --ignore-missing" , @" --refresh" , nil ]
143- inDir: [workingDirectory path ] ];
137+ inDir: self .repository.workingDirectoryURL. path];
144138
145139 [nc addObserver: self
146140 selector: @selector (indexRefreshFinished: )
@@ -152,9 +146,9 @@ - (void)refresh
152146
153147- (NSString *) parentTree
154148{
155- NSString *parent = amend ? @" HEAD^" : @" HEAD" ;
149+ NSString *parent = self. amend ? @" HEAD^" : @" HEAD" ;
156150
157- if (![repository parseReference: parent])
151+ if (![self . repository parseReference: parent])
158152 // We don't have a head ref. Return the empty tree.
159153 return @" 4b825dc642cb6eb9a060e54bf8d69288fbee4904" ;
160154
@@ -172,20 +166,20 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
172166 [commitSubject appendString: [commitMessage substringToIndex: newLine.location]];
173167
174168 NSString *commitMessageFile;
175- commitMessageFile = [repository.gitURL.path stringByAppendingPathComponent: @" COMMIT_EDITMSG" ];
169+ commitMessageFile = [self . repository.gitURL.path stringByAppendingPathComponent: @" COMMIT_EDITMSG" ];
176170
177171 [commitMessage writeToFile: commitMessageFile atomically: YES encoding: NSUTF8StringEncoding error: nil ];
178172
179173
180174 [self postCommitUpdate: @" Creating tree" ];
181- NSString *tree = [repository outputForCommand: @" write-tree" ];
175+ NSString *tree = [self . repository outputForCommand: @" write-tree" ];
182176 if ([tree length ] != 40 )
183177 return [self postCommitFailure: @" Creating tree failed" ];
184178
185179
186180 NSMutableArray *arguments = [NSMutableArray arrayWithObjects: @" commit-tree" , tree, nil ];
187- NSString *parent = amend ? @" HEAD^" : @" HEAD" ;
188- if ([repository parseReference: parent]) {
181+ NSString *parent = self. amend ? @" HEAD^" : @" HEAD" ;
182+ if ([self . repository parseReference: parent]) {
189183 [arguments addObject: @" -p" ];
190184 [arguments addObject: parent];
191185 }
@@ -197,13 +191,13 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
197191 [self postCommitUpdate: @" Running hooks" ];
198192 NSString *hookFailureMessage = nil ;
199193 NSString *hookOutput = nil ;
200- if (![repository executeHook: @" pre-commit" output: &hookOutput]) {
194+ if (![self . repository executeHook: @" pre-commit" output: &hookOutput]) {
201195 hookFailureMessage = [NSString stringWithFormat: @" Pre-commit hook failed%@%@ " ,
202196 [hookOutput length ] > 0 ? @" :\n " : @" " ,
203197 hookOutput];
204198 }
205199
206- if (![repository executeHook: @" commit-msg" withArgs: [NSArray arrayWithObject: commitMessageFile] output: nil ]) {
200+ if (![self . repository executeHook: @" commit-msg" withArgs: [NSArray arrayWithObject: commitMessageFile] output: nil ]) {
207201 hookFailureMessage = [NSString stringWithFormat: @" Commit-msg hook failed%@%@ " ,
208202 [hookOutput length ] > 0 ? @" :\n " : @" " ,
209203 hookOutput];
@@ -216,23 +210,23 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
216210
217211 commitMessage = [NSString stringWithContentsOfFile: commitMessageFile encoding: NSUTF8StringEncoding error: nil ];
218212
219- NSString *commit = [repository outputForArguments: arguments
213+ NSString *commit = [self . repository outputForArguments: arguments
220214 inputString: commitMessage
221- byExtendingEnvironment: amendEnvironment
215+ byExtendingEnvironment: self . amendEnvironment
222216 retValue: &ret];
223217
224218 if (ret || [commit length ] != 40 )
225219 return [self postCommitFailure: @" Could not create a commit object" ];
226220
227221 [self postCommitUpdate: @" Updating HEAD" ];
228- [repository outputForArguments: [NSArray arrayWithObjects: @" update-ref" , @" -m" , commitSubject, @" HEAD" , commit, nil ]
229- retValue: &ret];
222+ [self . repository outputForArguments: [NSArray arrayWithObjects: @" update-ref" , @" -m" , commitSubject, @" HEAD" , commit, nil ]
223+ retValue: &ret];
230224 if (ret)
231225 return [self postCommitFailure: @" Could not update HEAD" ];
232226
233227 [self postCommitUpdate: @" Running post-commit hook" ];
234228
235- BOOL success = [repository executeHook: @" post-commit" output: nil ];
229+ BOOL success = [self . repository executeHook: @" post-commit" output: nil ];
236230 NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject: [NSNumber numberWithBool: success] forKey: @" success" ];
237231 NSString *description;
238232 if (success)
@@ -249,10 +243,10 @@ - (void)commitWithMessage:(NSString *)commitMessage andVerify:(BOOL) doVerify
249243 if (!success)
250244 return ;
251245
252- repository.hasChanged = YES ;
246+ self. repository .hasChanged = YES ;
253247
254- amendEnvironment = nil ;
255- if (amend)
248+ self. amendEnvironment = nil ;
249+ if (self. amend )
256250 self.amend = NO ;
257251 else
258252 [self refresh ];
@@ -319,9 +313,9 @@ - (BOOL)stageFiles:(NSArray *)stageFiles
319313
320314
321315 int ret = 1 ;
322- [repository outputForArguments: [NSArray arrayWithObjects: @" update-index" , @" --add" , @" --remove" , @" -z" , @" --stdin" , nil ]
323- inputString: input
324- retValue: &ret];
316+ [self . repository outputForArguments: [NSArray arrayWithObjects: @" update-index" , @" --add" , @" --remove" , @" -z" , @" --stdin" , nil ]
317+ inputString: input
318+ retValue: &ret];
325319
326320 if (ret) {
327321 [self postOperationFailed: [NSString stringWithFormat: @" Error in staging files. Return value: %i " , ret]];
@@ -374,10 +368,10 @@ - (BOOL)unstageFiles:(NSArray *)unstageFiles
374368 }
375369
376370 int ret = 1 ;
377- [repository outputForArguments: [NSArray arrayWithObjects: @" update-index" , @" -z" , @" --index-info" , nil ]
378- inputString: input
379- retValue: &ret];
380-
371+ [self . repository outputForArguments: [NSArray arrayWithObjects: @" update-index" , @" -z" , @" --index-info" , nil ]
372+ inputString: input
373+ retValue: &ret];
374+
381375 if (ret)
382376 {
383377 [self postOperationFailed: [NSString stringWithFormat: @" Error in unstaging files. Return value: %i " , ret]];
@@ -410,7 +404,7 @@ - (void)discardChangesForFiles:(NSArray *)discardFiles
410404 NSArray *arguments = [NSArray arrayWithObjects: @" checkout-index" , @" --index" , @" --quiet" , @" --force" , @" -z" , @" --stdin" , nil ];
411405
412406 int ret = 1 ;
413- [PBEasyPipe outputForCommand: [PBGitBinary path ] withArgs: arguments inDir: [workingDirectory path ] inputString: input retValue: &ret];
407+ [PBEasyPipe outputForCommand: [PBGitBinary path ] withArgs: arguments inDir: self .repository.workingDirectoryURL. path inputString: input retValue: &ret];
414408
415409 if (ret) {
416410 [self postOperationFailed: [NSString stringWithFormat: @" Discarding changes failed with return value %i " , ret]];
@@ -433,9 +427,9 @@ - (BOOL)applyPatch:(NSString *)hunk stage:(BOOL)stage reverse:(BOOL)reverse;
433427 [array addObject: @" --reverse" ];
434428
435429 int ret = 1 ;
436- NSString *error = [repository outputForArguments: array
437- inputString: hunk
438- retValue: &ret];
430+ NSString *error = [self . repository outputForArguments: array
431+ inputString: hunk
432+ retValue: &ret];
439433
440434 if (ret) {
441435 [self postOperationFailed: [NSString stringWithFormat: @" Applying patch failed with return value %i . Error: %@ " , ret, error]];
@@ -455,9 +449,9 @@ - (NSString *)diffForFile:(PBChangedFile *)file staged:(BOOL)staged contextLines
455449 NSString *indexPath = [@" :0:" stringByAppendingString: file.path];
456450
457451 if (file.status == NEW)
458- return [repository outputForArguments: [NSArray arrayWithObjects: @" show" , indexPath, nil ]];
452+ return [self . repository outputForArguments: [NSArray arrayWithObjects: @" show" , indexPath, nil ]];
459453
460- return [repository outputInWorkdirForArguments: [NSArray arrayWithObjects: @" diff-index" , parameter, @" --cached" , [self parentTree ], @" --" , file.path, nil ]];
454+ return [self . repository outputInWorkdirForArguments: [NSArray arrayWithObjects: @" diff-index" , parameter, @" --cached" , [self parentTree ], @" --" , file.path, nil ]];
461455 }
462456
463457 // unstaged
@@ -474,7 +468,7 @@ - (NSString *)diffForFile:(PBChangedFile *)file staged:(BOOL)staged contextLines
474468 return contents;
475469 }
476470
477- return [repository outputInWorkdirForArguments: [NSArray arrayWithObjects: @" diff-files" , parameter, @" --" , file.path, nil ]];
471+ return [self . repository outputInWorkdirForArguments: [NSArray arrayWithObjects: @" diff-files" , parameter, @" --" , file.path, nil ]];
478472}
479473
480474- (void )postIndexChange
@@ -511,32 +505,32 @@ - (void)indexRefreshFinished:(NSNotification *)notification
511505 // Now that the index is refreshed, we need to read the information from the index
512506 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter ];
513507
514- if ([repository isBareRepository ])
508+ if ([self . repository isBareRepository ])
515509 {
516510 return ;
517511 }
518512
519513 // Other files (not tracked, not ignored)
520- refreshStatus++;
514+ self. refreshStatus ++;
521515 NSFileHandle *handle = [PBEasyPipe handleForCommand: [PBGitBinary path ]
522516 withArgs: [NSArray arrayWithObjects: @" ls-files" , @" --others" , @" --exclude-standard" , @" -z" , nil ]
523- inDir: [workingDirectory path ] ];
517+ inDir: self .repository.workingDirectoryURL. path];
524518 [nc addObserver: self selector: @selector (readOtherFiles: ) name: NSFileHandleReadToEndOfFileCompletionNotification object: handle];
525519 [handle readToEndOfFileInBackgroundAndNotify ];
526520
527521 // Unstaged files
528- refreshStatus++;
522+ self. refreshStatus ++;
529523 handle = [PBEasyPipe handleForCommand: [PBGitBinary path ]
530524 withArgs: [NSArray arrayWithObjects: @" diff-files" , @" -z" , nil ]
531- inDir: [workingDirectory path ] ];
525+ inDir: self .repository.workingDirectoryURL. path];
532526 [nc addObserver: self selector: @selector (readUnstagedFiles: ) name: NSFileHandleReadToEndOfFileCompletionNotification object: handle];
533527 [handle readToEndOfFileInBackgroundAndNotify ];
534528
535529 // Staged files
536- refreshStatus++;
530+ self. refreshStatus ++;
537531 handle = [PBEasyPipe handleForCommand: [PBGitBinary path ]
538532 withArgs: [NSArray arrayWithObjects: @" diff-index" , @" --cached" , @" -z" , [self parentTree ], nil ]
539- inDir: [workingDirectory path ] ];
533+ inDir: self .repository.workingDirectoryURL. path];
540534 [nc addObserver: self selector: @selector (readStagedFiles: ) name: NSFileHandleReadToEndOfFileCompletionNotification object: handle];
541535 [handle readToEndOfFileInBackgroundAndNotify ];
542536}
@@ -577,7 +571,7 @@ - (void) readUnstagedFiles:(NSNotification *)notification
577571- (void ) addFilesFromDictionary : (NSMutableDictionary *)dictionary staged : (BOOL )staged tracked : (BOOL )tracked
578572{
579573 // Iterate over all existing files
580- for (PBChangedFile *file in files) {
574+ for (PBChangedFile *file in self. files ) {
581575 NSArray *fileStatus = [dictionary objectForKey: file.path];
582576 // Object found, this is still a cached / uncached thing
583577 if (fileStatus) {
@@ -648,7 +642,7 @@ - (void) addFilesFromDictionary:(NSMutableDictionary *)dictionary staged:(BOOL)s
648642 file.hasStagedChanges = staged;
649643 file.hasUnstagedChanges = !staged;
650644
651- [files addObject: file];
645+ [self . files addObject: file];
652646 }
653647 [self didChangeValueForKey: @" indexChanges" ];
654648}
@@ -701,7 +695,7 @@ - (NSMutableDictionary *)dictionaryForLines:(NSArray *)lines
701695- (void )indexStepComplete
702696{
703697 // if we're still busy, do nothing :)
704- if (--refreshStatus) {
698+ if (--self. refreshStatus ) {
705699 [self postIndexChange ];
706700 return ;
707701 }
@@ -711,15 +705,15 @@ - (void)indexStepComplete
711705 // staged or unstaged files, and delete them
712706
713707 NSMutableArray *deleteFiles = [NSMutableArray array ];
714- for (PBChangedFile *file in files) {
708+ for (PBChangedFile *file in self. files ) {
715709 if (!file.hasStagedChanges && !file.hasUnstagedChanges )
716710 [deleteFiles addObject: file];
717711 }
718712
719713 if ([deleteFiles count ]) {
720714 [self willChangeValueForKey: @" indexChanges" ];
721715 for (PBChangedFile *file in deleteFiles)
722- [files removeObject: file];
716+ [self . files removeObject: file];
723717 [self didChangeValueForKey: @" indexChanges" ];
724718 }
725719
0 commit comments