diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..2550172 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libgit2"] + path = libgit2 + url = git://github.com/pieter/libgit2.git diff --git a/GitX.xcodeproj/project.pbxproj b/GitX.xcodeproj/project.pbxproj index 0d2b597..1c38537 100644 --- a/GitX.xcodeproj/project.pbxproj +++ b/GitX.xcodeproj/project.pbxproj @@ -80,6 +80,8 @@ F5AD56790E79B78100EDAAFE /* PBCommitList.m in Sources */ = {isa = PBXBuildFile; fileRef = F5AD56780E79B78100EDAAFE /* PBCommitList.m */; }; F5B721C40E05CF7E00AF29DC /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = F5B721C20E05CF7E00AF29DC /* MainMenu.xib */; }; F5C007750E731B48007B84B2 /* PBGitRef.m in Sources */ = {isa = PBXBuildFile; fileRef = F5C007740E731B48007B84B2 /* PBGitRef.m */; }; + F5C580E50EDA250900995434 /* libgit2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F5C580E40EDA250900995434 /* libgit2.a */; }; + F5C580F50EDA251100995434 /* libgit2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F5C580E40EDA250900995434 /* libgit2.a */; }; F5C6F68D0E65FF9300478D97 /* PBGitLane.mm in Sources */ = {isa = PBXBuildFile; fileRef = F5C6F68C0E65FF9300478D97 /* PBGitLane.mm */; }; F5DFFA6C0E075D8800617813 /* PBEasyFS.m in Sources */ = {isa = PBXBuildFile; fileRef = F5DFFA6B0E075D8800617813 /* PBEasyFS.m */; }; F5E424110EA3E4D60046E362 /* PBDiffWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = F5E424100EA3E4D60046E362 /* PBDiffWindow.xib */; }; @@ -214,6 +216,7 @@ F5B721C30E05CF7E00AF29DC /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = ""; }; F5C007730E731B48007B84B2 /* PBGitRef.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRef.h; sourceTree = ""; }; F5C007740E731B48007B84B2 /* PBGitRef.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitRef.m; sourceTree = ""; }; + F5C580E40EDA250900995434 /* libgit2.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libgit2.a; path = libgit2/libgit2.a; sourceTree = ""; }; F5C6F68B0E65FF9300478D97 /* PBGitLane.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitLane.h; sourceTree = ""; }; F5C6F68C0E65FF9300478D97 /* PBGitLane.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PBGitLane.mm; sourceTree = ""; }; F5D2DC850EA401A80034AD24 /* PBGitConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitConfig.h; sourceTree = ""; }; @@ -259,6 +262,7 @@ 911112370E5A097800BF76B4 /* Security.framework in Frameworks */, F580E6AE0E733276009E2D3F /* Sparkle.framework in Frameworks */, F5E4DBFB0EAB58D90013FAFC /* SystemConfiguration.framework in Frameworks */, + F5C580E50EDA250900995434 /* libgit2.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -273,6 +277,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + F5C580F50EDA251100995434 /* libgit2.a in Frameworks */, F5886A1E0ED5D3880066E74C /* Cocoa.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -375,6 +380,7 @@ 29B97323FDCFA39411CA2CEA /* Frameworks */ = { isa = PBXGroup; children = ( + F5C580E40EDA250900995434 /* libgit2.a */, 1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */, 1058C7A2FEA54F0111CA2CBB /* Other Frameworks */, ); @@ -578,6 +584,7 @@ isa = PBXNativeTarget; buildConfigurationList = 26FC0A840875C7B200E6366F /* Build configuration list for PBXNativeTarget "GitX" */; buildPhases = ( + F5792DFB0EDB570C001B0C31 /* Compilie libgit2 */, 8D1107290486CEB800E47090 /* Resources */, 8D11072C0486CEB800E47090 /* Sources */, 8D11072E0486CEB800E47090 /* Frameworks */, @@ -683,6 +690,20 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ + F5792DFB0EDB570C001B0C31 /* Compilie libgit2 */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Compilie libgit2"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "git submodule init\ngit submodule update\ncd libgit2\nrm -f libgit2.a\nmake CFLAGS=\"-arch i386 -arch ppc\"\nranlib libgit2.a"; + }; F5CF04A20EAE696C00D75C81 /* Copy HTML files */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -840,8 +861,10 @@ GCC_OPTIMIZATION_LEVEL = 0; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = GitX_Prefix.pch; + HEADER_SEARCH_PATHS = libgit2/src; INFOPLIST_FILE = Info.plist; INSTALL_PATH = "$(HOME)/Applications"; + LIBRARY_SEARCH_PATHS = libgit2; PRODUCT_NAME = GitX; WRAPPER_EXTENSION = app; ZERO_LINK = YES; @@ -860,8 +883,10 @@ GCC_MODEL_TUNING = G5; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = GitX_Prefix.pch; + HEADER_SEARCH_PATHS = libgit2/src; INFOPLIST_FILE = Info.plist; INSTALL_PATH = "$(HOME)/Applications"; + LIBRARY_SEARCH_PATHS = libgit2; PRODUCT_NAME = GitX; WRAPPER_EXTENSION = app; }; @@ -904,6 +929,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; INSTALL_PATH = /usr/local/bin; + LIBRARY_SEARCH_PATHS = libgit2; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -926,6 +952,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; INSTALL_PATH = /usr/local/bin; + LIBRARY_SEARCH_PATHS = libgit2; OTHER_LDFLAGS = ( "-framework", Foundation, @@ -949,10 +976,13 @@ GCC_OPTIMIZATION_LEVEL = 2; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = GitX_Prefix.pch; + HEADER_SEARCH_PATHS = libgit2/src; INFOPLIST_FILE = "SpeedTest-Info.plist"; INSTALL_PATH = "$(HOME)/Applications"; + LIBRARY_SEARCH_PATHS = libgit2; OTHER_CFLAGS = "-DCLI"; OTHER_LDFLAGS = ( + "-L.", "-framework", Foundation, "-framework", @@ -976,6 +1006,7 @@ GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/UIKit.framework/Headers/UIKit.h"; INFOPLIST_FILE = "SpeedTest-Info.plist"; INSTALL_PATH = "$(HOME)/Applications"; + LIBRARY_SEARCH_PATHS = libgit2; OTHER_LDFLAGS = ( "-framework", Foundation, diff --git a/PBGitCommit.h b/PBGitCommit.h index f95829a..87ce915 100644 --- a/PBGitCommit.h +++ b/PBGitCommit.h @@ -9,9 +9,10 @@ #import #import "PBGitRepository.h" #import "PBGitTree.h" +#include "git/oid.h" @interface PBGitCommit : NSObject { - NSString* sha; + git_oid sha; NSString* subject; NSString* author; NSString* details; @@ -24,12 +25,14 @@ PBGitRepository* repository; } -- initWithRepository:(PBGitRepository*) repo andSha:(NSString*) sha; +- initWithRepository:(PBGitRepository *)repo andSha:(git_oid)sha; - (void)addRef:(id)ref; - (void)removeRef:(id)ref; -@property (copy) NSString* sha; +- (NSString *)realSha; + +@property (readonly) git_oid *sha; @property (copy) NSString* subject; @property (copy) NSString* author; @property (retain) NSArray* parents; diff --git a/PBGitCommit.m b/PBGitCommit.m index f38bf43..4b418b8 100644 --- a/PBGitCommit.m +++ b/PBGitCommit.m @@ -11,7 +11,7 @@ @implementation PBGitCommit -@synthesize sha, repository, subject, author, date, parents, sign, lineInfo, refs; +@synthesize repository, subject, author, date, parents, sign, lineInfo, refs; - (NSString *) dateString @@ -25,14 +25,27 @@ return self.tree.children; } -- initWithRepository:(PBGitRepository*) repo andSha:(NSString*) newSha +- (git_oid *)sha +{ + return &sha; +} + +- initWithRepository:(PBGitRepository*) repo andSha:(git_oid)newSha { details = nil; - self.repository = repo; - self.sha = newSha; + repository = repo; + sha = newSha; return self; } +- (NSString *)realSha +{ + char *hex = git_oid_mkhex(&sha); + NSString *str = [NSString stringWithUTF8String:hex]; + free(hex); + return str; +} + // NOTE: This method should remain threadsafe, as we load it in async // from the web view. - (NSString*) details @@ -40,7 +53,7 @@ if (details != nil) return details; - details = [self.repository outputForCommand:[@"show --pretty=raw " stringByAppendingString:self.sha]]; + details = [self.repository outputForCommand:[@"show --pretty=raw " stringByAppendingString:[self realSha]]]; return details; } diff --git a/PBGitGrapher.h b/PBGitGrapher.h index 9d3a4ba..2e4af81 100644 --- a/PBGitGrapher.h +++ b/PBGitGrapher.h @@ -14,6 +14,9 @@ @interface PBGitGrapher : NSObject { PBGraphCellInfo* previous; void *pl; + void *storage; + int curLane; + NSDictionary* refs; PBGitRepository* repository; } diff --git a/PBGitGrapher.mm b/PBGitGrapher.mm index 2b26fdc..803f0bf 100644 --- a/PBGitGrapher.mm +++ b/PBGitGrapher.mm @@ -6,6 +6,10 @@ // Copyright 2008 __MyCompanyName__. All rights reserved. // +extern "C" { +#import "git/oid.h" +} + #import "PBGitGrapher.h" #import "PBGitCommit.h" #import "PBGitLane.h" @@ -31,7 +35,6 @@ using namespace std; - (void) decorateCommit: (PBGitCommit *) commit { - //NSLog(@"Decoriting commit %@", commit.sha); int i = 0, newPos = -1; std::vector *currentLanes = new std::vector; std::vector *previousLanes = (std::vector *)pl; @@ -48,7 +51,6 @@ using namespace std; i++; // This is our commit! We should do a "merge": move the line from // our upperMapping to their lowerMapping - if ((*it)->isCommit([commit sha])) { if (!didFirst) { didFirst = YES; @@ -116,7 +118,7 @@ using namespace std; // This boolean will tell us if that happened BOOL addedParent = NO; - for (NSString* parent in [commit.parents subarrayWithRange:NSMakeRange(1, [commit.parents count] -1)]) { + for (NSString *parent in [commit.parents subarrayWithRange:NSMakeRange(1, [commit.parents count] -1)]) { int i = 0; BOOL was_displayed = NO; std::vector::iterator it = currentLanes->begin(); diff --git a/PBGitHistoryView.xib b/PBGitHistoryView.xib index c5c4f23..90dbbf8 100644 --- a/PBGitHistoryView.xib +++ b/PBGitHistoryView.xib @@ -3,14 +3,14 @@ 1050 9F33 - 672 + 670 949.34 352.00 YES + - YES @@ -2361,87 +2361,6 @@ - - 3 - - - YES - - - - - - - - - 30 - - - - - 29 - - - - - 28 - - - - - 27 - - - YES - - - - - - Commit List - - - 33 - - - YES - - - - - - 32 - - - YES - - - - - - 31 - - - YES - - - - - - 36 - - - - - 35 - - - - - 34 - - - 231 @@ -2686,6 +2605,87 @@ + + 3 + + + YES + + + + + + + + + 27 + + + YES + + + + + + Commit List + + + 31 + + + YES + + + + + + 36 + + + + + 32 + + + YES + + + + + + 35 + + + + + 33 + + + YES + + + + + + 34 + + + + + 28 + + + + + 29 + + + + + 30 + + + @@ -2796,7 +2796,7 @@ com.apple.InterfaceBuilderKit com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{69, 366}, {616, 227}} + {{312, 366}, {616, 227}} com.apple.InterfaceBuilder.CocoaPlugin {{132, 614}, {616, 0}} com.apple.InterfaceBuilder.CocoaPlugin diff --git a/PBGitLane.h b/PBGitLane.h index 02e68cc..5a1ebef 100644 --- a/PBGitLane.h +++ b/PBGitLane.h @@ -6,32 +6,46 @@ // Copyright 2008 __MyCompanyName__. All rights reserved. // #import +extern "C" +{ +#include "git/oid.h" +} class PBGitLane { static int s_colorIndex; - NSString *d_sha; + git_oid d_sha; int d_index; public: - PBGitLane(NSString *sha) + PBGitLane(git_oid sha) { d_index = s_colorIndex++; - d_sha = [sha copy]; + d_sha = sha; + } + + PBGitLane(NSString *sha) + { + git_oid_mkstr(&d_sha, [sha UTF8String]); + d_index = s_colorIndex++; } PBGitLane() { d_index = s_colorIndex++; - d_sha = NULL; + //d_sha = NULL; } + bool isCommit(git_oid *sha) const; bool isCommit(NSString *sha) const; + + void setSha(git_oid sha); void setSha(NSString *sha); - NSString *sha() const + + git_oid const *sha() const { - return [d_sha copy]; + return &d_sha; } int index() const; diff --git a/PBGitLane.mm b/PBGitLane.mm index a712a5b..1e8218d 100644 --- a/PBGitLane.mm +++ b/PBGitLane.mm @@ -24,10 +24,22 @@ int PBGitLane::s_colorIndex = 0; +static git_oid str_to_oid(NSString *str) +{ + git_oid oid; + git_oid_mkstr(&oid, [str UTF8String]); + return oid; +} + +bool PBGitLane::isCommit(git_oid *sha) const +{ + return !git_oid_cmp(&d_sha, sha); +} + bool PBGitLane::isCommit(NSString *sha) const { - //NSLog(@"Comparing %@ with %@", d_sha, sha); - return [d_sha isEqualToString:sha]; + git_oid a = str_to_oid(sha); + return isCommit(&a); } int PBGitLane::index() const @@ -35,11 +47,17 @@ int PBGitLane::index() const return d_index; } -void PBGitLane::setSha(NSString *sha) +void PBGitLane::setSha(git_oid sha) { d_sha = sha; } +void PBGitLane::setSha(NSString *sha) +{ + return setSha(str_to_oid(sha)); +} + + void PBGitLane::resetColors() { s_colorIndex = 0; diff --git a/PBGitRevList.mm b/PBGitRevList.mm index 952d7d9..b53a183 100644 --- a/PBGitRevList.mm +++ b/PBGitRevList.mm @@ -6,6 +6,11 @@ // Copyright 2008 __MyCompanyName__. All rights reserved. // +extern "C" +{ +#include "git/oid.h" +} + #import "PBGitRevList.h" #import "PBGitRepository.h" #import "PBGitCommit.h" @@ -116,7 +121,9 @@ using namespace std; } // From now on, 1.2 seconds - PBGitCommit* newCommit = [[PBGitCommit alloc] initWithRepository: repository andSha: [NSString stringWithUTF8String:sha.c_str()]]; + git_oid oid; + git_oid_mkstr(&oid, sha.c_str()); + PBGitCommit* newCommit = [[PBGitCommit alloc] initWithRepository:repository andSha:oid]; string author; getline(stream, author, '\0'); @@ -154,11 +161,11 @@ using namespace std; } [revisions addObject: newCommit]; - //[g decorateCommit: newCommit]; + [g decorateCommit: newCommit]; // 0.1 second on linux-2.6 - if (refs && [refs objectForKey:newCommit.sha]) - newCommit.refs = [refs objectForKey:newCommit.sha]; + if (refs && [refs objectForKey:[newCommit realSha]]) + newCommit.refs = [refs objectForKey:[newCommit realSha]]; if (++num % 1000 == 0) [self performSelectorOnMainThread:@selector(setCommits:) withObject:revisions waitUntilDone:NO]; diff --git a/PBGitTree.m b/PBGitTree.m index 722b294..e98ac3f 100644 --- a/PBGitTree.m +++ b/PBGitTree.m @@ -22,7 +22,7 @@ PBGitTree* tree = [[self alloc] init]; tree.parent = nil; tree.leaf = NO; - tree.sha = c.sha; + tree.sha = [c realSha]; tree.repository = c.repository; tree.path = @""; return tree; diff --git a/PBWebHistoryController.m b/PBWebHistoryController.m index d546c8b..e3f5575 100644 --- a/PBWebHistoryController.m +++ b/PBWebHistoryController.m @@ -38,12 +38,12 @@ return; // The sha is the same, but refs may have changed.. reload it lazy - if ([currentSha isEqualToString: content.sha]) + if ([currentSha isEqualToString: [content realSha]]) { [[self script] callWebScriptMethod:@"reload" withArguments: nil]; return; } - currentSha = content.sha; + currentSha = [content realSha]; NSArray *arguments = [NSArray arrayWithObjects:content, [[[historyController repository] headRef] simpleRef], nil]; [[self script] callWebScriptMethod:@"loadCommit" withArguments: arguments]; diff --git a/html/views/history/history.js b/html/views/history/history.js index d9b64ee..ff4b1cf 100644 --- a/html/views/history/history.js +++ b/html/views/history/history.js @@ -4,7 +4,7 @@ var Commit = function(obj) { this.refs = obj.refs; this.author_name = obj.author; - this.sha = obj.sha; + this.sha = obj.realSha(); this.parents = obj.parents; this.subject = obj.subject; diff --git a/libgit2 b/libgit2 new file mode 160000 index 0000000..bda29d0 --- /dev/null +++ b/libgit2 @@ -0,0 +1 @@ +Subproject commit bda29d0f7bc59a821b03c716562aef6ea3b5903a