Viewing repository size over time

118 Views Asked by At

Is there a way to get the size of a repository for a given revision? I would like to create a graph showing how the size changes over time.

2

There are 2 best solutions below

0
On BEST ANSWER

Inspired by planetmaker's answer I wrote this command:

hg log -r0:tip --stat --template 'date: {date|shortdate}\n' \
    | awk \
        '/^date:/ { date = $2 }
        /^ *[0-9]+ files changed/ { sum += $4 - $6; print date, sum }' \
    | awk \
        '$1 != prevDate { if (prevLine != "") { print prevLine } }
        { prevLine = $0; prevDate = $1 }
        END { print prevLine }'

The second awk command filters out multiple commits with the same date, so that only the last commit on a given date is shown.

Example output:

2014-09-22 304
2014-10-25 308
2014-12-25 320
2014-12-27 253
2015-03-17 252
2015-04-28 230
2015-05-22 241
2015-08-12 301
2015-07-13 302
2015-08-12 306

Update 2015-08-19: Account for commits with no file changes (happens with merges sometimes).

0
On

It's a tricky question.

First: what is 'size'? Is it the size in bytes? Or is it the number of lines of code?

If the answer is 'bytes', then there is no other way than to checkout each revision, purge the working directory and check the size of the working directory.

If the answer is 'lines of code' and the repository contains text files exclusively, then you might do without checking out each revision, using hg log --stat (see also How Can I calculate the sum of a specific column using bash? ):

LC_ALL=C hg log -r0:tip --stat | grep 'insertions' | awk '{sum+=$4 ; min+=$6; print $4,$6} END {print "sum=",sum-min}'

This is tested with hg 3.4.2, but I'm not aware of any significant changes in the output of hg log --stat