Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
absorb: refuse empty replays and empty patches, normalise selectors, and print the whole-tree recovery command
v0lumehi49715da757ed
diff --git a/scripts/patches.py b/scripts/patches.pyindex 23222b8e..60807190 100644--- a/scripts/patches.py+++ b/scripts/patches.py@@ -284,7 +284,7 @@ def fix_hint(diff, patches):if f in gen: lines.append(f'{f} is generated: run `python3 scripts/patches.py apply`')else: lines.append(f'{f} differs from pin+patches: run `python3 scripts/patches.py absorb {f}` and commit patches/')if absorbable:- lines.append(f'To fold all of them at once: `python3 scripts/patches.py absorb {" ".join(absorbable[:6])}{" ..." if len(absorbable) > 6 else ""}`, then commit patches/ (and dm/fork_patches.txt if it changed).')+ lines.append('To fold all of them at once: `python3 scripts/patches.py absorb`, then commit patches/ (and dm/fork_patches.txt if it changed).')lines.append('A new file goes to the patch that owns its folder; if that is ambiguous, absorb stops and asks for `--into <patch>` (see `scripts/patches.py status`).')lines.append('A change that deserves its own patch (new Upstream-Status, Reason, Issue): commit it, then `python3 scripts/patches.py export <commit>`. See patches/README.md.')else:@@ -505,7 +505,12 @@ def cmd_absorb(a):want = tree_files(s.dir)have = local_files(root)changed = [p for p in sorted(set(want) | set(have)) if want.get(p) != have.get(p)]- sel = [x.rstrip('/') for x in a.paths]+ sel = []+ for x in a.paths:+ rel = os.path.relpath(os.path.realpath(x), root).replace(os.sep, '/')+ if rel == '..' or rel.startswith('../'): raise Fail(f'{x} is outside the checkout')+ sel.append('' if rel == '.' else rel)+ if '' in sel: sel = [] # "." is the whole treeif sel: changed = [p for p in changed if any(p == x or p.startswith(x + '/') for x in sel)]changed = [p for p in changed if p not in gen]if not changed:@@ -524,9 +529,12 @@ def cmd_absorb(a):with Scratch(root, sha, a.tmp) as s:wt, new = s.dir, {}for i, p in enumerate(patches):+ before = git('rev-parse', 'HEAD^{tree}', cwd=wt).stdoutr = am(wt, p)if r.returncode:raise Fail(f'{p.file} no longer applies after absorbing into an earlier patch ({(r.stderr or r.stdout).strip()[-300:]}); name a later patch with --into')+ if git('rev-parse', 'HEAD^{tree}', cwd=wt).stdout == before:+ raise Fail(f'{p.file} would be empty after absorbing into an earlier patch (its change is already there); name that patch with --into. No patch was changed')if i not in plan: continuefor f in plan[i]:if f in have:@@ -535,6 +543,8 @@ def cmd_absorb(a):git('add', '--', f, cwd=wt)else: git('rm', '-q', '-f', '--', f, cwd=wt)git(*ident, 'commit', '-q', '--amend', '--no-edit', '--allow-empty', cwd=wt)+ if git('diff', '--quiet', 'HEAD^', 'HEAD', cwd=wt, check=False).returncode == 0:+ raise Fail(f'absorbing {", ".join(plan[i])} would leave {p.file} empty (a full revert of that patch); delete the patch and its line in patches/series instead. No patch was changed')new[i] = git('format-patch', '--binary', '--zero-commit', '--no-signature', '--no-numbered', '--stdout', '-1', 'HEAD', cwd=wt, binary=True).stdoutfor i, text in new.items():patches[i].path.write_bytes(text)diff --git a/scripts/tests/test_patches.py b/scripts/tests/test_patches.pyindex b519ff7d..f8c8da15 100644--- a/scripts/tests/test_patches.py+++ b/scripts/tests/test_patches.py@@ -206,6 +206,35 @@ class Absorb(Fixture):def test_nothing_to_absorb_just_checks(self):self.assertIn('nothing to fold in', self.run_tool('absorb'))+ def test_selectors_are_normalised_and_dot_is_the_whole_tree(self):+ self.w('dm/a.c', 'line1\nline2 fork\nline3\nline4\nline5\nline6\nline7 one\n'); self.w('dm/new.c', 'n\n')+ self.assertIn('absorbed dm/a.c', self.run_tool('absorb', './dm/a.c', expect=1)) # dm/new.c is still a difference+ self.assertIn('absorbed dm/new.c', self.run_tool('absorb', str(self.r / 'dm') + '/')) # absolute, trailing slash+ self.w('dm/b.c', 'b1\nb2 edited\n')+ self.assertIn('absorbed dm/b.c', self.run_tool('absorb', '.'))+ self.assertIn('outside the checkout', self.run_tool('absorb', '../elsewhere', expect=2))++ def test_the_check_hint_lists_the_whole_tree_command_without_truncation(self):+ for n in range(8): self.w(f'dm/n{n}.c', 'n\n')+ out = self.run_tool('check', expect=1)+ self.assertNotIn('...', out)+ self.assertIn('`python3 scripts/patches.py absorb`', out)++ def test_a_full_revert_that_empties_a_patch_is_refused_and_changes_nothing(self):+ self.w('dm/a.c', 'line1\nline2\nline3\nline4\nline5\nline6\nline7\n')+ before = self.patch.read_text()+ out = self.run_tool('absorb', expect=2)+ self.assertIn('would leave', out); self.assertIn('empty', out)+ self.assertEqual(self.patch.read_text(), before)++ def test_into_that_makes_a_later_patch_empty_is_refused_before_writing(self):+ self.export_second() # 0002 sets b2 to "b2 fork"; putting dm/b.c into 0001 makes 0002 a no-op or a conflict+ self.w('dm/b.c', 'b1\nb2 fork\nb3\n')+ before = {f.name: f.read_text() for f in (self.r / 'patches').glob('*.patch')}+ out = self.run_tool('absorb', '--into', 'make-line-2-the-fork-s', 'dm/b.c', expect=2)+ self.assertTrue('would be empty' in out or 'no longer applies' in out, out)+ self.assertEqual(before, {f.name: f.read_text() for f in (self.r / 'patches').glob('*.patch')})+def test_the_shader_chain_is_refused(self):self.w('dm/gfx/nvn/dmsh_chain.h', 'x\n')self.assertIn('shader chain', self.run_tool('absorb', expect=2))