Skip to content

Commit

Permalink
settings: avoid syncing when cola.sync is configured to false
Browse files Browse the repository at this point in the history
We can now inhibit the use of `os.sync()` using `git config`:

    git config --global cola.sync false

Resolves: #1305
Reported-by: @installgentoo via github
Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information
davvid committed Mar 29, 2024
1 parent e7edb2b commit 69e32f0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ Fixes
(`#1385 <https://github.com/git-cola/git-cola/issues/1385>`_)
(`#1388 <https://github.com/git-cola/git-cola/pull/1388>`_)

* Git Cola syncs the OS-level filesystem when windows are closed, which can
cause performance issues. The `cola.sync` configuration variable can
be configured to `false` to avoid this behavior.
(`#1305 <https://github.com/git-cola/git-cola/issues/1305>`_)


.. _v4.6.1:

Expand Down
9 changes: 5 additions & 4 deletions cola/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def rename_recent(self, path, name, new_name):
def path(self):
return self.config_path

def save(self):
def save(self, sync=True):
"""Write settings robustly to avoid losing data during a forced shutdown.
To save robustly we take these steps:
Expand All @@ -190,7 +190,8 @@ def save(self):
if not rename_path(path_tmp, path):
return
# Flush the data to disk.
core.sync()
if sync:
core.sync()
# Delete the .bak file.
if core.exists(path_bak):
remove_path(path_bak)
Expand Down Expand Up @@ -276,11 +277,11 @@ def asdict(self, path=None):
entry['path'] = normalize(entry['path'])
return values

def save_gui_state(self, gui):
def save_gui_state(self, gui, sync=True):
"""Saves settings for a cola view"""
name = gui.name()
self.gui_state[name] = mkdict(gui.export_state())
self.save()
self.save(sync=sync)

def get_gui_state(self, gui):
"""Returns the saved state for a gui"""
Expand Down
4 changes: 3 additions & 1 deletion cola/widgets/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,16 @@ def name(self):

def save_state(self, settings=None):
save = True
sync = True
context = getattr(self, 'context', None)
if context:
cfg = context.cfg
save = cfg.get('cola.savewindowsettings', default=True)
sync = cfg.get('cola.sync', default=True)
if save:
if settings is None:
settings = Settings.read()
settings.save_gui_state(self)
settings.save_gui_state(self, sync=sync)

def restore_state(self, settings=None):
if settings is None:
Expand Down
6 changes: 6 additions & 0 deletions docs/git-cola.rst
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,12 @@ cola.statusshowtotals
Set to `true` to display files counts in the Status widget's category titles.
Defaults to `false`.

cola.sync
---------
Set to `false` to disable calling `os.sync()` when saving settings.
Defaults to `true`, which means that `os.sync()` is called when windows are closed
and their settings are saved.

cola.tabwidth
-------------
The number of columns occupied by a tab character. Defaults to 8.
Expand Down

0 comments on commit 69e32f0

Please sign in to comment.