Skip to content

Commit d2eafc2

Browse files
committed
Include libgit2 as submodule and use it to store sha's
This reduces GitX's memory usage and makes some operations much faster, like graphing, by having a cheaper comparison
1 parent 1a7ad94 commit d2eafc2

14 files changed

+206
-111
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "libgit2"]
2+
path = libgit2
3+
url = git://github.com/pieter/libgit2.git

GitX.xcodeproj/project.pbxproj

+31
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
F5AD56790E79B78100EDAAFE /* PBCommitList.m in Sources */ = {isa = PBXBuildFile; fileRef = F5AD56780E79B78100EDAAFE /* PBCommitList.m */; };
8181
F5B721C40E05CF7E00AF29DC /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = F5B721C20E05CF7E00AF29DC /* MainMenu.xib */; };
8282
F5C007750E731B48007B84B2 /* PBGitRef.m in Sources */ = {isa = PBXBuildFile; fileRef = F5C007740E731B48007B84B2 /* PBGitRef.m */; };
83+
F5C580E50EDA250900995434 /* libgit2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F5C580E40EDA250900995434 /* libgit2.a */; };
84+
F5C580F50EDA251100995434 /* libgit2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F5C580E40EDA250900995434 /* libgit2.a */; };
8385
F5C6F68D0E65FF9300478D97 /* PBGitLane.mm in Sources */ = {isa = PBXBuildFile; fileRef = F5C6F68C0E65FF9300478D97 /* PBGitLane.mm */; };
8486
F5DFFA6C0E075D8800617813 /* PBEasyFS.m in Sources */ = {isa = PBXBuildFile; fileRef = F5DFFA6B0E075D8800617813 /* PBEasyFS.m */; };
8587
F5E424110EA3E4D60046E362 /* PBDiffWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = F5E424100EA3E4D60046E362 /* PBDiffWindow.xib */; };
@@ -214,6 +216,7 @@
214216
F5B721C30E05CF7E00AF29DC /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
215217
F5C007730E731B48007B84B2 /* PBGitRef.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRef.h; sourceTree = "<group>"; };
216218
F5C007740E731B48007B84B2 /* PBGitRef.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitRef.m; sourceTree = "<group>"; };
219+
F5C580E40EDA250900995434 /* libgit2.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libgit2.a; path = libgit2/libgit2.a; sourceTree = "<group>"; };
217220
F5C6F68B0E65FF9300478D97 /* PBGitLane.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitLane.h; sourceTree = "<group>"; };
218221
F5C6F68C0E65FF9300478D97 /* PBGitLane.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PBGitLane.mm; sourceTree = "<group>"; };
219222
F5D2DC850EA401A80034AD24 /* PBGitConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitConfig.h; sourceTree = "<group>"; };
@@ -259,6 +262,7 @@
259262
911112370E5A097800BF76B4 /* Security.framework in Frameworks */,
260263
F580E6AE0E733276009E2D3F /* Sparkle.framework in Frameworks */,
261264
F5E4DBFB0EAB58D90013FAFC /* SystemConfiguration.framework in Frameworks */,
265+
F5C580E50EDA250900995434 /* libgit2.a in Frameworks */,
262266
);
263267
runOnlyForDeploymentPostprocessing = 0;
264268
};
@@ -273,6 +277,7 @@
273277
isa = PBXFrameworksBuildPhase;
274278
buildActionMask = 2147483647;
275279
files = (
280+
F5C580F50EDA251100995434 /* libgit2.a in Frameworks */,
276281
F5886A1E0ED5D3880066E74C /* Cocoa.framework in Frameworks */,
277282
);
278283
runOnlyForDeploymentPostprocessing = 0;
@@ -375,6 +380,7 @@
375380
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
376381
isa = PBXGroup;
377382
children = (
383+
F5C580E40EDA250900995434 /* libgit2.a */,
378384
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */,
379385
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */,
380386
);
@@ -578,6 +584,7 @@
578584
isa = PBXNativeTarget;
579585
buildConfigurationList = 26FC0A840875C7B200E6366F /* Build configuration list for PBXNativeTarget "GitX" */;
580586
buildPhases = (
587+
F5792DFB0EDB570C001B0C31 /* Compilie libgit2 */,
581588
8D1107290486CEB800E47090 /* Resources */,
582589
8D11072C0486CEB800E47090 /* Sources */,
583590
8D11072E0486CEB800E47090 /* Frameworks */,
@@ -683,6 +690,20 @@
683690
/* End PBXResourcesBuildPhase section */
684691

685692
/* Begin PBXShellScriptBuildPhase section */
693+
F5792DFB0EDB570C001B0C31 /* Compilie libgit2 */ = {
694+
isa = PBXShellScriptBuildPhase;
695+
buildActionMask = 2147483647;
696+
files = (
697+
);
698+
inputPaths = (
699+
);
700+
name = "Compilie libgit2";
701+
outputPaths = (
702+
);
703+
runOnlyForDeploymentPostprocessing = 0;
704+
shellPath = /bin/sh;
705+
shellScript = "git submodule init\ngit submodule update\ncd libgit2\nrm -f libgit2.a\nmake CFLAGS=\"-arch i386 -arch ppc\"\nranlib libgit2.a";
706+
};
686707
F5CF04A20EAE696C00D75C81 /* Copy HTML files */ = {
687708
isa = PBXShellScriptBuildPhase;
688709
buildActionMask = 2147483647;
@@ -840,8 +861,10 @@
840861
GCC_OPTIMIZATION_LEVEL = 0;
841862
GCC_PRECOMPILE_PREFIX_HEADER = YES;
842863
GCC_PREFIX_HEADER = GitX_Prefix.pch;
864+
HEADER_SEARCH_PATHS = libgit2/src;
843865
INFOPLIST_FILE = Info.plist;
844866
INSTALL_PATH = "$(HOME)/Applications";
867+
LIBRARY_SEARCH_PATHS = libgit2;
845868
PRODUCT_NAME = GitX;
846869
WRAPPER_EXTENSION = app;
847870
ZERO_LINK = YES;
@@ -860,8 +883,10 @@
860883
GCC_MODEL_TUNING = G5;
861884
GCC_PRECOMPILE_PREFIX_HEADER = YES;
862885
GCC_PREFIX_HEADER = GitX_Prefix.pch;
886+
HEADER_SEARCH_PATHS = libgit2/src;
863887
INFOPLIST_FILE = Info.plist;
864888
INSTALL_PATH = "$(HOME)/Applications";
889+
LIBRARY_SEARCH_PATHS = libgit2;
865890
PRODUCT_NAME = GitX;
866891
WRAPPER_EXTENSION = app;
867892
};
@@ -904,6 +929,7 @@
904929
GCC_PRECOMPILE_PREFIX_HEADER = YES;
905930
GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h";
906931
INSTALL_PATH = /usr/local/bin;
932+
LIBRARY_SEARCH_PATHS = libgit2;
907933
OTHER_LDFLAGS = (
908934
"-framework",
909935
Foundation,
@@ -926,6 +952,7 @@
926952
GCC_PRECOMPILE_PREFIX_HEADER = YES;
927953
GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h";
928954
INSTALL_PATH = /usr/local/bin;
955+
LIBRARY_SEARCH_PATHS = libgit2;
929956
OTHER_LDFLAGS = (
930957
"-framework",
931958
Foundation,
@@ -949,10 +976,13 @@
949976
GCC_OPTIMIZATION_LEVEL = 2;
950977
GCC_PRECOMPILE_PREFIX_HEADER = YES;
951978
GCC_PREFIX_HEADER = GitX_Prefix.pch;
979+
HEADER_SEARCH_PATHS = libgit2/src;
952980
INFOPLIST_FILE = "SpeedTest-Info.plist";
953981
INSTALL_PATH = "$(HOME)/Applications";
982+
LIBRARY_SEARCH_PATHS = libgit2;
954983
OTHER_CFLAGS = "-DCLI";
955984
OTHER_LDFLAGS = (
985+
"-L.",
956986
"-framework",
957987
Foundation,
958988
"-framework",
@@ -976,6 +1006,7 @@
9761006
GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/UIKit.framework/Headers/UIKit.h";
9771007
INFOPLIST_FILE = "SpeedTest-Info.plist";
9781008
INSTALL_PATH = "$(HOME)/Applications";
1009+
LIBRARY_SEARCH_PATHS = libgit2;
9791010
OTHER_LDFLAGS = (
9801011
"-framework",
9811012
Foundation,

PBGitCommit.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
#import <Cocoa/Cocoa.h>
1010
#import "PBGitRepository.h"
1111
#import "PBGitTree.h"
12+
#include "git/oid.h"
1213

1314
@interface PBGitCommit : NSObject {
14-
NSString* sha;
15+
git_oid sha;
1516
NSString* subject;
1617
NSString* author;
1718
NSString* details;
@@ -24,12 +25,14 @@
2425
PBGitRepository* repository;
2526
}
2627

27-
- initWithRepository:(PBGitRepository*) repo andSha:(NSString*) sha;
28+
- initWithRepository:(PBGitRepository *)repo andSha:(git_oid)sha;
2829

2930
- (void)addRef:(id)ref;
3031
- (void)removeRef:(id)ref;
3132

32-
@property (copy) NSString* sha;
33+
- (NSString *)realSha;
34+
35+
@property (readonly) git_oid *sha;
3336
@property (copy) NSString* subject;
3437
@property (copy) NSString* author;
3538
@property (retain) NSArray* parents;

PBGitCommit.m

+18-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
@implementation PBGitCommit
1313

14-
@synthesize sha, repository, subject, author, date, parents, sign, lineInfo, refs;
14+
@synthesize repository, subject, author, date, parents, sign, lineInfo, refs;
1515

1616

1717
- (NSString *) dateString
@@ -25,22 +25,35 @@ - (NSArray*) treeContents
2525
return self.tree.children;
2626
}
2727

28-
- initWithRepository:(PBGitRepository*) repo andSha:(NSString*) newSha
28+
- (git_oid *)sha
29+
{
30+
return &sha;
31+
}
32+
33+
- initWithRepository:(PBGitRepository*) repo andSha:(git_oid)newSha
2934
{
3035
details = nil;
31-
self.repository = repo;
32-
self.sha = newSha;
36+
repository = repo;
37+
sha = newSha;
3338
return self;
3439
}
3540

41+
- (NSString *)realSha
42+
{
43+
char *hex = git_oid_mkhex(&sha);
44+
NSString *str = [NSString stringWithUTF8String:hex];
45+
free(hex);
46+
return str;
47+
}
48+
3649
// NOTE: This method should remain threadsafe, as we load it in async
3750
// from the web view.
3851
- (NSString*) details
3952
{
4053
if (details != nil)
4154
return details;
4255

43-
details = [self.repository outputForCommand:[@"show --pretty=raw " stringByAppendingString:self.sha]];
56+
details = [self.repository outputForCommand:[@"show --pretty=raw " stringByAppendingString:[self realSha]]];
4457

4558
return details;
4659
}

PBGitGrapher.h

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
@interface PBGitGrapher : NSObject {
1515
PBGraphCellInfo* previous;
1616
void *pl;
17+
void *storage;
18+
int curLane;
19+
1720
NSDictionary* refs;
1821
PBGitRepository* repository;
1922
}

PBGitGrapher.mm

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
// Copyright 2008 __MyCompanyName__. All rights reserved.
77
//
88

9+
extern "C" {
10+
#import "git/oid.h"
11+
}
12+
913
#import "PBGitGrapher.h"
1014
#import "PBGitCommit.h"
1115
#import "PBGitLane.h"
@@ -31,7 +35,6 @@ - (id) initWithRepository: (PBGitRepository*) repo
3135

3236
- (void) decorateCommit: (PBGitCommit *) commit
3337
{
34-
//NSLog(@"Decoriting commit %@", commit.sha);
3538
int i = 0, newPos = -1;
3639
std::vector<PBGitLane *> *currentLanes = new std::vector<PBGitLane *>;
3740
std::vector<PBGitLane *> *previousLanes = (std::vector<PBGitLane *> *)pl;
@@ -48,7 +51,6 @@ - (void) decorateCommit: (PBGitCommit *) commit
4851
i++;
4952
// This is our commit! We should do a "merge": move the line from
5053
// our upperMapping to their lowerMapping
51-
5254
if ((*it)->isCommit([commit sha])) {
5355
if (!didFirst) {
5456
didFirst = YES;
@@ -116,7 +118,7 @@ - (void) decorateCommit: (PBGitCommit *) commit
116118
// This boolean will tell us if that happened
117119
BOOL addedParent = NO;
118120

119-
for (NSString* parent in [commit.parents subarrayWithRange:NSMakeRange(1, [commit.parents count] -1)]) {
121+
for (NSString *parent in [commit.parents subarrayWithRange:NSMakeRange(1, [commit.parents count] -1)]) {
120122
int i = 0;
121123
BOOL was_displayed = NO;
122124
std::vector<PBGitLane *>::iterator it = currentLanes->begin();

0 commit comments

Comments
 (0)