PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/carbonica/amp/
Ruby | 77 lines | 45 code | 9 blank | 23 comment | 5 complexity | 73df2d1c10fa86093c480a9f170074d9 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
  1. #######################################################################
  2. # Licensing Information #
  3. # #
  4. # The following code is a derivative work of the code from the #
  5. # Mercurial project, which is licensed GPLv2. This code therefore #
  6. # is also licensed under the terms of the GNU Public License, #
  7. # verison 2. #
  8. # #
  9. # For information on the license of this code when distributed #
  10. # with and used in conjunction with the other modules in the #
  11. # Amp project, please see the root-level LICENSE file. #
  12. # #
  13. # Š Michael J. Edgar and Ari Brown, 2009-2010 #
  14. # #
  15. #######################################################################
  16. command :outgoing do |c|
  17. c.workflow :hg
  18. c.opt :limit, "How much of the logs to show", :short => '-l', :type => :integer
  19. c.opt :rev, "Revision to clone up to (implies pull=True)", :short => '-r', :type => :integer
  20. c.opt :force, "Force getting new heads", :short => '-f'
  21. c.opt :"newest-first", 'Show the newest heads first'
  22. c.opt :"no-merges", "Don't show merges"
  23. c.desc "Prints the list of all changesets that can be pushed"
  24. c.help <<-HELP
  25. amp outgoing [options]+ dest
  26. show changesets not found in destination
  27. Show changesets not found in the specified destination repository or
  28. the default push location. These are the changesets that would be pushed
  29. if a push was requested.
  30. See pull for valid destination format details.
  31. HELP
  32. c.on_run do |opts, args|
  33. repo = opts[:repository]
  34. dest = args.shift
  35. path = c.expand_path dest || 'default-push', dest || 'default', repo.config
  36. url = Amp::Support::parse_hg_url path, opts[:rev]
  37. # dest, revs, checkout
  38. if url[:revs] && url[:revs].any? # url[:revs] isn't guaranteed to be an array
  39. url[:revs] = url[:revs].map {|r| repo.lookup rev }
  40. end
  41. remote = Amp::Repositories.pick nil, url[:url]
  42. Amp::UI::status "comparing with #{url[:url].hide_password}"
  43. o = repo.find_outgoing_roots remote, :force => opts[:force]
  44. (Amp::UI::status "no changes found"; return 1) if o.empty?
  45. o = repo.changelog.nodes_between(o, url[:revs])[:between]
  46. # reverse the order, because the newest are usually last
  47. # this is noticed if you get bitbucket email notifications
  48. o.reverse! if opts[:"newest-first"]
  49. # trim the list if it's bigger than our limit
  50. o = opts[:limit] ? o[0..opts[:limit]-1] : o
  51. Amp::UI::say # give us some space
  52. # print each changeset using the template in templates/
  53. o.each do |node_id|
  54. # get the parents of the node so that we can check if it's a merge
  55. # (merges have two parents)
  56. parents = repo[node_id].parents
  57. # We skip printing this if it's a merge (parents.size == 2)
  58. # and we're NOT printing merges (opts[:"no-merges"])
  59. next if opts[:"no-merges"] && parents.size == 2
  60. opts.merge! :template_type => :log
  61. Amp::UI::tell repo[node_id].to_templated_s(opts)
  62. end
  63. end
  64. end