forked from andreberg/gitx
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows to read in arbitrary blobs from the repository. For more information, see the CallingFromWebKit.txt document in the Documentation/ directory.
- Loading branch information
Showing
7 changed files
with
164 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// PBGitXProtocol.h | ||
// GitX | ||
// | ||
// Created by Pieter de Bie on 01-11-08. | ||
// Copyright 2008 Pieter de Bie. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
#import "PBGitRepository.h" | ||
|
||
@interface PBGitXProtocol : NSURLProtocol { | ||
NSFileHandle *handle; | ||
} | ||
@end | ||
|
||
@interface NSURLRequest (PBGitXProtocol) | ||
@property (readonly) PBGitRepository *repository; | ||
@end | ||
|
||
@interface NSMutableURLRequest (PBGitXProtocol) | ||
@property (retain) PBGitRepository *repository; | ||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// | ||
// PBGitXProtocol.m | ||
// GitX | ||
// | ||
// Created by Pieter de Bie on 01-11-08. | ||
// Copyright 2008 Pieter de Bie. All rights reserved. | ||
// | ||
|
||
#import "PBGitXProtocol.h" | ||
|
||
|
||
@implementation PBGitXProtocol | ||
|
||
+ (BOOL) canInitWithRequest:(NSURLRequest *)request | ||
{ | ||
return [[[request URL] scheme] isEqualToString:@"GitX"]; | ||
} | ||
|
||
+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request | ||
{ | ||
return request; | ||
} | ||
|
||
-(void)startLoading | ||
{ | ||
NSURL *url = [[self request] URL]; | ||
PBGitRepository *repo = [[self request] repository]; | ||
|
||
if(!repo) { | ||
[[self client] URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:nil]]; | ||
return; | ||
} | ||
|
||
NSString *specifier = [NSString stringWithFormat:@"%@:%@", [url host], [[url path] substringFromIndex:1]]; | ||
handle = [repo handleInWorkDirForArguments:[NSArray arrayWithObjects:@"cat-file", @"blob", specifier, nil]]; | ||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishFileLoad:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle]; | ||
[handle readToEndOfFileInBackgroundAndNotify]; | ||
|
||
NSURLResponse *response = [[NSURLResponse alloc] initWithURL:[[self request] URL] | ||
MIMEType:nil | ||
expectedContentLength:-1 | ||
textEncodingName:nil]; | ||
|
||
[[self client] URLProtocol:self | ||
didReceiveResponse:response | ||
cacheStoragePolicy:NSURLCacheStorageNotAllowed]; | ||
} | ||
|
||
- (void) didFinishFileLoad:(NSNotification *)notification | ||
{ | ||
NSData *data = [[notification userInfo] valueForKey:NSFileHandleNotificationDataItem]; | ||
[[self client] URLProtocol:self didLoadData:data]; | ||
[[self client] URLProtocolDidFinishLoading:self]; | ||
} | ||
|
||
- (void) stopLoading | ||
{ | ||
[[NSNotificationCenter defaultCenter] removeObserver:self]; | ||
} | ||
|
||
@end | ||
|
||
@implementation NSURLRequest (PBGitXProtocol) | ||
|
||
- (PBGitRepository *) repository | ||
{ | ||
return [NSURLProtocol propertyForKey:@"PBGitRepository" inRequest:self]; | ||
} | ||
@end | ||
|
||
@implementation NSMutableURLRequest (PBGitXProtocol) | ||
@dynamic repository; | ||
|
||
- (void) setRepository:(PBGitRepository *)repository | ||
{ | ||
[NSURLProtocol setProperty:repository forKey:@"PBGitRepository" inRequest:self]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters