Skip to content

Commit

Permalink
history: Ensure we copy items based on their multi-priority.
Browse files Browse the repository at this point in the history
That is, we want to insert new items from lowest multi-priority to
highest. This is to ensure we keep the proper order into the
destination.

Fixes #16372.
  • Loading branch information
TurboGit committed Feb 24, 2024
1 parent 48aff5f commit 2969674
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
26 changes: 16 additions & 10 deletions src/common/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -1007,23 +1007,27 @@ char *dt_history_get_name_label(const char *name,

GList *dt_history_get_items(const dt_imgid_t imgid,
const gboolean enabled,
const gboolean multi_priority_order,
const gboolean markup)
{
GList *result = NULL;
sqlite3_stmt *stmt;

gchar *query = g_strdup_printf
("SELECT num, operation, enabled, multi_name, blendop_params"
" FROM main.history"
" WHERE imgid=?1"
" AND num IN (SELECT MAX(num)"
" FROM main.history hst2"
" WHERE hst2.imgid=?1"
" AND hst2.operation=main.history.operation"
" GROUP BY multi_priority)"
" AND enabled in (1, ?2)"
" ORDER BY %s DESC", multi_priority_order ? "multi_priority" : "num");

// clang-format off
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"SELECT num, operation, enabled, multi_name, blendop_params"
" FROM main.history"
" WHERE imgid=?1"
" AND num IN (SELECT MAX(num)"
" FROM main.history hst2"
" WHERE hst2.imgid=?1"
" AND hst2.operation=main.history.operation"
" GROUP BY multi_priority)"
" AND enabled in (1, ?2)"
" ORDER BY num DESC",
query,
-1, &stmt, NULL);
// clang-format on
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid);
Expand All @@ -1050,6 +1054,8 @@ GList *dt_history_get_items(const dt_imgid_t imgid,
result = g_list_prepend(result, item);
}
sqlite3_finalize(stmt);
g_free(query);

return g_list_reverse(result); // list was built in reverse order, so un-reverse it
}

Expand Down
1 change: 1 addition & 0 deletions src/common/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ char *dt_history_get_name_label(const char *name,
/** get list of history items for image */
GList *dt_history_get_items(const dt_imgid_t imgid,
const gboolean enabled,
const gboolean multi_priority_order,
const gboolean markup);

/** get list of history items for image as a nice string */
Expand Down
2 changes: 1 addition & 1 deletion src/gui/hist_dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ int dt_gui_hist_dialog_new(dt_history_copy_item_t *d,
dt_draw_paint_to_pixbuf(GTK_WIDGET(dialog), 10, 0, dtgtk_cairo_paint_showmask);

/* fill list with history items */
GList *items = dt_history_get_items(imgid, FALSE, TRUE);
GList *items = dt_history_get_items(imgid, FALSE, TRUE, TRUE);
if(items)
{
GtkTreeIter iter;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/styles_dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ static void _gui_styles_dialog_run(gboolean edit,
-1);
g_free(label);

GList *items = dt_history_get_items(imgid, FALSE, TRUE);
GList *items = dt_history_get_items(imgid, FALSE, TRUE, TRUE);
if(items)
{
for(const GList *items_iter = items; items_iter; items_iter = g_list_next(items_iter))
Expand Down

0 comments on commit 2969674

Please sign in to comment.