mirror of
https://github.com/morgan9e/helium
synced 2026-04-14 00:14:20 +09:00
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.
This commit is contained in:
@@ -63,17 +63,19 @@ def _dir_empty(path):
|
||||
return False
|
||||
|
||||
|
||||
def _remove_files_with_dirs(root_dir, sorted_file_iter):
|
||||
def _rename_files_with_dirs(root_dir, source_dir, sorted_file_iter):
|
||||
'''
|
||||
Deletes a list of sorted files relative to root_dir, removing empty directories along the way
|
||||
Moves a list of sorted files back to their original location,
|
||||
removing empty directories along the way
|
||||
'''
|
||||
past_parent = None
|
||||
for partial_path in sorted_file_iter:
|
||||
complete_path = Path(root_dir, partial_path)
|
||||
complete_source_path = Path(source_dir, partial_path)
|
||||
try:
|
||||
complete_path.unlink()
|
||||
complete_path.rename(complete_source_path)
|
||||
except FileNotFoundError:
|
||||
get_logger().warning('Could not remove prepended patch: %s', complete_path)
|
||||
get_logger().warning('Could not move prepended patch: %s', complete_path)
|
||||
if past_parent != complete_path.parent:
|
||||
while past_parent and _dir_empty(past_parent):
|
||||
past_parent.rmdir()
|
||||
@@ -85,7 +87,7 @@ def _remove_files_with_dirs(root_dir, sorted_file_iter):
|
||||
complete_path = complete_path.parent
|
||||
|
||||
|
||||
def unmerge_platform_patches(platform_patches_dir):
|
||||
def unmerge_platform_patches(platform_patches_dir, prepend_patches_dir):
|
||||
'''
|
||||
Undo merge_platform_patches(), adding any new patches from series.merged as necessary
|
||||
|
||||
@@ -99,8 +101,8 @@ def unmerge_platform_patches(platform_patches_dir):
|
||||
filter(len,
|
||||
(platform_patches_dir / _SERIES_PREPEND).read_text(encoding=ENCODING).splitlines()))
|
||||
|
||||
# Remove prepended files with directories
|
||||
_remove_files_with_dirs(platform_patches_dir, sorted(prepend_series))
|
||||
# Move prepended files back to original location, preserving changes
|
||||
_rename_files_with_dirs(platform_patches_dir, prepend_patches_dir, sorted(prepend_series))
|
||||
|
||||
# Determine positions of blank spaces in series.orig
|
||||
if not (platform_patches_dir / _SERIES_ORIG).exists():
|
||||
@@ -169,10 +171,11 @@ def main():
|
||||
repo_dir = Path(__file__).resolve().parent.parent
|
||||
|
||||
success = False
|
||||
prepend_patches_dir = repo_dir / 'patches'
|
||||
if args.command == 'merge':
|
||||
success = merge_platform_patches(args.platform_patches, repo_dir / 'patches')
|
||||
success = merge_platform_patches(args.platform_patches, prepend_patches_dir)
|
||||
elif args.command == 'unmerge':
|
||||
success = unmerge_platform_patches(args.platform_patches)
|
||||
success = unmerge_platform_patches(args.platform_patches, prepend_patches_dir)
|
||||
else:
|
||||
raise NotImplementedError(args.command)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user