Skip to content

Commit 463c2d0

Browse files
committed
Merge branch 'devel/merge-summaries'
2 parents 8e18d20 + e62b45c commit 463c2d0

24 files changed

+859
-517
lines changed

Poedit.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
<ClCompile Include="src\catalog_po.cpp" />
119119
<ClCompile Include="src\catalog_xcloc.cpp" />
120120
<ClCompile Include="src\catalog_xliff.cpp" />
121+
<ClCompile Include="src\cat_operations.cpp" />
121122
<ClCompile Include="src\cat_sorting.cpp" />
122123
<ClCompile Include="src\cat_update.cpp" />
123124
<ClCompile Include="src\progress.cpp" />
@@ -193,6 +194,7 @@
193194
<ClInclude Include="src\catalog_po.h" />
194195
<ClInclude Include="src\catalog_xcloc.h" />
195196
<ClInclude Include="src\catalog_xliff.h" />
197+
<ClInclude Include="src\cat_operations.h" />
196198
<ClInclude Include="src\cat_sorting.h" />
197199
<ClInclude Include="src\cat_update.h" />
198200
<ClInclude Include="src\progress.h" />

Poedit.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@
222222
<ClCompile Include="src\subprocess.cpp">
223223
<Filter>Source Files</Filter>
224224
</ClCompile>
225+
<ClCompile Include="src\cat_operations.cpp">
226+
<Filter>Source Files</Filter>
227+
</ClCompile>
225228
</ItemGroup>
226229
<ItemGroup>
227230
<ClInclude Include="src\attentionbar.h">
@@ -446,6 +449,9 @@
446449
<ClInclude Include="src\subprocess.h">
447450
<Filter>Header Files</Filter>
448451
</ClInclude>
452+
<ClInclude Include="src\cat_operations.h">
453+
<Filter>Header Files</Filter>
454+
</ClInclude>
449455
</ItemGroup>
450456
<ItemGroup>
451457
<ResourceCompile Include="src\poedit.rc">

Poedit.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
796E87D980AB0659930E8540 /* catalog_json.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B260089229AE694D00349A0E /* catalog_json.cpp */; };
4242
7A7175DB2942BF59C950E93F /* subprocess.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 740C80154CE061778D7E5155 /* subprocess.cpp */; };
4343
7EC322151430D2F26AE64498 /* catalog_xcloc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5BA775F29C57EB5164B2B792 /* catalog_xcloc.cpp */; };
44+
80FBB464B5B4DC5E6B59B25C /* cat_operations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9E49DA74C93B5B0754849686 /* cat_operations.cpp */; };
4445
8816DADE560039E7FAD57F46 /* export_html.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B28F1CE216F629D30018AF7E /* export_html.cpp */; };
4546
8A905D6EA68B5E7AB51E2ADE /* QuickLookThumbnailing.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4C2A4C943959E8220417BD1 /* QuickLookThumbnailing.framework */; };
4647
90E923F206398EFAF8DD5D43 /* libicucore.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = B2CAC13A2BBEE95900707D8D /* libicucore.tbd */; };
@@ -342,6 +343,7 @@
342343
90D2D2B7CA0B58D4AD93F245 /* InfoPreview.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = InfoPreview.plist; sourceTree = "<group>"; };
343344
9A60B0E72939BB1B6692FAD8 /* UniformTypeIdentifiers.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UniformTypeIdentifiers.framework; path = System/Library/Frameworks/UniformTypeIdentifiers.framework; sourceTree = SDKROOT; };
344345
9B0077CCD746D870A816B2E0 /* progress_ui.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = progress_ui.cpp; sourceTree = "<group>"; };
346+
9E49DA74C93B5B0754849686 /* cat_operations.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = cat_operations.cpp; sourceTree = "<group>"; };
345347
AD4B1152DADD677FDAE5D5AB /* progress.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = progress.cpp; sourceTree = "<group>"; };
346348
B20024A01DFDB7510002A52F /* PoeditStyleKit.pcvd */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; name = PoeditStyleKit.pcvd; path = macos/PoeditStyleKit.pcvd; sourceTree = "<group>"; };
347349
B201EBDF1DCF755900FFB541 /* configuration.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = configuration.cpp; sourceTree = "<group>"; };
@@ -683,6 +685,7 @@
683685
CFA973FC5BE997B483F0A7A5 /* uilang.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = uilang.h; sourceTree = "<group>"; };
684686
E4C2A4C943959E8220417BD1 /* QuickLookThumbnailing.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuickLookThumbnailing.framework; path = System/Library/Frameworks/QuickLookThumbnailing.framework; sourceTree = SDKROOT; };
685687
F99D32BE79516DF3871487AD /* QuicklookPreview.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = QuicklookPreview.appex; sourceTree = BUILT_PRODUCTS_DIR; };
688+
FCBA6BC4E3B445B7254531C0 /* cat_operations.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = cat_operations.h; sourceTree = "<group>"; };
686689
/* End PBXFileReference section */
687690

688691
/* Begin PBXFrameworksBuildPhase section */
@@ -964,6 +967,8 @@
964967
5BA775F29C57EB5164B2B792 /* catalog_xcloc.cpp */,
965968
10F1342DED004E0BE40CBB35 /* subprocess.h */,
966969
740C80154CE061778D7E5155 /* subprocess.cpp */,
970+
FCBA6BC4E3B445B7254531C0 /* cat_operations.h */,
971+
9E49DA74C93B5B0754849686 /* cat_operations.cpp */,
967972
);
968973
name = "Non-GUI";
969974
path = src;
@@ -1795,6 +1800,7 @@
17951800
49CB09B8277DDFCE6533BE41 /* progress_ui.cpp in Sources */,
17961801
43518E06F21ED7EB8D754F2B /* progress.cpp in Sources */,
17971802
7A7175DB2942BF59C950E93F /* subprocess.cpp in Sources */,
1803+
80FBB464B5B4DC5E6B59B25C /* cat_operations.cpp in Sources */,
17981804
);
17991805
runOnlyForDeploymentPostprocessing = 0;
18001806
};

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ endif
2020
poedit_SOURCES = \
2121
app_updates.cpp app_updates.h \
2222
attentionbar.cpp attentionbar.h \
23+
cat_operations.h cat_operations.cpp \
2324
cat_update.h cat_update.cpp \
2425
cat_sorting.cpp cat_sorting.h \
2526
catalog.cpp catalog.h \

