mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
PBGitCommit: Use git_oids for parent shas
This uses a normal c array to store parent sha's. That means that we save a lot of room, as they are only 20 bytes rather than 40 + the cost of an NSArray and the NSStrings.
This commit is contained in:
+8
-1
@@ -13,6 +13,9 @@
|
||||
|
||||
@interface PBGitCommit : NSObject {
|
||||
git_oid sha;
|
||||
git_oid *parentShas;
|
||||
int nParents;
|
||||
|
||||
NSString* subject;
|
||||
NSString* author;
|
||||
NSString* details;
|
||||
@@ -35,7 +38,11 @@
|
||||
@property (readonly) git_oid *sha;
|
||||
@property (copy) NSString* subject;
|
||||
@property (copy) NSString* author;
|
||||
@property (retain) NSArray* parents;
|
||||
@property (readonly) NSArray* parents; // TODO: remove this and its uses
|
||||
|
||||
@property (assign) git_oid *parentShas;
|
||||
@property (assign) int nParents;
|
||||
|
||||
@property (retain) NSMutableArray* refs;
|
||||
@property (copy) NSDate* date;
|
||||
@property (readonly) NSString* dateString;
|
||||
|
||||
+22
-1
@@ -11,8 +11,23 @@
|
||||
|
||||
@implementation PBGitCommit
|
||||
|
||||
@synthesize repository, subject, author, date, parents, sign, lineInfo, refs;
|
||||
@synthesize repository, subject, author, date, parentShas, nParents, sign, lineInfo, refs;
|
||||
|
||||
- (NSArray *) parents
|
||||
{
|
||||
if (nParents == 0)
|
||||
return NULL;
|
||||
|
||||
int i;
|
||||
NSMutableArray *p = [NSMutableArray arrayWithCapacity:nParents];
|
||||
for (i = 0; i < nParents; ++i)
|
||||
{
|
||||
char *s = git_oid_mkhex(parentShas + i);
|
||||
[p addObject:[NSString stringWithUTF8String:s]];
|
||||
free(s);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
- (NSString *) dateString
|
||||
{
|
||||
@@ -92,6 +107,12 @@
|
||||
refs = NULL;
|
||||
}
|
||||
|
||||
- (void)finalize
|
||||
{
|
||||
free(parentShas);
|
||||
[super finalize];
|
||||
}
|
||||
|
||||
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
|
||||
{
|
||||
return NO;
|
||||
|
||||
+7
-5
@@ -47,7 +47,7 @@ void add_line(struct PBGitGraphLine *lines, int *nLines, int upper, int from, in
|
||||
std::vector<PBGitLane *> *currentLanes = new std::vector<PBGitLane *>;
|
||||
std::vector<PBGitLane *> *previousLanes = (std::vector<PBGitLane *> *)pl;
|
||||
|
||||
int maxLines = (previousLanes->size() + [commit.parents count] + 2) * 3;
|
||||
int maxLines = (previousLanes->size() + commit.nParents + 2) * 3;
|
||||
struct PBGitGraphLine *lines = (struct PBGitGraphLine *)malloc(sizeof(struct PBGitGraphLine) * maxLines);
|
||||
int currentLine = 0;
|
||||
|
||||
@@ -94,7 +94,7 @@ void add_line(struct PBGitGraphLine *lines, int *nLines, int upper, int from, in
|
||||
|
||||
// If we already did the first parent, don't do so again
|
||||
if (!didFirst && currentLanes->size() < MAX_LANES) {
|
||||
PBGitLane *newLane = new PBGitLane([commit.parents objectAtIndex:0]);
|
||||
PBGitLane *newLane = new PBGitLane(commit.parentShas);
|
||||
currentLanes->push_back(newLane);
|
||||
newPos = currentLanes->size();
|
||||
add_line(lines, ¤tLine, 0, newPos, newPos, newLane->index());
|
||||
@@ -106,7 +106,9 @@ void add_line(struct PBGitGraphLine *lines, int *nLines, int upper, int from, in
|
||||
// This boolean will tell us if that happened
|
||||
BOOL addedParent = NO;
|
||||
|
||||
for (NSString *parent in [commit.parents subarrayWithRange:NSMakeRange(1, [commit.parents count] -1)]) {
|
||||
int parentIndex;
|
||||
for (parentIndex = 1; parentIndex < commit.nParents; ++parentIndex) {
|
||||
git_oid *parent = commit.parentShas + parentIndex;
|
||||
int i = 0;
|
||||
BOOL was_displayed = NO;
|
||||
std::vector<PBGitLane *>::iterator it = currentLanes->begin();
|
||||
@@ -145,8 +147,8 @@ void add_line(struct PBGitGraphLine *lines, int *nLines, int upper, int from, in
|
||||
previous.numColumns = currentLanes->size();
|
||||
|
||||
// Update the current lane to point to the new parent
|
||||
if (currentLane && [commit.parents count] > 0 && ![[commit.parents objectAtIndex:0] isEqualToString:@""])
|
||||
currentLane->setSha([commit.parents objectAtIndex:0]);
|
||||
if (currentLane && commit.nParents > 0)
|
||||
currentLane->setSha(commit.parentShas[0]);
|
||||
// else
|
||||
// [currentLanes removeObject:currentLane];
|
||||
|
||||
|
||||
+2
-2
@@ -19,10 +19,10 @@ class PBGitLane {
|
||||
|
||||
public:
|
||||
|
||||
PBGitLane(git_oid sha)
|
||||
PBGitLane(git_oid *sha)
|
||||
{
|
||||
d_index = s_colorIndex++;
|
||||
d_sha = sha;
|
||||
d_sha = *sha;
|
||||
}
|
||||
|
||||
PBGitLane(NSString *sha)
|
||||
|
||||
+17
-4
@@ -131,8 +131,23 @@ using namespace std;
|
||||
string subject;
|
||||
getline(stream, subject, '\0');
|
||||
|
||||
string parents;
|
||||
getline(stream, parents, '\0');
|
||||
string parentString;
|
||||
getline(stream, parentString, '\0');
|
||||
if (parentString.size() != 0)
|
||||
{
|
||||
if (((parentString.size() + 1) % 41) != 0) {
|
||||
NSLog(@"invalid parents: %i", parentString.size());
|
||||
continue;
|
||||
}
|
||||
int nParents = (parentString.size() + 1) / 41;
|
||||
git_oid *parents = (git_oid *)malloc(sizeof(git_oid) * nParents);
|
||||
int parentIndex;
|
||||
for (parentIndex = 0; parentIndex < nParents; ++parentIndex)
|
||||
git_oid_mkstr(parents + parentIndex, parentString.substr(parentIndex * 41, 40).c_str());
|
||||
|
||||
newCommit.parentShas = parents;
|
||||
newCommit.nParents = nParents;
|
||||
}
|
||||
|
||||
int time;
|
||||
stream >> time;
|
||||
@@ -142,8 +157,6 @@ using namespace std;
|
||||
if (c != '\0')
|
||||
cout << "Error" << endl;
|
||||
|
||||
|
||||
[newCommit setParents:[[NSString stringWithUTF8String:parents.c_str()] componentsSeparatedByString:@" "]];
|
||||
[newCommit setSubject:[NSString stringWithUTF8String:subject.c_str()]];
|
||||
[newCommit setAuthor:[NSString stringWithUTF8String:author.c_str()]];
|
||||
NSDate *date = [NSDate dateWithTimeIntervalSince1970:time];
|
||||
|
||||
Reference in New Issue
Block a user