Skip to contentSkip to conversation

check_whence: Check link targets are valid

PATCH In review Adam Sampson 2 participants 2 messages Jun 26, 2023 – Jul 6, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 check_whence: Check link targets are valid

This should catch a couple of common errors: reversing the two arguments to Link, and not making the second argument relative to the first.

---
v2: rebase, as Emil's recent patches merged part of v1 anyway

 check_whence.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
check_whence.py +18 -0
index 2e6950a8..d45d90f8 100755
@@ -91,6 +91,24 @@ def main():
         sys.stderr.write('E: %s listed in WHENCE does not exist\n' % name)
         ret = 1
 
+    # A link can point to another link, or to a file...
+    valid_targets = set(link[0] for link in links_list) | git_files
+
+    # ... or to a directory
+    for target in set(valid_targets):
+        dirname = target
+        while True:
+            dirname = os.path.dirname(dirname)
+            if dirname == '':
+                break
+            valid_targets.add(dirname)
+
+    for name, target in sorted(links_list):
+        if target not in valid_targets:
+            sys.stderr.write('E: target %s of link %s in WHENCE'
+                             ' does not exist\n' % (target, name))
+            ret = 1
+
     for name in sorted(list(git_files - known_files)):
         # Ignore subdirectory changelogs and GPG detached signatures
         if (name.endswith('/ChangeLog') or
Signature · 1 line
2.41.0
#1 lore raw

Applied and pushed out.

josh

Quoted 43 lines · Adam Sampson

This should catch a couple of common errors: reversing the two arguments to Link, and not making the second argument relative to the first.

---
v2: rebase, as Emil's recent patches merged part of v1 anyway

 check_whence.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
check_whence.py +18 -1
index 2e6950a8..d45d90f8 100755
@@ -91,6 +91,24 @@ def main():
         sys.stderr.write('E: %s listed in WHENCE does not exist\n' % name)
         ret = 1
 
+    # A link can point to another link, or to a file...
+    valid_targets = set(link[0] for link in links_list) | git_files
+
+    # ... or to a directory
+    for target in set(valid_targets):
+        dirname = target
+        while True:
+            dirname = os.path.dirname(dirname)
+            if dirname == '':
+                break
+            valid_targets.add(dirname)
+
+    for name, target in sorted(links_list):
+        if target not in valid_targets:
+            sys.stderr.write('E: target %s of link %s in WHENCE'
+                             ' does not exist\n' % (target, name))
+            ret = 1
+
     for name in sorted(list(git_files - known_files)):
         # Ignore subdirectory changelogs and GPG detached signatures
         if (name.endswith('/ChangeLog') or
--

2.41.0