MCPcopy
hub / github.com/jisaacks/GitGutter / update

Method update

modules/view.py:101–142  ·  view source on GitHub ↗

Write view's content to a temporary file as source for git diff. The file is updated only if the view.change_count() has changed to reduce the number of required disk writes. Returns: bool: True indicates updated file. False is returned if file

(self)

Source from the content-addressed store, hash-verified

99 )
100
101 def update(self):
102 """Write view's content to a temporary file as source for git diff.
103
104 The file is updated only if the view.change_count() has changed to
105 reduce the number of required disk writes.
106
107 Returns:
108 bool: True indicates updated file.
109 False is returned if file is up to date.
110 """
111 # check change counter if exists
112 change_count = 0
113 if _HAVE_VIEW_CHANGE_COUNT:
114 # write view buffer to file only, if changed
115 change_count = self.view.change_count()
116 if self._change_count == change_count:
117 return False
118
119 # invalidate internal cache
120 self.invalidate()
121
122 # Try conversion
123 encoding = self.python_friendly_encoding()
124 try:
125 encoded = self.text.encode(encoding)
126 except (LookupError, UnicodeError):
127 # Fallback to utf8-encoding
128 encoded = self.text.encode('utf-8')
129
130 # Write the encoded content to file
131 try:
132 with self as file:
133 if encoding == 'utf-8-sig':
134 file.write(codecs.BOM_UTF8)
135 file.write(encoded)
136 except OSError as error:
137 print('GitGutter failed to create view cache: %s' % error)
138 return False
139
140 # Update internal change counter after job is done
141 self._change_count = change_count
142 return True
143
144 def python_friendly_encoding(self):
145 """Read view encoding and transform it for use with python.

Callers 4

update_git_statusMethod · 0.45
_run_diffMethod · 0.45
_update_statusMethod · 0.45
_render_blameFunction · 0.45

Calls 2

invalidateMethod · 0.95

Tested by

no test coverage detected