Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

some work on making the index api a bit friendlier

  • Loading branch information...
commit 43e759c6c8a1c669f2e099138d37e8df0bbf1b29 1 parent 126b51c
@joshaber joshaber authored
View
1  Classes/GTIndex.h
@@ -37,6 +37,7 @@
@property (nonatomic, assign) git_index *git_index;
@property (nonatomic, copy) NSURL *fileURL;
@property (nonatomic, readonly) NSUInteger entryCount;
+@property (nonatomic, readonly) NSArray *entries;
// Convenience initializers
- (id)initWithFileURL:(NSURL *)localFileUrl error:(NSError **)error;
View
9 Classes/GTIndex.m
@@ -131,4 +131,13 @@ - (BOOL)writeWithError:(NSError **)error {
return YES;
}
+- (NSArray *)entries {
+ NSMutableArray *entries = [NSMutableArray arrayWithCapacity:self.entryCount];
+ for(NSUInteger i = 0; i < self.entryCount; i++) {
+ [entries addObject:[self entryAtIndex:i]];
+ }
+
+ return [entries copy];
+}
+
@end
View
16 Classes/GTIndexEntry.h
@@ -28,9 +28,17 @@
//
#include "git2.h"
+#import "GTObject.h"
+typedef enum {
+ GTIndexEntryStatusUpdated = 0,
+ GTIndexEntryStatusRemoved,
+ GTIndexEntryStatusNew,
+ GTIndexEntryStatusUnchanged,
+} GTIndexEntryStatus;
-@interface GTIndexEntry : NSObject {}
+
+@interface GTIndexEntry : NSObject <GTObject> {}
@property (nonatomic, assign) git_index_entry *git_index_entry;
@property (nonatomic, copy) NSString *path;
@@ -43,8 +51,10 @@
@property (nonatomic, assign) NSUInteger uid;
@property (nonatomic, assign) NSUInteger gid;
@property (nonatomic, assign) NSUInteger flags;
-@property (nonatomic, getter=isStaged, assign) NSUInteger stage;
-@property (nonatomic, readonly) BOOL isValid;
+@property (nonatomic, getter=isStaged, readonly) NSUInteger staged;
+@property (nonatomic, getter=isValid, readonly) BOOL valid;
+@property (nonatomic, readonly) GTIndexEntryStatus status;
+@property (nonatomic, dct_weak) GTRepository *repository;
// Convenience initializers
- (id)initWithEntry:(git_index_entry *)theEntry;
View
18 Classes/GTIndexEntry.m
@@ -35,7 +35,7 @@
@implementation GTIndexEntry
- (NSString *)description {
- return [NSString stringWithFormat:@"<%@: %p> path: %@, modificationDate: %@, creationDate: %@, fileSize: %@ KB", NSStringFromClass([self class]), self, self.path, self.modificationDate, self.creationDate, [NSNumber numberWithLongLong:self.fileSize]];
+ return [NSString stringWithFormat:@"<%@: %p> path: %@, modificationDate: %@, creationDate: %@, fileSize: %ll KB, flags: %d", NSStringFromClass([self class]), self, self.path, self.modificationDate, self.creationDate, self.fileSize, self.flags];
}
- (void)dealloc {
@@ -56,8 +56,9 @@ - (void)dealloc {
@synthesize uid;
@synthesize gid;
@synthesize flags;
-@synthesize stage;
-@synthesize isValid;
+@synthesize staged;
+@synthesize valid;
+@synthesize repository;
+ (id)indexEntryWithEntry:(git_index_entry *)theEntry {
return [[self alloc] initWithEntry:theEntry];
@@ -161,11 +162,14 @@ - (NSUInteger)isStaged {
return (self.git_index_entry->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT;
}
-- (void)setStage:(NSUInteger)theStage {
- NSParameterAssert(theStage >= 0 && theStage <= 3);
+- (GTIndexEntryStatus)status {
+ if((self.flags & GIT_IDXENTRY_UPDATE) != 0) {
+ return GTIndexEntryStatusUpdated;
+ } else if((self.flags & GIT_IDXENTRY_UPTODATE) != 0) {
+ return GTIndexEntryStatusUnchanged;
+ }
- self.git_index_entry->flags &= ~GIT_IDXENTRY_STAGEMASK;
- self.git_index_entry->flags |= (theStage << GIT_IDXENTRY_STAGESHIFT);
+ return GTIndexEntryStatusUnchanged;
}
@end
View
12 Classes/GTRepository.m
@@ -480,6 +480,18 @@ - (GTConfiguration *)configuration {
return configuration;
}
+- (GTIndex *)index {
+ if(index == nil) {
+ NSError *error = nil;
+ BOOL success = [self setupIndexWithError:&error];
+ if(!success) {
+ GTLog(@"Error setting up index: %@", error);
+ }
+ }
+
+ return index;
+}
+
@end
Please sign in to comment.
Something went wrong with that request. Please try again.