git - Grit: how to to tell between two commits which is newer? -
i'd able tell between 2 grit::commit objects, newer. mean newer if commit_a parent (or parent of parent,etc) of commit_b, commit_b newer. assumes commit_a , commit_b on same branch.
i thought using grit::commit#date(), think this'll inaccurate.
any ideas?
here ended implementing. see comments explanation.
performance dog slow, worse when using repo.git.rev_list(via method_missing).
require 'grit' module grit class commit # returns true if commits in +commits+ decendants of calling commit. true # means 1 or more commits in +commits+ newer. def has_decendant_in? *commits total_commits = commits.flatten raise argumenterror "at least 1 commit required." if total_commits.empty? total_commits.each |commit| return true if repo.commits_between(commit.id, id).empty? end return false end # returns array of commits tie being newest commits. ties can # occur when commits in different branches. def self.newest *commits oldest_commits = [] total_commits = commits.flatten raise argumenterror "at least 1 commit required." if total_commits.empty? (total_commits).each |commit| if commit.has_decendant_in?(total_commits - [commit]) oldest_commits << commit end end return total_commits - oldest_commits end end end
Comments
Post a Comment