From 3ba6535c56dbec729b43005a9387bbe5917f5ac8 Mon Sep 17 00:00:00 2001 From: Rowan James Date: Mon, 4 Feb 2013 22:54:48 +1100 Subject: [PATCH] Use libgit2 to find the workdir directly, instead of Objective-Git Fixes #140 --- Classes/git/GitRepoFinder.m | 20 +++++++++++++++++--- Classes/gitx.m | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Classes/git/GitRepoFinder.m b/Classes/git/GitRepoFinder.m index 09d02880c..9d3460349 100644 --- a/Classes/git/GitRepoFinder.m +++ b/Classes/git/GitRepoFinder.m @@ -12,9 +12,23 @@ @implementation GitRepoFinder + (NSURL*)workDirForURL:(NSURL*)fileURL; { - GTRepository* repo = [[GTRepository alloc] initWithURL:fileURL - error:nil]; - NSURL* result = repo.fileURL; + if (!fileURL.isFileURL) + { + return nil; + } + git_repository* repo = nil; + git_repository_open_ext(&repo, fileURL.path.UTF8String, GIT_REPOSITORY_OPEN_CROSS_FS, NULL); + if (!repo) + { + return nil; + } + const char* workdir = git_repository_workdir(repo); + NSURL* result = nil; + if (workdir) + { + result = [NSURL fileURLWithPath:[NSString stringWithUTF8String:workdir]]; + } + git_repository_free(repo); repo = nil; return result; } diff --git a/Classes/gitx.m b/Classes/gitx.m index 701299675..ca0aea8e8 100644 --- a/Classes/gitx.m +++ b/Classes/gitx.m @@ -320,7 +320,7 @@ void handleGitXSearch(NSURL *repositoryURL, NSMutableArray *arguments) NSString *pwd = [[[NSProcessInfo processInfo] environment] objectForKey:@"PWD"]; NSURL* pwdURL = [NSURL fileURLWithPath:pwd]; - NSURL* repoURL = [GitRepoFinder workDirForURL:pwdURL]; + NSURL* repoURL = [GitRepoFinder fileURLForURL:pwdURL]; return repoURL; }