1

i'd like to know a algorithm which detect recent changes in the specified file as I'm learning git core architecture.

you know git log -n1 -- <file> show the commit which has recent change in the specified file. it's very simple to know the latest change. I casually want to implement it by self.

i uses libgit2 to walk each commits. and i've taken some days but I can't understand it. git commit model using DAG like structure it's hardly to seek that for me.

[for example]
o---o---o---o---o---M--[HEAD]
     `-o------M-o-o'
        `-C-o-'

o means: a commit
M means: merge commit
C means: rechange change in the specified file

whats the best way to detect recent change in the specified file?

chobie
  • 111
  • 2
  • This **[question](http://stackoverflow.com/questions/8481914/git-log-1-fullpath-myfile-with-libgit2/8484744#8484744)** deals with the same subject. – nulltoken Jan 04 '12 at 07:03
  • Thanks for notice me, i'll move there. this issue looks simple but little bit difficult when merge commit appeared. – chobie Jan 05 '12 at 03:11

1 Answers1

0

You will need to walk the parent commits. Merge commits have 2 or more parents. Eventually you end up at a common commit which is the branch. So if your function walks each parent recursively, you need to pass back as a return value the commits already inspected so you don't traverse the same commits again. Alternatively, if a change is found, then you can return the commit that houses the change and short-circuit out.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • Thank you introduce simply. i've stopped to walk each commits when i found the change in specified file. well, i'll seek the common commit and check commit time each found commits. – chobie Jan 05 '12 at 03:27