From 69e32f0d42d86e2ff62a2341edc460d2c044ef3f Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Fri, 29 Mar 2024 02:29:14 -0700 Subject: [PATCH] settings: avoid syncing when cola.sync is configured to false 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 --- CHANGES.rst | 5 +++++ cola/settings.py | 9 +++++---- cola/widgets/standard.py | 4 +++- docs/git-cola.rst | 6 ++++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 1fde023c..ff15c307 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -34,6 +34,11 @@ Fixes (`#1385 `_) (`#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 `_) + .. _v4.6.1: diff --git a/cola/settings.py b/cola/settings.py index 6ef5cd35..fb490894 100644 --- a/cola/settings.py +++ b/cola/settings.py @@ -165,7 +165,7 @@ class Settings: 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: @@ -190,7 +190,8 @@ class Settings: 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) @@ -276,11 +277,11 @@ class Settings: 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""" diff --git a/cola/widgets/standard.py b/cola/widgets/standard.py index 2fd7fc68..8eb7d958 100644 --- a/cola/widgets/standard.py +++ b/cola/widgets/standard.py @@ -63,14 +63,16 @@ class WidgetMixin: 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: diff --git a/docs/git-cola.rst b/docs/git-cola.rst index 7320d180..4abc5f25 100644 --- a/docs/git-cola.rst +++ b/docs/git-cola.rst @@ -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. -- 2.11.4.GIT