amp 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (295) hide show
  1. data/.gitignore +1 -0
  2. data/.hgignore +26 -0
  3. data/AUTHORS +2 -0
  4. data/History.txt +6 -0
  5. data/LICENSE +37 -0
  6. data/MANIFESTO +7 -0
  7. data/Manifest.txt +294 -0
  8. data/README.md +129 -0
  9. data/Rakefile +102 -0
  10. data/SCHEDULE.markdown +12 -0
  11. data/STYLE +27 -0
  12. data/TODO.markdown +149 -0
  13. data/ampfile.rb +47 -0
  14. data/bin/amp +30 -0
  15. data/bin/amp1.9 +30 -0
  16. data/ext/amp/bz2/README.txt +39 -0
  17. data/ext/amp/bz2/bz2.c +1582 -0
  18. data/ext/amp/bz2/extconf.rb +77 -0
  19. data/ext/amp/bz2/mkmf.log +29 -0
  20. data/ext/amp/mercurial_patch/extconf.rb +5 -0
  21. data/ext/amp/mercurial_patch/mpatch.c +405 -0
  22. data/ext/amp/priority_queue/extconf.rb +5 -0
  23. data/ext/amp/priority_queue/priority_queue.c +947 -0
  24. data/ext/amp/support/extconf.rb +5 -0
  25. data/ext/amp/support/support.c +250 -0
  26. data/lib/amp.rb +200 -0
  27. data/lib/amp/commands/command.rb +507 -0
  28. data/lib/amp/commands/command_support.rb +137 -0
  29. data/lib/amp/commands/commands/config.rb +143 -0
  30. data/lib/amp/commands/commands/help.rb +29 -0
  31. data/lib/amp/commands/commands/init.rb +10 -0
  32. data/lib/amp/commands/commands/templates.rb +137 -0
  33. data/lib/amp/commands/commands/version.rb +7 -0
  34. data/lib/amp/commands/commands/workflow.rb +28 -0
  35. data/lib/amp/commands/commands/workflows/git/add.rb +65 -0
  36. data/lib/amp/commands/commands/workflows/git/copy.rb +27 -0
  37. data/lib/amp/commands/commands/workflows/git/mv.rb +23 -0
  38. data/lib/amp/commands/commands/workflows/git/rm.rb +60 -0
  39. data/lib/amp/commands/commands/workflows/hg/add.rb +53 -0
  40. data/lib/amp/commands/commands/workflows/hg/addremove.rb +86 -0
  41. data/lib/amp/commands/commands/workflows/hg/annotate.rb +46 -0
  42. data/lib/amp/commands/commands/workflows/hg/archive.rb +126 -0
  43. data/lib/amp/commands/commands/workflows/hg/branch.rb +28 -0
  44. data/lib/amp/commands/commands/workflows/hg/branches.rb +30 -0
  45. data/lib/amp/commands/commands/workflows/hg/bundle.rb +115 -0
  46. data/lib/amp/commands/commands/workflows/hg/clone.rb +95 -0
  47. data/lib/amp/commands/commands/workflows/hg/commit.rb +42 -0
  48. data/lib/amp/commands/commands/workflows/hg/copy.rb +31 -0
  49. data/lib/amp/commands/commands/workflows/hg/debug/dirstate.rb +32 -0
  50. data/lib/amp/commands/commands/workflows/hg/debug/index.rb +36 -0
  51. data/lib/amp/commands/commands/workflows/hg/default.rb +9 -0
  52. data/lib/amp/commands/commands/workflows/hg/diff.rb +30 -0
  53. data/lib/amp/commands/commands/workflows/hg/forget.rb +11 -0
  54. data/lib/amp/commands/commands/workflows/hg/heads.rb +25 -0
  55. data/lib/amp/commands/commands/workflows/hg/identify.rb +23 -0
  56. data/lib/amp/commands/commands/workflows/hg/import.rb +135 -0
  57. data/lib/amp/commands/commands/workflows/hg/incoming.rb +85 -0
  58. data/lib/amp/commands/commands/workflows/hg/info.rb +18 -0
  59. data/lib/amp/commands/commands/workflows/hg/log.rb +21 -0
  60. data/lib/amp/commands/commands/workflows/hg/manifest.rb +13 -0
  61. data/lib/amp/commands/commands/workflows/hg/merge.rb +53 -0
  62. data/lib/amp/commands/commands/workflows/hg/move.rb +28 -0
  63. data/lib/amp/commands/commands/workflows/hg/outgoing.rb +61 -0
  64. data/lib/amp/commands/commands/workflows/hg/pull.rb +74 -0
  65. data/lib/amp/commands/commands/workflows/hg/push.rb +20 -0
  66. data/lib/amp/commands/commands/workflows/hg/remove.rb +45 -0
  67. data/lib/amp/commands/commands/workflows/hg/resolve.rb +83 -0
  68. data/lib/amp/commands/commands/workflows/hg/revert.rb +53 -0
  69. data/lib/amp/commands/commands/workflows/hg/root.rb +13 -0
  70. data/lib/amp/commands/commands/workflows/hg/serve.rb +38 -0
  71. data/lib/amp/commands/commands/workflows/hg/status.rb +116 -0
  72. data/lib/amp/commands/commands/workflows/hg/tag.rb +69 -0
  73. data/lib/amp/commands/commands/workflows/hg/tags.rb +27 -0
  74. data/lib/amp/commands/commands/workflows/hg/tip.rb +13 -0
  75. data/lib/amp/commands/commands/workflows/hg/update.rb +27 -0
  76. data/lib/amp/commands/commands/workflows/hg/verify.rb +9 -0
  77. data/lib/amp/commands/commands/workflows/hg/view.rb +36 -0
  78. data/lib/amp/commands/dispatch.rb +181 -0
  79. data/lib/amp/commands/hooks.rb +81 -0
  80. data/lib/amp/dependencies/amp_support.rb +1 -0
  81. data/lib/amp/dependencies/amp_support/ruby_amp_support.rb +103 -0
  82. data/lib/amp/dependencies/minitar.rb +979 -0
  83. data/lib/amp/dependencies/priority_queue.rb +18 -0
  84. data/lib/amp/dependencies/priority_queue/c_priority_queue.rb +1 -0
  85. data/lib/amp/dependencies/priority_queue/poor_priority_queue.rb +46 -0
  86. data/lib/amp/dependencies/priority_queue/ruby_priority_queue.rb +525 -0
  87. data/lib/amp/dependencies/python_config.rb +211 -0
  88. data/lib/amp/dependencies/trollop.rb +713 -0
  89. data/lib/amp/dependencies/zip/ioextras.rb +155 -0
  90. data/lib/amp/dependencies/zip/stdrubyext.rb +111 -0
  91. data/lib/amp/dependencies/zip/tempfile_bugfixed.rb +186 -0
  92. data/lib/amp/dependencies/zip/zip.rb +1850 -0
  93. data/lib/amp/dependencies/zip/zipfilesystem.rb +609 -0
  94. data/lib/amp/dependencies/zip/ziprequire.rb +90 -0
  95. data/lib/amp/encoding/base85.rb +97 -0
  96. data/lib/amp/encoding/binary_diff.rb +82 -0
  97. data/lib/amp/encoding/difflib.rb +166 -0
  98. data/lib/amp/encoding/mercurial_diff.rb +378 -0
  99. data/lib/amp/encoding/mercurial_patch.rb +1 -0
  100. data/lib/amp/encoding/patch.rb +292 -0
  101. data/lib/amp/encoding/pure_ruby/ruby_mercurial_patch.rb +123 -0
  102. data/lib/amp/extensions/ditz.rb +41 -0
  103. data/lib/amp/extensions/lighthouse.rb +167 -0
  104. data/lib/amp/graphs/ancestor.rb +147 -0
  105. data/lib/amp/graphs/copies.rb +261 -0
  106. data/lib/amp/merges/merge_state.rb +164 -0
  107. data/lib/amp/merges/merge_ui.rb +322 -0
  108. data/lib/amp/merges/simple_merge.rb +450 -0
  109. data/lib/amp/profiling_hacks.rb +36 -0
  110. data/lib/amp/repository/branch_manager.rb +234 -0
  111. data/lib/amp/repository/dir_state.rb +950 -0
  112. data/lib/amp/repository/journal.rb +203 -0
  113. data/lib/amp/repository/lock.rb +207 -0
  114. data/lib/amp/repository/repositories/bundle_repository.rb +214 -0
  115. data/lib/amp/repository/repositories/http_repository.rb +377 -0
  116. data/lib/amp/repository/repositories/local_repository.rb +2661 -0
  117. data/lib/amp/repository/repository.rb +94 -0
  118. data/lib/amp/repository/store.rb +485 -0
  119. data/lib/amp/repository/tag_manager.rb +319 -0
  120. data/lib/amp/repository/updatable.rb +532 -0
  121. data/lib/amp/repository/verification.rb +431 -0
  122. data/lib/amp/repository/versioned_file.rb +475 -0
  123. data/lib/amp/revlogs/bundle_revlogs.rb +246 -0
  124. data/lib/amp/revlogs/changegroup.rb +217 -0
  125. data/lib/amp/revlogs/changelog.rb +338 -0
  126. data/lib/amp/revlogs/changeset.rb +521 -0
  127. data/lib/amp/revlogs/file_log.rb +165 -0
  128. data/lib/amp/revlogs/index.rb +493 -0
  129. data/lib/amp/revlogs/manifest.rb +195 -0
  130. data/lib/amp/revlogs/node.rb +18 -0
  131. data/lib/amp/revlogs/revlog.rb +1032 -0
  132. data/lib/amp/revlogs/revlog_support.rb +126 -0
  133. data/lib/amp/server/amp_user.rb +44 -0
  134. data/lib/amp/server/extension/amp_extension.rb +396 -0
  135. data/lib/amp/server/extension/authorization.rb +201 -0
  136. data/lib/amp/server/fancy_http_server.rb +252 -0
  137. data/lib/amp/server/fancy_views/_browser.haml +28 -0
  138. data/lib/amp/server/fancy_views/_diff_file.haml +13 -0
  139. data/lib/amp/server/fancy_views/_navbar.haml +17 -0
  140. data/lib/amp/server/fancy_views/changeset.haml +31 -0
  141. data/lib/amp/server/fancy_views/commits.haml +32 -0
  142. data/lib/amp/server/fancy_views/file.haml +35 -0
  143. data/lib/amp/server/fancy_views/file_diff.haml +23 -0
  144. data/lib/amp/server/fancy_views/harshcss/all_hallows_eve.css +72 -0
  145. data/lib/amp/server/fancy_views/harshcss/amy.css +147 -0
  146. data/lib/amp/server/fancy_views/harshcss/twilight.css +138 -0
  147. data/lib/amp/server/fancy_views/stylesheet.sass +175 -0
  148. data/lib/amp/server/http_server.rb +140 -0
  149. data/lib/amp/server/repo_user_management.rb +287 -0
  150. data/lib/amp/support/amp_config.rb +164 -0
  151. data/lib/amp/support/amp_ui.rb +287 -0
  152. data/lib/amp/support/docs.rb +54 -0
  153. data/lib/amp/support/generator.rb +78 -0
  154. data/lib/amp/support/ignore.rb +144 -0
  155. data/lib/amp/support/loaders.rb +93 -0
  156. data/lib/amp/support/logger.rb +103 -0
  157. data/lib/amp/support/match.rb +151 -0
  158. data/lib/amp/support/multi_io.rb +87 -0
  159. data/lib/amp/support/openers.rb +121 -0
  160. data/lib/amp/support/ruby_19_compatibility.rb +66 -0
  161. data/lib/amp/support/support.rb +1095 -0
  162. data/lib/amp/templates/blank.commit.erb +23 -0
  163. data/lib/amp/templates/blank.log.erb +18 -0
  164. data/lib/amp/templates/default.commit.erb +23 -0
  165. data/lib/amp/templates/default.log.erb +26 -0
  166. data/lib/amp/templates/template.rb +165 -0
  167. data/site/Rakefile +24 -0
  168. data/site/src/about/ampfile.haml +57 -0
  169. data/site/src/about/commands.haml +106 -0
  170. data/site/src/about/index.haml +33 -0
  171. data/site/src/about/performance.haml +31 -0
  172. data/site/src/about/workflows.haml +34 -0
  173. data/site/src/contribute/index.haml +65 -0
  174. data/site/src/contribute/style.haml +297 -0
  175. data/site/src/css/active4d.css +114 -0
  176. data/site/src/css/all_hallows_eve.css +72 -0
  177. data/site/src/css/all_themes.css +3299 -0
  178. data/site/src/css/amp.css +260 -0
  179. data/site/src/css/amy.css +147 -0
  180. data/site/src/css/blackboard.css +88 -0
  181. data/site/src/css/brilliance_black.css +605 -0
  182. data/site/src/css/brilliance_dull.css +599 -0
  183. data/site/src/css/cobalt.css +149 -0
  184. data/site/src/css/cur_amp.css +185 -0
  185. data/site/src/css/dawn.css +121 -0
  186. data/site/src/css/eiffel.css +121 -0
  187. data/site/src/css/espresso_libre.css +109 -0
  188. data/site/src/css/idle.css +62 -0
  189. data/site/src/css/iplastic.css +80 -0
  190. data/site/src/css/lazy.css +73 -0
  191. data/site/src/css/mac_classic.css +123 -0
  192. data/site/src/css/magicwb_amiga.css +104 -0
  193. data/site/src/css/pastels_on_dark.css +188 -0
  194. data/site/src/css/reset.css +55 -0
  195. data/site/src/css/slush_poppies.css +85 -0
  196. data/site/src/css/spacecadet.css +51 -0
  197. data/site/src/css/sunburst.css +180 -0
  198. data/site/src/css/twilight.css +137 -0
  199. data/site/src/css/zenburnesque.css +91 -0
  200. data/site/src/get/index.haml +32 -0
  201. data/site/src/helpers.rb +121 -0
  202. data/site/src/images/amp_logo.png +0 -0
  203. data/site/src/images/carbonica.png +0 -0
  204. data/site/src/images/revolution.png +0 -0
  205. data/site/src/images/tab-bg.png +0 -0
  206. data/site/src/images/tab-sliding-left.png +0 -0
  207. data/site/src/images/tab-sliding-right.png +0 -0
  208. data/site/src/include/_footer.haml +22 -0
  209. data/site/src/include/_header.haml +17 -0
  210. data/site/src/index.haml +104 -0
  211. data/site/src/learn/index.haml +46 -0
  212. data/site/src/scripts/jquery-1.3.2.min.js +19 -0
  213. data/site/src/scripts/jquery.cookie.js +96 -0
  214. data/tasks/stats.rake +155 -0
  215. data/tasks/yard.rake +171 -0
  216. data/test/dirstate_tests/dirstate +0 -0
  217. data/test/dirstate_tests/hgrc +5 -0
  218. data/test/dirstate_tests/test_dir_state.rb +192 -0
  219. data/test/functional_tests/resources/.hgignore +2 -0
  220. data/test/functional_tests/resources/STYLE.txt +25 -0
  221. data/test/functional_tests/resources/command.rb +372 -0
  222. data/test/functional_tests/resources/commands/annotate.rb +57 -0
  223. data/test/functional_tests/resources/commands/experimental/lolcats.rb +17 -0
  224. data/test/functional_tests/resources/commands/heads.rb +22 -0
  225. data/test/functional_tests/resources/commands/manifest.rb +12 -0
  226. data/test/functional_tests/resources/commands/status.rb +90 -0
  227. data/test/functional_tests/resources/version2/.hgignore +5 -0
  228. data/test/functional_tests/resources/version2/STYLE.txt +25 -0
  229. data/test/functional_tests/resources/version2/command.rb +372 -0
  230. data/test/functional_tests/resources/version2/commands/annotate.rb +45 -0
  231. data/test/functional_tests/resources/version2/commands/experimental/lolcats.rb +17 -0
  232. data/test/functional_tests/resources/version2/commands/heads.rb +22 -0
  233. data/test/functional_tests/resources/version2/commands/manifest.rb +12 -0
  234. data/test/functional_tests/resources/version2/commands/status.rb +90 -0
  235. data/test/functional_tests/resources/version3/.hgignore +5 -0
  236. data/test/functional_tests/resources/version3/STYLE.txt +31 -0
  237. data/test/functional_tests/resources/version3/command.rb +376 -0
  238. data/test/functional_tests/resources/version3/commands/annotate.rb +45 -0
  239. data/test/functional_tests/resources/version3/commands/experimental/lolcats.rb +17 -0
  240. data/test/functional_tests/resources/version3/commands/heads.rb +22 -0
  241. data/test/functional_tests/resources/version3/commands/manifest.rb +12 -0
  242. data/test/functional_tests/resources/version3/commands/status.rb +90 -0
  243. data/test/functional_tests/resources/version4/.hgignore +5 -0
  244. data/test/functional_tests/resources/version4/STYLE.txt +31 -0
  245. data/test/functional_tests/resources/version4/command.rb +376 -0
  246. data/test/functional_tests/resources/version4/commands/experimental/lolcats.rb +17 -0
  247. data/test/functional_tests/resources/version4/commands/heads.rb +22 -0
  248. data/test/functional_tests/resources/version4/commands/manifest.rb +12 -0
  249. data/test/functional_tests/resources/version4/commands/stats.rb +25 -0
  250. data/test/functional_tests/resources/version4/commands/status.rb +90 -0
  251. data/test/functional_tests/resources/version5_1/.hgignore +5 -0
  252. data/test/functional_tests/resources/version5_1/STYLE.txt +2 -0
  253. data/test/functional_tests/resources/version5_1/command.rb +374 -0
  254. data/test/functional_tests/resources/version5_1/commands/experimental/lolcats.rb +17 -0
  255. data/test/functional_tests/resources/version5_1/commands/heads.rb +22 -0
  256. data/test/functional_tests/resources/version5_1/commands/manifest.rb +12 -0
  257. data/test/functional_tests/resources/version5_1/commands/stats.rb +25 -0
  258. data/test/functional_tests/resources/version5_1/commands/status.rb +90 -0
  259. data/test/functional_tests/resources/version5_2/.hgignore +5 -0
  260. data/test/functional_tests/resources/version5_2/STYLE.txt +14 -0
  261. data/test/functional_tests/resources/version5_2/command.rb +376 -0
  262. data/test/functional_tests/resources/version5_2/commands/experimental/lolcats.rb +17 -0
  263. data/test/functional_tests/resources/version5_2/commands/manifest.rb +12 -0
  264. data/test/functional_tests/resources/version5_2/commands/newz.rb +12 -0
  265. data/test/functional_tests/resources/version5_2/commands/stats.rb +25 -0
  266. data/test/functional_tests/resources/version5_2/commands/status.rb +90 -0
  267. data/test/functional_tests/test_functional.rb +604 -0
  268. data/test/localrepo_tests/test_local_repo.rb +121 -0
  269. data/test/localrepo_tests/testrepo.tar.gz +0 -0
  270. data/test/manifest_tests/00manifest.i +0 -0
  271. data/test/manifest_tests/test_manifest.rb +72 -0
  272. data/test/merge_tests/base.txt +10 -0
  273. data/test/merge_tests/expected.local.txt +16 -0
  274. data/test/merge_tests/local.txt +11 -0
  275. data/test/merge_tests/remote.txt +11 -0
  276. data/test/merge_tests/test_merge.rb +26 -0
  277. data/test/revlog_tests/00changelog.i +0 -0
  278. data/test/revlog_tests/revision_added_changelog.i +0 -0
  279. data/test/revlog_tests/test_adding_index.i +0 -0
  280. data/test/revlog_tests/test_revlog.rb +333 -0
  281. data/test/revlog_tests/testindex.i +0 -0
  282. data/test/store_tests/store.tar.gz +0 -0
  283. data/test/store_tests/test_fncache_store.rb +122 -0
  284. data/test/test_amp.rb +9 -0
  285. data/test/test_base85.rb +14 -0
  286. data/test/test_bdiff.rb +42 -0
  287. data/test/test_commands.rb +122 -0
  288. data/test/test_difflib.rb +50 -0
  289. data/test/test_helper.rb +15 -0
  290. data/test/test_journal.rb +29 -0
  291. data/test/test_match.rb +134 -0
  292. data/test/test_mdiff.rb +74 -0
  293. data/test/test_mpatch.rb +14 -0
  294. data/test/test_support.rb +24 -0
  295. metadata +385 -0
