MCPcopy Create free account
hub / github.com/daijro/camoufox / open_patch_workspace

Function open_patch_workspace

scripts/developer.py:66–134  ·  view source on GitHub ↗

Resets a workspace for editing a patch. Process: 1. Resets Camoufox 2. Patches all except the selected patch 3. Sets checkpoint 4. Reruns the selected patch, but reads rejects similar to "Find broken patches"

(selected_patch, stop_at_patch=False)

Source from the content-addressed store, hash-verified

64 return True
65
66def open_patch_workspace(selected_patch, stop_at_patch=False):
67 """
68 Resets a workspace for editing a patch.
69
70 Process:
71 1. Resets Camoufox
72 2. Patches all except the selected patch
73 3. Sets checkpoint
74 4. Reruns the selected patch, but reads rejects similar to "Find broken patches"
75 """
76 # Prepare UI
77 patch_files = list_patches()
78
79 # Reset workspace
80 reset_camoufox()
81
82 skipped_patches = []
83 applied_patches = []
84 # Patch all except the selected patch
85 for patch_file in patch_files:
86 if patch_file == selected_patch:
87 if stop_at_patch:
88 break
89 continue
90 if is_broken(patch_file):
91 print(f'Skipping broken patch: {patch_file}')
92 skipped_patches.append(patch_file)
93 continue
94 patch(patch_file, silent=True)
95 applied_patches.append(patch_file)
96
97 # Set checkpoint
98 if applied_patches:
99 with temp_cd('..'):
100 run('make first-checkpoint')
101
102 # Set message for patch result
103 patch_broken = is_broken(selected_patch)
104 if patch_broken:
105 message = "Broken patch has been applied to the workspace.\n\nPLEASE FIX THE FOLLOWING:\n"
106 else:
107 message = "Successfully applied patch to the workspace.\n"
108
109 # Run the selected patch
110 patch_result = os.popen(f'patch -p1 -i "{selected_patch}"').read()
111
112 # Find any line containing a file .rej
113 if patch_broken:
114 for line in patch_result.splitlines():
115 if file := re.search(r'[^\s]+\.rej', line):
116 message += f'> {file[0]}' + '\n'
117
118 def msg_format_paths(file_list):
119 message = ''
120 for patch_file in file_list:
121 message += '> ' + patch_file[len('../patches/') :] + '\n'
122 return message
123

Callers 1

handle_choiceFunction · 0.85

Calls 7

list_patchesFunction · 0.90
patchFunction · 0.90
temp_cdFunction · 0.90
runFunction · 0.90
reset_camoufoxFunction · 0.85
is_brokenFunction · 0.85
msg_format_pathsFunction · 0.85

Tested by

no test coverage detected