PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/amp/commands/commands/workflows/hg/outgoing.rb

https://bitbucket.org/casualjim/amp
Ruby | 61 lines | 45 code | 8 blank | 8 comment | 5 complexity | 5dc1da0ebb5c8cbe1ce7d2017c0c2cdb MD5 | raw file
  1. command :outgoing do |c|
  2. c.workflow :hg
  3. c.opt :limit, "How much of the logs to show", :short => '-l', :type => :integer
  4. c.opt :rev, "Revision to clone up to (implies pull=True)", :short => '-r', :type => :integer
  5. c.opt :force, "Force getting new heads", :short => '-f'
  6. c.opt :"newest-first", 'Show the newest heads first'
  7. c.opt :"no-merges", "Don't show merges"
  8. c.desc "Prints the list of all changesets that can be pushed"
  9. c.help <<-HELP
  10. amp outgoing [options]+ dest
  11. show changesets not found in destination
  12. Show changesets not found in the specified destination repository or
  13. the default push location. These are the changesets that would be pushed
  14. if a push was requested.
  15. See pull for valid destination format details.
  16. HELP
  17. c.on_run do |opts, args|
  18. repo = opts[:repository]
  19. dest = args.shift
  20. path = c.expand_path dest || 'default-push', dest || 'default', repo.config
  21. url = Amp::Support::parse_hg_url path, opts[:rev]
  22. # dest, revs, checkout
  23. if url[:revs] && url[:revs].any? # url[:revs] isn't guaranteed to be an array
  24. url[:revs] = url[:revs].map {|r| repo.lookup rev }
  25. end
  26. remote = Amp::Repositories.pick nil, url[:url]
  27. Amp::UI::status "comparing with #{url[:url].hide_password}"
  28. o = repo.find_outgoing_roots remote, :force => opts[:force]
  29. (Amp::UI::status "no changes found"; return 1) if o.empty?
  30. o = repo.changelog.nodes_between(o, url[:revs])[:between]
  31. # reverse the order, because the newest are usually last
  32. # this is noticed if you get bitbucket email notifications
  33. o.reverse! if opts[:"newest-first"]
  34. # trim the list if it's bigger than our limit
  35. o = opts[:limit] ? o[0..opts[:limit]-1] : o
  36. Amp::UI::say # give us some space
  37. # print each changeset using the template in templates/
  38. o.each do |node_id|
  39. # get the parents of the node so that we can check if it's a merge
  40. # (merges have two parents)
  41. parents = repo[node_id].parents
  42. # We skip printing this if it's a merge (parents.size == 2)
  43. # and we're NOT printing merges (opts[:"no-merges"])
  44. next if opts[:"no-merges"] && parents.size == 2
  45. opts.merge! :template_type => :log
  46. Amp::UI::tell repo[node_id].to_templated_s(opts)
  47. end
  48. end
  49. end