Skip to content

Instantly share code, notes, and snippets.

@cruessler
Created October 25, 2024 15:43
Show Gist options
  • Save cruessler/12ed15763fad3754364eaa0659a00ba2 to your computer and use it in GitHub Desktop.
Save cruessler/12ed15763fad3754364eaa0659a00ba2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
if not ENV.include?("GIT_WORK_TREE")
print "env variable GIT_WORK_TREE not set\n"
exit 1
end
if ARGV.count < 1
print "you need to supply the number of files to run the comparison for as an argument\n"
exit 1
end
GIT_WORK_TREE = ENV["GIT_WORK_TREE"]
GIT_DIR = "#{GIT_WORK_TREE}/.git"
filenames = `env GIT_DIR=#{GIT_WORK_TREE}/.git git ls-files`.lines(chomp: true)
number_of_files_to_run_log_for = ARGV.shift.to_i
print "#{filenames.size} files to run log for\n"
print "running log for #{number_of_files_to_run_log_for} files\n"
filenames.take(number_of_files_to_run_log_for).each do |filename|
print "comparing logs for #{filename}\n"
absolute_filename = "#{GIT_WORK_TREE}/#{filename}"
gix_logged_lines = `env GIT_DIR=#{GIT_DIR} gix log #{filename}`.lines(chomp: true)
git_logged_lines = `env GIT_DIR=#{GIT_DIR} git log --oneline #{absolute_filename}`.lines(chomp: true)
if gix_logged_lines.size != git_logged_lines.size
print "logs have different number of lines\n"
next
end
gix_logged_lines.zip(git_logged_lines).each do |(gix_logged_line, git_logged_line)|
match = gix_logged_line.match(/([0-9a-f]+) (.*)/)
if match.nil?
print "`#{git_logged_line}` does not look like a `gix log` line\n"
next
end
gix_hash = match[1]
match = git_logged_line.match(/([0-9a-f]+) (.*)/)
if match.nil?
print "`#{git_logged_line}` does not look like a `git log --oneline` line\n"
next
end
git_hash = match[1]
if not git_hash.start_with?(gix_hash) and not gix_hash.start_with?(git_hash)
print "log entries don't match\n"
print "gix logged #{gix_logged_line} while git logged #{git_logged_line}\n\n"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment