Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 130 lines (105 sloc) 2.378 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"
10
11
12 @implementation PBGitCommit
13
483cbc9 @pieter GitCommit: store the date as a timestamp
pieter authored
14 @synthesize repository, subject, timestamp, author, parentShas, nParents, sign, lineInfo, refs;
3979787 @pieter Optimize rev-list parsing
pieter authored
15
8372aee @pieter PBGitCommit: Use git_oids for parent shas
pieter authored
16 - (NSArray *) parents
17 {
18 if (nParents == 0)
19 return NULL;
20
21 int i;
22 NSMutableArray *p = [NSMutableArray arrayWithCapacity:nParents];
23 for (i = 0; i < nParents; ++i)
24 {
25 char *s = git_oid_mkhex(parentShas + i);
26 [p addObject:[NSString stringWithUTF8String:s]];
27 free(s);
28 }
29 return p;
30 }
3979787 @pieter Optimize rev-list parsing
pieter authored
31
483cbc9 @pieter GitCommit: store the date as a timestamp
pieter authored
32 - (NSDate *)date
33 {
34 return [NSDate dateWithTimeIntervalSince1970:timestamp];
35 }
36
3979787 @pieter Optimize rev-list parsing
pieter authored
37 - (NSString *) dateString
38 {
39 NSDateFormatter* formatter = [[NSDateFormatter alloc] initWithDateFormat:@"%Y-%m-%d %H:%M:%S" allowNaturalLanguage:NO];
40 return [formatter stringFromDate: self.date];
41 }
b752f5b @pieter Add a search field and subject
pieter authored
42
3106379 @pieter Use unified interface and display tree contents
pieter authored
43 - (NSArray*) treeContents
44 {
45 return self.tree.children;
46 }
47
d2eafc2 @pieter Include libgit2 as submodule and use it to store sha's
pieter authored
48 - (git_oid *)sha
49 {
50 return &sha;
51 }
52
53 - initWithRepository:(PBGitRepository*) repo andSha:(git_oid)newSha
b752f5b @pieter Add a search field and subject
pieter authored
54 {
3a672ae @pieter Cache commit details so we have to fork less
pieter authored
55 details = nil;
d2eafc2 @pieter Include libgit2 as submodule and use it to store sha's
pieter authored
56 repository = repo;
57 sha = newSha;
b752f5b @pieter Add a search field and subject
pieter authored
58 return self;
59 }
60
d2eafc2 @pieter Include libgit2 as submodule and use it to store sha's
pieter authored
61 - (NSString *)realSha
62 {
63 char *hex = git_oid_mkhex(&sha);
64 NSString *str = [NSString stringWithUTF8String:hex];
65 free(hex);
66 return str;
67 }
68
b7645ec @pieter PBWebHistoryController: show the commit diff async
pieter authored
69 // NOTE: This method should remain threadsafe, as we load it in async
70 // from the web view.
b752f5b @pieter Add a search field and subject
pieter authored
71 - (NSString*) details
72 {
3a672ae @pieter Cache commit details so we have to fork less
pieter authored
73 if (details != nil)
74 return details;
75
d2eafc2 @pieter Include libgit2 as submodule and use it to store sha's
pieter authored
76 details = [self.repository outputForCommand:[@"show --pretty=raw " stringByAppendingString:[self realSha]]];
d8b926c use outputForCommand instead of handleForCommand to save code, remove…
Bryce Kerley authored
77
e6da252 @pieter Add shortcuts and menu items for different views
pieter authored
78 return details;
b752f5b @pieter Add a search field and subject
pieter authored
79 }
79e9ba9 @pieter Add a detailed HTML view
pieter authored
80
c6966ad @pieter HistoryView: Add a method to put a commit online
pieter authored
81 - (NSString *) patch
82 {
83 if (_patch != nil)
84 return _patch;
85
d4f2b4a @pieter GitCommit: Add a GitX identifier to the patch output
pieter authored
86 NSString *p = [repository outputForArguments:[NSArray arrayWithObjects:@"format-patch", @"-1", @"--stdout", sha, nil]];
87 // Add a GitX identifier to the patch ;)
88 _patch = [[p substringToIndex:[p length] -1] stringByAppendingString:@"+GitX"];
c6966ad @pieter HistoryView: Add a method to put a commit online
pieter authored
89 return _patch;
90 }
91
9be3c50 @pieter Add a Tree displayer
pieter authored
92 - (PBGitTree*) tree
93 {
94 return [PBGitTree rootForCommit: self];
95 }
96
4cefe8e @pieter HistoryView: Allow dragging of refs to move them
pieter authored
97 - (void)addRef:(id)ref
98 {
99 if (!self.refs)
100 self.refs = [NSMutableArray arrayWithObject:ref];
101 else
102 [self.refs addObject:ref];
103 }
104
8a399c0 @pieter GitCommit: Add a 'removeRef' function
pieter authored
105 - (void)removeRef:(id)ref
106 {
107 if (!self.refs)
108 return;
109
110 [refs removeObject:ref];
111 if ([refs count] == 0)
112 refs = NULL;
113 }
114
8372aee @pieter PBGitCommit: Use git_oids for parent shas
pieter authored
115 - (void)finalize
116 {
117 free(parentShas);
118 [super finalize];
119 }
120
79e9ba9 @pieter Add a detailed HTML view
pieter authored
121 + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
122 {
123 return NO;
124 }
125
126 + (BOOL)isKeyExcludedFromWebScript:(const char *)name {
127 return NO;
128 }
b752f5b @pieter Add a search field and subject
pieter authored
129 @end
Something went wrong with that request. Please try again.