Commits

Jens Alfke committed 72d80a3

More work on opening binary files, continuing the previous commit. (Fixes #33)

  • Participants
  • Parent commits 2cb1893

Comments (0)

Files changed (4)

File Source/HgFile.h

 @property (readonly,nonatomic) NSImage* icon;
 @property (readonly,nonatomic) NSDictionary* fileAttributes;
 @property (readonly,nonatomic) CFAbsoluteTime modTime;
+@property (readonly,nonatomic) NSArray* revisions;    // array of HgRevision
 
 - (void) addFilesMatching: (Predicate)predicate toArray: (NSMutableArray*)array;
 
-@property (readonly,nonatomic) NSData* contents;
-
-@property (readonly,nonatomic) NSArray* revisions;    // array of HgRevision
-
 - (void) remove;
 
 @end

File Source/HgFile.m

 }
 
 
-- (NSData*) contents
-{
-    return [NSData dataWithContentsOfFile: self.absolutePath];
-}
-
-
 - (void) addFilesMatching: (Predicate)predicate toArray: (NSMutableArray*)array
 {
     if( CheckPredicate(predicate,self) )

File Source/HgUncommittedRevision.m

 
 - (NSData*) getFileContents: (HgFile*)file error: (NSError**)outError
 {
-    *outError = nil;
-    return file.contents;
+    return [NSData dataWithContentsOfFile: self.absolutePath
+                                  options: NSMappedRead
+                                    error: outError];
 }
 
 - (NSString*) getPathToFileContents: (HgFile*)file inTempDir: (HgTempDir*)tempDir error: (NSError**)outError
 {
+    if (outError) *outError = nil;
     return file.absolutePath;
 }
 

File Source/RepoController_Actions.m

 - (IBAction) showRevision: (id)sender
 {
     HgFile *file = self.selectedFile;
-    if( file.isFile && file==self.actuallySelectedFile ) {
-        HgRevision *rev = file.revision;
-        if( rev.isUncommitted ) {
-            if( [[NSWorkspace sharedWorkspace] openFile: file.absolutePath] )
-                return;
-        } else {
-            NSError *error = nil;
-            NSData *contents = [rev getFileContents: file error: &error];
-            if( contents ) {
-                NSString *filename = [NSString stringWithFormat: @"(r%i) %@", rev.localNumber,file.name];
-                if( [self.tempDir openDataInEditor: contents
-                                       asFileNamed: filename
-                                             error: &error] )
-                    return;
-            }
-        }
+    if( !file.isFile || file!=self.actuallySelectedFile ) {
+        NSBeep();
+        return;
     }
-    NSBeep();
+    NSError *error;
+    NSString *path = [file.revision getPathToFileContents: file
+                                                inTempDir: self.tempDir
+                                                    error: &error];
+    if (!path) {
+        [self presentError: error];
+        return;
+    }
+    if (![[NSWorkspace sharedWorkspace] openFile: path])
+        NSBeep();
 }