[misc] 02/03: has-only: more efficiently strip off xxd output

Chris West faux-guest at moszumanska.debian.org
Sun Apr 16 17:58:05 UTC 2017


This is an automated email from the git hooks/post-receive script.

faux-guest pushed a commit to branch master
in repository misc.

commit 6cb0cac8bf272e90c401d365c29c1107c44717f3
Author: Chris West (Faux) <git at goeswhere.com>
Date:   Sun Apr 16 17:13:36 2017 +0100

    has-only: more efficiently strip off xxd output
---
 has-only.py | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/has-only.py b/has-only.py
index 9bde9bd..e370a97 100755
--- a/has-only.py
+++ b/has-only.py
@@ -1,15 +1,12 @@
 #!/usr/bin/python3
 
+import itertools
 import sys
 import re
 
-def bodies():
-    for path in sys.argv[1:]:
-        with open(path) as f:
-            yield (path, f.readlines())
-
 DO_FILE_PREFIX = '├── '
 DO_DIFF_PREFIX = re.compile('(?:│ )+([+-])(.*)')
+XXD_LINE = re.compile('[0-9a-f]{8}: (?:[0-9a-f]{4} ){8} (.{16})')
 
 def diff_parse(lines):
     file = None
@@ -17,7 +14,7 @@ def diff_parse(lines):
     replacing = []
     replacement = []
 
-    for line in lines + ['\n']:
+    for line in itertools.chain(lines, ['\n']):
         if line.startswith(DO_FILE_PREFIX):
             file = line[len(DO_FILE_PREFIX):].strip()
             continue
@@ -40,10 +37,21 @@ def diff_parse(lines):
             replacing = []
             replacement = []
 
+def strip_xxd(lines):
+    stripped = ''
+    for line in lines:
+        ma = XXD_LINE.match(line)
+        if not ma:
+            return '\n'.join(lines)
+        stripped += ma.group(1)
+
+    return stripped
+
 
 def main():
-    for name, lines in bodies():
-        print(name, list(diff_parse(lines)))
+    for path in sys.argv[1:]:
+        with open(path) as f:
+            print (path, list((file, strip_xxd(bef), strip_xxd(aft)) for file, bef, aft in diff_parse(f)))
 
 
 if '__main__' == __name__:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/misc.git



More information about the Reproducible-commits mailing list