Skip to content

Commit de7a40b

Browse files
committed
hackorum-patch: fix sorting of patch files
Currently we did a basic sort which meant that "nocfbot-XXX" got always sorted before 0001, causing apllication failures. The new logic tries to extract the patch number correctly, even with different prefixes.
1 parent 58f668e commit de7a40b

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

public/scripts/hackorum-patch

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ class HackorumPatch
102102
puts msg if @options[:verbose]
103103
end
104104

105+
def sort_patch_files(files)
106+
files.sort_by do |f|
107+
basename = File.basename(f)
108+
# Match sequence number: digits followed by hyphen before the actual patch name
109+
# e.g., "0001-subject.patch" or "nocfbot.v2-0005-subject.patch"
110+
if basename =~ /(\d+)-[^-]+\.(patch|diff)$/i
111+
$1.to_i
112+
else
113+
# Fallback: sort alphabetically but after numbered patches
114+
[Float::INFINITY, basename]
115+
end
116+
end
117+
end
118+
105119
def parse_options!(argv)
106120
@option_parser = OptionParser.new do |opts|
107121
opts.banner = "Usage: hackorum-patch <topic_id|archive.tar.gz> [<branch_name>] [OPTIONS]"
@@ -369,7 +383,7 @@ class HackorumPatch
369383
end
370384
end
371385

372-
all_files = Dir.glob(File.join(@temp_dir, "*")).sort
386+
all_files = sort_patch_files(Dir.glob(File.join(@temp_dir, "*")))
373387
categorize_and_report_files(all_files)
374388
end
375389

@@ -396,7 +410,7 @@ class HackorumPatch
396410
end
397411
end
398412

399-
all_files = Dir.glob(File.join(@temp_dir, "*")).sort
413+
all_files = sort_patch_files(Dir.glob(File.join(@temp_dir, "*")))
400414
categorize_and_report_files(all_files)
401415
end
402416

@@ -432,8 +446,8 @@ class HackorumPatch
432446
return @options[:base_commit]
433447
end
434448

435-
patch_files = Dir.glob(File.join(patch_files_dir, "*.patch")).sort
436-
diff_files = Dir.glob(File.join(patch_files_dir, "*.diff")).sort
449+
patch_files = sort_patch_files(Dir.glob(File.join(patch_files_dir, "*.patch")))
450+
diff_files = sort_patch_files(Dir.glob(File.join(patch_files_dir, "*.diff")))
437451
all_patch_files = patch_files + diff_files
438452
return detect_default_branch_head if all_patch_files.empty?
439453

public/scripts/hackorum-patch.changelog.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"version": "1.2.0",
66
"date": "2026-02-04",
77
"changes": [
8+
"Fixed patch file sorting for files with prefixes (e.g., nocfbot.v2-0005-subject.patch now sorts by sequence number)",
89
"Improved base commit detection using submission date from archive metadata",
910
"Added --verbose option for detailed base commit detection debugging",
1011
"Copy extracted patch files and metadata to .hackorum/ directory for inspection"

0 commit comments

Comments
 (0)