[misc] 01/03: has-only: looking at parsing dbdtxt back to diff
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 4e54f61408f351ac7a60e46fc138e78c538d9f13
Author: Chris West (Faux) <git at goeswhere.com>
Date: Sun Apr 16 16:53:23 2017 +0100
has-only: looking at parsing dbdtxt back to diff
---
has-only.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/has-only.py b/has-only.py
new file mode 100755
index 0000000..9bde9bd
--- /dev/null
+++ b/has-only.py
@@ -0,0 +1,50 @@
+#!/usr/bin/python3
+
+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('(?:│ )+([+-])(.*)')
+
+def diff_parse(lines):
+ file = None
+ in_add = False
+ replacing = []
+ replacement = []
+
+ for line in lines + ['\n']:
+ if line.startswith(DO_FILE_PREFIX):
+ file = line[len(DO_FILE_PREFIX):].strip()
+ continue
+ ma = DO_DIFF_PREFIX.match(line)
+ if ma:
+ adding = ma.group(1) == '+'
+ data = ma.group(2)
+ if not adding:
+ if replacement:
+ yield (file, replacing, replacement)
+ replacing = []
+ replacement = []
+ replacing.append(data)
+ else:
+ replacement.append(data)
+ continue
+
+ if replacing or replacement:
+ yield (file, replacing, replacement)
+ replacing = []
+ replacement = []
+
+
+def main():
+ for name, lines in bodies():
+ print(name, list(diff_parse(lines)))
+
+
+if '__main__' == __name__:
+ main()
--
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