Skip to content

Need a git merge driver for po files? #1908

@JulienPalard

Description

@JulienPalard

I just got an issue:

Given a commit on 3.10 (c199947) containing:

@@ -507,10 +520,14 @@ msgid ""
 "`list` or :class:`tuple`, preferably in a deterministic order so that the "
 "sample is reproducible."
 msgstr ""
+"À l’avenir, la *population* devra être une séquence.  Les instances de :"
+"class:`set` ne sont plus prises en charge.  Le *set* doit d’abord être "
+"converti en une :class:`list` ou :class:`tuple`, de préférence dans un ordre "
+"déterministe de telle sorte que l’échantillon soit reproductible."

And a commit on 3.11 (fecaae6) containing:

-#: library/random.rst:260
+#: library/random.rst:259
 msgid ""
-"In the future, the *population* must be a sequence.  Instances of :class:"
-"`set` are no longer supported.  The set must first be converted to a :class:"
-"`list` or :class:`tuple`, preferably in a deterministic order so that the "
-"sample is reproducible."
+"The *population* must be a sequence.  Automatic conversion of sets to lists "
+"is longer supported."
 msgstr ""

the two¹ get silently merged to:

#: library/random.rst:259
msgid ""
"The *population* must be a sequence.  Automatic conversion of sets to lists "
"is no longer supported."
msgstr ""
"À l’avenir, la *population* devra être une séquence.  Les instances de :"
"class:`set` ne sont plus prises en charge.  Le *set* doit d’abord être "
"converti en une :class:`list` ou :class:`tuple`, de préférence dans un ordre "
"déterministe de telle sorte que l’échantillon soit reproductible."

Which is not a git issue! git is plain right here: those are two non-overlaping modifications, no need for a conflict. But it's very bad for us as it give a very wrong result.

  1. Yes I know git does not merge diffs, it merges the result of them: actual plain files. But showing diffs was usefull to give context.

So in other words, as git sees it, I have a base looking like:

#: library/random.rst:260
msgid ""
"In the future, the *population* must be a sequence.  Instances of :class:"
"`set` are no longer supported.  The set must first be converted to a :class:"
"`list` or :class:`tuple`, preferably in a deterministic order so that the "
"sample is reproducible."
msgstr ""

In one branch it gets to:

#: library/random.rst:259
msgid ""
"The *population* must be a sequence.  Automatic conversion of sets to lists "
"is no longer supported."
msgstr ""

While in the other it gets to:

#: library/random.rst:260
msgid ""
"In the future, the *population* must be a sequence.  Instances of :class:"
"`set` are no longer supported.  The set must first be converted to a :class:"
"`list` or :class:`tuple`, preferably in a deterministic order so that the "
"sample is reproducible."
msgstr ""
"À l’avenir, la *population* devra être une séquence.  Les instances de :"
"class:`set` ne sont plus prises en charge.  Le *set* doit d’abord être "
"converti en une :class:`list` ou :class:`tuple`, de préférence dans un ordre "
"déterministe de telle sorte que l’échantillon soit reproductible."

Git reolves it as:

#: library/random.rst:259
msgid ""
"The *population* must be a sequence.  Automatic conversion of sets to lists "
"is no longer supported."
msgstr ""
"À l’avenir, la *population* devra être une séquence.  Les instances de :"
"class:`set` ne sont plus prises en charge.  Le *set* doit d’abord être "
"converti en une :class:`list` ou :class:`tuple`, de préférence dans un ordre "
"déterministe de telle sorte que l’échantillon soit reproductible."

I think this may be cleanly resolved using a proper "git merge driver" to implement 3-way merge for po files specifically, but was unable to find one.

I bet we could spawn one based on polib, or difflib (which only does 2-way merges), or both, I don't know, but at the moment I'm just surprised it does not already exists.

Found a few leads but nothing that actually works:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions