Re: How to generate feature branch statistics?
- From
Jakub Narębski <jnareb@gmail.com>
- Date
- Jul 20, 2016, 13:56 UTC
- Message-ID
- <578F8306.3070306@gmail.com>
- In-Reply-To
- <CAOHAwykGkfY7M30jT8t0k6Gsdy5QSBHmAPiWYoKibjUgS-G6hg@mail.gmail.com>
W dniu 2016-07-20 o 10:05, Ernesto Maserati pisze:
Show 14 quoted lines
> I assume that feature branches are not frequently enough merged into > master. Because of that we discover bugs later than we could with a more > continuous code integration. I don't want to discuss here whether feature > branches are good or bad. > > I want just to ask is there a way how to generate a statistic for the > average duration of feature branches until they are merged to the master? I > would like to know if it is 1 day, 2 days or lets say 8 or 17 days. Also it > would be interesting to see the statistical outliers. > > I hope my motivation became clear and what kind of git repository data I > would like to produce. > > Any ideas?
There are at least two tools to generate statistics about git repository, namely Gitstat (https://sourceforge.net/projects/gitstat) and GitStats (https://github.com/hoxu/gitstats), both generating repo statistics as a web page. You can probably find more... but I don't know if any includes the statistics you need.
I assume that you have some way of determining if the merge in 'master' branch is a merge of a topic branch, or of long-lived graduation branch (e.g. 'maint' or equivalent). To simplify the situation, I assume that the only merges in master are merges of topic branches:
git rev-list --min-parents=2 master | while read merge_rev; do
You might want to add "--grep=maint --invert-grep" or something like that to exclude merges of 'maint' branch. We can get date of merge (authordate with %ad/%at, or committerdate with %cd/%ct), as an epoch (seconds since 1970 -- which is good for comparing datetimes and getting the interval between two events)
MERGE_DATE=$(git show -s --date=format:%s --pretty=%ad $merge_rev)
Assuming that topic branches are always merged using two-head merge as a second parent (--first-parent ancestry for master in master branch only), then we can get the first revision on a merged topic branch with
FIRST_REV=$(git rev-list $merge_rev^2 ^$merge_rev^1 | tail -1)
We can extract the date from this revision in the same way
FIRST_DATE=$(git show -s --pretty=%at $FIRST_REV)
Print the difference (here to standard output, you might want to write to a file)
echo $(expr $MERGE_DATE - $FIRST_DATE)
And finish the loop.
done
Then pass the output to some histogramming or statistics tool... or use a spreadsheet. Note the results are in seconds.
HTH (not checked much)
-- Jakub Narębski