git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Ernesto Maserati <ernesto.2.maserati@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: How to generate feature branch statistics?
Date: Wed, 20 Jul 2016 07:14:24 -0600	[thread overview]
Message-ID: <20160720131424.GC17469@sigill.intra.peff.net> (raw)
In-Reply-To: <CAOHAwykGkfY7M30jT8t0k6Gsdy5QSBHmAPiWYoKibjUgS-G6hg@mail.gmail.com>

On Wed, Jul 20, 2016 at 10:05:09AM +0200, Ernesto Maserati wrote:

> 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.

In a workflow that merges feature branches to master, you can generally
recognize them by looking for merges along the first-parent chain of
commits:

  git log --first-parent --merges master

(Depending on your workflow, some feature branches may be fast-forwards
with no merge commit, so this is just a sampling. Some workflows use
"git merge --no-ff" to merge in feature branches, so this would see all
of them).

And then for each merge, you can get the set of commits that were merged
in (it is the commits in the second parent that are not in the first).
The bottom-most one is the "start" of the branch (or close to it; of
course the author started writing code before they made a commit), and
the "end" is the merge itself.

So something like:

  git rev-list --first-parent --merges master |
  while read merge; do
	start=$(git log --format=%at $merge^1..$merge^2 | tail -1)
	end=$(git log -1 --format=%at $merge)
	subject=$(git log -1 --format=%s $merge)
	echo "$((end - start)) $subject"
  done

That should output a sequence of topic branch merges prefixed by the
number of seconds they were active. Two exercises for the reader:

  1. Converting seconds into some more useful time scale. :)

  2. This can probably be done with fewer invocations of git,
     which would be more efficient.

-Peff

  reply	other threads:[~2016-07-20 13:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-20  8:05 How to generate feature branch statistics? Ernesto Maserati
2016-07-20 13:14 ` Jeff King [this message]
2016-07-20 18:49   ` Junio C Hamano
2016-07-20 23:10     ` Jakub Narębski
2016-07-20 23:31       ` Junio C Hamano
2016-07-20 13:56 ` Jakub Narębski
2016-07-20 18:10   ` Jakub Narębski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160720131424.GC17469@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=ernesto.2.maserati@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).