Skip to content

Commit

Permalink
Refactoring. MRC removal. Part two. (#857)
Browse files Browse the repository at this point in the history
* kit: interface node mrc has been removed.

* kit: core repository reflog mrc has been removed.

* kit: core snapshot mrc has been removed.

* kit: interface graph view mrc has been removed.

* kit: macos target has been updated.
  • Loading branch information
lolgear authored Nov 3, 2022
1 parent 9282c9b commit 26cc95c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 116 deletions.
39 changes: 10 additions & 29 deletions GitUpKit/Core/GCRepository+Reflog.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#if __has_feature(objc_arc)
#error This file requires MRC
#endif

#import "GCPrivate.h"

@implementation GCReflogEntry {
Expand Down Expand Up @@ -44,12 +40,12 @@ - (id)initWithRepository:(GCRepository*)repository entry:(const git_reflog_entry

git_oid_cpy(&_fromOID, git_reflog_entry_id_old(entry));
if (!git_oid_iszero(&_fromOID)) {
_fromSHA1 = [GCGitOIDToSHA1(&_fromOID) retain];
_fromSHA1 = [GCGitOIDToSHA1(&_fromOID) copy];
_fromCommit = _LoadCommit(_repository, &_fromOID);
}
git_oid_cpy(&_toOID, git_reflog_entry_id_new(entry));
if (!git_oid_iszero(&_toOID)) {
_toSHA1 = [GCGitOIDToSHA1(&_toOID) retain];
_toSHA1 = [GCGitOIDToSHA1(&_toOID) copy];
_toCommit = _LoadCommit(_repository, &_toOID);
} else {
XLOG_DEBUG_UNREACHABLE();
Expand All @@ -65,20 +61,6 @@ - (id)initWithRepository:(GCRepository*)repository entry:(const git_reflog_entry
return self;
}

- (void)dealloc {
[_fromSHA1 release];
[_fromCommit release];
[_toSHA1 release];
[_toCommit release];
[_committerName release];
[_committerEmail release];

[_references release];
[_messages release];

[super dealloc];
}

- (const git_oid*)fromOID {
return &_fromOID;
}
Expand Down Expand Up @@ -198,13 +180,13 @@ static inline BOOL _EqualEntries(GCReflogEntry* entry1, GCReflogEntry* entry2) {
}

static Boolean _EntryEqualCallBack(const void* value1, const void* value2) {
GCReflogEntry* entry1 = (GCReflogEntry*)value1;
GCReflogEntry* entry2 = (GCReflogEntry*)value2;
GCReflogEntry* entry1 = (__bridge GCReflogEntry*)value1;
GCReflogEntry* entry2 = (__bridge GCReflogEntry*)value2;
return _EqualEntries(entry1, entry2);
}

static CFHashCode _EntryHashCallBack(const void* value) {
GCReflogEntry* entry = (GCReflogEntry*)value;
GCReflogEntry* entry = (__bridge GCReflogEntry*)value;
return *((CFHashCode*)&entry->_fromOID);
}

Expand Down Expand Up @@ -238,13 +220,12 @@ - (NSArray*)loadReflogEntriesForReference:(GCReference*)reference error:(NSError
GCReflogEntry* reflogEntry = [[GCReflogEntry alloc] initWithRepository:self entry:entry];
[reflogEntry addReference:reference withMessage:git_reflog_entry_message(entry)];
[entries addObject:reflogEntry];
[reflogEntry release];
}
}
git_reflog_free(reflog);
[entries sortUsingSelector:@selector(reverseTimeCompare:)];
}
return [entries autorelease];
return entries;
}

- (NSArray*)loadAllReflogEntries:(NSError**)error {
Expand Down Expand Up @@ -283,11 +264,11 @@ - (NSArray*)loadAllReflogEntries:(NSError**)error {
[entries addObject:reflogEntry];
CFSetAddValue(cache, (const void*)reflogEntry);
}
[reflogEntry release];
reflogEntry = nil;
}
}

[reference release];
reference = nil;
git_reflog_free(reflog);
} else {
git_reference_free(rawReference);
Expand All @@ -296,11 +277,11 @@ - (NSArray*)loadAllReflogEntries:(NSError**)error {
}];
CFRelease(cache);
if (!success) {
[entries release];
entries = nil;
return nil;
}
[entries sortUsingSelector:@selector(reverseTimeCompare:)];
return [entries autorelease];
return entries;
}

@end
55 changes: 21 additions & 34 deletions GitUpKit/Core/GCSnapshot.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#if __has_feature(objc_arc)
#error This file requires MRC
#endif

