From 1d19bd64dfa83def18d5271c9afef9300ef0d65e Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Wed, 29 Oct 2008 00:21:15 +0100 Subject: [PATCH] PBChangedFile: Don't use cat to read file contents This changes PBChangedFile to read in files by using NSString's stringWithContentsOfFile: method. It still uses the UTF8 encoding scheme so that we can capture binary files. This should perhaps be loosened to also allow other encodings. --- PBChangedFile.m | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/PBChangedFile.m b/PBChangedFile.m index 500954d..39cedd6 100644 --- a/PBChangedFile.m +++ b/PBChangedFile.m @@ -30,8 +30,15 @@ - (NSString *)unstagedChanges { - if (status == NEW) - return [PBEasyPipe outputForCommand:@"/bin/cat" withArgs:[NSArray arrayWithObject:path] inDir:[repository workingDirectory]]; + if (status == NEW) { + NSStringEncoding encoding; + NSError *error = nil; + NSString *contents = [NSString stringWithContentsOfFile:[[repository workingDirectory] stringByAppendingPathComponent:path] usedEncoding:&encoding error:&error]; + if (error) + return nil; + + return contents; + } return [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", @"--", path, nil]]; }