threads / discuss / 57602

How to determine the number of unique recent committers on a branch?

Subject: How to determine the number of unique recent committers on a branch?

## tl;dr

6 messages between Mar 23, 2022 and Mar 23, 2022.

replies: 5people: 3as markdown or json

Sebastian Schuberth· Mar 23, 2022, 10:23 UTC · lore
Hi,

I'm trying to determine the number of unique committers who have recently committed to a branch. "Recently" should be configurable, but for my example I'll use a period of 3 months.

At first, I thought the [<refname>]@{<date>} syntax [1] in conjunction with git "shortlog -s" could be helpful here, like

$ git shortlog -s main@{3.months.ago} | wc -l

But then I realized that just like with the --since option, the <date> counts relative to the current date, not relative to the date of the last commit on the given branch. To me, that's rather counterintuitive for the [<refname>]@{<date>} syntax.

So, what would be a good way to achieve what I want with only Git-means (and maybe `wc`), but without any awk / Perl scripting magic?

Thanks in advance!
[1]: http://git-scm.com/docs/gitrevisions#Documentation/gitrevisions.txt-emltrefnamegtltdategtemegemmasteryesterdayememHEAD5minutesagoem
-- 
Sebastian Schuberth
Ævar Arnfjörð Bjarmason· Mar 23, 2022, 12:30 UTC · re: Sebastian Schuberth · lore

Re: How to determine the number of unique recent committers on a branch?

On Wed, Mar 23 2022, Sebastian Schuberth wrote:
Show 23 quoted lines
> Hi,
>
> I'm trying to determine the number of unique committers who have
> recently committed to a branch. "Recently" should be configurable, but
> for my example I'll use a period of 3 months.
>
> At first, I thought the [<refname>]@{<date>} syntax [1] in conjunction
> with git "shortlog -s" could be helpful here, like
>
> $ git shortlog -s main@{3.months.ago} | wc -l
>
> But then I realized that just like with the --since option, the <date>
> counts relative to the current date, not relative to the date of the
> last commit on the given branch. To me, that's rather counterintuitive
> for the [<refname>]@{<date>} syntax.
>
> So, what would be a good way to achieve what I want with only
> Git-means (and maybe `wc`), but without any awk / Perl scripting
> magic?
>
> Thanks in advance!
>
> [1]: http://git-scm.com/docs/gitrevisions#Documentation/gitrevisions.txt-emltrefnamegtltdategtemegemmasteryesterdayememHEAD5minutesagoem

The ref@{} syntax will give you ref*log* times, which is probably not what you want.

I think --since to "rev-list" combined with e.g. "shortlog" is what you
want here, e.g. on git.git:
	
	$ git -P shortlog --since=2.weeks.ago -sn origin/master 
	    36  Junio C Hamano
	    12  Derrick Stolee
	     2  Shubham Mishra
	     1  Michael J Gruber
	     1  Ævar Arnfjörð Bjarmason

Maybe there's a way to get it to spew that out without the numeric summary, but I can't recall one offhand. I.e. you'd still need awk/cut, but at least not uniq anymore..

Sebastian Schuberth· Mar 23, 2022, 13:00 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: How to determine the number of unique recent committers on a branch?

On Wed, Mar 23, 2022 at 1:33 PM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:

> I think --since to "rev-list" combined with e.g. "shortlog" is what you
> want here, e.g. on git.git:
>
>         $ git -P shortlog --since=2.weeks.ago -sn origin/master

But that still interprets "2.weeks.ago" relative to today, right? So, for a repo to which no one committed to in the last 2 weeks, it would show nothing. But what I'd like to get is the number of committers since 2 weeks before the latest commit. Any idea how to get that easily?

-- 
Sebastian Schuberth
Ævar Arnfjörð Bjarmason· Mar 23, 2022, 14:47 UTC · re: Sebastian Schuberth · lore

Re: How to determine the number of unique recent committers on a branch?

On Wed, Mar 23 2022, Sebastian Schuberth wrote:
Show 13 quoted lines
> On Wed, Mar 23, 2022 at 1:33 PM Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
>
>> I think --since to "rev-list" combined with e.g. "shortlog" is what you
>> want here, e.g. on git.git:
>>
>>         $ git -P shortlog --since=2.weeks.ago -sn origin/master
>
> But that still interprets "2.weeks.ago" relative to today, right? So,
> for a repo to which no one committed to in the last 2 weeks, it would
> show nothing. But what I'd like to get is the number of committers
> since 2 weeks before the latest commit. Any idea how to get that
> easily?
Ah, sorry. I managed to (mis)read your question.

Perhaps there's a way to do that in one command, but I don't think so, but I may be wrong.

But you *can* do by grabbing the epoch from the tip commit and doing some basic shell-math on it:

    git log --since=$(($(git log --oneline -1 --date=unix --pretty=format:%ad origin/master) - $((60*60*24*7*2)) )) origin/master
It would be nice if we had some option to to do that, e.g.:
    git log --since=2.weeks.ago --date-now=February.2018
Or To get you things in late January 2018. Or even:
    git -c core.time="February.2018" log --since=2.weeks.ago

To fool the entirety of git to use a given time() as current (but of course it would also need to "adjust back" commit dates for relative --since).

I'm 99% sure we don't have that, especially from looking at some of the code just now. But in the meantime you can hack it as above.

Sebastian Schuberth· Mar 23, 2022, 22:14 UTC · re: Ævar Arnfjörð Bjarmason · lore

Re: How to determine the number of unique recent committers on a branch?

On Wed, Mar 23, 2022 at 3:57 PM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:

> But you *can* do by grabbing the epoch from the tip commit and doing
> some basic shell-math on it:
>
>     git log --since=$(($(git log --oneline -1 --date=unix --pretty=format:%ad origin/master) - $((60*60*24*7*2)) )) origin/master
Thanks, that works!

However, as --since works on the commit date, shouldn't it also be %cd instead of %ad in the format string for consistency?

-- 
Sebastian Schuberth
Junio C Hamano· Mar 23, 2022, 20:48 UTC · re: Sebastian Schuberth · lore

Re: How to determine the number of unique recent committers on a branch?

Sebastian Schuberth <sschuberth@gmail.com> writes:
Show 8 quoted lines
> I'm trying to determine the number of unique committers who have
> recently committed to a branch. "Recently" should be configurable, but
> for my example I'll use a period of 3 months.
>
> At first, I thought the [<refname>]@{<date>} syntax [1] in conjunction
> with git "shortlog -s" could be helpful here, like
>
> $ git shortlog -s main@{3.months.ago} | wc -l

As reflog is pretty much the local matter, this is "find out the commit _I_ happened to have seen at the tip of 'main' in _this_ repository 3 months ago, and count all commits before that one".

If you were taking 6 months sabbatical, not fetching the repository during that time, and then you fetched to become up to date with the upstream, you may have had a copy of the shared project history only as of 6 months ago with that notation, even though the syntax is asking for "3 months ago", simply because that was the commit your repository had 3 months ago at the tip of the branch.

    $ git log --until=3.months.ago

would instead look at the timestamp recorded in commit objects, which would probably be more relevant to project participants.

← back to recent threads