Skip to content

gkeyfile: Fix group comment management

Gaël Bonithon requested to merge neyfag/glib:fix-group-comment into main

This removes the comment member of the GKeyFileGroup structure, which seemed intended to distinguish comments just above a group from comments above them, separated by one or more blank lines. Indeed:

  • This does not seem to match any specification in the documentation, where blank lines and lines starting with # are indiscriminately considered comments. In particular, no distinction is made between the comment above the first group and the comment at the beginning of the file.
  • This distinction was only half implemented, resulting in confusion between comment above a group and comment at the end of the preceding group.

Instead, the same logic is used for groups as for keys: the comment above a group is simply the sequence of key-value pairs of the preceding group where the key is null, starting from the bottom.

The addition of a blank line above groups when writing, involved in bugs #104 (closed) and #2927 (closed), is kept, but:

  • It is now added as a comment as soon as the group is added (since a blank line is considered a comment), so that g_key_file_get_comment() returns the correct result right away.
  • It is always added if comments are not kept.
  • Otherwise it is only added if the group is newly created (not present in the original data), in order to really keep comments (existing and not existing).

Closes: #104 (closed), #2927 (closed)

Merge request reports