Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a diff window

This allows you to do something like

	gitx --diff

to display a diff similar to 'git diff', but with GitX prettification.

It accepts all git diff parameters, so you can do something like

	gitx --diff HEAD~10

to show the diff compared to the last 10 commits. Or, you can something like

	git diff | gitx

to pipe anything that produces a diff to GitX
  • Loading branch information...
commit e8131c3898a7d831faa76b9f45460ec18adeb48a 1 parent e054a17
Pieter de Bie authored
34 GitX.xcodeproj/project.pbxproj
View
@@ -63,6 +63,9 @@
F5C007750E731B48007B84B2 /* PBGitRef.m in Sources */ = {isa = PBXBuildFile; fileRef = F5C007740E731B48007B84B2 /* PBGitRef.m */; };
F5C6F68D0E65FF9300478D97 /* PBGitLane.m in Sources */ = {isa = PBXBuildFile; fileRef = F5C6F68C0E65FF9300478D97 /* PBGitLane.m */; };
F5DFFA6C0E075D8800617813 /* PBEasyFS.m in Sources */ = {isa = PBXBuildFile; fileRef = F5DFFA6B0E075D8800617813 /* PBEasyFS.m */; };
+ F5E424110EA3E4D60046E362 /* PBDiffWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = F5E424100EA3E4D60046E362 /* PBDiffWindow.xib */; };
+ F5E424150EA3E4E10046E362 /* PBDiffWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = F5E424130EA3E4E10046E362 /* PBDiffWindowController.m */; };
+ F5E424180EA3E4EB0046E362 /* PBWebDiffController.m in Sources */ = {isa = PBXBuildFile; fileRef = F5E424160EA3E4EB0046E362 /* PBWebDiffController.m */; };
F5E4DBFB0EAB58D90013FAFC /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F5E4DBFA0EAB58D90013FAFC /* SystemConfiguration.framework */; };
F5E926060E8827D300056E75 /* PBViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F5E926050E8827D300056E75 /* PBViewController.m */; };
F5E927F80E883E7200056E75 /* PBChangedFile.m in Sources */ = {isa = PBXBuildFile; fileRef = F5E927F70E883E7200056E75 /* PBChangedFile.m */; };
@@ -190,6 +193,11 @@
F5D2DC850EA401A80034AD24 /* PBGitConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitConfig.h; sourceTree = "<group>"; };
F5DFFA6A0E075D8800617813 /* PBEasyFS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBEasyFS.h; sourceTree = "<group>"; };
F5DFFA6B0E075D8800617813 /* PBEasyFS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBEasyFS.m; sourceTree = "<group>"; };
+ F5E424100EA3E4D60046E362 /* PBDiffWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PBDiffWindow.xib; sourceTree = "<group>"; };
+ F5E424130EA3E4E10046E362 /* PBDiffWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBDiffWindowController.m; sourceTree = "<group>"; };
+ F5E424140EA3E4E10046E362 /* PBDiffWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBDiffWindowController.h; sourceTree = "<group>"; };
+ F5E424160EA3E4EB0046E362 /* PBWebDiffController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBWebDiffController.m; sourceTree = "<group>"; };
+ F5E424170EA3E4EB0046E362 /* PBWebDiffController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBWebDiffController.h; sourceTree = "<group>"; };
F5E4DBFA0EAB58D90013FAFC /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = /System/Library/Frameworks/SystemConfiguration.framework; sourceTree = "<absolute>"; };
F5E926040E8827D300056E75 /* PBViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBViewController.h; sourceTree = "<group>"; };
F5E926050E8827D300056E75 /* PBViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBViewController.m; sourceTree = "<group>"; };
@@ -311,6 +319,7 @@
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */,
F5B721C20E05CF7E00AF29DC /* MainMenu.xib */,
911111E00E58BD5A00BF76B4 /* RepositoryWindow.xib */,
+ F5E424100EA3E4D60046E362 /* PBDiffWindow.xib */,
F52BCE020E84208300AA3741 /* PBGitHistoryView.xib */,
F59116E50E843BB50072CCB1 /* PBGitCommitView.xib */,
);
@@ -347,6 +356,7 @@
F56174540E05887E001DCD79 /* Git */ = {
isa = PBXGroup;
children = (
+ F5E424120EA3E4DD0046E362 /* Diff */,
F5E927E30E883D6800056E75 /* Commit */,
F5E927E10E883D2E00056E75 /* History */,
F5945E150E02B0C200706420 /* PBGitRepository.h */,
@@ -362,6 +372,7 @@
F57CC3850E05DDC1000472E2 /* Controllers */ = {
isa = PBXGroup;
children = (
+ F5B161BB0EAB6E0C005A1DE1 /* Diff */,
F5EF8C880E9D498F0050906B /* History */,
F5E927F90E883EF600056E75 /* Commit */,
77C8280B06725ACE000B614F /* ApplicationController.h */,
@@ -421,6 +432,15 @@
name = HTML;
sourceTree = "<group>";
};
+ F5B161BB0EAB6E0C005A1DE1 /* Diff */ = {
+ isa = PBXGroup;
+ children = (
+ F5E424140EA3E4E10046E362 /* PBDiffWindowController.h */,
+ F5E424130EA3E4E10046E362 /* PBDiffWindowController.m */,
+ );
+ name = Diff;
+ sourceTree = "<group>";
+ };
F5C6F6750E65FE2B00478D97 /* Graphing */ = {
isa = PBXGroup;
children = (
@@ -438,6 +458,15 @@
name = Graphing;
sourceTree = "<group>";
};
+ F5E424120EA3E4DD0046E362 /* Diff */ = {
+ isa = PBXGroup;
+ children = (
+ F5E424160EA3E4EB0046E362 /* PBWebDiffController.m */,
+ F5E424170EA3E4EB0046E362 /* PBWebDiffController.h */,
+ );
+ name = Diff;
+ sourceTree = "<group>";
+ };
F5E927E10E883D2E00056E75 /* History */ = {
isa = PBXGroup;
children = (
@@ -575,6 +604,7 @@
F5E92A230E88569500056E75 /* new_file.png in Resources */,
F5EC2DAD0E8C235C000FA381 /* spinner.gif in Resources */,
F57240BB0E9678EA00D8EE66 /* deleted_file.png in Resources */,
+ F5E424110EA3E4D60046E362 /* PBDiffWindow.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -620,8 +650,10 @@
F53C4DF70E97FC630022AD59 /* PBGitBinary.m in Sources */,
F593DF780E9E636C003A8559 /* PBFileChangesTableView.m in Sources */,
93F7857F0EA3ABF100C1F443 /* PBCommitMessageView.m in Sources */,
- 93FCCBA90EA8AF450061B02B /* PBGitConfig.m in Sources */,
93CB42C20EAB7B2200530609 /* PBGitDefaults.m in Sources */,
+ F5D2DC870EA401A80034AD24 /* PBGitConfig.m in Sources */,
+ F5E424150EA3E4E10046E362 /* PBDiffWindowController.m in Sources */,
+ F5E424180EA3E4EB0046E362 /* PBWebDiffController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
1  PBCLIProxy.h
View
@@ -21,4 +21,5 @@
@protocol GitXCliToolProtocol
- (BOOL)openRepository:(NSURL*)repositoryPath arguments: (NSArray*) args error:(NSError**)error;
+- (void)openDiffWindowWithDiff:(NSString *)diff;
@end
8 PBCLIProxy.mm
View
@@ -12,6 +12,7 @@
#import "PBGitRepository.h"
#import "PBGitWindowController.h"
#import "PBGitBinary.h"
+#import "PBDiffWindowController.h"
@implementation PBCLIProxy
@synthesize connection;
@@ -61,4 +62,11 @@ - (BOOL)openRepository:(NSURL*)repositoryPath arguments: (NSArray*) args error:(
return YES;
}
+
+- (void)openDiffWindowWithDiff:(NSString *)diff
+{
+ PBDiffWindowController *diffController = [[PBDiffWindowController alloc] initWithDiff:[diff copy]];
+ [diffController showWindow:nil];
+ [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
+}
@end
302 PBDiffWindow.xib
View
@@ -0,0 +1,302 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.02">
+ <data>
+ <int key="IBDocument.SystemTarget">1050</int>
+ <string key="IBDocument.SystemVersion">9F33</string>
+ <string key="IBDocument.InterfaceBuilderVersion">670</string>
+ <string key="IBDocument.AppKitVersion">949.34</string>
+ <string key="IBDocument.HIToolboxVersion">352.00</string>
+ <object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <integer value="1" id="9"/>
+ </object>
+ <object class="NSArray" key="IBDocument.PluginDependencies">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>com.apple.WebKitIBPlugin</string>
+ <string>com.apple.InterfaceBuilderKit</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ </object>
+ <object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSCustomObject" id="1001">
+ <string key="NSClassName">PBDiffWindowController</string>
+ </object>
+ <object class="NSCustomObject" id="1003">
+ <string key="NSClassName">FirstResponder</string>
+ </object>
+ <object class="NSCustomObject" id="1004">
+ <string key="NSClassName">NSApplication</string>
+ </object>
+ <object class="NSCustomObject" id="1068009310">
+ <string key="NSClassName">PBWebDiffController</string>
+ </object>
+ <object class="NSWindowTemplate" id="693309652">
+ <int key="NSWindowStyleMask">15</int>
+ <int key="NSWindowBacking">2</int>
+ <string key="NSWindowRect">{{196, 240}, {480, 270}}</string>
+ <int key="NSWTFlags">603979776</int>
+ <string key="NSWindowTitle">GitX Diff</string>
+ <string key="NSWindowClass">NSWindow</string>
+ <nil key="NSViewClass"/>
+ <string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string>
+ <object class="NSView" key="NSWindowView" id="49049747">
+ <reference key="NSNextResponder"/>
+ <int key="NSvFlags">256</int>
+ <object class="NSMutableArray" key="NSSubviews">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="WebView" id="426284859">
+ <reference key="NSNextResponder" ref="49049747"/>
+ <int key="NSvFlags">274</int>
+ <object class="NSMutableSet" key="NSDragTypes">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSMutableArray" key="set.sortedObjects">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>Apple HTML pasteboard type</string>
+ <string>Apple PICT pasteboard type</string>
+ <string>Apple URL pasteboard type</string>
+ <string>Apple Web Archive pasteboard type</string>
+ <string>NSColor pasteboard type</string>
+ <string>NSFilenamesPboardType</string>
+ <string>NSStringPboardType</string>
+ <string>NeXT RTFD pasteboard type</string>
+ <string>NeXT Rich Text Format v1.0 pasteboard type</string>
+ <string>NeXT TIFF v4.0 pasteboard type</string>
+ <string>WebURLsWithTitlesPboardType</string>
+ <string>public.url</string>
+ <string>public.url-name</string>
+ </object>
+ </object>
+ <string key="NSFrameSize">{480, 270}</string>
+ <reference key="NSSuperview" ref="49049747"/>
+ <reference key="NSNextKeyView"/>
+ <string key="FrameName"/>
+ <string key="GroupName"/>
+ <object class="WebPreferences" key="Preferences">
+ <string key="Identifier"/>
+ <object class="NSMutableDictionary" key="Values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSMutableArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>WebKitDefaultFixedFontSize</string>
+ <string>WebKitDefaultFontSize</string>
+ <string>WebKitMinimumFontSize</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <integer value="12" id="1030250856"/>
+ <reference ref="1030250856"/>
+ <reference ref="9"/>
+ </object>
+ </object>
+ </object>
+ <bool key="UseBackForwardList">YES</bool>
+ <bool key="AllowsUndo">YES</bool>
+ </object>
+ </object>
+ <string key="NSFrameSize">{480, 270}</string>
+ <reference key="NSSuperview"/>
+ </object>
+ <string key="NSScreenRect">{{0, 0}, {1680, 1028}}</string>
+ <string key="NSMaxSize">{3.40282e+38, 3.40282e+38}</string>
+ <string key="NSFrameAutosaveName">DiffWindow</string>
+ </object>
+ </object>
+ <object class="IBObjectContainer" key="IBDocument.Objects">
+ <object class="NSMutableArray" key="connectionRecords">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">window</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="693309652"/>
+ </object>
+ <int key="connectionID">6</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">view</string>
+ <reference key="source" ref="1068009310"/>
+ <reference key="destination" ref="426284859"/>
+ </object>
+ <int key="connectionID">9</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">frameLoadDelegate</string>
+ <reference key="source" ref="426284859"/>
+ <reference key="destination" ref="1068009310"/>
+ </object>
+ <int key="connectionID">10</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">UIDelegate</string>
+ <reference key="source" ref="426284859"/>
+ <reference key="destination" ref="1068009310"/>
+ </object>
+ <int key="connectionID">11</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">diffController</string>
+ <reference key="source" ref="1068009310"/>
+ <reference key="destination" ref="1001"/>
+ </object>
+ <int key="connectionID">12</int>
+ </object>
+ </object>
+ <object class="IBMutableOrderedSet" key="objectRecords">
+ <object class="NSArray" key="orderedObjects">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBObjectRecord">
+ <int key="objectID">0</int>
+ <object class="NSArray" key="object" id="1002">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ <reference key="children" ref="1000"/>
+ <nil key="parent"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-2</int>
+ <reference key="object" ref="1001"/>
+ <reference key="parent" ref="1002"/>
+ <string type="base64-UTF8" key="objectName">RmlsZSdzIE93bmVyA</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-1</int>
+ <reference key="object" ref="1003"/>
+ <reference key="parent" ref="1002"/>
+ <string key="objectName">First Responder</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-3</int>
+ <reference key="object" ref="1004"/>
+ <reference key="parent" ref="1002"/>
+ <string key="objectName">Application</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">1</int>
+ <reference key="object" ref="693309652"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="49049747"/>
+ </object>
+ <reference key="parent" ref="1002"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">2</int>
+ <reference key="object" ref="49049747"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="426284859"/>
+ </object>
+ <reference key="parent" ref="693309652"/>
+ <string key="objectName">Diff View</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">7</int>
+ <reference key="object" ref="426284859"/>
+ <reference key="parent" ref="49049747"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">8</int>
+ <reference key="object" ref="1068009310"/>
+ <reference key="parent" ref="1002"/>
+ </object>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="flattenedProperties">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSMutableArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>-1.IBPluginDependency</string>
+ <string>-2.IBPluginDependency</string>
+ <string>-3.IBPluginDependency</string>
+ <string>1.IBEditorWindowLastContentRect</string>
+ <string>1.IBPluginDependency</string>
+ <string>1.IBWindowTemplateEditedContentRect</string>
+ <string>1.NSWindowTemplate.visibleAtLaunch</string>
+ <string>1.windowTemplate.maxSize</string>
+ <string>2.IBPluginDependency</string>
+ <string>7.IBPluginDependency</string>
+ <string>8.IBPluginDependency</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilderKit</string>
+ <string>com.apple.InterfaceBuilderKit</string>
+ <string>{{312, 725}, {480, 270}}</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>{{312, 725}, {480, 270}}</string>
+ <reference ref="9"/>
+ <string>{3.40282e+38, 3.40282e+38}</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.WebKitIBPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="unlocalizedProperties">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ </object>
+ <nil key="activeLocalization"/>
+ <object class="NSMutableDictionary" key="localizations">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ </object>
+ <nil key="sourceID"/>
+ <int key="maxID">12</int>
+ </object>
+ <object class="IBClassDescriber" key="IBDocument.Classes">
+ <object class="NSMutableArray" key="referencedPartialClassDescriptions">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBPartialClassDescription">
+ <string key="className">PBDiffWindowController</string>
+ <string key="superclassName">NSWindowController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">PBDiffWindowController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">PBWebController</string>
+ <string key="superclassName">NSObject</string>
+ <object class="NSMutableDictionary" key="outlets">
+ <string key="NS.key.0">view</string>
+ <string key="NS.object.0">WebView</string>
+ </object>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">PBWebController.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">PBWebDiffController</string>
+ <string key="superclassName">PBWebController</string>
+ <object class="NSMutableDictionary" key="outlets">
+ <string key="NS.key.0">diffController</string>
+ <string key="NS.object.0">PBDiffWindowController</string>
+ </object>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">PBWebDiffController.h</string>
+ </object>
+ </object>
+ </object>
+ </object>
+ <int key="IBDocument.localizationMode">0</int>
+ <string key="IBDocument.LastKnownRelativeProjectPath">GitX.xcodeproj</string>
+ <int key="IBDocument.defaultPropertyAccessControl">3</int>
+ </data>
+</archive>
18 PBDiffWindowController.h
View
@@ -0,0 +1,18 @@
+//
+// PBDiffWindowController.h
+// GitX
+//
+// Created by Pieter de Bie on 13-10-08.
+// Copyright 2008 Pieter de Bie. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface PBDiffWindowController : NSWindowController {
+ NSString *diff;
+}
+
+- initWithDiff:(NSString *)diff;
+@property (readonly) NSString *diff;
+@end
24 PBDiffWindowController.m
View
@@ -0,0 +1,24 @@
+//
+// PBDiffWindowController.m
+// GitX
+//
+// Created by Pieter de Bie on 13-10-08.
+// Copyright 2008 Pieter de Bie. All rights reserved.
+//
+
+#import "PBDiffWindowController.h"
+
+
+@implementation PBDiffWindowController
+@synthesize diff;
+
+- (id) initWithDiff:(NSString *)aDiff
+{
+ if (![super initWithWindowNibName:@"PBDiffWindow"])
+ return nil;
+
+ diff = aDiff;
+ return self;
+}
+
+@end
18 PBWebDiffController.h
View
@@ -0,0 +1,18 @@
+//
+// PBWebDiffController.h
+// GitX
+//
+// Created by Pieter de Bie on 13-10-08.
+// Copyright 2008 Pieter de Bie. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+#import "PBWebController.h"
+#import "PBDiffWindowController.h"
+
+@interface PBWebDiffController : PBWebController {
+ IBOutlet PBDiffWindowController *diffController;
+}
+
+- (void) showDiff:(NSString *)diff;
+@end
41 PBWebDiffController.m
View
@@ -0,0 +1,41 @@
+//
+// PBWebDiffController.m
+// GitX
+//
+// Created by Pieter de Bie on 13-10-08.
+// Copyright 2008 Pieter de Bie. All rights reserved.
+//
+
+#import "PBWebDiffController.h"
+
+
+@implementation PBWebDiffController
+
+- (void) awakeFromNib
+{
+ startFile = @"simpleDiff";
+ [super awakeFromNib];
+ [diffController addObserver:self forKeyPath:@"diff" options:0 context:@"ChangedDiff"];
+}
+
+- (void) didLoad
+{
+ [self showDiff:diffController.diff];
+}
+
+- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(NSString *)context
+{
+ if ([context isEqualToString: @"ChangedDiff"])
+ [self showDiff:diffController.diff];
+}
+
+- (void) showDiff: (NSString *) diff
+{
+ if (diff == nil || !finishedLoading)
+ return;
+
+ id script = [view windowScriptObject];
+ [script callWebScriptMethod:@"showDiff" withArguments: [NSArray arrayWithObject:diff]];
+}
+
+@end
121 gitx.mm
View
@@ -8,6 +8,7 @@
#import "PBCLIProxy.h"
#import "PBGitBinary.h"
+#import "PBEasyPipe.h"
NSDistantObject* connect()
{
@@ -16,6 +17,33 @@
return proxy;
}
+NSDistantObject *createProxy()
+{
+ NSDistantObject *proxy = connect();
+
+ if (proxy)
+ return proxy;
+
+ // The connection failed, so try to launch the app
+ [[NSWorkspace sharedWorkspace] launchAppWithBundleIdentifier: @"nl.frim.GitX"
+ options: NSWorkspaceLaunchWithoutActivation
+ additionalEventParamDescriptor: nil
+ launchIdentifier: nil];
+
+ // Now attempt to connect, allowing the app time to startup
+ for (int attempt = 0; proxy == nil && attempt < 50; ++attempt) {
+ if (proxy = connect())
+ return proxy;
+
+ usleep(15000);
+ }
+
+ // not succesful!
+ fprintf(stderr, "Couldn't connect to app server!\n");
+ exit(1);
+ return nil;
+}
+
void usage(char const *programName)
{
@@ -46,6 +74,32 @@ void version_info()
exit(1);
}
+void handleSTDINDiff(id<GitXCliToolProtocol> proxy)
+{
+ NSFileHandle *handle = [NSFileHandle fileHandleWithStandardInput];
+ NSData *data = [handle readDataToEndOfFile];
+ NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
+
+ if (string && [string length] > 0) {
+ [proxy openDiffWindowWithDiff:string];
+ exit(0);
+ }
+}
+
+void handleDiffWithArguments(NSArray *arguments, NSString *directory, id<GitXCliToolProtocol> proxy)
+{
+ int ret;
+ arguments = [[NSArray arrayWithObject:@"diff"] arrayByAddingObjectsFromArray:arguments];
+ NSString *diff = [PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:arguments inDir:directory retValue:&ret];
+ if (ret) {
+ printf("Invalid diff command\n");
+ exit(3);
+ }
+
+ [proxy openDiffWindowWithDiff:diff];
+ exit(0);
+}
+
int main(int argc, const char** argv)
{
if (argc >= 2 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")))
@@ -59,43 +113,34 @@ int main(int argc, const char** argv)
}
// Attempt to connect to the app
- id proxy = connect();
-
- if (!proxy) {
- // If the connection failed, try to launch the app
- [[NSWorkspace sharedWorkspace] launchAppWithBundleIdentifier: @"nl.frim.GitX"
- options: NSWorkspaceLaunchWithoutActivation
- additionalEventParamDescriptor: nil
- launchIdentifier: nil];
-
- // Now attempt to connect, allowing the app time to startup
- for (int attempt = 0; proxy == nil && attempt < 50; ++attempt){
- if (proxy = connect())
- break;
- usleep(15000);
- }
- }
- if (!proxy) {
- fprintf(stderr, "Couldn't connect to app server!\n");
- exit(1);
- }
+ id proxy = createProxy();
- if ([[[NSProcessInfo processInfo] environment] objectForKey:@"PWD"]) {
- int i;
- argv++; argc--;
- NSURL* url = [NSURL fileURLWithPath:[[[NSProcessInfo processInfo] environment] objectForKey:@"PWD"]];
-
- NSMutableArray* arguments = [NSMutableArray arrayWithCapacity:argc];
- for (i = 0; i < argc; i++)
- [arguments addObject: [NSString stringWithCString:argv[i]]];
-
- NSError* error = nil;
- if (![proxy openRepository:url arguments: arguments error:&error]) {
- fprintf(stderr, "Error opening repository at %s", [[url path] UTF8String]);
- if (error) {
- fprintf(stderr, ": %s", [[error localizedFailureReason] UTF8String]);
- }
- fprintf(stderr, "\n");
- }
+ // Create arguments
+ argv++; argc--;
+ NSMutableArray* arguments = [NSMutableArray arrayWithCapacity:argc];
+ int i = 0;
+ for (i = 0; i < argc; i++)
+ [arguments addObject: [NSString stringWithCString:argv[i]]];
+
+ if (!isatty(STDIN_FILENO) && fdopen(STDIN_FILENO, "r"))
+ handleSTDINDiff(proxy);
+
+ // From this point, we require a working directory
+ NSString *pwd = [[[NSProcessInfo processInfo] environment] objectForKey:@"PWD"];
+ if (!pwd)
+ exit(2);
+
+ if ([arguments count] > 0 && ([[arguments objectAtIndex:0] isEqualToString:@"--diff"] ||
+ [[arguments objectAtIndex:0] isEqualToString:@"-d"]))
+ handleDiffWithArguments([arguments subarrayWithRange:NSMakeRange(1, [arguments count] - 1)], pwd, proxy);
+
+ // No diff, just open the current dir
+ NSURL* url = [NSURL fileURLWithPath:pwd];
+ NSError* error = nil;
+
+ if (![proxy openRepository:url arguments: arguments error:&error]) {
+ fprintf(stderr, "Error opening repository at %s\n", [[url path] UTF8String]);
+ if (error)
+ fprintf(stderr, "\t%s\n", [[error localizedFailureReason] UTF8String]);
}
-}
+}
19 html/simpleDiff.html
View
@@ -0,0 +1,19 @@
+<html>
+<head>
+ <title>Details for commit</title>
+ <link rel="stylesheet" href="commits.css" type="text/css" media="screen" title="no title" charset="utf-8">
+ <link rel="stylesheet" href="diff_style.css" type="text/css" media="screen" title="no title" charset="utf-8">
+ <script src="prototype.js" type="text/javascript" charset="utf-8"></script>
+ <script src="diffHighlighter.js" type="text/javascript" charset="utf-8"></script>
+ <script type="text/javascript" charset="utf-8">
+
+ var showDiff = function(diff) {
+ document.getElementById("details").innerHTML = diff.escapeHTML();
+ highlightDiffs();
+ }
+ </script>
+</head>
+
+<body style="padding: 0px; border: 0px">
+ <pre><code class="diffcode" id='details'></code></pre>
+</body>
Please sign in to comment.
Something went wrong with that request. Please try again.