{"thread":{"id":"11441","subject":"observing changes to a git repository","startedAt":"2007-12-31T22:28:20Z","lastAt":"2008-01-01T06:54:03Z","messageCount":2,"participants":["Brian Swetland","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"64282","messageId":"20071231222820.GA11278@bulgaria.corp.google.com","threadId":"11441","inReplyTo":null,"subject":"observing changes to a git repository","fromName":"Brian Swetland","fromEmail":"swetland@google.com","sentAt":"2007-12-31T22:28:20Z","receivedAt":"2007-12-31T22:28:20Z","isPatch":false,"sender":{"key":"swetland@google.com","avatar":"https://gravatar.com/avatar/b26b7c772097c55d8febb0fc027dd2ef577a05994a321819f49ab3c9153ac8b1?d=mp&s=160"},"body":"\nAssuming I wanted to use a script (possibly run from cron) to observe\nand report changes to a git repository (instead of running something\nfrom the various hooks), does the following strategy seem workable:\n\n- for each branch to observe, record the initial position of that \n  branch (sha1 commit id) -- call this Last\n\n- periodically:\n  - grab the current head (call this Current)\n  - if it's the same as Last stop\n  - do a git log Current ^Last to observe what has happened since\n    we last noticed a change.  report on these commits.\n  - Last = Current\n\nIf these branches can be updated such that history is rewritten (not\na concern in my particular case), I assume that for correctness you'd\nhave to make Last and Current actual branches (perhaps under\nrefs/heads/observer/... or whatever) to ensure that they don't get gc'd\nout from under you.\n\nAm I correct in believing that the above strategy will (if history\nis not rewritten) correctly report all the commits between the last-\nobserved and current state of the branch?  Even if history *is*\nrewritten, I think (assuming I ensure things aren't gc'd) I'd get\nstill get it right.\n\nIf I'm tracking several branches which can be merged between, I might\nwant to keep track of which commits I've sent reports about if I don't\nwant to re-report commits when they're merged into another branch.\n\nBrian\n"},{"id":"64290","messageId":"20080101065403.GA21912@coredump.intra.peff.net","threadId":"11441","inReplyTo":"20071231222820.GA11278@bulgaria.corp.google.com","subject":"Re: observing changes to a git repository","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-01-01T06:54:03Z","receivedAt":"2008-01-01T06:54:03Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Dec 31, 2007 at 02:28:20PM -0800, Brian Swetland wrote:\n\n> - periodically:\n>   - grab the current head (call this Current)\n>   - if it's the same as Last stop\n>   - do a git log Current ^Last to observe what has happened since\n>     we last noticed a change.  report on these commits.\n>   - Last = Current\n\nOverall this makes sense. But in the case of history going backwards,\nyou might want to show a log of \"Current...Last\". IOW, imagine this\nhistory:\n\n  B-C\n /\nA-D-E\n\nLast is set to 'C' from some iteration of your script. In one period,\nsomebody does a git-reset back to A, then makes commits D and E. So you\nwant to see not just B and C, but some representation that D and E are\nno longer of interest.  \"gitk Last...Current\" will show you a nice graph\nwith a fork. git-log's --left-right option can represent the same\ninformation textually. What you want depends, I think, on the goal of\nyour script.\n\n> If these branches can be updated such that history is rewritten (not\n> a concern in my particular case), I assume that for correctness you'd\n> have to make Last and Current actual branches (perhaps under\n> refs/heads/observer/... or whatever) to ensure that they don't get gc'd\n> out from under you.\n\nYes, although realistically the reflog will keep it intact (unless you\nhave a bare repo without reflog).\n\n> If I'm tracking several branches which can be merged between, I might\n> want to keep track of which commits I've sent reports about if I don't\n> want to re-report commits when they're merged into another branch.\n\nWhat you have should work in the face of merges. Here's a history with\nsome merges:\n\n  B-C     H-I <-- branch1\n /   \\   /   \\\nA-D-E-F-G-J-K-L <-- master\n\nwhere 'F' and 'L' are our merges. Because ^H implies ^G, but not ^J, if\nwe have something like Current=L, Last=H, you will see I, J, K, L.\n\nSo you will see each commit only once, unless you are running this\nscript per-branch, in which case you will see it once per branch. :) In\nthat case, you can do something like \"git log Current ^LastBranch1\n^LastBranch2 ...\". IOW, Last* indicates \"I've seen this and don't care\nabout it anymore\".\n\n-Peff\n"}]}