Skip to content

Commit

Permalink
Show changed examples on update [telemachus]
Browse files Browse the repository at this point in the history
* Also move updater output into the class itself
  • Loading branch information
adamv committed Aug 8, 2010
1 parent 2e8d07b commit ebd958b
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 26 deletions.
82 changes: 74 additions & 8 deletions Library/Homebrew/update.rb
Expand Up @@ -5,19 +5,26 @@ class RefreshBrew
UPDATE_COMMAND = "git pull #{RESPOSITORY_URL} master"
REVISION_COMMAND = 'git log -l -1 --pretty=format:%H 2> /dev/null'
GIT_UP_TO_DATE = 'Already up-to-date.'

formula_regexp = 'Library/Formula/(.+?)\.rb'
ADDED_FORMULA = %r{^\s+create mode \d+ #{formula_regexp}$}
UPDATED_FORMULA = %r{^\s+#{formula_regexp}\s}
DELETED_FORMULA = %r{^\s+delete mode \d+ #{formula_regexp}$}


example_regexp = 'Library/Contributions/examples/([^.\s]+).*'
ADDED_EXAMPLE = %r{^\s+create mode \d+ #{example_regexp}$}
UPDATED_EXAMPLE = %r{^\s+#{example_regexp}}
DELETED_EXAMPLE = %r{^\s+delete mode \d+ #{example_regexp}$}

attr_reader :added_formulae, :updated_formulae, :deleted_formulae, :initial_revision

attr_reader :added_examples, :updated_examples, :deleted_examples

def initialize
@added_formulae, @updated_formulae, @deleted_formulae = [], [], []
@added_examples, @updated_examples, @deleted_examples = [], [], []
@initial_revision = self.current_revision
end

# Performs an update of the homebrew source. Returns +true+ if a newer
# version was available, +false+ if already up-to-date.
def update_from_masterbrew!
Expand All @@ -39,19 +46,28 @@ def update_from_masterbrew!
@deleted_formulae << $1
when UPDATED_FORMULA
@updated_formulae << $1 unless @added_formulae.include?($1) or @deleted_formulae.include?($1)
when ADDED_EXAMPLE
@added_examples << $1
when DELETED_EXAMPLE
@deleted_examples << $1
when UPDATED_EXAMPLE
@updated_examples << $1 unless @added_examples.include?($1) or @deleted_examples.include?($1)
end
end
@added_formulae.sort!
@updated_formulae.sort!
@deleted_formulae.sort!

@added_examples.sort!
@updated_examples.sort!
@deleted_examples.sort!

output.strip != GIT_UP_TO_DATE
end

def pending_formulae_changes?
!@updated_formulae.empty?
end

def pending_new_formulae?
!@added_formulae.empty?
end
Expand All @@ -60,12 +76,62 @@ def deleted_formulae?
!@deleted_formulae.empty?
end

def pending_examples_changes?
!@updated_examples.empty?
end

def pending_new_examples?
!@added_examples.empty?
end

def deleted_examples?
!@deleted_examples.empty?
end

def current_revision
HOMEBREW_REPOSITORY.cd { execute(REVISION_COMMAND).strip }
rescue
'TAIL'
end


def report
puts "Updated Homebrew from #{initial_revision[0,8]} to #{current_revision[0,8]}."
## New Formulae
if pending_new_formulae?
ohai "The following formulae are new:"
puts_columns added_formulae
end
## Deleted Formulae
if deleted_formulae?
ohai "The following formulae were removed:"
puts_columns deleted_formulae
end
## Updated Formulae
if pending_formulae_changes?
ohai "The following formulae were updated:"
puts_columns updated_formulae
else
puts "No formulae were updated."
end
## New examples
if pending_new_examples?
ohai "The following external commands are new:"
puts_columns added_examples
end
## Deleted examples
if deleted_examples?
ohai "The following external commands were removed:"
puts_columns deleted_examples
end
## Updated Formulae
if pending_examples_changes?
ohai "The following external commands were updated:"
puts_columns updated_examples
else
puts "No external commands were updated."
end
end

private

def execute(cmd)
Expand Down
19 changes: 1 addition & 18 deletions bin/brew
Expand Up @@ -172,24 +172,7 @@ begin
unless updater.update_from_masterbrew!
puts "Already up-to-date."
else
puts "Updated Homebrew from #{updater.initial_revision[0,8]} to #{updater.current_revision[0,8]}."
## New Formulae
if updater.pending_new_formulae?
ohai "The following formulae are new:"
puts_columns updater.added_formulae
end
## Deleted Formulae
if updater.deleted_formulae?
ohai "The following formulae were removed:"
puts_columns updater.deleted_formulae
end
## Updated Formulae
if updater.pending_formulae_changes?
ohai "The following formulae were updated:"
puts_columns updater.updated_formulae
else
puts "No formulae were updated."
end
updater.report
end

when 'ln', 'link'
Expand Down

0 comments on commit ebd958b

Please sign in to comment.