forked from pieter/gitx
-
Notifications
You must be signed in to change notification settings - Fork 2
/
PBDiffWindowController.m
54 lines (41 loc) · 1.36 KB
/
PBDiffWindowController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// PBDiffWindowController.m
// GitX
//
// Created by Pieter de Bie on 13-10-08.
// Copyright 2008 Pieter de Bie. All rights reserved.
//
#import "PBDiffWindowController.h"
#import "PBGitRepository.h"
#import "PBGitCommit.h"
@implementation PBDiffWindowController
@synthesize diff;
- (id) initWithDiff:(NSString *)aDiff
{
if (![super initWithWindowNibName:@"PBDiffWindow"])
return nil;
diff = aDiff;
return self;
}
+ (void) showDiffWindowWithFiles:(NSArray *)filePaths fromCommit:(PBGitCommit *)startCommit diffCommit:(PBGitCommit *)diffCommit
{
if (!startCommit)
return;
if (!diffCommit)
diffCommit = [startCommit.repository headCommit];
NSString *commitSelector = [NSString stringWithFormat:@"%@..%@", [startCommit realSha], [diffCommit realSha]];
NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"diff", commitSelector, nil];
if (filePaths) {
[arguments addObject:@"--"];
[arguments addObjectsFromArray:filePaths];
}
int retValue;
NSString *diff = [startCommit.repository outputInWorkdirForArguments:arguments retValue:&retValue];
if (retValue) {
NSLog(@"diff failed with retValue: %d for command: '%@' output: '%@'", retValue, [arguments componentsJoinedByString:@" "], diff);
return;
}
PBDiffWindowController *diffController = [[PBDiffWindowController alloc] initWithDiff:[diff copy]];
[diffController showWindow:nil];
}
@end