changeset 31740:a40e979b9d97

largefiles: use readasstandin() to read hex hash directly from filectx BTW, C implementation of hexdigest() for SHA-1/256/512 returns hex hash in lower case, and doctest in Python standard hashlib assumes that, too. But it isn't explicitly described in API document or so. Therefore, we can't assume that hexdigest() always returns hex hash in lower case, for any hash algorithms, on any Python runtimes and versions. From point of view of that, it is reasonable for portability that 40800668e019 applies lower() on hex hash in overridefilemerge(). But on the other hand, in largefiles extension, there are still many code paths comparing between hex hashes or storing hex hash into standin file, without lower(). Switching to hash algorithm other than SHA-1 may be good chance to clarify our policy about hexdigest()-ed hash value string. - assume that hexdigest() always returns hex hash in lower case, or - apply lower() on hex hash in appropriate layers to ensure lower-case-ness of it for portability
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Sat, 01 Apr 2017 02:32:49 +0900
parents 4e446d31a744
children 728d37353e1e
files hgext/largefiles/basestore.py hgext/largefiles/lfcommands.py hgext/largefiles/lfutil.py hgext/largefiles/overrides.py hgext/largefiles/reposetup.py
diffstat 5 files changed, 9 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/largefiles/basestore.py	Sat Apr 01 02:32:49 2017 +0900
+++ b/hgext/largefiles/basestore.py	Sat Apr 01 02:32:49 2017 +0900
@@ -130,7 +130,7 @@
                     key = (filename, fctx.filenode())
                     if key not in verified:
                         verified.add(key)
-                        expectedhash = fctx.data().strip()
+                        expectedhash = lfutil.readasstandin(fctx)
                         filestocheck.append((cset, filename, expectedhash))
 
         failed = self._verifyfiles(contents, filestocheck)
--- a/hgext/largefiles/lfcommands.py	Sat Apr 01 02:32:49 2017 +0900
+++ b/hgext/largefiles/lfcommands.py	Sat Apr 01 02:32:49 2017 +0900
@@ -406,7 +406,7 @@
     ctx = repo[node]
     for lfile in lfiles:
         try:
-            expectedhash = ctx[lfutil.standin(lfile)].data().strip()
+            expectedhash = lfutil.readasstandin(ctx[lfutil.standin(lfile)])
         except IOError as err:
             if err.errno == errno.ENOENT:
                 continue # node must be None and standin wasn't found in wctx
--- a/hgext/largefiles/lfutil.py	Sat Apr 01 02:32:49 2017 +0900
+++ b/hgext/largefiles/lfutil.py	Sat Apr 01 02:32:49 2017 +0900
@@ -174,7 +174,7 @@
             fctx = pctx[standin(lfile)]
         except LookupError:
             fctx = None
-        if not fctx or fctx.data().strip() != hashfile(repo.wjoin(lfile)):
+        if not fctx or readasstandin(fctx) != hashfile(repo.wjoin(lfile)):
             modified.append(lfile)
         else:
             clean.append(lfile)
@@ -528,7 +528,7 @@
                     files.add(f)
         for fn in files:
             if isstandin(fn) and fn in ctx:
-                addfunc(fn, ctx[fn].data().strip())
+                addfunc(fn, readasstandin(ctx[fn]))
     repo.ui.progress(_('finding outgoing largefiles'), None)
 
 def updatestandinsbymatch(repo, match):
--- a/hgext/largefiles/overrides.py	Sat Apr 01 02:32:49 2017 +0900
+++ b/hgext/largefiles/overrides.py	Sat Apr 01 02:32:49 2017 +0900
@@ -553,9 +553,9 @@
         return origfn(premerge, repo, mynode, orig, fcd, fco, fca,
                       labels=labels)
 
-    ahash = fca.data().strip().lower()
-    dhash = fcd.data().strip().lower()
-    ohash = fco.data().strip().lower()
+    ahash = lfutil.readasstandin(fca).lower()
+    dhash = lfutil.readasstandin(fcd).lower()
+    ohash = lfutil.readasstandin(fco).lower()
     if (ohash != ahash and
         ohash != dhash and
         (dhash == ahash or
--- a/hgext/largefiles/reposetup.py	Sat Apr 01 02:32:49 2017 +0900
+++ b/hgext/largefiles/reposetup.py	Sat Apr 01 02:32:49 2017 +0900
@@ -172,7 +172,7 @@
                             if standin not in ctx1:
                                 # from second parent
                                 modified.append(lfile)
-                            elif ctx1[standin].data().strip() \
+                            elif lfutil.readasstandin(ctx1[standin]) \
                                     != lfutil.hashfile(self.wjoin(lfile)):
                                 modified.append(lfile)
                             else:
@@ -188,7 +188,7 @@
                             standin = lfutil.standin(lfile)
                             if standin in ctx1:
                                 abslfile = self.wjoin(lfile)
-                                if ((ctx1[standin].data().strip() !=
+                                if ((lfutil.readasstandin(ctx1[standin]) !=
                                      lfutil.hashfile(abslfile)) or
                                     (checkexec and
                                      ('x' in ctx1.flags(standin)) !=