PageRenderTime 25ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/carbonica/amp_old
Ruby | 87 lines | 72 code | 7 blank | 8 comment | 5 complexity | 0f429daa2123df47f6ff664dd7eb44cd 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. show changesets not found in destination
  11. Show changesets not found in the specified destination repository or
  12. the default push location. These are the changesets that would be pushed
  13. if a push was requested.
  14. See pull for valid destination format details.
  15. HELP
  16. c.on_run do |opts, args|
  17. repo = opts[:repository]
  18. config = repo.config
  19. local_path = proc do |path|
  20. case path
  21. when /file:\/\/localhost\//
  22. path[17..-1]
  23. when /file:\/\//
  24. path[8..-1]
  25. when /file:/
  26. path[6..-1]
  27. else
  28. path
  29. end
  30. end
  31. # Return repository location relative to cwd or from [paths]
  32. expand_path = proc do |*arr|
  33. loc = arr.shift
  34. dflt = arr.shift
  35. return loc if loc =~ /:\/\// or File.directory?(File.join(loc, '.hg'))
  36. path = config['paths'][loc]
  37. if !path && dflt
  38. path = config['paths'][dflt]
  39. end
  40. path || loc
  41. end
  42. dest = args.shift
  43. path = expand_path[ dest || 'default-push', dest || 'default' ]
  44. url = Amp::Support::parse_hg_url path, opts[:rev]
  45. # dest, revs, checkout
  46. if url[:revs] && url[:revs].any? # url[:revs] isn't guaranteed to be an array
  47. url[:revs] = url[:revs].map {|r| repo.lookup rev }
  48. end
  49. remote = Amp::Repositories.pick nil, url[:url]
  50. Amp::UI::status "comparing with #{url[:url].hide_password}"
  51. o = repo.find_outgoing_roots remote, :force => opts[:force]
  52. (Amp::UI::status "no changes found"; return 1) if o.empty?
  53. o = repo.changelog.nodes_between(o, url[:revs])[:between]
  54. # reverse the order, because the newest are usually last
  55. # this is noticed if you get bitbucket notifications
  56. o.reverse! if opts[:"newest-first"]
  57. # trim the list if it's bigger than our limit
  58. o = opts[:limit] ? o[0..opts[:limit]-1] : o
  59. # print each changeset using the template in templates/
  60. o.each do |node_id|
  61. # get the parents of the node so that we can check if it's a merge
  62. # (merges have two parents)
  63. parents = repo.changelog.parents(node_id).select {|p| p.not_null? }
  64. # We skip printing this if it's a merge (parents.size == 2)
  65. # and we're NOT printing merges (opts[:"no-merges"])
  66. next if opts[:"no-merges"] && parents.size == 2
  67. opts.merge! :template_type => :log
  68. Amp::UI::say repo[node_id].to_templated_s(opts)
  69. end
  70. end
  71. end