2

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

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
user703681
  • 21
  • 2

2 Answers2

1

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.

sehe
  • 374,641
  • 47
  • 450
  • 633
  • 1
    I would *not* use a porcelain command (`git log`) in a script, but otherwise I agree with your idea. +1 – VonC Apr 12 '11 at 10:44
  • Mind you that I simply took a stab at the requirements here. No sense in perfecting a useless solution yet :) I'll await the OP response and work from there – sehe Apr 12 '11 at 10:49
  • On the porcelain vs. plumbing part, see http://stackoverflow.com/questions/3878624/how-do-i-programmatically-determine-if-there-are-uncommited-changes/3879077#3879077 or http://stackoverflow.com/questions/2657935/checking-for-a-dirty-index-or-untracked-files-with-git/2659808#2659808 – VonC Apr 12 '11 at 10:52
  • I'm here no longer(it is an internship), so i didn't know if they use commit note or not but in the different commit informations after doing <> there is this characteristic: closes: #3444 for example or only #3444 the number permit to trace a feature, but some people doesn't add this number after the commit so the idea is to have the number of commit wich are not referenced by closes or #nnnn where n is an integer. and thank you for your first response – user703681 Apr 12 '11 at 12:35
  • `'#bug3' '#update4' '#featureY'` are just examples of strings that you could look for, since you didn't specify any :). Your new question in the comment would be simply `git log --oneline | egrep -iv 'closed|#[0123456789]+'` ... – sehe Apr 12 '11 at 13:57
  • i try it but, i have many git comment, but is it possible to have only a number, but a number of the opposite of <> result; because this command give me all of the commit wich contain closed or #[0123456789]+ but i need the commit wich don't contain closed or #[0123456789]+, it will be cool if i have the number of this commit type...for example <<148 commit without closed or #[0123456789]+>>...thank you a lot for your help – user703681 Apr 12 '11 at 14:43
  • @user703681; You didn't try it (correctly). I think it time for you to read some man pages: [`egrep -v or --invert-match`](http://unixhelp.ed.ac.uk/CGI/man-cgi?egrep) – sehe Apr 12 '11 at 14:49
  • Please remove the confusing comments, I will update my answer shortly. **I do think that the next thing you should read is a [beginner's course in `bash](http://www.ee.surrey.ac.uk/Teaching/Unix/)** (_and possibly more on [bash](http://tldp.org/LDP/Bash-Beginners-Guide/html/)_ If you can't figure out how to copy simple command options, you will have a very hard time getting things done, or even asking questions. – sehe Apr 12 '11 at 16:32
  • thank you for the guide, excuse me but i am a beginner in this language. – user703681 Apr 12 '11 at 16:41
1

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I try for example git rev-list --after=10/02/20 or git rev-list --after=<10/02/20> or git rev-list --after="10/02/20" but nothing – user703681 Apr 12 '11 at 16:07
  • @user703681: I suspect an issue in the date format: try `YYYY-MM-DD` as in '`--after=2010-02-20`'. No quote or '`<`' or '`>`' should be necessary around the date. – VonC Apr 12 '11 at 16:50