开发者

git commit metrics

开发者 https://www.devze.com 2023-02-25 10:45 出处:网络
I want to determine git commit metricsusingbash script. But I never use bash script. The idea is to have the number of commit wich are not referenced in their status during a specific time

I want to determine git commit metrics using bash script.

But I never use bash script.

The idea is to have the number of commit wich are not referenced in their status during a specific time

(i开发者_Python百科.e.: not closed or no #nnnn reference where n is a number, because we use Redmine to show the reference of open commit)

the algorithm is:

fonction (initial date, final date)
  read initial date
  read final date
  int n=0
  while (initial date<date<final date) do 
    if (status!=closed or status!= #nnnn) //where #nnnn is a reference and n a number
      n=+1
    end if
  end while
  echo "the number of none referenced commit is"
  echo n 
  return 0

If there is a specific git command or other idea, please leave a response, it will help me a lot. thank you


Such a script would use and exploit the git low-level commands (plumbing, suitable for scripting) command git rev-list:

The commit limiting options allow you to define a range of date, and to select the right log message:

--skip=<number>
    Skip number commits before starting to show the commit output.
--since=<date>
--after=<date>
    Show commits more recent than a specific date.
--until=<date>
--before=<date>
    Show commits older than a specific date.
--max-age=<timestamp>
--min-age=<timestamp>
    Limit the commits output to specified time range.

--grep=<pattern>

Limit the commits output to ones with log message that matches the specified pattern (regular expression).

The commit formatting options allow you to display only what you need, mainly the comment of the commit, for you to parse (I suppose it is in the comment of a commit that you have stored the status of said commit, although you could also have used git notes):

--pretty[=<format>]
--format=<format>

Pretty-print the contents of the commit logs in a given format, where can be one of oneline, short, medium, full, fuller, email, raw and format:. See the "PRETTY FORMATS" section for some additional details for each format. When omitted, the format defaults to medium.


Update After the comments:

It seems you really are helped by the much simpler

git log --oneline | egrep -ivw 'closed|#[0123456789]+'

filtering out just common patterns from commit messages. If you wanted a count of that

git log --oneline | egrep -ivwc 'closed|#[0123456789]+'

You can add from the original answer flags to reduce the output of git log, like so

git log --oneline --after=2011-01-01 --until=today | egrep -ivwc 'closed|#[0123456789]+'

Original answer:

Come again. This question does not parse. "wich are not referenced in their status" What status? A commit doesn't normally have one. Are you using commit notes?

I'm getting the impression you want to find certain information that was not mentioned in git commit messages during a specific period of time? If so, give examples of what kind of commit messages you use, and how the list of 'relation ids' to look for is stored. E.g.:

from="3 months ago"
until="1 week ago"

lookforids=( '#bug3' '#update4' '#featureY' )
for lookfor in "${lookforids[@]}";
do
    commitcount=$(git log --no-merges --oneline --after="$from" --until="$until" --all -i --grep="$lookfor" | wc -l)

    if [ "$commitcount" -le 1 ]; then echo "Not referenced: $lookfor"; fi
done

Of course you should mix and match to your needs, altering the output to your liking. from/until can of course be absolute date literals if you like.

0

精彩评论

暂无评论...
验证码 换一张
取 消