From 50767c60773b290eb8d203695852a6a0c21c71e4 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Fri, 10 Aug 2012 16:06:51 -0400 Subject: [PATCH] Record HEAD SHA and date of installs in receipt --- Library/Homebrew/extend/string.rb | 11 +++++++++++ Library/Homebrew/tab.rb | 19 +++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/extend/string.rb b/Library/Homebrew/extend/string.rb index 16171310bb..e9f475b6e4 100644 --- a/Library/Homebrew/extend/string.rb +++ b/Library/Homebrew/extend/string.rb @@ -21,6 +21,17 @@ class String self[0, prefix.length] == prefix end end + + # String.chomp, but if result is empty: returns nil instead. + # Allows `chuzzle || foo` short-circuits. + def chuzzle + s = chomp + s unless s.empty? + end +end + +class NilClass + def chuzzle; end end # used by the inreplace function (in utils.rb) diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb index e28ce1eda5..15f2911d9d 100644 --- a/Library/Homebrew/tab.rb +++ b/Library/Homebrew/tab.rb @@ -9,17 +9,19 @@ require 'vendor/multi_json' # `Tab.for_install`. class Tab < OpenStruct def self.for_install f, args + sha = `cd '#{HOMEBREW_REPOSITORY}' && git rev-parse --verify -q HEAD 2>/dev/null`.chuzzle Tab.new :used_options => args.used_options(f), :unused_options => args.unused_options(f), :tabfile => f.prefix + "INSTALL_RECEIPT.json", :built_as_bottle => !!args.build_bottle?, - :tapped_from => f.tap + :tapped_from => f.tap, + :time => Time.now.to_i, # to_s would be better but Ruby has no from_s function :P + :HEAD => sha end def self.from_file path tab = Tab.new MultiJson.decode(open(path).read) tab.tabfile = path - return tab end @@ -35,7 +37,9 @@ class Tab < OpenStruct Tab.new :used_options => [], :unused_options => [], :built_as_bottle => false, - :tapped_from => "" + :tapped_from => "", + :time => nil, + :HEAD => nil end end end @@ -63,7 +67,9 @@ class Tab < OpenStruct Tab.new :used_options => [], :unused_options => f.build.as_flags, :built_as_bottle => false, - :tapped_from => "" + :tapped_from => "", + :time => nil, + :HEAD => nil end def installed_with? opt @@ -79,8 +85,9 @@ class Tab < OpenStruct :used_options => used_options, :unused_options => unused_options, :built_as_bottle => built_as_bottle, - :tapped_from => tapped_from - }) + :tapped_from => tapped_from, + :time => time, + :HEAD => send("HEAD")}) end def write