@@ -0,0 +1,69 @@
1
+ command :tag do |c|
2
+ c.workflow :hg
3
+
4
+ c.desc "Tags a revision with a given tag name"
5
+ c.opt :rev, "Specifies which revision to tag", :short => "-r", :type => :string
6
+ c.opt :message, "Specifies the commit message", :short => "-m", :type => :string
7
+ c.opt :local, "Marks the tag as local only (not shared among repositories)", :short => "-l"
8
+ c.opt :remove, "Removes the tag, instead of applying it", :short => "-R"
9
+ c.opt :force, "Forces the tag to be applied, ignoring existing tags", :short => "-f"
10
+ c.opt :user, "Specifies which user to commit under", :short => "-u", :type => :string
11
+ c.opt :date, "Specifies which date to use", :short => "-d", :type => :string
12
+
13
+ c.on_run do |opts, args|
14
+ repo = opts[:repository]
15
+
16
+ user = opts[:user] || opts[:global_config].username
17
+ date = opts[:date] ? DateTime.parse(opts[:date]) : Time.now
18
+ rev = opts[:rev] || "."
19
+ message = opts[:message]
20
+
21
+ names = args
22
+ if names.map! {|n| n.strip}.uniq!
23
+ raise abort("tag names must be unique")
24
+ end
25
+ names.each do |n|
26
+ if ["tip",".","null"].include? n
27
+ raise abort("the tag name #{n} is reserved")
28
+ end
29
+ end
30
+ if opts[:rev] && opts[:remove]
31
+ raise abort("--rev and --remove are incompatible")
32
+ end
33
+
34
+ #removing a tag
35
+ if opts[:remove]
36
+ expected_type = opts[:local] ? "local" : "global"
37
+ names.each do |name|
38
+ unless repo.tag_type name
39
+ raise abort("tag #{name} does not exist")
40
+ end
41
+ if repo.tag_type(name) != expected_type
42
+ raise abort("tag #{name} is not a #{expected_type} tag")
43
+ end
44
+ end
45
+ rev = Amp::RevlogSupport::Node::NULL_ID
46
+ message ||= "Removed tag #{names.join(", ")}"
47
+ elsif !opts[:force]
48
+ names.each do |name|
49
+ if repo.tags[name]
50
+ raise abort("tag #{name} already exists" +
51
+ " (use -f to force)")
52
+ end
53
+ end
54
+ end
55
+
56
+ if !rev && repo.dirstate.parents[1] != Amp::RevlogSupport::Node::NULL_ID
57
+ raise abort("uncommited merge - please provide" +
58
+ " a specific revision")
59
+ end
60
+
61
+ node = repo[rev].node
62
+
63
+ message ||= "Added tag #{names.join(", ")} for changeset #{node.short_hex}"
64
+ repo.apply_tag names, node, :message => message,
65
+ :local => opts[:local],
66
+ :user => user,
67
+ :date => date
68
+ end
69
+ end
@@ -0,0 +1,27 @@
1
+ command "tags" do |c|
2
+ c.workflow :hg
3
+
4
+ c.desc "Lists the repository tags."
5
+ c.opt :quiet, "Prints only tag names", :short => "-q"
6
+
7
+ c.on_run do |opts, args|
8
+ repo = opts[:repository]
9
+ list = repo.tag_list
10
+ list.reverse!
11
+ tag_type = ""
12
+ list.each do |entry|
13
+ tag, node, revision = entry[:tag], entry[:node], entry[:revision]
14
+ if opts[:quiet]
15
+ Amp::UI.say "#{tag}"
16
+ next
17
+ end
18
+ if revision == -2
19
+ revision = repo.changelog.rev(node)
20
+ end
21
+ text = "#{revision.to_s.rjust(5)}:#{node.short_hex}"
22
+ tag_type = (repo.tag_type(tag) == "local") ? " local" : ""
23
+
24
+ Amp::UI.say("#{tag.ljust(30)} #{text}#{tag_type}")
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ command :tip do |c|
2
+ c.workflow :hg
3
+
4
+ c.desc "Prints the information about the repository's tip"
5
+ c.opt :template, "Which template to use while printing", :short => "-t", :type => :string, :default => "default"
6
+
7
+ c.on_run do |options, args|
8
+ repo = options[:repository]
9
+ options.merge! :template_type => :log
10
+ puts repo[repo.size - 1].to_templated_s(options)
11
+
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ command :update do |c|
2
+ c.workflow :hg
3
+
4
+ c.desc "Updates the current repository to the specified (or tip-most) revision"
5
+ c.opt :rev, "The revision # to use for updating.", { :short => "-r", :type => :string }
6
+ c.opt :node, "The node ID to use for updating.", { :short => "-n", :type => :string }
7
+ c.opt :clean, "Remove uncommitted changes from the working directory.", { :short => "-C" }
8
+
9
+ c.on_run do |opts, args|
10
+ repo = opts[:repository]
11
+
12
+ if opts[:rev] && opts[:node]
13
+ raise ArgumentError.new("Please only specify either --rev or --node.")
14
+ end
15
+
16
+ rev = opts[:rev] ? opts[:rev] : opts[:node]
17
+
18
+ # TODO: add --date option
19
+ if opts[:clean]
20
+ stats = repo.clean(rev)
21
+ else
22
+ stats = repo.update(rev)
23
+ end
24
+
25
+ c.print_update_stats stats
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ command :verify do |c|
2
+ c.desc "Verifies the mercurial repository, checking for integrity errors"
3
+ c.workflow :hg
4
+ c.on_run do |opts, args|
5
+ results = opts[:repository].verify
6
+ puts "#{results.files} files, #{results.changesets} changesets, #{results.revisions} revisions"
7
+ puts "#{results.errors} integrity errors, #{results.warnings} warnings." if results.errors > 0 || results.warnings > 0
8
+ end
9
+ end
@@ -0,0 +1,36 @@
1
+ command :view do |c|
2
+ c.workflow :hg
3
+
4
+ c.desc "Decompresses a file (or files) at a given revision and prints its data"
5
+ c.opt :output, "print output to file with formatted name", :type => :string
6
+ c.opt :rev, "specify which revision to view", :type => :string
7
+
8
+ c.synonym :cat # mercurial notation
9
+ c.on_run do |opts, args|
10
+ repo = opts[:repository]
11
+
12
+ changeset = repo[opts[:rev]] # if unspecified will give nil which gives working directory anyway
13
+ changeset = changeset.parents.first unless opts[:rev] # parent of working dir if unspecified
14
+
15
+ should_close = !!opts[:output]
16
+
17
+ output_io = lambda do |filename|
18
+ if opts[:output]
19
+ path = opts[:output].gsub(/%s/, File.basename(filename)).gsub(/%d/, File.dirname(filename)).
20
+ gsub(/%p/, filename)
21
+ File.open(path, "w")
22
+ else
23
+ $stdout
24
+ end
25
+ end
26
+
27
+ args.each do |file|
28
+ versioned_file = changeset.get_file(repo.relative_join(file))
29
+ text = versioned_file.data
30
+ output = output_io[versioned_file.repo_path]
31
+
32
+ output.write text # write it exactly as is
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,181 @@
1
+ require 'abbrev'
2
+ require "amp/commands/command.rb"
3
+ require_dir { "commands/*.rb" }
4
+ require_dir { "commands/commands/*.rb" }
5
+
6
+ module Amp
7
+
8
+ ##
9
+ # = Dispatch
10
+ # This class handles parsing command-line options, finding commands, and running them.
11
+ class Dispatch
12
+
13
+ ##
14
+ # This method essentially runs the amp executable. It first parses global options (--config)
15
+ # finds the subcommand (eg add, init, clone), parses the subcommand's options, merges the
16
+ # two, and then runs the entire thing.
17
+ def self.run
18
+ # Get the subcommands so we can stop on them
19
+ sub_commands = Amp::Command.all_commands.keys
20
+ # Get the global options (everything before the subcommand)
21
+ global_opts = Trollop::options do
22
+ banner "Amp - some more crystal, sir?"
23
+ version "Amp version #{Amp::VERSION} (#{Amp::VERSION_TITLE})"
24
+ opt :debug_opts, "Debug the command-line options", :short => "-d", :default => false, :type => :boolean
25
+ opt :verbose, "Verbose output"
26
+ opt :profile, "Profile the command being run, running it the given number of times"
27
+ opt :repository, "The path to the repository to use", :short => "-R", :type => :string, :default => Dir.pwd
28
+ opt :"pure-ruby", "Use only pure ruby (no C-extensions)"
29
+ opt :testing, "Running a test. Not for users to use"
30
+ stop_on_unknown
31
+ end
32
+ global_opts = global_opts.first # we don't need the parser here
33
+
34
+ # This loads the built-in ruby profiler - it's extremely slow. Use with care.
35
+ if global_opts[:profile]
36
+ require 'profile'
37
+ end
38
+
39
+ # Never load a C extension if we're in pure-ruby mode.
40
+ if global_opts[:"pure-ruby"]
41
+ $USE_RUBY = true
42
+ end
43
+
44
+ global_config = Amp::AmpConfig.new
45
+ Amp::UI.config = global_config
46
+ cmd = ARGV.shift # get the subcommand
47
+ cmd ||= "default"
48
+
49
+ opts_as_arr = ARGV.dup
50
+
51
+ if global_opts[:debug_opts]
52
+ global_config["debug", "messages"] = true
53
+ end
54
+
55
+ unless global_config["amp"]["workflow"]
56
+ global_config["amp"]["workflow"] = :hg
57
+ global_config.save! rescue Errno::EACCES
58
+ end
59
+
60
+ # the options to send to the command
61
+ cmd_opts = {}
62
+
63
+ # Load the repository
64
+ #path_to_repo = find_repo(".", cmd_opts) unless global_opts[:repository]
65
+ path_to_repo = ""
66
+
67
+ if path_to_repo.empty?
68
+ local_config = global_config
69
+ else
70
+ local_config = AmpConfig.new(:parent_config => global_config)
71
+ local_config.read_file File.join(path_to_repo, ".hg", "hgrc")
72
+ end
73
+
74
+ begin
75
+ cmd_opts[:repository] = Repositories.pick(local_config, global_opts[:repository])
76
+ rescue
77
+ unless Command::NO_REPO_ALLOWED[cmd] || Command::MAYBE_REPO_ALLOWED[cmd]
78
+ raise
79
+ end
80
+ end
81
+
82
+ if cmd_opts[:repository].respond_to? :config
83
+ cmd_opts[:repository].config && local_config = cmd_opts[:repository].config
84
+ end
85
+
86
+ workflow = local_config["amp"]["workflow"]
87
+
88
+ if File.exists?(File.expand_path(File.join(File.dirname(__FILE__), "commands/workflows/#{workflow}/")))
89
+ require_dir { "amp/commands/commands/workflows/#{workflow}/**/*.rb" }
90
+ end
91
+
92
+ user_amprc = File.expand_path("~/.amprc")
93
+ File.exist?(user_amprc) && load(user_amprc)
94
+
95
+ path_to_ampfile = find_ampfile
96
+ load path_to_ampfile if path_to_ampfile
97
+
98
+ command = pick_command cmd, local_config
99
+
100
+ unless command
101
+ puts "Invalid command! #{cmd}"
102
+ exit(-1)
103
+ end
104
+
105
+ # get the sub-command's options
106
+ # if there's a conflict, check to see that the newest value isn't nil
107
+ cmd_opts.merge!(command.collect_options) {|k, v1, v2| v2 || v1 }
108
+
109
+ cmd_opts[:global_config] = local_config
110
+ if global_opts[:debug_opts]
111
+ require 'yaml'
112
+ puts "Current directory: #{Dir.pwd}"
113
+ puts "Global options: \n#{global_opts.inspect.to_yaml}"
114
+ puts "Subcommand: #{cmd.inspect}"
115
+ puts "Subcommand options: \n#{cmd_opts.to_yaml}"
116
+ puts "Remaining arguments: #{ARGV.inspect}"
117
+ puts "\n"
118
+ puts "Parsed and merged global config files:"
119
+ puts local_config.config.to_s
120
+ puts
121
+ end
122
+
123
+ # Run that fucker!!!
124
+ begin
125
+ full_backtrace_please do
126
+ command.run cmd_opts, ARGV
127
+ end
128
+ rescue AbortError => e
129
+ puts e.to_s
130
+ end
131
+
132
+ #Amp::Support::Logger.outdent.info("</#{command.name}>")
133
+ end
134
+
135
+ ##
136
+ # Gets the path to the Ampfile if there is one.
137
+ #
138
+ # @return [String] the path to an Ampfile
139
+ def self.find_ampfile(dir=Dir.pwd)
140
+ rock_bottom = false
141
+ begin
142
+ rock_bottom = true if dir == "/"
143
+ ["ampfile","Ampfile","ampfile.rb","Ampfile.rb"].each do |pos|
144
+ file = File.join(dir, pos)
145
+ return file if File.exist? file
146
+ end
147
+ dir = File.dirname(dir)
148
+ end until rock_bottom
149
+ end
150
+
151
+ ##
152
+ # Picks a command from the list of all possible commands, based on a couple
153
+ # simple rules.
154
+ #
155
+ # 1. Look up the command by exact name. If no command is provided, supply "default".
156
+ # 2. Check for "synonyms" - "remove" is synonym'd as "rm". This check occurs inside
157
+ # the call to Amp::Command[].
158
+ # 3. Check to see if there is only 1 command with our "cmd" as the prefix. For example,
159
+ # if the user inputs "amp stat", and only one command starts with "stat" (ie "status"),
160
+ # then return that command. If there is more than 1 match, then exit, showing an error
161
+ # due to the ambiguity.
162
+ #
163
+ # @param [String] cmd the command to look up
164
+ # @return [Amp::Command] the command object that was found, or nil if none was found.
165
+ def self.pick_command(cmd, config)
166
+ my_flow = config["amp"]["workflow"]
167
+ if c = Amp::Command.all_for_workflow(my_flow).keys.map {|k| k.to_s}.abbrev[cmd]
168
+ Amp::Command.command_for_workflow(c, my_flow)
169
+ else
170
+ prefix_list = Amp::Command.all_for_workflow(my_flow).keys.map {|k| k.to_s}.select {|k| k.start_with? cmd.to_s }
171
+
172
+ if prefix_list.size > 1
173
+ puts "Ambiguous command: #{cmd}. Could mean: #{prefix_list.join(", ")}"
174
+ exit(-1)
175
+ end
176
+ nil
177
+ end
178
+ end
179
+
180
+ end
181
+ end
@@ -0,0 +1,81 @@
1
+ module Amp
2
+
3
+ ##
4
+ # = Hook
5
+ # The hook class allows the end-user to easily provide hooks into the code that
6
+ # makes Amp go. For example, one might want to easily hook into the commit command,
7
+ # and send an e-mail out to your team after every commit. You could use the Hook class,
8
+ # as well as the Kernel-level "hook" method, to do this.
9
+ #
10
+ # Hooks are global, currently - they cannot only be applied to one repo at a time.
11
+ class Hook
12
+ @@all_hooks = Hash.new {|h, k| h[k] = []}
13
+ def self.all_hooks; @@all_hooks; end
14
+
15
+ class << self
16
+
17
+ raise "hell" if defined? DEFAULTS
18
+ DEFAULTS = {:throw => false}
19
+
20
+ ##
21
+ # Call the hooks that run under +call+
22
+ #
23
+ # @param [Symbol] call the location in the system where the hooks
24
+ # are to be called
25
+ # @param [Hash] opts the options to pass to the hook
26
+ def run_hook(call, opts={})
27
+ opts = DEFAULTS.merge opts
28
+ all_hooks[call].each {|hook| hook[opts] }
29
+ end
30
+ end
31
+
32
+ ##
33
+ # The call symbol this hook is associated with
34
+ attr_accessor :name
35
+
36
+ ##
37
+ # The block to be executed when the hook is called
38
+ attr_accessor :block
39
+
40
+ ##
41
+ # Registers a hook with the system. A hook is simply a proc that takes some
42
+ # options. The hook has a name, which specifies which action it is hooking into.
43
+ # Some hooks include:
44
+ # :outgoing
45
+ # :prechangegroup
46
+ # :changegroup
47
+ #
48
+ # @param [Symbol] hook_type the type of hook
49
+ # @yield the given block is the action to take when the hook is executed
50
+ # @yieldparam opts the options that are passed to the hook. See hook.rb for details
51
+ # on all possible hooks and their passed-in options.
52
+ def initialize(name, &block)
53
+ @name = name
54
+ @block = block
55
+ @@all_hooks[name] << self
56
+ end
57
+
58
+ ##
59
+ # Runs the hook.
60
+ #
61
+ # @param [Hash] opts the options to pass to the hook.
62
+ def call(opts)
63
+ @block.call(opts)
64
+ end
65
+ alias_method :run, :call
66
+ alias_method :[], :call
67
+ end
68
+ end
69
+
70
+ module Kernel
71
+
72
+ ##
73
+ # Adds a hook to each of the provided hook entry points.
74
+ # Requires a block.
75
+ #
76
+ # @param [Symbol] names the hook entry points for which to add the block as a hook
77
+ # @yield The block provided is the code that will be run as a hook at a later time.
78
+ def hook(names, &block)
79
+ Amp::Hook.new(names, &block)
80
+ end
81
+ end