-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpkgdiff
More file actions
executable file
·133 lines (101 loc) · 3.97 KB
/
pkgdiff
File metadata and controls
executable file
·133 lines (101 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python
from collections import defaultdict
import itertools
import pathlib
import re
import subprocess
import sys
import tempfile
def usage():
print(f'usage: {sys.argv[0]} PACKAGE.src.tar.zst PACKAGE_DIRECTORY/', file=sys.stderr)
sys.exit(1)
# The following fields may appear only once in each .SRCINFO file, in the pkgbase section
SRCINFO_SINGULAR_PKGBASE = {'pkgver', 'pkgrel', 'epoch'}
# The following fields may appear up to once in any section
SRCINFO_SINGULAR_ANY = {'pkgdesc', 'url', 'install', 'changelog'}
# The following fields may be repeated within a section to specify multiple values
SRCINFO_MULTIPLE_VALUES = {
'arch',
'groups',
'license',
'noextract',
'options',
'backup',
'validpgpkeys', # can only be in pkgbase
}
# The following fields may, additionally, specify multiple architectures as shown below
SRCINFO_MULTIARCH = {
'source',
'depends', 'checkdepends', 'makedepends', 'optdepends',
'provides', 'conflicts', 'replaces',
'md5sums', 'sha1sums', 'sha224sums', 'sha256sums', 'sha384sums', 'sha512sums',
}
def parse_srcinfo(f):
pkgbase_section = defaultdict(list)
package_sections = defaultdict(lambda: defaultdict(list))
current_section = None
for line in f:
line = line.rstrip()
line = re.sub(r'#.*', '', line)
line = re.sub(r'\s+$', '', line)
if line == '':
continue
m = re.match(r'^\s*(\w+)\s*=\s*(.*)', line)
assert m, f'line {line!r} did not match!'
key, value = m.groups()
match key:
case 'pkgbase':
current_section = pkgbase_section
case 'pkgname':
assert value not in package_sections
package_sections[value] = current_section = defaultdict(list)
case _:
current_section[key].append(value)
return { name:dict(pkgbase_section | section) for name, section in package_sections.items() }
def identify_remote_files(pkg_dir):
with pathlib.Path(pkg_dir, '.SRCINFO').open() as f:
src_info = parse_srcinfo(f)
sources = list(itertools.chain.from_iterable(package.get('source', []) for package in src_info.values()))
for source in sources:
if '::' in source:
filename, source = source.split('::')
else:
filename = pathlib.Path(source).name
# XXX other protocols
if source.startswith('http://') or source.startswith('https://'):
yield filename
def gather_files(pkg_dir, name_blocklist):
files = set()
git_subdir = pathlib.Path(pkg_dir) / '.git'
for child in pathlib.Path(pkg_dir).glob('**/*'):
if child.is_dir():
continue
if child.name in name_blocklist:
continue
if child.name == '.SRCINFO':
continue
if child.is_relative_to(git_subdir):
continue
files.add(child.relative_to(pkg_dir))
return files
if len(sys.argv) < 3:
usage()
_, older_src_pkg, pkg_dir, *_ = sys.argv
with tempfile.TemporaryDirectory() as tempdir:
subprocess.check_call(['tar', 'xf', older_src_pkg, '--zstd', '--strip-components=1', '--directory=' + tempdir])
old_remote_files = set(identify_remote_files(tempdir))
new_remote_files = set(identify_remote_files(pkg_dir))
old_files = gather_files(tempdir, old_remote_files)
new_files = gather_files(pkg_dir, new_remote_files)
compare_me = []
for rel_path in old_files | new_files:
old_path = tempdir / rel_path
new_path = pkg_dir / rel_path
if rel_path in old_files and rel_path in new_files:
if old_path.read_bytes() != new_path.read_bytes():
compare_me.extend( (old_path, new_path) )
elif rel_path in old_files:
compare_me.extend( (old_path, pathlib.Path('/dev/null')) )
else: # rel_path in new_files
compare_me.extend( (pathlib.Path('/dev/null'), new_path) )
subprocess.check_call(['vimdiff-pairs'] + compare_me)