Constants that are used once are dumb

It just means nobody knows what is being done without scrolling up and down, up and down the file like a doofus on a pogo stick.
This commit is contained in:
Max Howell 2011-08-04 13:45:48 +01:00
parent e9aaef0e25
commit 31885c2a99

View File

@ -13,11 +13,6 @@ end
class RefreshBrew class RefreshBrew
REPOSITORY_URL = "http://github.com/mxcl/homebrew.git" REPOSITORY_URL = "http://github.com/mxcl/homebrew.git"
CHECKOUT_COMMAND = "git checkout -q master"
UPDATE_COMMAND = "git pull #{REPOSITORY_URL} master"
REVISION_COMMAND = "git rev-parse HEAD"
DIFF_COMMAND = "git diff-tree -r --name-status -z %s %s"
FORMULA_DIR = 'Library/Formula/' FORMULA_DIR = 'Library/Formula/'
EXAMPLE_DIR = 'Library/Contributions/examples/' EXAMPLE_DIR = 'Library/Contributions/examples/'
@ -36,7 +31,7 @@ class RefreshBrew
def update_from_masterbrew! def update_from_masterbrew!
HOMEBREW_REPOSITORY.cd do HOMEBREW_REPOSITORY.cd do
if git_repo? if git_repo?
safe_system CHECKOUT_COMMAND safe_system "git checkout -q master"
@initial_revision = read_revision @initial_revision = read_revision
else else
begin begin
@ -44,11 +39,11 @@ class RefreshBrew
safe_system "git fetch #{REPOSITORY_URL}" safe_system "git fetch #{REPOSITORY_URL}"
safe_system "git reset --hard FETCH_HEAD" safe_system "git reset --hard FETCH_HEAD"
rescue Exception rescue Exception
safe_system "rm -rf .git" safe_system "/bin/rm -rf .git"
raise raise
end end
end end
execute(UPDATE_COMMAND) execute "git pull #{REPOSITORY_URL} master"
@current_revision = read_revision @current_revision = read_revision
end end
@ -58,7 +53,7 @@ class RefreshBrew
@changes_map = Hash.new {|h,k| h[k] = [] } @changes_map = Hash.new {|h,k| h[k] = [] }
changes = HOMEBREW_REPOSITORY.cd do changes = HOMEBREW_REPOSITORY.cd do
execute(DIFF_COMMAND % [initial_revision, current_revision]).split("\0") execute("git diff-tree -r --name-status -z #{initial_revision} #{current_revision}").split("\0")
end end
while status = changes.shift while status = changes.shift
@ -150,7 +145,7 @@ class RefreshBrew
private private
def read_revision def read_revision
execute(REVISION_COMMAND).chomp execute("git rev-parse HEAD").chomp
end end
def filter_by_directory(files, dir) def filter_by_directory(files, dir)