amp-pure 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 +116 -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 +382 -0
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'yard'
3
+
4
+ YARD::Registry.load
5
+
6
+ module Docable
7
+
8
+ def tag_callbacks; @tag_callbacks ||= {}; end
9
+
10
+ def tag_callback(name, &block)
11
+ tag_callbacks[name] = block
12
+ end
13
+
14
+ def docs_for(method)
15
+ klass = YARD::Registry.all(:class).detect do |k|
16
+ k.name == name.split("::").last.to_sym
17
+ end
18
+
19
+ meth = klass.meths.detect {|m| m.name == method }
20
+
21
+ puts "=== Documentation for #{self}##{method}"
22
+ puts meth.docstring
23
+ puts "---"
24
+ puts meth.signature
25
+ puts
26
+
27
+ tag_callbacks.to_a.sort.each do |(tag, block)|
28
+ if meth.has_tag? tag
29
+ puts
30
+ tags = meth.tags.select {|t| t.tag_name == tag.to_s }
31
+ block.call meth, tags
32
+ puts
33
+ end
34
+ end
35
+
36
+ puts "It can be found at #{meth.file}:#{meth.line}"
37
+ puts "==="
38
+ end
39
+ end
40
+
41
+ class Object
42
+ extend Docable
43
+
44
+ tag_callback :param do |meth, tags|
45
+ puts "Arguments are:"
46
+ tags.each do |p|
47
+ puts "\t[#{p.types.join ', '}] #{p.name} #{"|" if p.text } #{p.text}"
48
+ end
49
+ end
50
+
51
+ tag_callback :tags do |meth, tags|
52
+ puts "Tagged with: #{tags.map {|t| t.tags }.join ', '}"
53
+ end
54
+ end
@@ -0,0 +1,78 @@
1
+ ##
2
+ # Stolen/heavily modified from
3
+ # http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/140603
4
+ # Thanks man
5
+
6
+ ##
7
+ # Example generator. Note that we put +nil+ at the end to indicate the end of generation.
8
+ # class Fibonacci < Generator
9
+ # def generator_loop
10
+ # previous, current=0,1
11
+ # 10.times do
12
+ #
13
+ # # works
14
+ # yield_gen current
15
+ # previous, current = current, previous + current
16
+ # end
17
+ # nil
18
+ # end
19
+ # end
20
+
21
+ ##
22
+ # Generic generator. woo. Implement +generator_loop+ to make a concrete subclass.
23
+ #
24
+ # Allows you to create an object that lazily generates values and yields them
25
+ # when the next() method is called.
26
+ class Generator
27
+
28
+ ##
29
+ # Generic initializer for a Generator. If you subclass, you must caller super
30
+ # to initialize the continuation ivars.
31
+ def initialize
32
+ @current_context = nil
33
+ reset
34
+ end
35
+
36
+ ##
37
+ # Runs the next iteration of the generator. Uses continuations to jump across
38
+ # the stack all willy-nilly like.
39
+ #
40
+ # @return [Object] the next generated object.
41
+ def next
42
+ # by setting @current_context to +here+, when @current_context is called, next() will
43
+ # return to its caller.
44
+ callcc do |here|
45
+ @current_context = here
46
+ if @yield_context
47
+ # Run next iteration of the running loop
48
+ @yield_context.call
49
+ else
50
+ # Start the loop
51
+ generator_loop
52
+ end
53
+ end
54
+ end
55
+
56
+ ##
57
+ # Resets the generator from the beginning
58
+ def reset
59
+ @yield_context = nil
60
+ end
61
+
62
+ private
63
+
64
+ ##
65
+ # Yields a value from within the generator_loop method to the caller of +next+.
66
+ # This method actually is what returns a value from a call to next through the
67
+ # roundabout nature of continuations.
68
+ #
69
+ # @param value the value to return from +next+
70
+ def yield_gen(value)
71
+ callcc do |cont|
72
+ @yield_context = cont
73
+ @current_context.call value # causes next() to immediately return +value+
74
+ end
75
+ end
76
+
77
+ end
78
+
@@ -0,0 +1,144 @@
1
+ module Amp
2
+ module Ignore
3
+ extend self
4
+
5
+ COMMENT = /((^|[^\\])(\\\\)*)#.*/
6
+ SYNTAXES = {'re' => :regexp, 'regexp' => :regexp, 'glob' => :glob,
7
+ 'relglob' => :relglob, 'relre' => :regexp, 'path' => :glob,
8
+ 'relpath' => :relglob}
9
+ ##
10
+ # Parses the ignore file, +file+ (or ".hgignore")
11
+ #
12
+ # @param [String] root the root of the repo
13
+ # @param [Array<String>] files absolute paths to files
14
+ def parse_ignore(root, files=[])
15
+ patterns = {} # not sure what this is
16
+
17
+ files.each do |file|
18
+ syntax = 're' # default syntax
19
+ text = File.read File.join(root,file) rescue next
20
+ pattern = matcher_for_text text
21
+ patterns[file] = pattern if pattern
22
+ end # files.each
23
+
24
+ all_patterns = patterns.values.flatten
25
+ # let the system know that nothing is ignored
26
+ return proc { false } if all_patterns.empty?
27
+ # here's the proc to do the tests
28
+ regexps_to_proc all_patterns
29
+ end
30
+
31
+ ##
32
+ # Parse the lines into valid syntax
33
+ #
34
+ # @param [String] file and open file
35
+ def parse_lines(text)
36
+ lines = text.split("\n").map do |line|
37
+ if line =~ /#/
38
+ line.sub! COMMENT, "\\1"
39
+ line.gsub! "\\#", "#"
40
+ end
41
+
42
+ line.rstrip!
43
+ line.empty? ? nil : line
44
+ end
45
+ lines.compact
46
+ end
47
+
48
+ ##
49
+ # Produces an array of regexps which can be used
50
+ # for matching files
51
+ #
52
+ # @param [String] text the text to parse
53
+ # @return [[Regexp]] the regexps generated from the strings and syntaxes
54
+ def matcher_for_text(text)
55
+ return [] unless text
56
+ syntax = nil
57
+ patterns = parse_lines(text).map do |line|
58
+ next if line.empty?
59
+ # check for syntax changes
60
+ if line =~ /^syntax:/
61
+ syntax = SYNTAXES[line[7..-1].strip] || :regexp
62
+ next # move on
63
+ end
64
+ parse_line syntax, line # could be nil, so we need to compact it
65
+ end # parsed_lines(text)
66
+ patterns.compact # kill the nils
67
+ end
68
+
69
+ ##
70
+ # Much like matcher_for_text, except tailored to single line strings
71
+ #
72
+ # @see matcher_for_text
73
+ # @param [String] string the string to parse
74
+ # @return [Regexp] the regexps generated from the strings and syntaxes
75
+ def matcher_for_string(string)
76
+ scanpt = string =~ /(\w+):(.+)/
77
+ if scanpt.nil?
78
+ # just a line, no specified syntax
79
+ syntax = 'regexp'
80
+ # no syntax, the whole thing is a pattern
81
+ include_regexp = string
82
+ else
83
+ syntax = $1 # the syntax is the first match
84
+ include_regexp = $2.strip # the rest of the string is the pattern
85
+ end
86
+ include_syntax = syntax.to_sym
87
+ parse_line include_syntax, include_regexp
88
+ end
89
+
90
+ ##
91
+ # Turns a single line, given a syntax, into either
92
+ # a valid regexp or nil. If it is nil, it means the
93
+ # syntax was incorrect.
94
+ #
95
+ # @param [Symbol] syntax the syntax to parse with (:regexp, :glob, :relglob)
96
+ # @param [String] line the line to parse
97
+ # @return [NilClass, Regexp] nil means the syntax was a bad choice
98
+ def parse_line(syntax, line)
99
+ return nil unless syntax
100
+
101
+ # find more valid syntax stuff
102
+ # we need to make everything here valid regexps
103
+ case syntax.to_sym
104
+ when :regexp
105
+ # basic regex
106
+ pattern = /#{line}/
107
+ when :glob, :relglob
108
+ # glob: glob (shell style), relative to the root of the repository
109
+ # relglob: glob, except we just match somewhere in the string, not from the root of
110
+ # the repository
111
+ ps = line.split '/**/'
112
+ ps.map! do |l|
113
+ parts = l.split '*' # split it up and we'll escape all the parts
114
+ parts.map! {|p| Regexp.escape p }
115
+ /#{parts.join '[^/]*'}/ # anything but a slash, ie, no change in directories
116
+ end
117
+ joined = ps.join '/(?:.*/)*'
118
+ pattern = (syntax.to_sym == :glob) ? /^#{joined}/ : /#{joined}/
119
+ else
120
+ pattern = nil
121
+ end
122
+
123
+ pattern
124
+ end
125
+
126
+ ##
127
+ # Converts all the ignored regexps into a proc that matches against all of these
128
+ # regexps. That way we can pass around a single proc that checks if a file is ignored.
129
+ #
130
+ # @param [Array<Regexp>] regexps all of the regexes that we need to match against
131
+ # @return [Proc] a proc that, when called with a file's path, will return whether
132
+ # it matches any of the regexps.
133
+ def regexps_to_proc(*regexps)
134
+ regexps = regexps.flatten.compact # needed because of possible nils
135
+ if regexps.empty?
136
+ proc { false }
137
+ else
138
+ proc { |file| regexps.any? {|p| file =~ p } }
139
+ end
140
+ end
141
+ alias_method :regexp_to_proc, :regexps_to_proc
142
+
143
+ end
144
+ end
@@ -0,0 +1,93 @@
1
+ # taken straight from the need gem!
2
+ # need takes a block which should contain a string of the relative path to the file
3
+ # you wish to need.
4
+ $times = []
5
+
6
+ ##
7
+ # Loads a given file, relative to the directory of the file executing the need statement.
8
+ #
9
+ # @example need { "silly.rb" }
10
+ # @example need("silly.rb")
11
+ # @param [String] file the file to load
12
+ def need(file=nil, &block)
13
+ # do some timing if we're still benchmarking
14
+ s = Time.now if ENV["TESTING"] == "true"
15
+
16
+ if block_given?
17
+ if RUBY_VERSION < "1.9" && (!defined?(RUBY_ENGINE) || RUBY_ENGINE != 'rbx')
18
+ require File.expand_path(File.join(File.dirname(eval("__FILE__", block.binding)),block.call)) # 1.9 hack
19
+ else
20
+ require File.expand_path(File.join(File.dirname(caller_file(0)),block.call))
21
+ end
22
+ elsif file
23
+ require File.expand_path(File.join(File.dirname(__FILE__),file))
24
+ end
25
+ # do some timing if we're still benchmarking
26
+ $times << [Time.now - s, block ? block.call : file] if ENV["TESTING"] == "true"
27
+ end
28
+
29
+ ##
30
+ # Loads an entire directory, relative to the caller's file
31
+ #
32
+ # @example require_dir { "commands/**/*.rb" }
33
+ # @param [String] dir the directory, in glob format, to load
34
+ # @yield returns the string of the directory
35
+ def require_dir(dir=nil, &block)
36
+ # do some timing if we're still benchmarking
37
+ s = Time.now if ENV["TESTING"] == "true"
38
+
39
+ if block_given?
40
+ Dir[File.join(Amp::CODE_ROOT, block.call)].each do |f|
41
+ unless File.directory? f
42
+ f = f[Amp::CODE_ROOT.size+1..-1]
43
+ require f
44
+ end
45
+ end
46
+ else
47
+ Dir[dir].each {|f| require f unless File.directory? f }
48
+ end
49
+
50
+ # do some timing if we're still benchmarking
51
+ $times << [Time.now - s, block ? block.call : file] if ENV["TESTING"] == "true"
52
+ end
53
+
54
+ ##
55
+ # Finds the caller's file path. +level+ specifies how far down the call stack to look.
56
+ #
57
+ # @param [Fixnum] level the point in the call stack to look - 0 = top, 1 = caller, etc.
58
+ # @return [String, NilClass] the path to the caller function's file.
59
+ def caller_file(level=0)
60
+ if caller[level] # call stack big enough?
61
+ if RUBY_VERSION < "1.9" # this is for 1.8
62
+ File.expand_path(caller[level].split(":").first)
63
+ else
64
+ File.expand_path(caller[level+1].split(":").first)
65
+ end
66
+ end # returns nil by default
67
+ end
68
+ private :caller_file
69
+
70
+ ##
71
+ # Loads a C extension, or an alternate file if the C cannot be loaded for any reason
72
+ # (such as the user not compiling it).
73
+ #
74
+ # @param [String] path_to_c the path to the C library. Will be loaded relative to
75
+ # the caller's file.
76
+ # @param [String] path_to_alt the path to the pure ruby version of the C library. Will
77
+ # be loaded relative to the caller's file
78
+ def amp_c_extension(path_to_c, path_to_alt)
79
+
80
+ if $USE_RUBY
81
+ Amp::UI.debug "Loading alternative ruby: #{path_to_alt}"
82
+ require File.join(File.dirname(caller_file(1)), path_to_alt)
83
+ return
84
+ end
85
+
86
+ begin
87
+ offset = RUBY_VERSION < "1.9" ? 1 : 0
88
+ require File.expand_path(File.join(File.dirname(caller_file(offset)), path_to_c))
89
+ rescue LoadError # C Version could not be found, try ruby version
90
+ Amp::UI.debug "Loading alternative ruby: #{path_to_alt}"
91
+ require File.join(File.dirname(caller_file(1)), path_to_alt)
92
+ end
93
+ end
@@ -0,0 +1,103 @@
1
+ require 'delegate'
2
+ require 'logger'
3
+ module Amp
4
+ module Support
5
+ module SingletonLogger
6
+ attr_accessor :singleton_object
7
+ def global_logger
8
+ singleton_object
9
+ end
10
+
11
+ def warn(*args); global_logger.warn(*args); end
12
+ def info(*args); global_logger.info(*args); end
13
+ def fatal(*args); global_logger.fatal(*args); end
14
+ def error(*args); global_logger.error(*args); end
15
+ def debug(*args); global_logger.debug(*args); end
16
+
17
+ def method_missing(meth, *args, &block)
18
+ if global_logger.respond_to?(meth)
19
+ global_logger.__send__(meth, *args, &block)
20
+ else
21
+ super
22
+ end
23
+ end
24
+ end
25
+
26
+ class IOForwarder
27
+ def initialize(output)
28
+ @output = output
29
+ end
30
+
31
+ def warn(input); @output.puts(input); end
32
+ def info(input); @output.puts(input); end
33
+ def fatal(input); @output.puts(input); end
34
+ def error(input); @output.puts(input); end
35
+ def debug(input); @output.puts(input); end
36
+ end
37
+
38
+ class Logger < DelegateClass(::Logger)
39
+ extend SingletonLogger
40
+
41
+ def initialize(output)
42
+ @show_times = true
43
+ @output = output
44
+ @source = ::Logger.new(output)
45
+ @indent = 0
46
+ super(@source)
47
+ self.class.singleton_object = self
48
+ end
49
+
50
+ def show_times=(bool)
51
+ if @show_times && !bool # turn off times
52
+ @normal_source = @source
53
+ @source = IOForwarder.new(@output)
54
+ elsif !@show_times && bool # turn it back on
55
+ @source = @normal_source
56
+ end
57
+ end
58
+
59
+ def section(section_name)
60
+ info("<#{section_name}>").indent
61
+ yield
62
+ outdent.info("</#{section_name}>")
63
+ end
64
+
65
+ def indent
66
+ @indent += 1
67
+ self
68
+ end
69
+
70
+ def outdent
71
+ @indent -= 1
72
+ self
73
+ end
74
+
75
+ def warn(input); @source.warn( "\t\t"*@indent + input); self; end
76
+ def info(input); @source.info( "\t\t"*@indent + input); self; end
77
+ def fatal(input); @source.fatal("\t\t"*@indent + input); self; end
78
+ def error(input); @source.error("\t\t"*@indent + input); self; end
79
+ def debug(input); @source.debug("\t\t"*@indent + input); self; end
80
+
81
+
82
+ def level=(level)
83
+ receiver = @source
84
+ case level
85
+ when :warn
86
+ receiver.level = ::Logger::WARN
87
+ when :fatal
88
+ receiver.level = ::Logger::FATAL
89
+ when :error
90
+ receiver.level = ::Logger::ERROR
91
+ when :info
92
+ receiver.level = ::Logger::INFO
93
+ when :debug
94
+ receiver.level = ::Logger::DEBUG
95
+ when :none
96
+ receiver.level = ::Logger::UNKNOWN
97
+ else
98
+ receiver.level = level
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end