Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 138 lines (111 sloc) 2.567 kb
b752f5b @pieter Add a search field and subject
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
ddc9ae7 @pieter PBGitCommit: Don't store refs
authored
14 @synthesize repository, subject, timestamp, author, parentShas, nParents, sign, lineInfo;
3979787 @pieter Optimize rev-list parsing
authored
15
8372aee @pieter PBGitCommit: Use git_oids for parent shas
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
authored
31
483cbc9 @pieter GitCommit: store the date as a timestamp
authored
32 - (NSDate *)date
33 {
34 return [NSDate dateWithTimeIntervalSince1970:timestamp];
35 }
36
3979787 @pieter Optimize rev-list parsing
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
authored
42
3106379 @pieter Use unified interface and display tree contents
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
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
authored
54 {
3a672ae @pieter Cache commit details so we have to fork less
authored
55 details = nil;
d2eafc2 @pieter Include libgit2 as submodule and use it to store sha's
authored
56 repository = repo;
57 sha = newSha;
b752f5b @pieter Add a search field and subject
authored
58 return self;
59 }
60
d2eafc2 @pieter Include libgit2 as submodule and use it to store sha's
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
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
authored
71 - (NSString*) details
72 {
3a672ae @pieter Cache commit details so we have to fork less
authored
73 if (details != nil)
74 return details;
75
22f4ac3 @pieter Show renames changes by default
authored
76 details = [self.repository outputForArguments:[NSArray arrayWithObjects:@"show", @"--pretty=raw", @"-M", [self realSha], nil]];
d8b926c use outputForCommand instead of handleForCommand to save code, remove zo...
Bryce Kerley authored
77
e6da252 @pieter Add shortcuts and menu items for different views
authored
78 return details;
b752f5b @pieter Add a search field and subject
authored
79 }
79e9ba9 @pieter Add a detailed HTML view
authored
80
c6966ad @pieter HistoryView: Add a method to put a commit online
authored
81 - (NSString *) patch
82 {
83 if (_patch != nil)
84 return _patch;
85
2bab86c @pieter GitCommit: Fix patch generation
authored
86 NSString *p = [repository outputForArguments:[NSArray arrayWithObjects:@"format-patch", @"-1", @"--stdout", [self realSha], nil]];
d4f2b4a @pieter GitCommit: Add a GitX identifier to the patch output
authored
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
authored
89 return _patch;
90 }
91
9be3c50 @pieter Add a Tree displayer
authored
92 - (PBGitTree*) tree
93 {
94 return [PBGitTree rootForCommit: self];
95 }
96
d38c195 Fix moving of refs
Pieter de Bie authored
97 - (void)addRef:(PBGitRef *)ref
4cefe8e @pieter HistoryView: Allow dragging of refs to move them
authored
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
authored
105 - (void)removeRef:(id)ref
106 {
107 if (!self.refs)
108 return;
109
ddc9ae7 @pieter PBGitCommit: Don't store refs
authored
110 [self.refs removeObject:ref];
111 }
112
113 - (NSMutableArray *)refs
114 {
115 return [[repository refs] objectForKey:[self realSha]];
116 }
117
118 - (void) setRefs:(NSMutableArray *)refs
119 {
d38c195 Fix moving of refs
Pieter de Bie authored
120 [[repository refs] setObject:refs forKey:[self realSha]];
8a399c0 @pieter GitCommit: Add a 'removeRef' function
authored
121 }
122
8372aee @pieter PBGitCommit: Use git_oids for parent shas
authored
123 - (void)finalize
124 {
125 free(parentShas);
126 [super finalize];
127 }
128
79e9ba9 @pieter Add a detailed HTML view
authored
129 + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
130 {
131 return NO;
132 }
133
134 + (BOOL)isKeyExcludedFromWebScript:(const char *)name {
135 return NO;
136 }
b752f5b @pieter Add a search field and subject
authored
137 @end
Something went wrong with that request. Please try again.