diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0d778dd675d3b00a19b76a22a2620e14d98b3ff9..f46693f0a733cd8e9120d5bbe5f7cd9d83961184 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,6 +10,7 @@ class ApplicationController < ActionController::Base before_filter :count_requests before_filter :set_invites before_filter :set_locale + before_filter :set_git_header before_filter :which_action_and_user prepend_before_filter :clear_gc_stats @@ -33,6 +34,11 @@ class ApplicationController < ActionController::Base end end + def set_git_header + headers['X-Git-Update'] = GIT_UPDATE unless GIT_UPDATE.nil? + headers['X-Git-Revision'] = GIT_REVISION unless GIT_REVISION.nil? + end + def which_action_and_user str = "event=request_with_user controller=#{self.class} action=#{self.action_name} " if current_user diff --git a/config/initializers/version_header.rb b/config/initializers/version_header.rb index 588c83cd945704f8fbc6d364b511b2c7310b4881..56ec60cf102345ac8030e59355728072f6e6ab04 100644 --- a/config/initializers/version_header.rb +++ b/config/initializers/version_header.rb @@ -1,31 +1,13 @@ -#original from https://github.com/jopper/diaspora -#modified by David Morley -require 'time' +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. - def last_modified - git_last='git log -1 --pretty=format:"%cd"' - filepath = Rails.root.join('tmp', '.last_pull') - time_min = 60 - @header_name = "X-Git-Update" - if File.writable?(filepath) - begin - mtime = File.mtime(filepath) - last = IO.readlines(filepath).at(0) - rescue Exception => e - Rails.logger.info("Failed to read git status #{filepath}: #{e}") - end - end - if (mtime.nil? || mtime < Time.now-time_min) - last = `#{git_last}` - begin - f = File.open(filepath, 'w') - f.puts(last) - f.close - rescue Exception => e - Rails.logger.info("Failed to log git status #{filepath}: #{e}") - end - end - last - headers[@header_name] = "#{last}" - end +git_cmd = `git log -1 --format="%H %ci"` +if git_cmd =~ /^([\d\w]+?)\s(.+)$/ + GIT_REVISION = $1 + GIT_UPDATE = $2.strip +else + GIT_REVISION = nil + GIT_UPDATE = nil +end