From 8ff44646cee937283b5bd565737abb2b73baa7e5 Mon Sep 17 00:00:00 2001 From: Philipp Lutz Date: Sat, 4 Jul 2026 20:06:16 +0200 Subject: [PATCH 1/2] Do not override library edit history from XMP When darktable-cli is executed via the --library and the file to be exported has an associated (potentially stale) XMP sidecar file, the library history stack gets overridden. This change proposes to prefer the library database history entry over an existing XMP sidecar file once the --library argument is provided to darktable-cli. --- src/cli/main.c | 3 +++ src/common/darktable.h | 3 +++ src/common/image.c | 9 +++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/cli/main.c b/src/cli/main.c index f3f61c703f8c..06f1f5eb18f6 100644 --- a/src/cli/main.c +++ b/src/cli/main.c @@ -575,6 +575,9 @@ int main(int argc, char *arg[]) exit(1); } + // When --library was provided, use the DB history; otherwise keep XMP override mode. + darktable.prefer_library_history = (library != NULL); + GList *id_list = NULL; for(GList *l = inputs; l != NULL; l=g_list_next(l)) diff --git a/src/common/darktable.h b/src/common/darktable.h index 1979f437b403..e1bcb2e1086e 100644 --- a/src/common/darktable.h +++ b/src/common/darktable.h @@ -486,6 +486,9 @@ typedef struct darktable_t int32_t unmuted_signal_dbg_acts; gboolean unmuted_signal_dbg[DT_SIGNAL_COUNT]; gboolean pipe_cache; + // Keep database history for known images rather than replacing it from XMP. + // Set by darktable-cli with explicit --library ; GUI and CLI use XMP by default. + gboolean prefer_library_history; int gui_running; // atomic, access with g_atomic_int_*() GTimeZone *utc_tz; GDateTime *origin_gdt; diff --git a/src/common/image.c b/src/common/image.c index 05605921dc2f..78941254ab40 100644 --- a/src/common/image.c +++ b/src/common/image.c @@ -1874,8 +1874,13 @@ static dt_imgid_t _image_import_internal(const dt_filmid_t film_id, if(img) img->flags &= ~DT_IMAGE_REMOVE; dt_image_cache_write_release(img, DT_IMAGE_CACHE_RELAXED); - _image_read_duplicates(id, normalized_filename, raise_signals); - dt_image_synch_all_xmp(normalized_filename); + // Reconcile with XMP sidecars unless library history is preferred to avoid + // overwriting library edit history with potentially stale XMP history. + if(!darktable.prefer_library_history) + { + _image_read_duplicates(id, normalized_filename, raise_signals); + dt_image_synch_all_xmp(normalized_filename); + } g_free(ext); g_free(normalized_filename); if(raise_signals) From 0eb05499c7ec0c549a3e4ee93d3ac3ea893e233b Mon Sep 17 00:00:00 2001 From: Philipp Lutz Date: Sat, 4 Jul 2026 22:29:16 +0200 Subject: [PATCH 2/2] Discourage usage of --library :memory: for darktable-cli --- src/cli/main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cli/main.c b/src/cli/main.c index 06f1f5eb18f6..9efb7b29273a 100644 --- a/src/cli/main.c +++ b/src/cli/main.c @@ -95,6 +95,8 @@ fprintf(stderr, "darktable %s\n" " multiple times instead of input file\n" " --library read the history stack from library database\n" " instead of XMP sidecar files\n" + " using ':memory:' for an empty in-memory library\n" + " is useless for darktable cli export\n" " --icc-type specify icc type, default to NONE\n" " use --help icc-type for list of supported types\n" " --icc-file specify icc filename, default to NONE\n" @@ -384,6 +386,13 @@ int main(int argc, char *arg[]) { k++; library = arg[k]; + if(!strcmp(library, ":memory:")) + { + fprintf(stderr, _("empty in-memory library is useless for darktable cli export\n")); + usage(arg[0]); + exit(1); + } + } else if(!strcmp(arg[k], "--icc-type") && argc > k + 1) {