aboutsummaryrefslogtreecommitdiffstats
path: root/src/io.c
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@calcurse.org>2017-09-07 19:45:07 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2017-09-08 21:08:53 +0200
commite5a824e5766f6c33f766b02ba0e56a6cafab4f72 (patch)
tree3a534bb054607c3017ce76c7b282e7b9324cc18c /src/io.c
parent74d90e7cbc0f21136a40cd96b48ec41e38962cb2 (diff)
downloadcalcurse-e5a824e5766f6c33f766b02ba0e56a6cafab4f72.tar.gz
calcurse-e5a824e5766f6c33f766b02ba0e56a6cafab4f72.zip
Factor out merge routine
Move the code, which runs the merge tool with current and updated data files, to a separate function to make it reusable. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c92
1 files changed, 44 insertions, 48 deletions
diff --git a/src/io.c b/src/io.c
index ac3836e..55ec22b 100644
--- a/src/io.c
+++ b/src/io.c
@@ -424,6 +424,49 @@ unsigned io_save_keys(void)
return 1;
}
+static void io_merge_data(void)
+{
+ char *path_apts_backup, *path_todo_backup;
+ const char *backup_ext = ".sav";
+
+ asprintf(&path_apts_backup, "%s%s", path_apts, backup_ext);
+ asprintf(&path_todo_backup, "%s%s", path_todo, backup_ext);
+
+ io_save_mutex_lock();
+ io_save_apts(path_apts_backup);
+ io_save_todo(path_todo_backup);
+ io_save_mutex_unlock();
+
+ /*
+ * We do not directly write to the data files here; however, the
+ * external merge tool might incorporate changes from the backup file
+ * into the main data files.
+ */
+ run_hook("pre-save");
+
+ if (!io_files_equal(path_apts, path_apts_backup)) {
+ const char *arg_apts[] = { conf.mergetool, path_apts,
+ path_apts_backup, NULL };
+ wins_launch_external(arg_apts);
+ }
+
+ if (!io_files_equal(path_todo, path_todo_backup)) {
+ const char *arg_todo[] = { conf.mergetool, path_todo,
+ path_todo_backup, NULL };
+ wins_launch_external(arg_todo);
+ }
+
+ mem_free(path_apts_backup);
+ mem_free(path_todo_backup);
+
+ /*
+ * We do not directly write to the data files here; however, the
+ * external merge tool will likely have incorporated changes from the
+ * backup file into the main data files at this point.
+ */
+ run_hook("post-save");
+}
+
/* Save the calendar data */
void io_save_cal(enum save_display display)
{
@@ -781,58 +824,11 @@ void io_reload_data(void)
asprintf(&msg_um_asktype, "%s %s, %s, %s", msg_um_prefix,
msg_um_discard, msg_um_merge, msg_um_keep);
- char *path_apts_backup, *path_todo_backup;
- const char *backup_ext = ".sav";
-
switch (status_ask_choice(msg_um_asktype, msg_um_choice, 3)) {
case 1:
break;
case 2:
- asprintf(&path_apts_backup, "%s%s", path_apts,
- backup_ext);
- asprintf(&path_todo_backup, "%s%s", path_todo,
- backup_ext);
-
- io_save_mutex_lock();
- io_save_apts(path_apts_backup);
- io_save_todo(path_todo_backup);
- io_save_mutex_unlock();
-
- /*
- * We do not directly write to the data files here;
- * however, the external merge tool might incorporate
- * changes from the backup file into the main data
- * files.
- */
- run_hook("pre-save");
-
- if (!io_files_equal(path_apts, path_apts_backup)) {
- const char *arg_apts[] = { conf.mergetool,
- path_apts,
- path_apts_backup,
- NULL };
- wins_launch_external(arg_apts);
- }
-
- if (!io_files_equal(path_todo, path_todo_backup)) {
- const char *arg_todo[] = { conf.mergetool,
- path_todo,
- path_todo_backup,
- NULL };
- wins_launch_external(arg_todo);
- }
-
- mem_free(path_apts_backup);
- mem_free(path_todo_backup);
-
- /*
- * We do not directly write to the data files here;
- * however, the external merge tool will likely have
- * incorporated changes from the backup file into the
- * main data files at this point.
- */
- run_hook("post-save");
-
+ io_merge_data();
break;
case 3:
/* FALLTHROUGH */