Skip to content

Commit 3af85e2

Browse files
committed
Merge branch 'refs/heads/master' into issues/182
2 parents 99fffa4 + 029f4c0 commit 3af85e2

21 files changed

+399
-103
lines changed

Classes/Controllers/PBGitHistoryController.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ - (void)awakeFromNib
7676
else
7777
[repository lazyReload];
7878

79+
if (![repository hasSVNRemote])
80+
{
81+
// Remove the SVN revision table column for repositories with no SVN remote configured
82+
[commitList removeTableColumn:[commitList tableColumnWithIdentifier:@"GitSVNRevision"]];
83+
}
84+
7985
// Set a sort descriptor for the subject column in the history list, as
8086
// It can't be sorted by default (because it's bound to a PBGitCommit)
8187
[[commitList tableColumnWithIdentifier:@"SubjectColumn"] setSortDescriptorPrototype:[[NSSortDescriptor alloc] initWithKey:@"subject" ascending:YES]];

Classes/Controllers/PBWebController.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ - (void)webView:(WebView *)sender
114114
}
115115
}
116116

117+
- (NSUInteger)webView:(WebView *)webView
118+
dragDestinationActionMaskForDraggingInfo:(id<NSDraggingInfo>)draggingInfo
119+
{
120+
return NSDragOperationNone;
121+
}
122+
117123
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
118124
{
119125
return NO;

Classes/git/PBGitCommit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extern NSString * const kGitXCommitType;
2626
NSString *_patch;
2727
NSArray *parents;
2828
NSString *realSHA;
29+
NSString *SVNRevision;
2930

3031
int timestamp;
3132
char sign;
@@ -52,6 +53,7 @@ extern NSString * const kGitXCommitType;
5253
@property (copy) NSString* subject;
5354
@property (copy) NSString* author;
5455
@property (copy) NSString *committer;
56+
@property (copy) NSString *SVNRevision;
5557
@property NSArray *parents;
5658

5759
@property (assign) int timestamp;

Classes/git/PBGitCommit.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
@implementation PBGitCommit
1818

19-
@synthesize repository, subject, timestamp, author, sign, lineInfo;
19+
@synthesize repository, subject, timestamp, author, sign, lineInfo, SVNRevision;
2020
@synthesize sha;
2121
@synthesize parents;
2222
@synthesize committer;
@@ -77,10 +77,13 @@ - (BOOL)isEqual:(id)otherCommit
7777
if (self == otherCommit)
7878
return YES;
7979

80+
if (!otherCommit)
81+
return NO;
82+
8083
if (![otherCommit isMemberOfClass:[PBGitCommit class]])
8184
return NO;
8285

83-
return [self.sha isEqual:[(PBGitCommit *)otherCommit sha]];
86+
return [self->sha isEqual:((PBGitCommit *)otherCommit)->sha];
8487
}
8588

8689
- (NSUInteger)hash

Classes/git/PBGitGrapher.mm

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@
1010
#import "PBGitCommit.h"
1111
#import "PBGitLane.h"
1212
#import "PBGitGraphLine.h"
13-
#import <list>
13+
14+
#import <vector>
1415
#import <git2/oid.h>
1516
#include <algorithm>
1617

1718
using namespace std;
19+
typedef std::vector<PBGitLane *> LaneCollection;
20+
1821

1922
@implementation PBGitGrapher
2023

