Skip to content

Add KeyValues.Merge#2184

Merged
psychonic merged 2 commits intomasterfrom
kvmerge
Apr 28, 2026
Merged

Add KeyValues.Merge#2184
psychonic merged 2 commits intomasterfrom
kvmerge

Conversation

@Fyren
Copy link
Copy Markdown
Contributor

@Fyren Fyren commented Jun 18, 2024

AI in Discord brought up that Import/CopySubkeys doesn't do what you want if you want to merge together KVs. Although it does copy the foreign data in, it also replaces the existing data when it does so. To get around this, his workaround was to manually iterate, create, and import:

if (!hKVSource.GotoFirstSubKey(false)) {
    return;
}

char sSectionName[256];
do {
    hKVSource.GetSectionName(sSectionName, sizeof(sSectionName));
    hKVDestination.JumpToKey(sSectionName, true);
    hKVDestination.Import(hKVSource);
    hKVDestination.GoBack();
} while (hKVSource.GotoNextKey(false));

With this PR, you should be able to just do hKVDestination.Merge(hKVSource).

@peace-maker
Copy link
Copy Markdown
Member

I think the docs should mention that this preserves the old value if the key already exists. That's what I understood from your PR description.

Fyren and others added 2 commits April 27, 2026 19:50
Co-authored-by: Copilot <copilot@github.com>
@psychonic psychonic merged commit c11164c into master Apr 28, 2026
5 of 7 checks passed
@psychonic psychonic deleted the kvmerge branch April 28, 2026 01:58
@geominorai
Copy link
Copy Markdown

Kudos, everyone. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants