Use a better algorithm to get the last commit