Skip to content

Commit cbee513

Browse files
author
Pavel Kosov
committed
[LNT] Fixed incorrect orders behavior in case of miss formatted llvm_project_revision
LNT expected that llvm_project_revision is a version in the format 1.2.3. But it is a string and may contain any symbols. Someone may use hex numbers, dashes, etc. If llvm_project_revision does not contain any digit at all the behavior is undefined and caused inconsistent DB. hash(str) is a workaround to fix this behavior. Note it does not fix the sorting. Reviewed By: cmatthews Differential Revision: https://reviews.llvm.org/D109577
1 parent 1a9bfb6 commit cbee513

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lnt/server/ui/util.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import colorsys
2+
import hashlib
23
import math
34
import re
45
from lnt.server.reporting.analysis import REGRESSED
@@ -262,25 +263,26 @@ def convert_revision(dotted, cache=None):
262263
that is ordered and sortable.
263264
"1" -> (1)
264265
"1.2.3" -> (1,2,3)
266+
"1a2,3-45:b6;" -> (1,2,3,45,6)
267+
"abc" -> (hash("abc"))
265268
266269
:param dotted: the string revision to convert
267270
:param cache: a dict to use as a cache or None for no cache.
268271
because this is called many times, it is a nice performance
269272
increase to cache these conversions.
270273
:return: a tuple with the numeric bits of this revision as ints.
271-
274+
return a hash in case of miss formatted version to avoid wrong equals.
272275
"""
273276
if cache is not None:
274277
val = cache.get(dotted)
275278
if val:
276279
return val
277-
else:
278-
dotted_parsed = integral_rex.findall(dotted)
279-
val = tuple([int(d) for d in dotted_parsed])
280-
cache[dotted] = val
281-
return val
280+
282281
dotted_parsed = integral_rex.findall(dotted)
283-
val = tuple([int(d) for d in dotted_parsed])
282+
val = tuple([int(d) for d in dotted_parsed] or
283+
[int(hashlib.sha1(dotted.encode("utf-8")).hexdigest(), 16)])
284+
if cache is not None:
285+
cache[dotted] = val
284286
return val
285287

286288

0 commit comments

Comments
 (0)