Example #1
0
 def diff(self):
     if self.on_disk() and self.git_path:
         self.update_git_file()
         self.update_buf_file()
         args = [
             git_helper.git_command(self.view), 'diff', '-U0',
             self.git_temp_file.name,
             self.buf_temp_file.name,
         ]
         results = self.run_command(args)
         encoding = self._get_view_encoding()
         try:
             decoded_results = results.decode(encoding.replace(' ', ''))
         except UnicodeError:
             decoded_results = results.decode("utf-8")
         return self.process_diff(decoded_results)
     else:
         return ([], [], [])
Example #2
0
 def update_git_file(self):
     # the git repo won't change that often
     # so we can easily wait 5 seconds
     # between updates for performance
     if ViewCollection.git_time(self.view) > 5:
         open(self.git_temp_file.name, 'w').close()
         args = [
             git_helper.git_command(self.view),
             '--git-dir=' + self.git_dir,
             '--work-tree=' + self.git_tree,
             'show',
             'HEAD:' + self.git_path,
         ]
         try:
             contents = self.run_command(args)
             contents = contents.replace(b'\r\n', b'\n')
             contents = contents.replace(b'\r', b'\n')
             f = open(self.git_temp_file.name, 'wb')
             f.write(contents)
             f.close()
             ViewCollection.update_git_time(self.view)
         except Exception:
             pass