From 2a3b63fa133bd393a62144384968c83265b48f47 Mon Sep 17 00:00:00 2001 From: Scott Chacon Date: Fri, 7 Nov 2008 13:40:48 -0800 Subject: [PATCH] a lot more tolerant of messed up repos --- commands/commands.rb | 21 +++++++++++---------- commands/helpers.rb | 4 ++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/commands/commands.rb b/commands/commands.rb index 7801f556..ef662b61 100644 --- a/commands/commands.rb +++ b/commands/commands.rb @@ -54,24 +54,25 @@ data = get_network_data(user) data['users'].each do |hsh| u = hsh['name'] - ids += hsh['heads'].map { |a| a['id'] } + user_ids = hsh['heads'].map { |a| a['id'] } + user_ids.each do |id| + if !helper.has_commit?(id) + GitHub.invoke(:track, u) unless helper.tracking?(u) + puts "fetching #{u}" + GitHub.invoke(:fetch_all, u) + end + end + ids += user_ids end ids.uniq! # check that we have all these shas locally - ids.each do |id| - if !helper.has_commit?(id) - GitHub.invoke(:track, u) unless helper.tracking?(u) - puts "fetching #{u}" - GitHub.invoke(:fetch_all, u) - end - end - + local_heads = helper.local_heads local_heads_not = local_heads.map { |a| "^#{a}"} looking_for = (ids - local_heads) + local_heads_not commits = helper.get_commits(looking_for) - + cherry = [] ids.each do |id| cherry += helper.get_cherry(id) diff --git a/commands/helpers.rb b/commands/helpers.rb index e0ddf6bb..90d90613 100644 --- a/commands/helpers.rb +++ b/commands/helpers.rb @@ -39,7 +39,7 @@ end helper :has_commit? do |sha| - `git rev-parse #{sha}` + `git show #{sha} >/dev/null 2>/dev/null` $?.exitstatus == 0 end @@ -79,7 +79,7 @@ end helper :get_commits do |rev_array| - list = rev_array.join(' ') + list = rev_array.select { |a| has_commit?(a) }.join(' ') `git log --pretty=format:"%H::%ae::%s::%ar::%ad" --no-merges #{list}`.split("\n").map { |a| a.split('::') } end