src/cat_operations.cpp

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* This file is part of Poedit (https://poedit.net)
3+
*
4+
* Copyright (C) 2000-2025 Vaclav Slavik
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a
7+
* copy of this software and associated documentation files (the "Software"),
8+
* to deal in the Software without restriction, including without limitation
9+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
10+
* and/or sell copies of the Software, and to permit persons to whom the
11+
* Software is furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22+
* DEALINGS IN THE SOFTWARE.
23+
*
24+
*/
25+
26+
#include "cat_operations.h"
27+
28+
#include "catalog_po.h"
29+
#include "concurrency.h"
30+
#include "progress.h"
31+
32+
#include <set>
33+
34+
35+
namespace
36+
{
37+
38+
inline wxString ItemMergeSummary(const CatalogItemPtr& item)
39+
{
40+
wxString s = item->GetRawString();
41+
if ( item->HasPlural() )
42+
s += " | " + item->GetRawPluralString();
43+
if ( item->HasContext() )
44+
s += wxString::Format(" [%s]", item->GetContext());
45+
46+
return s;
47+
}
48+
49+
} // anonymous namespace
50+
51+
52+
void ComputeMergeStats(MergeStats& r, CatalogPtr po, CatalogPtr refcat)
53+
{
54+
Progress progress(2);
55+
56+
r.added.clear();
57+
r.removed.clear();
58+
59+
// First collect all strings from both sides, then diff the sets.
60+
// Run the two sides in parallel for speed up on large files.
61+
62+
std::set<wxString> strsThis, strsRef;
63+
64+
auto collect1 = dispatch::async([&]
65+
{
66+
for (auto& i: po->items())
67+
strsThis.insert(ItemMergeSummary(i));
68+
});
69+
70+
auto collect2 = dispatch::async([&]
71+
{
72+
for (auto& i: refcat->items())
73+
strsRef.insert(ItemMergeSummary(i));
74+
});
75+
76+
collect1.get();
77+
collect2.get();
78+
progress.increment();
79+
80+
auto add1 = dispatch::async([&]
81+
{
82+
for (auto& i: strsThis)
83+
{
84+
if (strsRef.find(i) == strsRef.end())
85+
r.removed.push_back(i);
86+
}
87+
});
88+
89+
auto add2 = dispatch::async([&]
90+
{
91+
for (auto& i: strsRef)
92+
{
93+
if (strsThis.find(i) == strsThis.end())
94+
r.added.push_back(i);
95+
}
96+
});
97+
98+
add1.get();
99+
add2.get();
100+
progress.increment();
101+
}
102+
103+
104+
MergeResult MergeCatalogWithReference(CatalogPtr catalog, CatalogPtr reference)
105+
{
106+
auto po_catalog = std::dynamic_pointer_cast<POCatalog>(catalog);
107+
auto po_ref = std::dynamic_pointer_cast<POCatalog>(reference);
108+
if (!po_catalog || !po_ref)
109+
return {};
110+
111+
if (!po_catalog->UpdateFromPOT(po_ref))
112+
return {};
113+
114+
return {po_catalog};
115+
}

src/cat_operations.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* This file is part of Poedit (https://poedit.net)
3+
*
4+
* Copyright (C) 2000-2025 Vaclav Slavik
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a
7+
* copy of this software and associated documentation files (the "Software"),
8+
* to deal in the Software without restriction, including without limitation
9+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
10+
* and/or sell copies of the Software, and to permit persons to whom the
11+
* Software is furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22+
* DEALINGS IN THE SOFTWARE.
23+
*
24+
*/
25+
26+
#ifndef Poedit_cat_operations_h
27+
#define Poedit_cat_operations_h
28+
29+
#include "catalog.h"
30+
#include "gexecute.h"
31+
32+
33+
/// Summary data about the result of merging two catalogs.
34+
struct MergeStats
35+
{
36+
// Added and removed strings (as their summary representation, not the full items)
37+
std::vector<wxString> added;
38+
std::vector<wxString> removed;
39+
40+
int changes_count() const { return int(added.size() + removed.size()); }
41+
42+
// Any errors/warnings that occurred during the merge
43+
ParsedGettextErrors errors;
44+
};
45+
46+
47+
/// Resulting data from a merge operation.
48+
struct MergeResult
49+
{
50+
CatalogPtr updated_catalog;
51+
ParsedGettextErrors errors;
52+
53+
explicit operator bool() const { return updated_catalog != nullptr; }
54+
};
55+
56+
57+
/**
58+
Calculates difference between a catalog and a reference ("upstream") one
59+
w.r.t. merging operation, i.e. different in source strings.
60+
*/
61+
extern void ComputeMergeStats(MergeStats& r, CatalogPtr catalog, CatalogPtr reference);
62+
63+
/**
64+
Merges catalog with a reference catalog, updating catalog with new strings
65+
present in @a reference and removing strings that are no longer present there.
66+
67+
*/
68+
extern MergeResult MergeCatalogWithReference(CatalogPtr catalog, CatalogPtr reference);
69+
70+
#endif // Poedit_cat_operations_h

0 commit comments

Comments
 (0)