Testing: add missing file
[GitX.git] / PBGitCommit.m
blob9ebe3b5753726ffbef7c3a70e46b5a549cdb8571
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 //
9 #import "PBGitCommit.h"
10 #import "PBGitDefaults.h"
12 @implementation PBGitCommit
14 @synthesize repository, subject, timestamp, author, parentShas, nParents, sign, lineInfo;
16 - (NSArray *) parents
18         if (nParents == 0)
19                 return NULL;
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;
32 - (NSDate *)date
34         return [NSDate dateWithTimeIntervalSince1970:timestamp];
37 - (NSString *) dateString
39         NSDateFormatter* formatter = [[NSDateFormatter alloc] initWithDateFormat:@"%Y-%m-%d %H:%M:%S" allowNaturalLanguage:NO];
40         return [formatter stringFromDate: self.date];
43 - (NSArray*) treeContents
45         return self.tree.children;
48 - (git_oid *)sha
50         return &sha;
53 - initWithRepository:(PBGitRepository*) repo andSha:(git_oid)newSha
55         details = nil;
56         repository = repo;
57         sha = newSha;
58         return self;
61 - (NSString *)realSha
63         char *hex = git_oid_mkhex(&sha);
64         NSString *str = [NSString stringWithUTF8String:hex];
65         free(hex);
66         return str;
69 // FIXME: Remove this method once it's unused.
70 - (NSString*) details
72         return @"";
75 - (NSString *) patch
77         if (_patch != nil)
78                 return _patch;
80         NSString *p = [repository outputForArguments:[NSArray arrayWithObjects:@"format-patch",  @"-1", @"--stdout", [self realSha], nil]];
81         // Add a GitX identifier to the patch ;)
82         _patch = [[p substringToIndex:[p length] -1] stringByAppendingString:@"+GitX"];
83         return _patch;
86 - (PBGitTree*) tree
88         return [PBGitTree rootForCommit: self];
91 - (void)addRef:(PBGitRef *)ref
93         if (!self.refs)
94                 self.refs = [NSMutableArray arrayWithObject:ref];
95         else
96                 [self.refs addObject:ref];
99 - (void)removeRef:(id)ref
101         if (!self.refs)
102                 return;
104         [self.refs removeObject:ref];
107 - (NSMutableArray *)refs
109         return [[repository refs] objectForKey:[self realSha]];
112 - (void) setRefs:(NSMutableArray *)refs
114         [[repository refs] setObject:refs forKey:[self realSha]];
117 - (void)finalize
119         free(parentShas);
120         [super finalize];
123 + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
125         return NO;
128 + (BOOL)isKeyExcludedFromWebScript:(const char *)name {
129         return NO;
131 @end