Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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