Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 195 lines (152 sloc) 3.361 kB
b752f5b @pieter Add a search field and subject
pieter authored
1 //
2 // PBGitCommit.m
3 // GitTest
4 //
5 // Created by Pieter de Bie on 13-06-08.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "PBGitCommit.h"
c00f736 @pieter Add preference to ignore whitespace differences in history view
pieter authored
10 #import "PBGitDefaults.h"
b752f5b @pieter Add a search field and subject
pieter authored
11
39def32 @brotherbard Add <PBGitRefish> protocol.
brotherbard authored
12
13 NSString * const kGitXCommitType = @"commit";
14
15
b752f5b @pieter Add a search field and subject
pieter authored
16 @implementation PBGitCommit
17
ddc9ae7 @pieter PBGitCommit: Don't store refs
pieter authored
18 @synthesize repository, subject, timestamp, author, parentShas, nParents, sign, lineInfo;
e067390 @brotherbard Bugfix: Stop committer names from getting mangled
brotherbard authored
19 @synthesize committer;
3979787 @pieter Optimize rev-list parsing
pieter authored
20
8372aee @pieter PBGitCommit: Use git_oids for parent shas
pieter authored
21 - (NSArray *) parents
22 {
23 if (nParents == 0)
24 return NULL;
25
26 int i;
27 NSMutableArray *p = [NSMutableArray arrayWithCapacity:nParents];
28 for (i = 0; i < nParents; ++i)
29 {
30 char *s = git_oid_mkhex(parentShas + i);
31 [p addObject:[NSString stringWithUTF8String:s]];
32 free(s);
33 }
34 return p;
35 }
3979787 @pieter Optimize rev-list parsing
pieter authored
36
483cbc9 @pieter GitCommit: store the date as a timestamp
pieter authored
37 - (NSDate *)date
38 {
39 return [NSDate dateWithTimeIntervalSince1970:timestamp];
40 }
41
3979787 @pieter Optimize rev-list parsing
pieter authored
42 - (NSString *) dateString
43 {
44 NSDateFormatter* formatter = [[NSDateFormatter alloc] initWithDateFormat:@"%Y-%m-%d %H:%M:%S" allowNaturalLanguage:NO];
45 return [formatter stringFromDate: self.date];
46 }
b752f5b @pieter Add a search field and subject
pieter authored
47
3106379 @pieter Use unified interface and display tree contents
pieter authored
48 - (NSArray*) treeContents
49 {
50 return self.tree.children;
51 }
52
d2eafc2 @pieter Include libgit2 as submodule and use it to store sha's
pieter authored
53 - (git_oid *)sha
54 {
55 return &sha;
56 }
57
b61028a @brotherbard Add support methods needed for future commits.
brotherbard authored
58 + commitWithRepository:(PBGitRepository*)repo andSha:(git_oid)newSha
59 {
60 return [[[self alloc] initWithRepository:repo andSha:newSha] autorelease];
61 }
62
d2eafc2 @pieter Include libgit2 as submodule and use it to store sha's
pieter authored
63 - initWithRepository:(PBGitRepository*) repo andSha:(git_oid)newSha
b752f5b @pieter Add a search field and subject
pieter authored
64 {
3a672ae @pieter Cache commit details so we have to fork less
pieter authored
65 details = nil;
d2eafc2 @pieter Include libgit2 as submodule and use it to store sha's
pieter authored
66 repository = repo;
67 sha = newSha;
b752f5b @pieter Add a search field and subject
pieter authored
68 return self;
69 }
70
d2eafc2 @pieter Include libgit2 as submodule and use it to store sha's
pieter authored
71 - (NSString *)realSha
72 {
b61028a @brotherbard Add support methods needed for future commits.
brotherbard authored
73 if (!realSHA) {
74 char *hex = git_oid_mkhex(&sha);
75 realSHA = [NSString stringWithUTF8String:hex];
76 free(hex);
77 }
78
79 return realSHA;
80 }
81
82 - (BOOL) isOnSameBranchAs:(PBGitCommit *)other
83 {
84 if (!other)
85 return NO;
86
87 NSString *mySHA = [self realSha];
88 NSString *otherSHA = [other realSha];
89
90 if ([otherSHA isEqualToString:mySHA])
91 return YES;
92
46b6057 @brotherbard Speed up commit's isOnSameBranch
brotherbard authored
93 return [repository isOnSameBranch:otherSHA asSHA:mySHA];
b61028a @brotherbard Add support methods needed for future commits.
brotherbard authored
94 }
95
96 - (BOOL) isOnHeadBranch
97 {
98 return [self isOnSameBranchAs:[repository headCommit]];
d2eafc2 @pieter Include libgit2 as submodule and use it to store sha's
pieter authored
99 }
100
0363eea @pieter HistoryView: don't load in commit information in a separate thread an…
pieter authored
101 // FIXME: Remove this method once it's unused.
b752f5b @pieter Add a search field and subject
pieter authored
102 - (NSString*) details
103 {
0363eea @pieter HistoryView: don't load in commit information in a separate thread an…
pieter authored
104 return @"";
b752f5b @pieter Add a search field and subject
pieter authored
105 }
79e9ba9 @pieter Add a detailed HTML view
pieter authored
106
c6966ad @pieter HistoryView: Add a method to put a commit online
pieter authored
107 - (NSString *) patch
108 {
109 if (_patch != nil)
110 return _patch;
111
2bab86c @pieter GitCommit: Fix patch generation
pieter authored
112 NSString *p = [repository outputForArguments:[NSArray arrayWithObjects:@"format-patch", @"-1", @"--stdout", [self realSha], nil]];
d4f2b4a @pieter GitCommit: Add a GitX identifier to the patch output
pieter authored
113 // Add a GitX identifier to the patch ;)
114 _patch = [[p substringToIndex:[p length] -1] stringByAppendingString:@"+GitX"];
c6966ad @pieter HistoryView: Add a method to put a commit online
pieter authored
115 return _patch;
116 }
117
9be3c50 @pieter Add a Tree displayer
pieter authored
118 - (PBGitTree*) tree
119 {
120 return [PBGitTree rootForCommit: self];
121 }
122
d38c195 Fix moving of refs
Pieter de Bie authored
123 - (void)addRef:(PBGitRef *)ref
4cefe8e @pieter HistoryView: Allow dragging of refs to move them
pieter authored
124 {
125 if (!self.refs)
126 self.refs = [NSMutableArray arrayWithObject:ref];
127 else
128 [self.refs addObject:ref];
129 }
130
8a399c0 @pieter GitCommit: Add a 'removeRef' function
pieter authored
131 - (void)removeRef:(id)ref
132 {
133 if (!self.refs)
134 return;
135
ddc9ae7 @pieter PBGitCommit: Don't store refs
pieter authored
136 [self.refs removeObject:ref];
137 }
138
b61028a @brotherbard Add support methods needed for future commits.
brotherbard authored
139 - (BOOL) hasRef:(PBGitRef *)ref
140 {
141 if (!self.refs)
142 return NO;
143
144 for (PBGitRef *existingRef in self.refs)
145 if ([existingRef isEqualToRef:ref])
146 return YES;
147
148 return NO;
149 }
150
ddc9ae7 @pieter PBGitCommit: Don't store refs
pieter authored
151 - (NSMutableArray *)refs
152 {
153 return [[repository refs] objectForKey:[self realSha]];
154 }
155
156 - (void) setRefs:(NSMutableArray *)refs
157 {
d38c195 Fix moving of refs
Pieter de Bie authored
158 [[repository refs] setObject:refs forKey:[self realSha]];
8a399c0 @pieter GitCommit: Add a 'removeRef' function
pieter authored
159 }
160
8372aee @pieter PBGitCommit: Use git_oids for parent shas
pieter authored
161 - (void)finalize
162 {
163 free(parentShas);
164 [super finalize];
165 }
166
79e9ba9 @pieter Add a detailed HTML view
pieter authored
167 + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
168 {
169 return NO;
170 }
171
172 + (BOOL)isKeyExcludedFromWebScript:(const char *)name {
173 return NO;
174 }
39def32 @brotherbard Add <PBGitRefish> protocol.
brotherbard authored
175
176
177 #pragma mark <PBGitRefish>
178
179 - (NSString *) refishName
180 {
181 return [self realSha];
182 }
183
184 - (NSString *) shortName
185 {
186 return [[self realSha] substringToIndex:10];
187 }
188
189 - (NSString *) refishType
190 {
191 return kGitXCommitType;
192 }
193
b752f5b @pieter Add a search field and subject
pieter authored
194 @end
Something went wrong with that request. Please try again.