Permalink
Browse files

Add Windows support

- replace backslashes with slashes in path
- call subprocesses with correct flags to hide the command prompt
- close temporary files on create to prevent reopening
  • Loading branch information...
1 parent b8f7c39 commit e5c627686a66ad7ae778f742096d2a02ed03a0d6 @genezys genezys committed Dec 14, 2012
Showing with 16 additions and 8 deletions.
  1. +12 −6 git_gutter_handler.py
  2. +1 −1 git_helper.py
  3. +3 −1 view_collection.py
View
@@ -1,4 +1,5 @@
import git_helper
+import os
import sublime
import subprocess
import re
@@ -49,9 +50,7 @@ def update_git_file(self):
'HEAD:' + self.git_path,
]
try:
- proc = subprocess.Popen(args, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
- contents = proc.stdout.read()
+ contents = self.run_command(args)
contents = contents.replace('\r\n', '\n')
contents = contents.replace('\r', '\n')
f = open(self.git_temp_file.name, 'w')
@@ -102,9 +101,16 @@ def diff(self):
self.git_temp_file.name,
self.buf_temp_file.name,
]
- proc = subprocess.Popen(args, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
- results = proc.stdout.read()
+ results = self.run_command(args)
return self.process_diff(results)
else:
return ([], [], [])
+
+ def run_command(self, args):
+ startupinfo = None
+ if os.name == 'nt':
+ startupinfo = subprocess.STARTUPINFO()
+ startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
+ proc = subprocess.Popen(args, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT, startupinfo=startupinfo)
+ return proc.stdout.read()
View
@@ -4,7 +4,7 @@ def git_file_path(view, git_path):
if not git_path:
return False
full_file_path = os.path.realpath(view.file_name())
- git_path_to_file = full_file_path.replace(git_path, '')
+ git_path_to_file = full_file_path.replace(git_path, '').replace('\\', '/')
if git_path_to_file[0] == '/':
git_path_to_file = git_path_to_file[1:]
return git_path_to_file
View
@@ -48,11 +48,13 @@ def git_tmp_file(view):
key = ViewCollection.get_key(view)
if not key in ViewCollection.git_files:
ViewCollection.git_files[key] = tempfile.NamedTemporaryFile()
+ ViewCollection.git_files[key].close()
return ViewCollection.git_files[key]
@staticmethod
def buf_tmp_file(view):
key = ViewCollection.get_key(view)
if not key in ViewCollection.buf_files:
ViewCollection.buf_files[key] = tempfile.NamedTemporaryFile()
- return ViewCollection.buf_files[key]
+ ViewCollection.buf_files[key].close()
+ return ViewCollection.buf_files[key]

0 comments on commit e5c6276

Please sign in to comment.