Skip to content

Commit

Permalink
Remove duplicates while merging fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke committed Nov 3, 2022
1 parent f69e5fa commit f72373e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion industrial_ci/src/tests/merge_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,36 @@
import sys


def key(item):
name = item.get("DiagnosticName")
msg = item.get("DiagnosticMessage")
file = msg.get("FilePath")
offset = msg.get("FileOffset")
return name, file, offset

def merge_fixes(files):
"""Merge all fixes files into mergefile"""
# The fixes suggested by clang-tidy >= 4.0.0 are given under
# the top level key 'Diagnostics' in the output yaml files
mergefile = files[0]
mergekey = "Diagnostics"
merged = []
seen = set() # efficiently remember fixes already inserted

def have(x):
k = key(x)
return k in seen or seen.add(k)

def unique(seq):
return [x for x in seq if not have(x)]

for file in files:
try:
with open(file, 'r') as inp:
content = yaml.safe_load(inp)
if not content:
continue # Skip empty files.
merged.extend(content.get(mergekey, []))
merged.extend(unique(content.get(mergekey, [])))
except FileNotFoundError:
pass

Expand Down

0 comments on commit f72373e

Please sign in to comment.