Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 155 lines (122 sloc) 2.638 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
57 - initWithRepository:(PBGitRepository*) repo andSha:(git_oid)newSha
b752f5b @pieter Add a search field and subject
pieter authored
58 {
3a672ae @pieter Cache commit details so we have to fork less
pieter authored
59 details = nil;
d2eafc2 @pieter Include libgit2 as submodule and use it to store sha's
pieter authored
60 repository = repo;
61 sha = newSha;
b752f5b @pieter Add a search field and subject
pieter authored
62 return self;
63 }
64
d2eafc2 @pieter Include libgit2 as submodule and use it to store sha's
pieter authored
65 - (NSString *)realSha
66 {
67 char *hex = git_oid_mkhex(&sha);
68 NSString *str = [NSString stringWithUTF8String:hex];
69 free(hex);
70 return str;
71 }
72
0363eea @pieter HistoryView: don't load in commit information in a separate thread anymo...
pieter authored
73 // FIXME: Remove this method once it's unused.
b752f5b @pieter Add a search field and subject
pieter authored
74 - (NSString*) details
75 {
0363eea @pieter HistoryView: don't load in commit information in a separate thread anymo...
pieter authored
76 return @"";
b752f5b @pieter Add a search field and subject
pieter authored
77 }
79e9ba9 @pieter Add a detailed HTML view
pieter authored
78
c6966ad @pieter HistoryView: Add a method to put a commit online
pieter authored
79 - (NSString *) patch
80 {
81 if (_patch != nil)
82 return _patch;
83
2bab86c @pieter GitCommit: Fix patch generation
pieter authored
84 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
85 // Add a GitX identifier to the patch ;)
86 _patch = [[p substringToIndex:[p length] -1] stringByAppendingString:@"+GitX"];
c6966ad @pieter HistoryView: Add a method to put a commit online
pieter authored
87 return _patch;
88 }
89
9be3c50 @pieter Add a Tree displayer
pieter authored
90 - (PBGitTree*) tree
91 {
92 return [PBGitTree rootForCommit: self];
93 }
94
d38c195 Fix moving of refs
Pieter de Bie authored
95 - (void)addRef:(PBGitRef *)ref
4cefe8e @pieter HistoryView: Allow dragging of refs to move them
pieter authored
96 {
97 if (!self.refs)
98 self.refs = [NSMutableArray arrayWithObject:ref];
99 else
100 [self.refs addObject:ref];
101 }
102
8a399c0 @pieter GitCommit: Add a 'removeRef' function
pieter authored
103 - (void)removeRef:(id)ref
104 {
105 if (!self.refs)
106 return;
107
ddc9ae7 @pieter PBGitCommit: Don't store refs
pieter authored
108 [self.refs removeObject:ref];
109 }
110
111 - (NSMutableArray *)refs
112 {
113 return [[repository refs] objectForKey:[self realSha]];
114 }
115
116 - (void) setRefs:(NSMutableArray *)refs
117 {
d38c195 Fix moving of refs
Pieter de Bie authored
118 [[repository refs] setObject:refs forKey:[self realSha]];
8a399c0 @pieter GitCommit: Add a 'removeRef' function
pieter authored
119 }
120
8372aee @pieter PBGitCommit: Use git_oids for parent shas
pieter authored
121 - (void)finalize
122 {
123 free(parentShas);
124 [super finalize];
125 }
126
79e9ba9 @pieter Add a detailed HTML view
pieter authored
127 + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
128 {
129 return NO;
130 }
131
132 + (BOOL)isKeyExcludedFromWebScript:(const char *)name {
133 return NO;
134 }
39def32 @brotherbard Add <PBGitRefish> protocol.
brotherbard authored
135
136
137 #pragma mark <PBGitRefish>
138
139 - (NSString *) refishName
140 {
141 return [self realSha];
142 }
143
144 - (NSString *) shortName
145 {
146 return [[self realSha] substringToIndex:10];
147 }
148
149 - (NSString *) refishType
150 {
151 return kGitXCommitType;
152 }
153
b752f5b @pieter Add a search field and subject
pieter authored
154 @end
Something went wrong with that request. Please try again.