Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't load fixins when it's opendiff rather than Xcode that's loading.

This is to cut down on terminal output when using opendiff from the
terminal via git difftool.

(It's open to debate whether this is the best thing to do. Other options
might be cutting down on the NSLog calls, only logging if isatty(stderr),
etc.)
  • Loading branch information...
commit 49df716448a73861045ce7a16986ae81933f3e2e 1 parent a9a284d
@tom-seddon tom-seddon authored
Showing with 66 additions and 22 deletions.
  1. +30 −22 Shared Code/XCFixin.h
  2. +36 −0 Shared Code/XCFixin.m
View
52 Shared Code/XCFixin.h
@@ -1,27 +1,35 @@
#import <Foundation/Foundation.h>
-#define XCFixinPreflight() \
- static NSUInteger loadAttempt = 0; \
- loadAttempt++; \
- NSLog(@"%@ initialization attempt %ju/%ju...", NSStringFromClass([self class]), (uintmax_t)loadAttempt, (uintmax_t)XCFixinMaxLoadAttempts);
-
-#define XCFixinPostflight() \
- NSLog(@"%@ initialization successful!", NSStringFromClass([self class])); \
- return; \
- failed: \
- { \
- NSLog(@"%@ initialization failed.", NSStringFromClass([self class])); \
- \
- if (loadAttempt < XCFixinMaxLoadAttempts) \
- { \
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC), dispatch_get_main_queue(), \
- ^(void) \
- { \
- [self pluginDidLoad: plugin]; \
- }); \
- } \
- \
- else NSLog(@"%@ failing permanently. :(", NSStringFromClass([self class])); \
+BOOL XCFixinShouldLoad(void);
+
+#define XCFixinPreflight() \
+ if (!XCFixinShouldLoad()) \
+ return; \
+ \
+ static NSUInteger loadAttempt = 0; \
+ loadAttempt++; \
+ NSLog(@"%@ initialization attempt %ju/%ju...", \
+ NSStringFromClass([self class]), \
+ (uintmax_t)loadAttempt, \
+ (uintmax_t)XCFixinMaxLoadAttempts);
+
+#define XCFixinPostflight() \
+ NSLog(@"%@ initialization successful!", NSStringFromClass([self class])); \
+ return; \
+ failed: \
+ { \
+ NSLog(@"%@ initialization failed.", NSStringFromClass([self class])); \
+ \
+ if (loadAttempt < XCFixinMaxLoadAttempts) \
+ { \
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC), dispatch_get_main_queue(), \
+ ^(void) \
+ { \
+ [self pluginDidLoad: plugin]; \
+ }); \
+ } \
+ \
+ else NSLog(@"%@ failing permanently. :(", NSStringFromClass([self class])); \
}
#define XCFixinAssertMessageFormat @"Assertion failed (file: %s, function: %s, line: %u): %s\n"
View
36 Shared Code/XCFixin.m
@@ -2,6 +2,42 @@
#import <objc/runtime.h>
+// tries to figure out (based on the main bundle path) whether the app named
+// by `appFileName' is the one that's loading.
+static BOOL IsApp(NSString *appFileName)
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
+
+ NSString *lastPathComponent = [bundlePath lastPathComponent];
+
+ NSComparisonResult cmpResult = [lastPathComponent compare:appFileName
+ options:NSCaseInsensitiveSearch];
+
+ //NSLog(@"bundlePath=%@; lastPathComponent=%@; appFileName=%@; same=%d\n",bundlePath,lastPathComponent,appFileName,(int)same);
+
+ [pool drain];
+ pool = nil;
+
+ if (cmpResult != NSOrderedSame)
+ return NO;
+
+ return YES;
+}
+
+BOOL XCFixinShouldLoad(void)
+{
+ if (IsApp(@"FileMerge.app"))
+ {
+ // Don't load plugins as part of opendiff; they mostly don't
+ // work, and they spam stdout when running from the terminal.
+ return NO;
+ }
+
+ return YES;
+}
+
const NSUInteger XCFixinMaxLoadAttempts = 3;
IMP XCFixinOverrideMethod(Class class, SEL selector, IMP newImplementation)
{
Please sign in to comment.
Something went wrong with that request. Please try again.