0

I am trying to find the coding days(active days) along with number of commits and each commit's size per coding days. This is what I meant to say

{
   "2014-05-2": {
      "commit_count": "1",
      "commit": [{ 'commit_hash': {'lines_added': 10, 'lines_removed': 4 }}]
    },
    "2014-05-3": {
      "commit_count": "2",
      "commit": [
          { 'commit_hash': {'lines_added': 10, 'lines_removed': 4 }},
          { 'commit_hash': {'lines_added': 14, 'lines_removed': 0 }},
        ]
    }
}

For now, I could only find coding days and number of commits this way

async def get_coding_days(self, author, before, after):
    cmd = (
        f'git log {self.conf.get("branch", "master")} --author="{author}" --date=short'
    )
    cmd += ' --pretty=format:"%ad %an"'
    if before:
        cmd += f' --before="{before}"'
    if after:
        cmd += f' --after="{after}"'
    results = get_proc_out([cmd, "sort", "uniq -c"]).splitlines()
    np_results = np.array(results)
    stripped_array = np.char.strip(np_results)
    for result in stripped_array:
        second_space_pos = result.find(" ", 2)
        if second_space_pos > 2:
            count_with_time = result[0 : second_space_pos - 1]
            [commit_count, coding_day] = count_with_time.split(" ")
            author = result[second_space_pos + 1 :]
            # default_dict[author].append(
            #     {"commit_count": commit_count, "coding_day": coding_day}
            # )
            if author not in self.coding_days:
                self.coding_days[author] = []
            self.coding_days[author].append(
                {coding_day: {"commit_count": commit_count}}
            )
    return self.coding_days

How can I show commit size for each commit?

1 Answer 1

0

Use --shortstat to get the stat for the commit

git log --date=short --after="e5e16518" --pretty="%h %an %ad" --shortstat

to get

cb807c0d clmno 2021-06-15

 4 files changed, 71 insertions(+), 15 deletions(-)
2f8de5fb clmno 2021-06-15

 4 files changed, 76 insertions(+), 23 deletions(-)
92a0e1e3 clmno 2021-06-15

 2 files changed, 9 insertions(+)

Now you can simply parse these to generate the JSON you need.

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

3 Comments

Thank you @clmno for your answer. Is it possible to get the result in something like this 43f4cc160, Dan ab, 2021-06-17, 1 file changed, 10 insertions(+), 19 deletions(-) so it will be easier to split those items in numpy.
@Serenity It looks like you've asked for the gates of doom to be opened - Link
I felt a bit complex for above format to get commit hash, author, date, lines_added. removed using numpy so I wanted to know if the format I mentioned will be possible just from script or not. Haha, I agree with you now on your say on "you've asked for the gates of doom to be opened "

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.