Visualizing Small Batch Sizes with Git

Creative Commons License jasleen_kaur

I’ve recently finished reading Web Operations: Keeping the Data on Time. Written by John Allspaw and Jesse Robins, by far my favorite chapter was Eric Ries’ submission for Chapter 4: Continuous Deployment. One of the graphs in this chapter compellingly portrays Flickr’s “release early, release often” mantra. This inspired me to start monitoring my own production “drift” – or, what’s the measurable difference between production and the last commit?

For the longest time, I’ve used the number of unread items in my Gmail filter “codebase” to tell me how many commits were queueing up for release. It’s trivial to setup, stays visible in the corner of your eye, and it’s especially fulfilling to “select unread” -> “mark as read” after doing a release.

While this is fine for me, what about the team? Or even the company? How could I get this critical information distributed? Eric’s graph showed me just how to do it. I decided to dig this data out and graph it with LogicMonitor.

Here’s a ruby script I wrote to do it. Let’s say your local git repo lives at /src/code/

#!/usr/local/bin/ruby
prepare = `"git --git-dir=/src/code/.git fetch -q origin"`
local_git_head = `git --git-dir=/src/code/.git show --shortstat --pretty=format:%H | awk 'NR==1{print $1}'`.chop

git_gap_cmd = 'git --git-dir=/src/code/.git diff ' + local_git_head + '..origin/HEAD --shortstat --pretty=oneline'
git_gap = `#{git_gap_cmd}`
if (git_gap.empty?)
  git_gap = '0'
else
  # 17 files changed, 374 insertions(+), 54 deletions(-)
  matches = git_gap.match(/^.*, ([0-9]+).*, ([0-9]+).*$/)
  if (!matches.nil?)
    git_gap = matches[1].to_i + matches[2].to_i
  end
end

puts 'sha=' + local_git_head + ',diff=' + git_gap.to_s

Notice, I’m adding insertions and deletions to get the total number of lines changed. The resulting string will look something like
sha=afae6e540f5cc55c8a5d4d100d2e5acf22ee2ed5,diff=428

Plotting these values against time, gives you a great overview of your production “drift” from your development repository:

Releases are seen here as line drops and you see we average about one release a day.

How do you keep track of your batch sizes? Share with us below!

3 thoughts on “Visualizing Small Batch Sizes with Git

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.