I'm trying to use preg_match_all
to process the log from git log --pretty=raw --all
.
The sample data I got is something like this:
commit 5650c7841f72c4c65689b0d4bc83ccd70e5b2362 (HEAD, origin/master, origin/HEAD, master)
tree 69c6036c64c805e9c335b2eadd87b43af90ee1ad
parent a912fdd530efe69dae4b0f417c8a8631d68f469c
parent 113e128efe54511f2b0bdd589301ffe039fc185e
author Author Name 3 <author.name.3@gmail.com> 1371835063 -0700
committer Committer Name 3 <committer.name.3@gmail.com> 1371835063 -0700
Merge pull request #60 from sample/master
Line 2 message
commit 94e99889226671dc479be770968df2692e09db11 (origin/fixit)
tree f900c172fa633b3769b982614ce639e3ee6f3b62
parent dc56687f1597b317064b0d899c2450fb6805791e
author Author Name 2 <author.name.2@something.com.tld> 1370944188 +0300
committer Committer Name 2 <committer.name.2@something.com.tld> 1370944188 +0300
1 line message
commit dc56687f1597b317064b0d899c2450fb6805791e
tree cb1573ccde7ddcb2e54b9b9a777e11a435d532ac
parent a912fdd530efe69dae4b0f417c8a8631d68f469c
author Author Name 1 <author.name.1@gmail.com> 1370640640 +0300
committer Committer Name 1 <committer.name.1@gmail.com> 1370943413 +0300
Message contain words like commit tree parent author committer to screw your regex.
Also contain other symbols like @ # ! % ( ) = - |
Can you handle 2nd paragraph?
3rd paragraph?
`
I would like to extract the
- commit hash
- tree hash
- parents hash
- author name
- commiter, and
- commit message
The closest I can get is with:
/^commit (.{40})(.*)\s^tree (.{40})\s^parent (.{40})\s(^parent (.{40})\s)?^author (.+)\s^committer (.+)\s+(.+)\s+/m
Which come out something like this: http://regex101.com/r/cY4qV4
Is there more accurate regex for above data that don't break easily like mine?
Something to take note:
- tags, branches in () after commit (additional question: Is it possible to separate tag/branch by comma (,) also within 1 regex?)
- some commit has 2 parents
- commit message may contains multiple paragraph, weird symbols or words that you use in regex