git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Odd results writing a Git pre-receive hook to syntax check PHP files.

From
CPChris Patti <cpatti@gmail.com>
Date
Sep 1, 2010, 13:43 UTC
Message-ID
<AANLkTi=GP-3QV+2cVUV1zCS_n2gPie_rBmBnbXgmmbgn@mail.gmail.com>
In-Reply-To
<7vk4n68hpk.fsf@alter.siamese.dyndns.org>
On Tue, Aug 31, 2010 at 7:50 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 15 quoted lines
> Chris Patti <cpatti@gmail.com> writes:
>
>> function parseCommit($old_sha1,$new_sha1) {
>>         # if this is the first commit on a new branch, $old_sha1 will
>> be a bunch of zeroes, and so
>>         # git diff --raw will fail, since there's no old ref to
>> compare against.  So, we parse the
>>         # results of git diff-tree -root=$new_sha1 instead to get the
>> blob and filename we'll need.
>>         if (detectNewBranch($old_sha1,$new_sha1)) {
>>                 $diffcmd="git diff-tree --root $new_sha1";
>
> This somehow feels wrong.  If the tree of the new commit is flat without
> subdirectory, the above would do, but don't you need "diff-tree -r" here?
>

That's a good point, I'll try creating a subdirectory in my testing, thanks for pointing this out.

Show 7 quoted lines
>>                 $regex="/\:\w+ \w+ \w+ (\w+) \w (.+)/";
>>         }
>>         else {
>>                 $diffcmd="git diff --raw $old_sha1 $new_sha1";
>
> And you are better off using "diff-tree -r" here instead of "diff --raw"
> here as well, to keep the input to your parser for both cases uniform.
r> The parser would be easier that way, no?
>
>>                 $regex="/\:\d+ \d+ \w+... (\w+)... \w\t(.+)/";
>>         }
>

As you can see, it's just the regex that differs, so I'm not sure what you mean by 'parser'. The power of regular expressions handles this quite nicely, but I'll definitely consider that for a simplifying rewrite in the future.

-Chris
-- 
Christopher Patti - Geek At Large | GTalk: cpatti@gmail.com | AIM:
chrisfeohpatti | P: (260) 54PATTI
"Technology challenges art, art inspires technology." - John Lasseter, Pixar
Previous: Junio C HamanoNext: Chris Patti
Message 19 of 20 in “Odd results writing a Git pre-receive hook to syntax check PHP files.”
  1. Chris PattiAug 27, 2010
  2. Michael J GruberAug 30, 2010
  3. Chris PattiAug 30, 2010
  4. Jonathan NiederAug 30, 2010
  5. Chris PattiAug 30, 2010
  6. Example git hooks (Re: Odd results writing a Git pre-receive hook to syntax check PHP files.)Jonathan Nieder, Aug 30, 2010
  7. Todd ZullingerAug 31, 2010
  8. Chris PattiAug 31, 2010
  9. Chris PattiAug 31, 2010
  10. Michael J GruberAug 30, 2010
  11. Chris PattiAug 30, 2010
  12. Chris PattiAug 30, 2010
  13. Sverre RabbelierAug 30, 2010
  14. Jonathan NiederAug 30, 2010
  15. Chris PattiAug 30, 2010
  16. Michael J GruberAug 30, 2010
  17. Chris PattiAug 31, 2010
  18. Junio C HamanoAug 31, 2010
  19. Chris PattiSep 1, 2010
  20. Chris PattiSep 2, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.