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

observing changes to a git repository

From
Brian Swetland <swetland@google.com>
Date
Dec 31, 2007, 22:28 UTC
Message-ID
<20071231222820.GA11278@bulgaria.corp.google.com>

Assuming I wanted to use a script (possibly run from cron) to observe and report changes to a git repository (instead of running something from the various hooks), does the following strategy seem workable:

- for each branch to observe, record the initial position of that 
  branch (sha1 commit id) -- call this Last
- periodically:
  - grab the current head (call this Current)
  - if it's the same as Last stop
  - do a git log Current ^Last to observe what has happened since
    we last noticed a change.  report on these commits.
  - Last = Current

If these branches can be updated such that history is rewritten (not a concern in my particular case), I assume that for correctness you'd have to make Last and Current actual branches (perhaps under refs/heads/observer/... or whatever) to ensure that they don't get gc'd out from under you.

Am I correct in believing that the above strategy will (if history is not rewritten) correctly report all the commits between the last- observed and current state of the branch? Even if history *is* rewritten, I think (assuming I ensure things aren't gc'd) I'd get still get it right.

If I'm tracking several branches which can be merged between, I might want to keep track of which commits I've sent reports about if I don't want to re-report commits when they're merged into another branch.

Brian
Next: Jeff King
Message 1 of 2 in “observing changes to a git repository”
  1. Brian SwetlandDec 31, 2007
  2. Jeff KingJan 1, 2008

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.