Skip to content

Instantly share code, notes, and snippets.

@elandesign
Created March 16, 2016 17:47
Show Gist options
  • Save elandesign/6e5a2386c3a082c9cac2 to your computer and use it in GitHub Desktop.
Save elandesign/6e5a2386c3a082c9cac2 to your computer and use it in GitHub Desktop.
Find the oldest line of extant ruby code in a git repository
class OldestLineOfCode
IGNORE_LINES = /.*?\)\s*(class |module |def |#|$)/
def initialize
@oldest = "2016-03-16"
@oldest_file = nil
@oldest_line = nil
end
def scan
Dir.glob("**/*.rb").each(&method(:scan_file))
puts "Oldest line of code is in #{@oldest_file} from #{@oldest} (#{@oldest_line})"
end
def scan_file(file)
puts "Scanning #{file}"
`git blame #{file}`.split("\n").each do |line|
if (line =~ IGNORE_LINES).nil?
last_modified = line.match(/\d{4}-\d{2}-\d{2}/)[0]
if last_modified < @oldest
@oldest = last_modified
@oldest_file = file
@oldest_line = line
end
end
end
end
end
OldestLineOfCode.new.scan
@elandesign
Copy link
Author

Oldest line of code is in app/controllers/admin/companies_controller.rb from 2006-11-10 (73687b83 app/controllers/companies_controller.rb (Graeme Mathison 2006-11-10 14:02:34 +0000 17) respond_to do |format|)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment