How to do it...

Let's see how many commits in the repository are referring to a bug:

  1.  First of all, we need to know the pattern for bugs referred to in the commit messages. I did this by looking in the commits, and the pattern for jgit is to use Bug: 6 digits; so, to find all of these commits, we use the --grep option for git log, and we can grep for "[Bb][Uu][gG]: [0-9]+":
$ git log --all --grep="^[bB][uU][gG]: [0-9]" 
commit 3db6e05e52b24e16fbe93376d3fd8935e5f4fc9b 
Author: Stefan Lay <[email protected]> 
Date:   Wed Jan 15 13:23:49 2014 +0100 
 
    Fix fast forward rebase with rebase.autostash=true 
 
    The folder .git/rebase-merge was not removed in this case. The 
    repository was then still in rebase state, but neither abort nor 
    continue worked. 
 
    Bug: 425742 
    Change-Id: I43cea6c9e5f3cef9d6b15643722fddecb40632d9 
  1. You should get a lot of commits as output, but you should notice that all the commits have a referral to a bug ID. So what was the grep doing? The ^[Bb][Uu][gG]: part matches any combination of lowercase and uppercase bugs. The ^ character means from the beginning of the line. The : character is matching :. Then, we have [0-9]+, which will match any number between zero and nine, and the + part means one or more occurrences. But enough with regular expressions for grep. We have a lot of output (which is valuable), but for now, we just want to count the commits. We can do this by piping it to wc -l (word count -l is to count the lines):
$ git log --all --oneline --grep="^[bB][uU][gG]: [0-9]+" | wc -l 

    366
  1. Before piping it to wc, remember to use --oneline to limit the output to one line for each commit. As you can see, when I was writing this, jgit has reference to 366 bugs that have all been fixed and released into the repository. If you are used to using regular expressions in another scripting or programming language, you will see that using --grep does not support everything. You can enable a more extensive regular expression support using the --extended-regexp option for git log; however, the pattern still has to be used with --grep as follows:
$ git log --all --oneline  --extended-regexp --grep="^[bB][uU][gG]: [0-9]{6}" 

3db6e05 Fix fast forward rebase with rebase.autostash=true 
c6194c7 Update com.jcraft.jsch to 0.1.50 in Kepler target platform 
1def0a1 Fix for core.autocrlf=input resulting in modified file and unsmudge 
0ce61ca Canonicalize worktree path in BaseRepositoryBuilder if set via config 
e90438c Fix aborting rebase with detached head 
2e0d178 Add recursive variant of Config.getNames() methods 
  1. We have used it in the preceding example, and you can see that we are getting the same commits. I have used a slightly different expression, and have now added {6} instead of +; the {6} searches for six occurrences of the associated pattern. In our case, it is six digits as it is next to the [0-9] pattern. We can verify by counting the lines or commits again with wc -l as follows:
$ git log --all --oneline  --extended-regexp --grep="^[bB][uU][gG]: [0-9]{6}" | wc -l 

    366 
  1. We get the same number. To shrink the regular expression even more, we can use --regexp-ignore-case, which will ignore the case for the pattern:
$ git log --all --oneline  --regexp-ignore-case --extended-regexp --grep="^bug: [0-9]{6}" 

3db6e05 Fix fast forward rebase with rebase.autostash=true 
c6194c7 Update com.jcraft.jsch to 0.1.50 in Kepler target platform 
1def0a1 Fix for core.autocrlf=input resulting in modified file and unsmudge 
0ce61ca Canonicalize worktree path in BaseRepositoryBuilder if set via config 
e90438c Fix aborting rebase with detached head 
2e0d178 Add recursive variant of Config.getNames() methods

  1. Now we have the exact same output, and we no longer have [bB][uU][Gg] but just bug.

Now you know how to grep the commit messages for information, and you can grep for anything in the commit message and list all the commits where the regular expression matches.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.86.138