Skip to content

Commit e343cba

Browse files
committed
diff on file view
1 parent 945a861 commit e343cba

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

PBGitTree.m

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ - (NSString *) log:(NSString *)format
145145

146146
if ([self fileSize] > 52428800) // ~50MB
147147
return [NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]];
148-
148+
149149
NSString *contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"log", [NSString stringWithFormat:@"--pretty=format:%@",format], @"--", [self fullPath], nil]];
150150

151151
if ([self hasBinaryHeader:contents])
@@ -155,6 +155,35 @@ - (NSString *) log:(NSString *)format
155155
return contents;
156156
}
157157

158+
- (NSString *) diff:(NSString *)format
159+
{
160+
if (!leaf)
161+
return [NSString stringWithFormat:@"This is a tree with path %@", [self fullPath]];
162+
163+
if ([self hasBinaryAttributes])
164+
return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
165+
166+
if ([self fileSize] > 52428800) // ~50MB
167+
return [NSString stringWithFormat:@"%@ is too big to be displayed (%d bytes)", [self fullPath], [self fileSize]];
168+
169+
NSString *contents=@"";
170+
if(format==@"p") {
171+
contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", sha, [NSString stringWithFormat:@"%@^",sha],[self fullPath], nil]];
172+
}else if(format==@"h") {
173+
contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", sha, @"HEAD",[self fullPath], nil]];
174+
}else if(format==@"l") {
175+
contents=[repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", sha, @"--",[self fullPath], nil]];
176+
}
177+
178+
179+
180+
if ([self hasBinaryHeader:contents])
181+
return [NSString stringWithFormat:@"%@ appears to be a binary file of %d bytes", [self fullPath], [self fileSize]];
182+
183+
184+
return contents;
185+
}
186+
158187
- (long long)fileSize
159188
{
160189
if (_fileSize)

0 commit comments

Comments
 (0)