From be338a99e9bfdc2f196fbcfb391c2e6003231dea Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Fri, 23 Jan 2009 02:34:23 +0100 Subject: launch_here: rewrite git revision retrieval Use low-level ('plumbing') git commands to retrieve the current commit/revision/work tree status when we're being launched from a git tree. This is faster (less shell escapes) and should work equally well with all git versions (past, present and future). --- launch_here.rb | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'launch_here.rb') diff --git a/launch_here.rb b/launch_here.rb index e1e4a011..7bc21c80 100755 --- a/launch_here.rb +++ b/launch_here.rb @@ -16,31 +16,29 @@ begin if File.exists? '.git' begin - git_out = `git status` - git_out.match(/^# On branch (.*)\n/) - if $1 # git 1.5.x - branch = $1.dup || "unknown" - changed = git_out.match(/^# Change(.*)\n/) - rev = "revision " - git_out = `git log -1 --pretty=format:"%h%n%s%n%ct"`.split("\n") - rev << git_out.first - subject = git_out[1].strip - subject[77,subject.length] = "..." if subject.length > 80 - rev << " [#{subject}]" unless subject.empty? - $version_timestamp = git_out.last.to_i - rev << ", local changes" if changed - else # older gits - git_out = `git branch` - git_out.match(/^\* (.*)\n/) - branch = $1.dup rescue "unknown" - rev = "revision " + `git rev-parse HEAD`[0,6] + git_out = `git log -1 --pretty=format:"%H%n%s%n%ct" | git name-rev --stdin`.split("\n") + $version_timestamp = git_out.last.to_i + subject = git_out[1].strip + subject[77..-1] = "..." if subject.length > 80 + commit, branch_spec = git_out.first.scan(/^(\S+)(?: \((\S+)\))?$/).first + rev = "revision #{commit[0,7]}" + rev << " [#{subject}]" unless subject.empty? + changes = `git diff --shortstat HEAD`.split(", ").first + rev << ", #{changes.strip}" if changes + if branch_spec + tag, branch, offset = branch_spec.scan(/^(?:(tag)s\/)?(\S+?)(?:^0)?(?:~(\d+))?$/).first + tag ||= "branch" + branch << " #{tag}" + branch << "-#{offset}" if offset + else + branch = "unknown branch" end rescue => e puts e.inspect branch = "unknown branch" rev = "unknown revision" end - $version << " (#{branch} branch, #{rev})" + $version << " (#{branch}, #{rev})" elsif File.directory? File.join(SCM_DIR, '.svn') rev = " (unknown revision)" begin -- cgit v1.2.3