Bug 1391789 - Make hash_path() a "public" API; r?dustin draft
authorGregory Szorc <gps@mozilla.com>
Fri, 18 Aug 2017 13:30:05 -0700
changeset 650035 7e99813a0437b77f72668c80cf9712b28646cc40
parent 650034 edf9caf80d7542dd12da8356370e5cc83c2a06c8
child 650036 5178a7f5269a76edd2cb6ac559279e86ae1357e7
push id75226
push userbmo:gps@mozilla.com
push dateMon, 21 Aug 2017 16:19:27 +0000
reviewersdustin
bugs1391789
milestone57.0a1
Bug 1391789 - Make hash_path() a "public" API; r?dustin So we can use it from another module without feeling dirty. MozReview-Commit-ID: 1TCk9dda6mL
taskcluster/taskgraph/util/hash.py
--- a/taskcluster/taskgraph/util/hash.py
+++ b/taskcluster/taskgraph/util/hash.py
@@ -5,17 +5,21 @@
 from __future__ import absolute_import, print_function, unicode_literals
 from mozbuild.util import memoize
 from mozpack.files import FileFinder
 import mozpack.path as mozpath
 import hashlib
 
 
 @memoize
-def _hash_path(path):
+def hash_path(path):
+    """Hash a single file.
+
+    Returns the SHA-256 hash in hex form.
+    """
     with open(path) as fh:
         return hashlib.sha256(fh.read()).hexdigest()
 
 
 def hash_paths(base_path, patterns):
     """
     Give a list of path patterns, return a digest of the contents of all
     the corresponding files, similarly to git tree objects or mercurial
@@ -30,12 +34,12 @@ def hash_paths(base_path, patterns):
     for pattern in patterns:
         found = list(finder.find(pattern))
         if found:
             files.update(found)
         else:
             raise Exception('%s did not match anything' % pattern)
     for path in sorted(files.keys()):
         h.update('{} {}\n'.format(
-            _hash_path(mozpath.abspath(mozpath.join(base_path, path))),
+            hash_path(mozpath.abspath(mozpath.join(base_path, path))),
             mozpath.normsep(path)
         ))
     return h.hexdigest()