#import "GCPrivate.h"

// SPIs from libgit2
Expand Down Expand Up @@ -89,7 +85,7 @@ + (BOOL)supportsSecureCoding {

- (id)initWithReference:(git_reference*)reference resolvedObject:(git_object*)object {
if ((self = [super init])) {
_name = [_NSDataFromCString(git_reference_name(reference)) retain];
_name = [_NSDataFromCString(git_reference_name(reference)) copy];
_type = git_reference_type(reference);
switch (_type) {
case GIT_REF_OID: {
Expand All @@ -99,14 +95,13 @@ - (id)initWithReference:(git_reference*)reference resolvedObject:(git_object*)ob
}

case GIT_REF_SYMBOLIC: {
_symbol = [_NSDataFromCString(git_reference_symbolic_target(reference)) retain];
_symbol = [_NSDataFromCString(git_reference_symbolic_target(reference)) copy];
XLOG_DEBUG_CHECK(_symbol.length);
break;
}

default: {
XLOG_DEBUG_UNREACHABLE();
[self release];
return nil;
}
}
Expand All @@ -123,10 +118,8 @@ - (id)initWithReference:(git_reference*)reference resolvedObject:(git_object*)ob
}

- (void)dealloc {
[_symbol release];
[_name release];

[super dealloc];
_symbol = nil;
_name = nil;
}

- (void)encodeWithCoder:(NSCoder*)coder {
Expand All @@ -140,7 +133,7 @@ - (void)encodeWithCoder:(NSCoder*)coder {

- (id)initWithCoder:(NSCoder*)decoder {
if ((self = [super init])) {
_name = [[decoder decodeObjectOfClass:[NSData class] forKey:@"name"] retain];
_name = [[decoder decodeObjectOfClass:[NSData class] forKey:@"name"] copy];
XLOG_DEBUG_CHECK(_name);
_type = [decoder decodeIntForKey:@"type"];
XLOG_DEBUG_CHECK((_type == GIT_REF_OID) || (_type == GIT_REF_SYMBOLIC));
Expand All @@ -153,7 +146,7 @@ - (id)initWithCoder:(NSCoder*)decoder {
XLOG_DEBUG_UNREACHABLE();
}

_symbol = [[decoder decodeObjectOfClass:[NSData class] forKey:@"symbol"] retain];
_symbol = [[decoder decodeObjectOfClass:[NSData class] forKey:@"symbol"] copy];

_resolvedType = [decoder decodeIntForKey:@"resolved_type"];

Expand Down Expand Up @@ -268,7 +261,7 @@ + (BOOL)supportsSecureCoding {
- (id)initWithRepository:(GCRepository*)repository error:(NSError**)error {
if ((self = [super init])) {
// Capture local config
_config = [_LoadRepositoryConfig(repository, error) retain];
_config = _LoadRepositoryConfig(repository, error);
if (_config == nil) {
return nil;
}
Expand All @@ -292,8 +285,7 @@ - (id)initWithRepository:(GCRepository*)repository error:(NSError**)error {
GCSerializedReference* serializedReference = [[GCSerializedReference alloc] initWithReference:reference resolvedObject:object];
[_serializedReferences addObject:serializedReference];
XLOG_DEBUG_CHECK(!CFDictionaryContainsKey(_cache, serializedReference.name));
CFDictionarySetValue(_cache, serializedReference.name, serializedReference);
[serializedReference release];
CFDictionarySetValue(_cache, serializedReference.name, (__bridge const void *)(serializedReference));

git_object_free(object);
return YES;
Expand All @@ -309,11 +301,9 @@ - (id)initWithRepository:(GCRepository*)repository error:(NSError**)error {

- (void)dealloc {
CFRelease(_cache);
[_info release];
[_serializedReferences release];
[_config release];

[super dealloc];
_info = nil;
_serializedReferences = nil;
_config = nil;
}

- (void)encodeWithCoder:(NSCoder*)coder {
Expand All @@ -324,18 +314,18 @@ - (void)encodeWithCoder:(NSCoder*)coder {

- (id)initWithCoder:(NSCoder*)decoder {
if ((self = [super init])) {
_config = [[decoder decodeObjectOfClass:[NSMutableDictionary class] forKey:@"config"] retain];
_config = [decoder decodeObjectOfClass:[NSMutableDictionary class] forKey:@"config"];
XLOG_DEBUG_CHECK(_config);
_serializedReferences = [[decoder decodeObjectOfClass:[NSMutableArray class] forKey:@"serialized_references"] retain];
_serializedReferences = [decoder decodeObjectOfClass:[NSMutableArray class] forKey:@"serialized_references"];
XLOG_DEBUG_CHECK(_serializedReferences);
_info = [[decoder decodeObjectOfClass:[NSMutableDictionary class] forKey:@"info"] retain];
_info = [decoder decodeObjectOfClass:[NSMutableDictionary class] forKey:@"info"];
XLOG_DEBUG_CHECK(_info);

CFDictionaryKeyCallBacks callbacks = {0, NULL, NULL, NULL, GCCStringEqualCallBack, GCCStringHashCallBack};
_cache = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &callbacks, NULL);
for (GCSerializedReference* serializedReference in _serializedReferences) {
XLOG_DEBUG_CHECK(!CFDictionaryContainsKey(_cache, serializedReference.name));
CFDictionarySetValue(_cache, serializedReference.name, serializedReference);
CFDictionarySetValue(_cache, serializedReference.name, (__bridge const void *)(serializedReference));
}
}
return self;
Expand All @@ -350,7 +340,7 @@ - (NSString*)description {
for (GCSerializedReference* serializedReference in _serializedReferences) {
[description appendFormat:@"\n %s = %s", serializedReference.name, serializedReference.symbolicTarget ? serializedReference.symbolicTarget : git_oid_tostr_s(serializedReference.directTarget)];
}
return [description autorelease];
return description;
}

@end
Expand Down Expand Up @@ -469,7 +459,7 @@ - (BOOL)isEqual:(id)object {
@implementation GCRepository (GCSnapshot)

- (GCSnapshot*)takeSnapshot:(NSError**)error {
return [[[GCSnapshot alloc] initWithRepository:self error:error] autorelease];
return [[GCSnapshot alloc] initWithRepository:self error:error];
}

static BOOL _UpdateRepositoryConfig(GCRepository* repository, NSDictionary* changes, NSError** error) {
Expand Down Expand Up @@ -524,8 +514,6 @@ static void _DiffConfigsForLocalBranch(const char* name, NSDictionary* fromConfi
[changes setObject:copy[toVariable] forKey:toVariable];
}
}

[copy release];
}

- (BOOL)_restoreFromReferences:(NSArray*)fromReferences
Expand Down Expand Up @@ -579,7 +567,7 @@ - (BOOL)_restoreFromReferences:(NSArray*)fromReferences

// Finally recreate references present in "to" but missing in "from"
GCDictionaryApplyBlock(copy, ^(const void* key, const void* value) {
GCSerializedReference* toSerializedReference = (const void*)value;
GCSerializedReference* toSerializedReference = (__bridge GCSerializedReference *)value;
if (!_ShouldSkipReference(toSerializedReference.name, options)) {
switch (toSerializedReference.type) {
case GIT_REF_OID:
Expand Down Expand Up @@ -623,9 +611,9 @@ - (BOOL)_restoreFromReferences:(NSArray*)fromReferences
success = YES;

cleanup:
[changes release];
changes = nil;
CFRelease(copy);
[transform release];
transform = nil;
return success;
}

Expand All @@ -644,13 +632,12 @@ - (BOOL)restoreSnapshot:(GCSnapshot*)snapshot
usingBlock:^BOOL(git_reference* reference) {
GCSerializedReference* serializedReference = [[GCSerializedReference alloc] initWithReference:reference resolvedObject:NULL];
[references addObject:serializedReference];
[serializedReference release];
return YES;
}];
if (result) {
result = [self _restoreFromReferences:references andConfig:config toSnapshot:snapshot withOptions:options reflogMessage:message didUpdateReferences:didUpdateReferences error:error];
}
[references release];
references = nil;
return result;
}

Expand Down
8 changes: 4 additions & 4 deletions GitUpKit/GitUpKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@
E267E1E21B84D83100BAB377 /* GCRepository+Config.m in Sources */ = {isa = PBXBuildFile; fileRef = E24508FF1A9A50EA003E602D /* GCRepository+Config.m */; };
E267E1E31B84D83100BAB377 /* GCRepository+HEAD.m in Sources */ = {isa = PBXBuildFile; fileRef = E27F9B731A549097009C9B3D /* GCRepository+HEAD.m */; };
E267E1E41B84D83100BAB377 /* GCRepository+Mock.m in Sources */ = {isa = PBXBuildFile; fileRef = E299D0121A749C26005035F7 /* GCRepository+Mock.m */; };
E267E1E51B84D83100BAB377 /* GCRepository+Reflog.m in Sources */ = {isa = PBXBuildFile; fileRef = E27B6D651A84451900D05452 /* GCRepository+Reflog.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
E267E1E51B84D83100BAB377 /* GCRepository+Reflog.m in Sources */ = {isa = PBXBuildFile; fileRef = E27B6D651A84451900D05452 /* GCRepository+Reflog.m */; };
E267E1E61B84D83100BAB377 /* GCRepository+Reset.m in Sources */ = {isa = PBXBuildFile; fileRef = E20EB08A19FC75CA0031A075 /* GCRepository+Reset.m */; };
E267E1E71B84D83100BAB377 /* GCRepository+Status.m in Sources */ = {isa = PBXBuildFile; fileRef = E20EB08E19FC76160031A075 /* GCRepository+Status.m */; };
E267E1E81B84D83100BAB377 /* GCSnapshot.m in Sources */ = {isa = PBXBuildFile; fileRef = E2F5C27D1A8171C900C30739 /* GCSnapshot.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
E267E1E81B84D83100BAB377 /* GCSnapshot.m in Sources */ = {isa = PBXBuildFile; fileRef = E2F5C27D1A8171C900C30739 /* GCSnapshot.m */; };
E267E1E91B84D83100BAB377 /* GCSQLiteRepository.m in Sources */ = {isa = PBXBuildFile; fileRef = E299D00A1A71F0E9005035F7 /* GCSQLiteRepository.m */; };
E267E1EA1B84D83100BAB377 /* GCStash.m in Sources */ = {isa = PBXBuildFile; fileRef = E2C338E719F85C8600063D95 /* GCStash.m */; };
E267E1EB1B84D83100BAB377 /* GCSubmodule.m in Sources */ = {isa = PBXBuildFile; fileRef = E21739FD1A51FA6200EC6777 /* GCSubmodule.m */; };
Expand All @@ -210,10 +210,10 @@
E267E2161B84DB6E00BAB377 /* GIDiffView.m in Sources */ = {isa = PBXBuildFile; fileRef = E2891AB51AE1684A00E58C77 /* GIDiffView.m */; };
E267E2171B84DB6E00BAB377 /* GIFunctions.m in Sources */ = {isa = PBXBuildFile; fileRef = E2B1BF321A85923800A999DF /* GIFunctions.m */; };
E267E2181B84DB6E00BAB377 /* GIGraph.m in Sources */ = {isa = PBXBuildFile; fileRef = E2D4DEA11A4D562300B6AF66 /* GIGraph.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
E267E2191B84DB6E00BAB377 /* GIGraphView.m in Sources */ = {isa = PBXBuildFile; fileRef = E2D4DEA31A4D562300B6AF66 /* GIGraphView.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
E267E2191B84DB6E00BAB377 /* GIGraphView.m in Sources */ = {isa = PBXBuildFile; fileRef = E2D4DEA31A4D562300B6AF66 /* GIGraphView.m */; };
E267E21A1B84DB6E00BAB377 /* GILayer.m in Sources */ = {isa = PBXBuildFile; fileRef = E2D4DEB11A4D599200B6AF66 /* GILayer.m */; };
E267E21B1B84DB6E00BAB377 /* GILine.m in Sources */ = {isa = PBXBuildFile; fileRef = E2D4DEAB1A4D587800B6AF66 /* GILine.m */; };
E267E21C1B84DB6E00BAB377 /* GINode.m in Sources */ = {isa = PBXBuildFile; fileRef = E2D4DEA71A4D57AA00B6AF66 /* GINode.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
E267E21C1B84DB6E00BAB377 /* GINode.m in Sources */ = {isa = PBXBuildFile; fileRef = E2D4DEA71A4D57AA00B6AF66 /* GINode.m */; };
E267E21D1B84DB6E00BAB377 /* GIPrivate.m in Sources */ = {isa = PBXBuildFile; fileRef = E21A88F21A9471B300255AC3 /* GIPrivate.m */; };
E267E21E1B84DB6E00BAB377 /* GISplitDiffView.m in Sources */ = {isa = PBXBuildFile; fileRef = E2891AB21AE15BB600E58C77 /* GISplitDiffView.m */; };
E267E21F1B84DB6E00BAB377 /* GIUnifiedDiffView.m in Sources */ = {isa = PBXBuildFile; fileRef = E2C9FF871AA510170051B2AE /* GIUnifiedDiffView.m */; };
Expand Down
Loading

0 comments on commit 26cc95c

Please sign in to comment.