Generate stable targets rather than random
A random value can still easily hit collision, and at least one was found easily on the gates (gone with a recheck). Moreover, the usage of a random target does not allow for ensuring reproducible builds: the usage of an hash build from the node content makes sure that the target is stable across different runs of api-ref generation. Change-Id: I3fcd8a4e5b0a66c9dbf34f4a4c472f3c93c46bb8
This commit is contained in:
parent
4e56d09daf
commit
8626ce5d88
|
@ -11,8 +11,8 @@
|
|||
# under the License.
|
||||
|
||||
from collections import OrderedDict
|
||||
import hashlib
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
|
||||
from docutils import nodes
|
||||
|
@ -199,8 +199,11 @@ class RestMethodDirective(rst.Directive):
|
|||
|
||||
# We need to build a temporary target that we can replace
|
||||
# later in the processing to get the TOC to resolve correctly.
|
||||
temp_target = "%s-%d-selector" % (node['target'],
|
||||
random.randint(1, 1000))
|
||||
# SHA-1 is used even if collisions are possible, because
|
||||
# they are still unlikely to occurr and it is way shorter
|
||||
# than stronger SHAs.
|
||||
node_hash = hashlib.sha1(str(node).encode('utf-8')).hexdigest()
|
||||
temp_target = "%s-%s-selector" % (node['target'], node_hash)
|
||||
target = nodes.target(ids=[temp_target])
|
||||
self.state.add_target(temp_target, '', target, lineno)
|
||||
section += node
|
||||
|
|
Loading…
Reference in New Issue