16

I want to graph the # of new lines of code written each hour over the course of the day.

I'm aware of git diff, git log and they are very powerful for determining total # of lines committed to a branch. The --since="7am" option is really great as well.

Some of the git commands I'm utilizing are:

Total # of lines

git log --numstat --pretty="%H" master | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}' 

# lines additional in devel branch compared to master

git log --numstat --pretty="%H" master..devel | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}' 

# lines since a time of day

git log --since="7am" --format=format: --numstat | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("%d, -%d\n", plus, minus)}' 

# lines currently uncommitted

git diff --stat | tail -1 | awk '{print $4}' 

I've been struggling though with coming up with a way to track the # of new lines written in the past hour including uncommitted changes, across all branches in the current repo.

This may be more of a math problem.

The Question:

  • How can I determine the exact amount of lines written in the past hour across all branches, including uncommitted changes.

Gotchas/Scenarios:

  • +200 uncommitted at 7pm is 200 new lines written. +250 uncommitted at 8pm is only 50 new lines written the past hour.
  • +200 uncommitted at 7pm is 200 new lines written. At 8pm we commit 100 of the lines and then write 50 more new lines. Now +150 show as uncommitted, but we would need to determine that only 50 new lines were written in the past hour. Reconciling committed and uncommitted stats.
  • +200 uncommitted at 7pm. At 7:30pm we write 500 additional new lines and commit them. At 8pm we write 100 more new lines thus showing +300 as uncommitted. We should end up with 600 new lines written in the last hour.
12
  • 1
    Because of the Gotchas you mention, you're probably going to have to go with a solution that stores the last run's results (in a file, DB, in the repository with git config, etc.) and then compares this time's results against them. The simplest of the storage options for keeping the last value is probably the git config one, but since you want to keep historical data to graph, you probably want a simple database anyway. If you already have a running database server, you could use it, or you could use a file-based DB like SQLite. Commented Nov 6, 2013 at 3:35
  • 1
    Compare the uncommitted lines from this run with the total of uncommitted from last run and committed from this run. The difference will be the number of new lines. For your first example: 250 + 0 - 200 = 50. For your second example: 150 + 100 - 200 = 50. For your third, 300 + 500 - 200 = 600. Commented Nov 6, 2013 at 17:58
  • 1
    Who is to say that the number of lines in a commit at a certain time represent the when it was written? What if I stashed my changes and left them there for eons? Commented Nov 14, 2013 at 13:05
  • 21
    I hope some poor sods aren't going to get judged on their productivity by this measure - it\n could\n drive\n some\n serious\n degradation\n in\n code\n quality!\n :) Commented Nov 14, 2013 at 14:10
  • 6
    You should track the number of lines removed instead. Commented Nov 29, 2013 at 6:49

1 Answer 1

2

There's a tool gitstats that can give you Lines of Code by date. Maybe you can tweak a little the code (is written in python) to let him generate hourly stats.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.