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,7 @@
1
+ command :version do |c|
2
+ c.desc "Prints the current version of Amp."
3
+ c.workflow :all
4
+ c.on_run do |options, args|
5
+ puts "Amp version #{Amp::VERSION} (#{Amp::VERSION_TITLE})"
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ command :workflow do |c|
2
+ c.workflow :all
3
+ c.maybe_repo
4
+
5
+ c.desc "Sets the workflow amp uses for commands"
6
+ c.opt :local, "Sets the workflow locally, instead of globally", :short => "-l"
7
+
8
+ c.before do |opts, args|
9
+ if args.size < 1
10
+ puts "Usage: amp workflow workflow_name"
11
+ c.break
12
+ end
13
+
14
+ true
15
+ end
16
+
17
+ c.on_run do |opts, args|
18
+ config = opts[:global_config]
19
+ unless opts[:local]
20
+ while config.parent_config
21
+ config = config.parent_config
22
+ end
23
+ end
24
+
25
+ config["amp"]["workflow"] = args.shift
26
+ config.save!
27
+ end
28
+ end
@@ -0,0 +1,65 @@
1
+ command :add do |c|
2
+ c.workflow :git
3
+ c.desc "Add a file to the repository (it will be tracked from here on)"
4
+ c.opt :all, "Adds all untracked files to the repository", :short => "-a"
5
+ c.opt :force, "Forces addition of ignored files", :short => "-f"
6
+ c.opt :"dry-run", "Doesn't actually add files - just shows output", :short => "-n"
7
+ c.opt :verbose, "Verbose output", :short => "-v"
8
+ c.help <<-HELP
9
+ amp add [-n] [--force | -f] [--interactive | -i] [--patch | -p]
10
+ [--all | [--update | -u]] [--refresh] [--ignore-errors] [--]
11
+ <filepattern>...
12
+
13
+ add the specified files on the next commit
14
+ This command:
15
+
16
+ * Schedules files to be version controlled and added to the repository.
17
+
18
+ * If an ignored file is explicitly named to be added, then the command will
19
+ abort. If an ignored file is added with a pattern, then they will be ignored silently.
20
+
21
+ * The files will be added to the repository at the next commit. To
22
+ undo an add before that, see [amp revert].
23
+
24
+ * See the help for `git add` to see how this differs from the Mercurial implementation.
25
+
26
+ HELP
27
+
28
+ c.on_run do |opts, args|
29
+ repo = opts[:repository]
30
+ working_changeset = repo[nil]
31
+
32
+ files = args.reject {|p| p.include?("*") }
33
+ patterns = args.select {|p| p.include?("*") }
34
+
35
+ if opts[:all]
36
+ matcher = Amp::Match.create(:files => []) { |file| !repo.dirstate.include?(file) }
37
+ else
38
+ matcher = Amp::Match.create(:files => files, :includer => (["syntax: glob"] + patterns)) { false }
39
+ end
40
+
41
+ names = []
42
+ exact = {}
43
+ working_changeset.walk(matcher, true).each do |file, _|
44
+ if matcher.exact? file
45
+ if repo.dirstate.ignore(file) && !opts[:force]
46
+ raise abort("Can't add the ignored file #{file}. Use --force to override")
47
+ end
48
+ Amp::UI.status "adding #{file.relative_path repo.root}" if opts[:verbose]
49
+ names << file
50
+ exact[file] = true
51
+ elsif !repo.dirstate.include?(file) && (!repo.dirstate.ignore(file) || opts[:force])
52
+ Amp::UI.status "adding #{file.relative_path repo.root}"
53
+ names << file
54
+ end
55
+ end
56
+
57
+ rejected = repo.add names unless opts[:"dry-run"]
58
+
59
+ if names.size == 1
60
+ Amp::UI.say "File #{names.first.blue} has been added at #{Time.now}"
61
+ else
62
+ Amp::UI.say "#{names.size.to_s.blue} files have been added at #{Time.now}"
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,27 @@
1
+ command :copy do |c|
2
+ c.workflow :git
3
+ c.desc "Copies a file from one location to another, while maintaining history"
4
+ c.opt :force, "Forces the copy, ignoring overwrites", :short => "-f"
5
+ c.opt :"dry-run", "Doesn't actually move files - only prints what would happen", :short => "-n"
6
+ c.synonym :cp
7
+ c.before do |opts, args|
8
+ if args.size < 2
9
+ Amp::UI.say "Usage: amp copy source [other-sources...] destination"
10
+ c.break
11
+ elsif args.size > 2 && !File.directory?(args.last)
12
+ Amp::UI.say "If you want to copy more than 1 file, your destination must" +
13
+ " be a directory."
14
+ c.break
15
+ end
16
+ end
17
+
18
+ c.on_run do |opts, args|
19
+ repo = opts[:repository]
20
+
21
+ sources = args[0..-2]
22
+ destination = args.last
23
+ sources.each do |source|
24
+ repo.copy(source, destination, opts)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ command :mv do |c|
2
+ c.workflow :git
3
+ c.desc "Moves a file from one place to another"
4
+
5
+ c.opt :force, "Forces the move, ignoring overwrites", :short => "-f"
6
+ c.opt :"dry-run", "Doesn't actually move files - only prints what would happen", :short => "-n"
7
+
8
+ c.before do |opts, args|
9
+ if args.size < 2
10
+ Amp::UI.say "Usage: amp move source destination"
11
+ c.break
12
+ elsif args.size > 2 && !File.directory?(args.last)
13
+ Amp::UI.say "If you want to move more than 1 file, your destination must" +
14
+ " be a directory."
15
+ c.break
16
+ end
17
+ end
18
+
19
+ c.on_run do |opts, args|
20
+ opts.merge!(:rename => true)
21
+ Amp::Command["copy"].run(opts, args)
22
+ end
23
+ end
@@ -0,0 +1,60 @@
1
+ command :rm do |c|
2
+ c.workflow :git
3
+ c.desc "Removes files from the repository on next commit"
4
+ c.opt :force, "Forces removal of files", :short => "-f", :default => false
5
+ c.opt :quiet, "Doesn't print which files are removed", :short => "-q"
6
+ c.opt :"dry-run", "Doesn't actually remove files - just prints output", :short => "-n"
7
+ c.opt :cached, "Removes the file only from the index (doesn't unlink file)"
8
+ c.opt :recursive, "Recursively remove named directories", :short => "-r"
9
+ c.on_run do |opts, args|
10
+ repo = opts[:repository]
11
+ working_changeset = repo[nil]
12
+
13
+ args = args.map {|p| repo.relative_join(p) }
14
+ files = args.reject {|p| p.include?("*") }
15
+ patterns = args.select {|p| p.include?("*") }
16
+ #
17
+ # files.select {|f| File.directory?(repo.working_join(f))}.each do |folder|
18
+ # patterns +=
19
+
20
+ match = Amp::Match.create(:files => files, :includer => (["syntax: glob"] + patterns)) { false }
21
+
22
+ s = repo.status :match => match, :clean => true
23
+ modified, added, deleted, clean = s[:modified], s[:added], s[:deleted], s[:clean]
24
+
25
+ remove, forget = [], []
26
+
27
+ remove += clean
28
+ remove += deleted
29
+ remove += modified if opts[:force]
30
+
31
+ if opts[:cached]
32
+ forget += added
33
+ elsif opts[:force]
34
+ remove += added
35
+ end
36
+
37
+ unless opts[:force]
38
+ modified.each {|p| Amp::UI.warn "not removing #{p} - file is modified (use --force)" }
39
+ end
40
+
41
+ unless opts[:cached] || opts[:force]
42
+ added.each {|p| Amp::UI.warn "not removing #{p} - file is marked for add (use --cached)" }
43
+ end
44
+
45
+ unless opts[:quiet]
46
+ (remove + forget).sort.each {|f| Amp::UI.say "removing #{f}" }
47
+ end
48
+
49
+ repo.remove remove, :unlink => ! opts[:after] unless opts[:"dry-run"] # forgetting occurs here
50
+ repo.forget forget unless opts[:"dry-run"]
51
+
52
+ remove += forget
53
+ #
54
+ # if remove.size == 1
55
+ # Amp::UI.say "File #{remove.first.red} removed at #{Time.now}"
56
+ # else
57
+ # Amp::UI.say "#{remove.size.to_s.red} files removed at #{Time.now}"
58
+ # end
59
+ end
60
+ end
@@ -0,0 +1,53 @@
1
+ command :add do |c|
2
+ c.workflow :hg
3
+
4
+ c.desc "Add a file to the repository (it will be tracked from here on)"
5
+ c.opt :include, "include names matching the given patterns", :short => "-I", :type => :string
6
+ c.opt :exclude, "exclude names matching the given patterns", :short => "-X", :type => :string
7
+ c.opt :"dry-run", "Doesn't actually add files - just shows output", :short => "-n"
8
+ c.help <<-HELP
9
+ amp add [FILE]+ [options]
10
+
11
+ add the specified files on the next commit
12
+ This command:
13
+
14
+ * Schedules files to be version controlled and added to the repository.
15
+
16
+ * The files will be added to the repository at the next commit. To
17
+ undo an add before that, see [amp revert].
18
+
19
+ If no names are given, all files are added to the repository.
20
+
21
+ Where options are:
22
+ HELP
23
+
24
+ c.on_run do |opts, args|
25
+ repo = opts[:repository]
26
+ list = args.map {|p| repo.relative_join(p) }
27
+
28
+ matcher = Amp::Match.create :files => list,
29
+ :includer => opts[:include],
30
+ :excluder => opts[:exclude]
31
+ names = []
32
+ exact = {}
33
+ repo.walk(nil, matcher).each do |file, _|
34
+ if matcher.exact? file
35
+ Amp::UI.status "adding #{file.relative_path repo.root}" if opts[:verbose]
36
+ names << file
37
+ exact[file] = true
38
+ elsif not repo.dirstate.include? file
39
+ Amp::UI.status "adding #{file.relative_path repo.root}"
40
+ names << file
41
+ end
42
+ end
43
+
44
+ rejected = repo.add names unless opts[:"dry-run"]
45
+
46
+
47
+ if names.size == 1
48
+ Amp::UI.say "File #{names.first.blue} has been added at #{Time.now}"
49
+ else
50
+ Amp::UI.say "#{names.size.to_s.blue} files have been added at #{Time.now}"
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,86 @@
1
+ ##
2
+ # This command will go through your repository's working directory, and if it
3
+ # discovers any files that it was tracking, but have mysteriously disappeared,
4
+ # the command will assume you meant to remove it (stop tracking it), and remove it
5
+ # for you. Similarly, if you have any files that are untracked and have appeared
6
+ # in your repository, and they aren't ignored by your .hgignore file, then we
7
+ # assume you wanted to add them, and add them for you.
8
+ #
9
+ # The only significant difference between this command and Mercurial's implementation
10
+ # is the addition of the interactive mode. This mode asks the user before each removal
11
+ # and addition. Personally, I added it because I don't like blanket actions taken across
12
+ # my entire repository. It's off by default.
13
+ command :addremove do |c|
14
+ c.workflow :hg
15
+
16
+ c.desc "Add all new files, delete all missing files"
17
+ c.opt :interactive, "Asks about each file before adding/removing", :default => false, :short => "-a"
18
+ c.opt :include, "include names matching the given patterns", :type => :string, :short => "-I"
19
+ c.opt :exclude, "exclude names matching the given patterns", :type => :string, :short => "-E"
20
+ c.opt :"dry-run", "Don't perform actions, just print output", :short => "-n"
21
+ c.help <<-EOS
22
+ amp addremove [options]+
23
+
24
+ New files are ignored if they match any of the patterns in .hgignore. As
25
+ with add, these changes take effect at the next commit.
26
+
27
+ Use the -s option to detect renamed files. With a parameter > 0,
28
+ this compares every removed file with every added file and records
29
+ those similar enough as renames. This option takes a percentage
30
+ between 0 (disabled) and 100 (files must be identical) as its
31
+ parameter. Detecting renamed files this way can be expensive.
32
+
33
+ Where options are:
34
+ EOS
35
+
36
+ c.on_run do |opts, args|
37
+ repo = opts[:repository]
38
+
39
+ # Standard preparation for mercurial-style matching. We need a match object.
40
+ # If a file is missed by our matcher, assume we want it included (unknown files match
41
+ # this situation)
42
+ matcher = Amp::Match.create(:includer => opts[:include], :excluder => opts[:exclude]) { true }
43
+ # Get only the deleted and unknown files. We'll remove the former and add the latter.
44
+ results = repo.status(:match => matcher, :deleted => true, :added => false, :unknown => true,
45
+ :ignored => false, :modified => false, :clean => false)
46
+
47
+ Amp::UI.say
48
+ # Prettified, add check later if user disables colors
49
+ Amp::UI.say "ADDING FILES".blue if results[:unknown].any?
50
+ # Handle adding the files now
51
+ if opts[:interactive]
52
+ # Interactive means we ask the user if they want to add the file or not.
53
+ # Build a list based on what they agree upon, then add that list
54
+ to_add = []
55
+ results[:unknown].each do |file|
56
+ add = Amp::UI.yes_or_no("Add #{file.relative_path(repo.root).blue}? [y/n] ")
57
+ to_add << file if add
58
+ end
59
+ else
60
+ # Otherwise, just let the user know what we're about to add
61
+ results[:unknown].each {|file| Amp::UI.say "Adding #{file.relative_path repo.root}" }
62
+ to_add = results[:unknown]
63
+ end
64
+ repo.add(to_add) unless opts[:"dry-run"]
65
+
66
+ Amp::UI.say
67
+ # Prettified, add check later if user disables colors
68
+ Amp::UI.say "REMOVING FILES".red if results[:deleted].any?
69
+ # Now we remove any files that mysteriously disappeared on us
70
+ if opts[:interactive]
71
+ # Interactive means ask the user if they want to remove a file from the repo or not.
72
+ # Build a list.
73
+ to_del = []
74
+ results[:deleted].each do |file|
75
+ del = Amp::UI.yes_or_no("Remove #{file.relative_path(repo.root).red}?")
76
+ to_del << file if del
77
+ end
78
+ else
79
+ # Otherwise, just inform the user of the damage (yes I'm biased against this command)
80
+ results[:deleted].each {|file| Amp::UI.say "Removing #{file.relative_path repo.root}" }
81
+ to_del = results[:deleted]
82
+ end
83
+ repo.remove to_del unless opts[:"dry-run"]
84
+
85
+ end
86
+ end
@@ -0,0 +1,46 @@
1
+ command :annotate do |c|
2
+ c.workflow :hg
3
+
4
+ c.desc "Shows who committed each line in a given file."
5
+ c.opt :rev, "Which revision to annotate", :short => "-r", :type => :integer, :default => nil
6
+ c.opt :"line-number", "Show line number of first appearance", :short => "-l"
7
+ c.opt :changeset, "Show the changeset ID instead of revision number", :short => "-c"
8
+ c.opt :user, "Shows the user who committed instead of the revision", :short => "-u"
9
+ c.opt :date, "Shows the date when the line was committed", :short => "-d"
10
+ c.synonyms :blame, :praise
11
+
12
+ c.on_run do |opts, args|
13
+ repo = opts[:repository]
14
+
15
+
16
+ args.each do |arg|
17
+ newopts = {:line_numbers => opts[:"line-number"]}
18
+ results = repo.annotate(arg, opts[:rev], newopts)
19
+ revpart = ""
20
+ max_size = 0
21
+ full_results = results.map do |file, line_number, line|
22
+ revpart = ""
23
+ showrev = !([opts[:changeset], opts[:user], opts[:date]].any?)
24
+
25
+ revpart += (opts[:verbose] ? file.changeset.user : file.changeset.user.split("@").first[0..15]) if opts[:user]
26
+ revpart += Time.at(file.changeset.date.first).to_s if opts[:date]
27
+ revpart += " " + file.changeset.node_id.hexlify[0..11] if opts[:changeset]
28
+ revpart += file.change_id.to_s if showrev
29
+
30
+ if line_number
31
+ revpart += ":" + line_number.to_s + ":"
32
+ else
33
+ revpart += ":"
34
+ end
35
+ max_size = revpart.size if revpart.size > max_size
36
+ [revpart, file, line_number, line]
37
+ end
38
+
39
+
40
+ full_results.map! do |revpart, file, line_number, line|
41
+ (revpart).rjust(max_size) + " " + line
42
+ end
43
+ puts full_results.join
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,126 @@
1
+ command :archive do |c|
2
+ c.workflow :hg
3
+ c.desc "Create an unversioned archive of a repository revision"
4
+
5
+ c.opt :"no-decode", "Do not pass files through decoders"
6
+ c.opt :prefix , "Directory prefix for files in archive", :short => '-p', :type => :string
7
+ c.opt :rev , "Revision to distribute", :short => '-r', :type => :integer
8
+ c.opt :type , "Type of distribution to create", :short => '-t', :type => :string
9
+ c.opt :include , "Include names matching the given patterns", :short => '-I', :type => :string
10
+ c.opt :exclude , "Exclude names matching the given patterns", :short => '-X', :type => :string
11
+
12
+ c.help <<-HELP
13
+ amp archive [options]+ dest
14
+
15
+ By default, the revision used is the parent of the working
16
+ directory; use "-r" to specify a different revision.
17
+
18
+ To specify the type of archive to create, use "-t". Valid
19
+ types are:
20
+
21
+ "files" (default): a directory full of files
22
+ "tar": tar archive, uncompressed
23
+ "tbz2": tar archive, compressed using bzip2
24
+ "tgz": tar archive, compressed using gzip
25
+ "uzip": zip archive, uncompressed
26
+ "zip": zip archive, compressed using deflate
27
+
28
+ The exact name of the destination archive or directory is given
29
+ using a format string; see "hg help export" for details.
30
+
31
+ Each member added to an archive file has a directory prefix
32
+ prepended. Use "-p" to specify a format string for the prefix.
33
+ The default is the basename of the archive, with suffixes removed.
34
+
35
+ Where options are:
36
+ HELP
37
+ c.synonyms :export, :x
38
+
39
+ c.on_run do |opts, args|
40
+ repo = opts[:repository]
41
+ rev = opts[:rev]
42
+ changeset = repo[rev]
43
+ dest = args.shift
44
+
45
+ matcher = Amp::Match.create(:includer => opts[:include],
46
+ :excluder => opts[:exclude]) { true }
47
+
48
+
49
+ Amp::UI::tell "created destination \"#{dest}\", now writing files"
50
+
51
+ make_tar_file = lambda do |tar_dest|
52
+ File.open(tar_dest, 'w') do |tarfile|
53
+ Archive::Tar::Minitar::Writer.open(tarfile) do |tar|
54
+ changeset.walk(matcher).each do |file|
55
+ Amp::UI::tell '.' # use dots to keep track
56
+ data = changeset.get_file(file).data
57
+ tar.add_file_simple(File.join(File.amp_split_extension(dest).first,file), :size => data.size, :mode => 0644) { |f| f.write data }
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ case opts[:type]
64
+ when 'files' # a directory full of files
65
+ FileUtils.mkdir_p dest
66
+ Dir.chdir dest
67
+
68
+ changeset.walk(matcher).each do |file|
69
+ Amp::UI::tell '.' # use dots to keep track
70
+ FileUtils.mkdir_p File.dirname(file) # make all the leading dirs
71
+ File.open(file, 'w') {|f| f.write changeset.get_file(file).data } # now write the data
72
+ end
73
+
74
+ when 'tar' # tar archive, uncompressed
75
+ make_tar_file[dest]
76
+ when 'tbz2' # tar archive, compressed using bzip2
77
+ # http://www.nabble.com/how-to-stream-or-write-data-into-a-tar.gz-file-as-if-the-data-were--from-files--td19498643.html
78
+ need { '../../../../../../ext/amp/bz2/bz2' }
79
+
80
+ tar_name = File.amp_split_extension(dest).first + '.tar'
81
+
82
+ make_tar_file[tar_name]
83
+
84
+ File.open(tar_name) do |in_tar|
85
+ BZ2::Writer.open(dest) do |f|
86
+ in_tar.amp_each_chunk { |chunk| Amp::UI::tell 'c'; f.write chunk }
87
+ end
88
+ end
89
+
90
+ File.unlink(tar_name)
91
+ when 'tgz' # tar archive, compressed using gzip
92
+ # http://www.nabble.com/how-to-stream-or-write-data-into-a-tar.gz-file-as-if-the-data-were--from-files--td19498643.html
93
+ require 'zlib'
94
+ tar_name = File.amp_split_extension(dest).first + '.tar'
95
+
96
+ make_tar_file[tar_name]
97
+
98
+ File.open(tar_name) do |in_tar|
99
+ Zlib::GzipWriter.open(dest) do |f|
100
+ in_tar.amp_each_chunk { |chunk| Amp::UI::tell 'c'; f.write chunk }
101
+ end
102
+ end
103
+
104
+ File.unlink(tar_name)
105
+ when 'uzip' # zip archive, uncompressed
106
+ raise "Not Yet Implemented"
107
+ when 'zip' # zip archive, compressed using deflate
108
+
109
+ # Open up the destination
110
+ Zip::ZipFile.open dest, Zip::ZipFile::CREATE do |z|
111
+ # For each file in the revision that matches what we want
112
+ changeset.walk(matcher).each do |f|
113
+ Amp::UI::tell '.' # use dots to keep track
114
+ # create a file-spot for the file in the changeset
115
+ # and write the data to it
116
+ z.get_output_stream(f) {|q| q << changeset.get_file(f).data }
117
+ end
118
+ z.commit
119
+ end
120
+ else
121
+ raise "Unknown compression type: #{opts[:type]}"
122
+ end
123
+
124
+ Amp::UI::say " revision exported!"
125
+ end
126
+ end