Skip to content

Commit af907ce

Browse files
committed
hackorum-patch: improve base commit lookup logic
Currently we simply looked at the first 50 commits, which wasn't able to properly find the parent for old commits. We also can't rely on the "Date" field in the patches, because with rebases/changes, it might be significantly before the actual submission date of the latest patch version. To properly find earlier bases without going through a long list of commits, this change adds a new metadata file containing the submission date on the mailing list, which should be a better start time for lookups.
1 parent dc5f2bd commit af907ce

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

app/controllers/topics_controller.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,29 @@ def latest_patchset
147147
patches = latest_message.attachments.select(&:patch?).sort_by(&:file_name)
148148
return head :not_found if patches.empty?
149149

150+
# Calculate attachment number (1-based index among all messages with attachments)
151+
messages_with_attachments = @topic.messages
152+
.where(id: Attachment.where(message_id: @topic.messages.select(:id))
153+
.select(:message_id))
154+
.order(created_at: :asc)
155+
attachment_number = messages_with_attachments.index { |msg| msg.id == latest_message.id }.to_i + 1
156+
150157
require 'zlib'
151158
require 'rubygems/package'
152159

153160
tar_gz_data = StringIO.new
154161
Zlib::GzipWriter.wrap(tar_gz_data) do |gz|
155162
Gem::Package::TarWriter.new(gz) do |tar|
163+
# Add metadata file first
164+
metadata = {
165+
attachment_number: attachment_number,
166+
topic_id: @topic.id,
167+
submission_date: latest_message.created_at.iso8601
168+
}.to_json
169+
tar.add_file_simple('hackorum.json', 0644, metadata.bytesize) do |io|
170+
io.write(metadata)
171+
end
172+
156173
patches.each do |patch|
157174
content = patch.decoded_body_utf8
158175
tar.add_file_simple(patch.file_name, 0644, content.bytesize) do |io|

public/scripts/hackorum-patch

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class HackorumPatch
2323
@local_archive = nil
2424
@using_local_file = false
2525
@using_diff_mode = false
26+
@metadata = nil
2627

2728
parse_options!(argv)
2829

@@ -355,6 +356,11 @@ class HackorumPatch
355356
Gem::Package::TarReader.new(gz) do |tar|
356357
tar.each do |entry|
357358
next unless entry.file?
359+
if entry.full_name == 'hackorum.json'
360+
@metadata = JSON.parse(entry.read)
361+
verbose_log " Parsed metadata: submission_date=#{@metadata['submission_date']}"
362+
next
363+
end
358364
dest = File.join(@temp_dir, entry.full_name)
359365
File.write(dest, entry.read)
360366
puts " Extracted: #{entry.full_name}"
@@ -376,6 +382,11 @@ class HackorumPatch
376382
Gem::Package::TarReader.new(gz) do |tar|
377383
tar.each do |entry|
378384
next unless entry.file?
385+
if entry.full_name == 'hackorum.json'
386+
@metadata = JSON.parse(entry.read)
387+
verbose_log " Parsed metadata: submission_date=#{@metadata['submission_date']}"
388+
next
389+
end
379390
dest = File.join(@temp_dir, entry.full_name)
380391
File.write(dest, entry.read)
381392
puts " Extracted: #{entry.full_name}"
@@ -503,7 +514,16 @@ class HackorumPatch
503514
# Find commits on the default branch that touched these files
504515
paths = file_info.keys.map { |p| Shellwords.escape(p) }.join(" ")
505516
verbose_log " Searching commits that touched: #{file_info.keys.join(', ')}"
506-
commits = `git log #{default_branch} --pretty=format:%H -n 50 -- #{paths} 2>/dev/null`.strip.split("\n")
517+
518+
# Use submission date from metadata to constrain search
519+
until_flag = ""
520+
if @metadata && @metadata['submission_date']
521+
submission_date = @metadata['submission_date']
522+
verbose_log " Using submission date constraint: --until=#{submission_date}"
523+
until_flag = "--until=#{Shellwords.escape(submission_date)}"
524+
end
525+
526+
commits = `git log #{default_branch} --pretty=format:%H #{until_flag} -n 200 -- #{paths} 2>/dev/null`.strip.split("\n")
507527
verbose_log " Found #{commits.size} candidate commits to check"
508528

509529
commits.each_with_index do |commit, idx|

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+
"Improved base commit detection using submission date from archive metadata",
89
"Added --verbose option for detailed base commit detection debugging"
910
]
1011
},

0 commit comments

Comments
 (0)