Skip to content

Commit 7cc394a

Browse files
committed
devutils/platform_patches: update shared patches instead of deleting
Instead of deleting copies of generic patches when unmerging them from platform patches, move them back into the shared repository. This makes it much more pleasant and ergonomic to work on patches as a merged series, and allows to e.g. refresh existing patches without having to move them back to the original folder manually.
1 parent 0b53546 commit 7cc394a

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

devutils/update_platform_patches.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,19 @@ def _dir_empty(path):
6363
return False
6464

6565

66-
def _remove_files_with_dirs(root_dir, sorted_file_iter):
66+
def _rename_files_with_dirs(root_dir, source_dir, sorted_file_iter):
6767
'''
68-
Deletes a list of sorted files relative to root_dir, removing empty directories along the way
68+
Moves a list of sorted files back to their original location,
69+
removing empty directories along the way
6970
'''
7071
past_parent = None
7172
for partial_path in sorted_file_iter:
7273
complete_path = Path(root_dir, partial_path)
74+
complete_source_path = Path(source_dir, partial_path)
7375
try:
74-
complete_path.unlink()
76+
complete_path.rename(complete_source_path)
7577
except FileNotFoundError:
76-
get_logger().warning('Could not remove prepended patch: %s', complete_path)
78+
get_logger().warning('Could not move prepended patch: %s', complete_path)
7779
if past_parent != complete_path.parent:
7880
while past_parent and _dir_empty(past_parent):
7981
past_parent.rmdir()
@@ -85,7 +87,7 @@ def _remove_files_with_dirs(root_dir, sorted_file_iter):
8587
complete_path = complete_path.parent
8688

8789

88-
def unmerge_platform_patches(platform_patches_dir):
90+
def unmerge_platform_patches(platform_patches_dir, prepend_patches_dir):
8991
'''
9092
Undo merge_platform_patches(), adding any new patches from series.merged as necessary
9193
@@ -99,8 +101,8 @@ def unmerge_platform_patches(platform_patches_dir):
99101
filter(len,
100102
(platform_patches_dir / _SERIES_PREPEND).read_text(encoding=ENCODING).splitlines()))
101103

102-
# Remove prepended files with directories
103-
_remove_files_with_dirs(platform_patches_dir, sorted(prepend_series))
104+
# Move prepended files back to original location, preserving changes
105+
_rename_files_with_dirs(platform_patches_dir, prepend_patches_dir, sorted(prepend_series))
104106

105107
# Determine positions of blank spaces in series.orig
106108
if not (platform_patches_dir / _SERIES_ORIG).exists():
@@ -169,10 +171,11 @@ def main():
169171
repo_dir = Path(__file__).resolve().parent.parent
170172

171173
success = False
174+
prepend_patches_dir = repo_dir / 'patches'
172175
if args.command == 'merge':
173-
success = merge_platform_patches(args.platform_patches, repo_dir / 'patches')
176+
success = merge_platform_patches(args.platform_patches, prepend_patches_dir)
174177
elif args.command == 'unmerge':
175-
success = unmerge_platform_patches(args.platform_patches)
178+
success = unmerge_platform_patches(args.platform_patches, prepend_patches_dir)
176179
else:
177180
raise NotImplementedError(args.command)
178181

0 commit comments

Comments
 (0)