2124
- (id) initWithRepository: (PBGitRepository*) repo
2225
{
23-
pl = new std::list<PBGitLane *>;
26+
pl = new LaneCollection;
2427

2528
PBGitLane::resetColors();
2629
return self;
@@ -36,8 +39,8 @@ void add_line(struct PBGitGraphLine *lines, int *nLines, int upper, int from, in
3639
- (void) decorateCommit: (PBGitCommit *) commit
3740
{
3841
int i = 0, newPos = -1;
39-
std::list<PBGitLane *> *currentLanes = new std::list<PBGitLane *>;
40-
std::list<PBGitLane *> *previousLanes = (std::list<PBGitLane *> *)pl;
42+
LaneCollection *currentLanes = new LaneCollection;
43+
LaneCollection *previousLanes = (LaneCollection *)pl;
4144
NSArray *parents = [commit parents];
4245
int nParents = [parents count];
4346

@@ -52,7 +55,7 @@ - (void) decorateCommit: (PBGitCommit *) commit
5255
// First, iterate over earlier columns and pass through any that don't want this commit
5356
if (previous != nil) {
5457
// We can't count until numColumns here, as it's only used for the width of the cell.
55-
std::list<PBGitLane *>::iterator it = previousLanes->begin();
58+
LaneCollection::iterator it = previousLanes->begin();
5659
for (; it != previousLanes->end(); ++it) {
5760
i++;
5861
if (!*it) // This is an empty lane, created when the lane previously had a parentless(root) commit
@@ -108,7 +111,7 @@ - (void) decorateCommit: (PBGitCommit *) commit
108111
git_oid parentOID = [(PBGitSHA*)[parents objectAtIndex:parentIndex] oid];
109112
int i = 0;
110113
BOOL was_displayed = NO;
111-
std::list<PBGitLane *>::iterator it = currentLanes->begin();
114+
LaneCollection::iterator it = currentLanes->begin();
112115
for (; it != currentLanes->end(); ++it) {
113116
i++;
114117
if ((*it)->isCommit(parentOID)) {
@@ -171,8 +174,8 @@ - (void) decorateCommit: (PBGitCommit *) commit
171174

172175
- (void) dealloc
173176
{
174-
std::list<PBGitLane *> *lanes = (std::list<PBGitLane *> *)pl;
175-
std::list<PBGitLane *>::iterator it = lanes->begin();
177+
LaneCollection *lanes = (LaneCollection *)pl;
178+
LaneCollection::iterator it = lanes->begin();
176179
for (; it != lanes->end(); ++it)
177180
delete *it;
178181

Classes/git/PBGitRepository.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
106106
- (BOOL)isBareRepository;
107107
+ (BOOL)isBareRepository:(NSURL*)repositoryURL;
108108

109+
- (BOOL)hasSVNRemote;
110+
+ (BOOL)hasSVNRemote:(NSURL*)repositoryURL;
109111

110112
- (void) reloadRefs;
111113
- (void) lazyReload;

Classes/git/PBGitRepository.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,32 @@ - (BOOL) isBareRepository
5656
return [PBGitRepository isBareRepository:[self fileURL]];
5757
}
5858

59+
+ (BOOL) hasSVNRemote: (NSURL *)url
60+
{
61+
// ObjectiveGit doesn't give us the machinery to determine whether there's an SVN remote
62+
// defined; so let's just find out ourselves...
63+
64+
NSError* pError;
65+
GTRepository* gitRepo = [[GTRepository alloc] initWithURL:url error:&pError];
66+
67+
if (gitRepo)
68+
{
69+
NSURL *configURL = [NSURL URLWithString:@".git/config" relativeToURL:url];
70+
NSString *gitConfig = [NSString stringWithContentsOfURL:configURL encoding:NSUTF8StringEncoding error:&pError];
71+
72+
if ([gitConfig rangeOfString:@"svn-remote"].location != NSNotFound) {
73+
return YES;
74+
}
75+
}
76+
77+
return NO;
78+
}
79+
80+
- (BOOL) hasSVNRemote
81+
{
82+
return [PBGitRepository hasSVNRemote:[self fileURL]];
83+
}
84+
5985
// NSFileWrapper is broken and doesn't work when called on a directory containing a large number of directories and files.
6086
//because of this it is safer to implement readFromURL than readFromFileWrapper.
6187
//Because NSFileManager does not attempt to recursively open all directories and file when fileExistsAtPath is called

Classes/git/PBGitRevList.mm

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ - (void) walkRevisionListWithSpecifier:(PBGitRevSpecifier*)rev
105105
std::map<string, NSStringEncoding> encodingMap;
106106
NSThread *currentThread = [NSThread currentThread];
107107

108-
NSString *formatString = @"--pretty=format:%H\03%e\03%aN\03%cN\03%s\03%P\03%at";
108+
NSString *formatString = @"--pretty=format:%H\03%e\03%aN\03%cN\03%s\03%b\03%P\03%at";
109+
109110
BOOL showSign = [rev hasLeftRight];
110111

111112
if (showSign)
@@ -132,6 +133,10 @@ - (void) walkRevisionListWithSpecifier:(PBGitRevSpecifier*)rev
132133
__gnu_cxx::stdio_filebuf<char> buf(fd, std::ios::in);
133134
std::istream stream(&buf);
134135

136+
// Regular expression for pulling out the SVN revision from the git log
137+
NSError *error = nil;
138+
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^git-svn-id: .*@(\\d+) .*$" options:NSRegularExpressionAnchorsMatchLines error:&error];
139+
135140
int num = 0;
136141
while (true) {
137142
if ([currentThread isCancelled])
@@ -167,6 +172,9 @@ - (void) walkRevisionListWithSpecifier:(PBGitRevSpecifier*)rev
167172

168173
string subject;
169174
getline(stream, subject, '\3');
175+
176+
string message;
177+
getline(stream, message, '\3');
170178

171179
string parentString;
172180
getline(stream, parentString, '\3');
@@ -197,6 +205,31 @@ - (void) walkRevisionListWithSpecifier:(PBGitRevSpecifier*)rev
197205
[newCommit setSubject:[NSString stringWithCString:subject.c_str() encoding:encoding]];
198206
[newCommit setAuthor:[NSString stringWithCString:author.c_str() encoding:encoding]];
199207
[newCommit setCommitter:[NSString stringWithCString:committer.c_str() encoding:encoding]];
208+
209+
if ([repository hasSVNRemote])
210+
{
211+
// get the git-svn-id from the subject
212+
NSString *string = [NSString stringWithCString:subject.c_str() encoding:encoding];
213+
NSArray *matches = [regex matchesInString:string options:0 range:NSMakeRange(0, [string length])];
214+
for (NSTextCheckingResult *match in matches)
215+
{
216+
NSRange matchRange = [match rangeAtIndex:1];
217+
NSString *matchString = [string substringWithRange:matchRange];
218+
[newCommit setSVNRevision:matchString];
219+
}
220+
221+
// get the git-svn-id from the message
222+
string = [NSString stringWithCString:message.c_str() encoding:encoding];
223+
matches = [regex matchesInString:string options:0 range:NSMakeRange(0, [string length])];
224+
225+
for (NSTextCheckingResult *match in matches)
226+
{
227+
NSRange matchRange = [match rangeAtIndex:1];
228+
NSString *matchString = [string substringWithRange:matchRange];
229+
[newCommit setSVNRevision:matchString];
230+
}
231+
}
232+
200233
[newCommit setTimestamp:time];
201234

202235
if (showSign)

Classes/git/PBGitSHA.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ - (BOOL)isEqual:(id)otherSHA
9999
if (self == otherSHA)
100100
return YES;
101101

102-
git_oid other_oid = [(PBGitSHA *)otherSHA oid];
102+
if (!otherSHA)
103+
return NO;
104+
105+
git_oid other_oid = ((PBGitSHA *)otherSHA)->oid;
103106
return git_oid_cmp(&oid, &other_oid) == 0;
104107
}
105108

0 commit comments

Comments
 (0)