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,77 @@
1
+ #!/usr/bin/ruby
2
+ ARGV.collect! {|x| x.sub(/^--with-bz2-prefix=/, "--with-bz2-dir=") }
3
+
4
+ require 'mkmf'
5
+
6
+ if unknown = enable_config("unknown")
7
+ libs = if CONFIG.key?("LIBRUBYARG_STATIC")
8
+ Config::expand(CONFIG["LIBRUBYARG_STATIC"].dup).sub(/^-l/, '')
9
+ else
10
+ Config::expand(CONFIG["LIBRUBYARG"].dup).sub(/^lib([^.]*).*/, '\\1')
11
+ end
12
+ unknown = find_library(libs, "ruby_init",
13
+ Config::expand(CONFIG["archdir"].dup))
14
+ end
15
+
16
+ dir_config('bz2')
17
+ if !have_library('bz2', 'BZ2_bzWriteOpen')
18
+ raise "libz2 not found"
19
+ end
20
+
21
+ if enable_config("shared", true)
22
+ $static = nil
23
+ end
24
+
25
+ create_makefile('bz2')
26
+
27
+ begin
28
+ make = open("Makefile", "a")
29
+ if unknown
30
+ make.print <<-EOF
31
+
32
+ unknown: $(DLLIB)
33
+ \t@echo "main() {}" > /tmp/a.c
34
+ \t$(CC) -static /tmp/a.c $(OBJS) $(CPPFLAGS) $(LIBPATH) $(LIBS) $(LOCAL_LIBS)
35
+ \t@-rm /tmp/a.c a.out
36
+
37
+ EOF
38
+ end
39
+ make.print <<-EOF
40
+
41
+ %.html: %.rd
42
+ \trd2 $< > ${<:%.rd=%.html}
43
+
44
+ EOF
45
+ make.print "HTML = bz2.html"
46
+ docs = Dir['docs/*.rd']
47
+ docs.each {|x| make.print " \\\n\t#{x.sub(/\.rd$/, '.html')}" }
48
+ make.print "\n\nRDOC = docs/bz2.rb"
49
+ make.puts
50
+ make.print <<-EOF
51
+
52
+ rdoc: docs/doc/index.html
53
+
54
+ docs/doc/index.html: $(RDOC)
55
+ \t@-(cd docs; rdoc bz2.rb)
56
+
57
+ ri: docs/bz2.rb
58
+ \t@-(cd docs; rdoc -r bz2.rb)
59
+
60
+ ri-site:
61
+ \t@-(cd docs; rdoc -R bz2.rb)
62
+
63
+ rd2: html
64
+
65
+ html: $(HTML)
66
+
67
+ test: $(DLLIB)
68
+ EOF
69
+ Dir.foreach('../../../test') do |x|
70
+ next if /^\./ =~ x || /(_\.rb|~)$/ =~ x
71
+ next if FileTest.directory?(x)
72
+ make.print "\t-$(RUBY) tests/#{x}\n"
73
+ end
74
+ ensure
75
+ make.close
76
+ end
77
+
@@ -0,0 +1,29 @@
1
+ have_library: checking for BZ2_bzWriteOpen() in -lbz2... -------------------- yes
2
+
3
+ "gcc -o conftest -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0 -I/Users/michaeledgar/mygems/amp/ext/amp/bz2 -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -arch i386 -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common conftest.c -L. -L/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib -L. -arch i386 -arch x86_64 -lruby -lbz2 -lpthread -ldl "
4
+ conftest.c: In function ‘t’:
5
+ conftest.c:3: error: ‘BZ2_bzWriteOpen’ undeclared (first use in this function)
6
+ conftest.c:3: error: (Each undeclared identifier is reported only once
7
+ conftest.c:3: error: for each function it appears in.)
8
+ conftest.c: In function ‘t’:
9
+ conftest.c:3: error: ‘BZ2_bzWriteOpen’ undeclared (first use in this function)
10
+ conftest.c:3: error: (Each undeclared identifier is reported only once
11
+ conftest.c:3: error: for each function it appears in.)
12
+ lipo: can't figure out the architecture type of: /var/folders/zy/zyqc-SWsGjeyuLdp+7qPO++++TI/-Tmp-//cc7a8sUN.out
13
+ checked program was:
14
+ /* begin */
15
+ 1: /*top*/
16
+ 2: int main() { return 0; }
17
+ 3: int t() { void ((*volatile p)()); p = (void ((*)()))BZ2_bzWriteOpen; return 0; }
18
+ /* end */
19
+
20
+ "gcc -o conftest -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0 -I/Users/michaeledgar/mygems/amp/ext/amp/bz2 -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -arch i386 -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common conftest.c -L. -L/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib -L. -arch i386 -arch x86_64 -lruby -lbz2 -lpthread -ldl "
21
+ checked program was:
22
+ /* begin */
23
+ 1: /*top*/
24
+ 2: int main() { return 0; }
25
+ 3: int t() { BZ2_bzWriteOpen(); return 0; }
26
+ /* end */
27
+
28
+ --------------------
29
+
@@ -0,0 +1,5 @@
1
+ require 'mkmf'
2
+ if RUBY_VERSION =~ /1.9/ then
3
+ $CPPFLAGS += " -DRUBY_19"
4
+ end
5
+ create_makefile("MercurialPatch")
@@ -0,0 +1,405 @@
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include "ruby.h"
4
+ #include "rubyio.h"
5
+
6
+ // these defines are taken from the mercurial source. They're relatively standard for
7
+ // byte-swapping, but credit goes where credit's due.
8
+ #ifdef _WIN32
9
+ # ifdef _MSC_VER
10
+ /* msvc 6.0 has problems */
11
+ # define inline __inline
12
+ typedef unsigned long uint32_t;
13
+ typedef unsigned __int64 uint64_t;
14
+ # else
15
+ # include <stdint.h>
16
+ # endif
17
+ static uint32_t ntohl(uint32_t x)
18
+ {
19
+ return ((x & 0x000000ffUL) << 24) |
20
+ ((x & 0x0000ff00UL) << 8) |
21
+ ((x & 0x00ff0000UL) >> 8) |
22
+ ((x & 0xff000000UL) >> 24);
23
+ }
24
+ #else
25
+ /* not windows */
26
+ # include <sys/types.h>
27
+ # if defined __BEOS__ && !defined __HAIKU__
28
+ # include <ByteOrder.h>
29
+ # else
30
+ # include <arpa/inet.h>
31
+ # endif
32
+ # include <inttypes.h>
33
+ #endif
34
+
35
+
36
+ VALUE rb_mAmp, rb_mDiffs, rb_mMercurialPatch;
37
+
38
+
39
+ struct frag {
40
+ uint32_t start, end, len;
41
+ const char *data;
42
+ };
43
+
44
+ struct flist {
45
+ struct frag *base, *head, *tail;
46
+ };
47
+
48
+ static struct flist *lalloc(int size)
49
+ {
50
+ struct flist *a = NULL;
51
+
52
+ if (size < 1)
53
+ size = 1;
54
+
55
+ a = (struct flist *)malloc(sizeof(struct flist));
56
+ if (a) {
57
+ a->base = (struct frag *)malloc(sizeof(struct frag) * size);
58
+ if (a->base) {
59
+ a->head = a->tail = a->base;
60
+ return a;
61
+ }
62
+ free(a);
63
+ a = NULL;
64
+ }
65
+ // if (!PyErr_Occurred())
66
+ // PyErr_NoMemory();
67
+ return NULL;
68
+ }
69
+
70
+ static void lfree(struct flist *a)
71
+ {
72
+ if (a) {
73
+ free(a->base);
74
+ free(a);
75
+ }
76
+ }
77
+
78
+ static int lsize(struct flist *a)
79
+ {
80
+ return a->tail - a->head;
81
+ }
82
+
83
+ /* move hunks in source that are less cut to dest, compensating
84
+ for changes in offset. the last hunk may be split if necessary.
85
+ */
86
+ static int gather(struct flist *dest, struct flist *src, int cut, int offset)
87
+ {
88
+ struct frag *d = dest->tail, *s = src->head;
89
+ int postend, c, l;
90
+
91
+ while (s != src->tail) {
92
+ if (s->start + offset >= cut)
93
+ break; /* we've gone far enough */
94
+
95
+ postend = offset + s->start + s->len;
96
+ if (postend <= cut) {
97
+ /* save this hunk */
98
+ offset += s->start + s->len - s->end;
99
+ *d++ = *s++;
100
+ }
101
+ else {
102
+ /* break up this hunk */
103
+ c = cut - offset;
104
+ if (s->end < c)
105
+ c = s->end;
106
+ l = cut - offset - s->start;
107
+ if (s->len < l)
108
+ l = s->len;
109
+
110
+ offset += s->start + l - c;
111
+
112
+ d->start = s->start;
113
+ d->end = c;
114
+ d->len = l;
115
+ d->data = s->data;
116
+ d++;
117
+ s->start = c;
118
+ s->len = s->len - l;
119
+ s->data = s->data + l;
120
+
121
+ break;
122
+ }
123
+ }
124
+
125
+ dest->tail = d;
126
+ src->head = s;
127
+ return offset;
128
+ }
129
+
130
+ /* like gather, but with no output list */
131
+ static int discard(struct flist *src, int cut, int offset)
132
+ {
133
+ struct frag *s = src->head;
134
+ int postend, c, l;
135
+
136
+ while (s != src->tail) {
137
+ if (s->start + offset >= cut)
138
+ break;
139
+
140
+ postend = offset + s->start + s->len;
141
+ if (postend <= cut) {
142
+ offset += s->start + s->len - s->end;
143
+ s++;
144
+ }
145
+ else {
146
+ c = cut - offset;
147
+ if (s->end < c)
148
+ c = s->end;
149
+ l = cut - offset - s->start;
150
+ if (s->len < l)
151
+ l = s->len;
152
+
153
+ offset += s->start + l - c;
154
+ s->start = c;
155
+ s->len = s->len - l;
156
+ s->data = s->data + l;
157
+
158
+ break;
159
+ }
160
+ }
161
+
162
+ src->head = s;
163
+ return offset;
164
+ }
165
+
166
+ /* combine hunk lists a and b, while adjusting b for offset changes in a/
167
+ this deletes a and b and returns the resultant list. */
168
+ static struct flist *combine(struct flist *a, struct flist *b)
169
+ {
170
+ struct flist *c = NULL;
171
+ struct frag *bh, *ct;
172
+ int offset = 0, post;
173
+
174
+ if (a && b)
175
+ c = lalloc((lsize(a) + lsize(b)) * 2);
176
+
177
+ if (c) {
178
+
179
+ for (bh = b->head; bh != b->tail; bh++) {
180
+ /* save old hunks */
181
+ offset = gather(c, a, bh->start, offset);
182
+
183
+ /* discard replaced hunks */
184
+ post = discard(a, bh->end, offset);
185
+
186
+ /* insert new hunk */
187
+ ct = c->tail;
188
+ ct->start = bh->start - offset;
189
+ ct->end = bh->end - post;
190
+ ct->len = bh->len;
191
+ ct->data = bh->data;
192
+ c->tail++;
193
+ offset = post;
194
+ }
195
+
196
+ /* hold on to tail from a */
197
+ memcpy(c->tail, a->head, sizeof(struct frag) * lsize(a));
198
+ c->tail += lsize(a);
199
+ }
200
+
201
+ lfree(a);
202
+ lfree(b);
203
+ return c;
204
+ }
205
+
206
+ /* decode a binary patch into a hunk list */
207
+ static struct flist *decode(const char *bin, int len)
208
+ {
209
+ struct flist *l;
210
+ struct frag *lt;
211
+ const char *data = bin + 12, *end = bin + len;
212
+ char decode[12]; /* for dealing with alignment issues */
213
+
214
+ /* assume worst case size, we won't have many of these lists */
215
+ l = lalloc(len / 12);
216
+ if (!l)
217
+ return NULL;
218
+
219
+ lt = l->tail;
220
+
221
+ while (data <= end) {
222
+ memcpy(decode, bin, 12);
223
+ lt->start = (uint32_t)ntohl(*(uint32_t *)decode);
224
+ lt->end = (uint32_t)ntohl(*(uint32_t *)(decode + 4));
225
+ lt->len = (uint32_t)ntohl(*(uint32_t *)(decode + 8));
226
+ if (lt->start > lt->end)
227
+ break; /* sanity check */
228
+ bin = data + lt->len;
229
+ if (bin < data)
230
+ break; /* big data + big (bogus) len can wrap around */
231
+ lt->data = data;
232
+ data = bin + 12;
233
+ lt++;
234
+ }
235
+
236
+ if (bin != end) {
237
+ rb_raise(rb_eStandardError, "patch cannot be decoded");
238
+ lfree(l);
239
+ return NULL;
240
+ }
241
+
242
+ l->tail = lt;
243
+ return l;
244
+ }
245
+
246
+ /* calculate the size of resultant text */
247
+ static int calcsize(int len, struct flist *l)
248
+ {
249
+ int outlen = 0, last = 0;
250
+ struct frag *f = l->head;
251
+
252
+ while (f != l->tail) {
253
+ if (f->start < last || f->end > len) {
254
+ rb_raise(rb_eStandardError, "invalid patch");
255
+ return -1;
256
+ }
257
+ outlen += f->start - last;
258
+ last = f->end;
259
+ outlen += f->len;
260
+ f++;
261
+ }
262
+
263
+ outlen += len - last;
264
+ return outlen;
265
+ }
266
+
267
+ static int apply(char *buf, const char *orig, int len, struct flist *l)
268
+ {
269
+ struct frag *f = l->head;
270
+ int last = 0;
271
+ char *p = buf;
272
+
273
+ while (f != l->tail) {
274
+ if (f->start < last || f->end > len) {
275
+ rb_raise(rb_eStandardError, "invalid patch");
276
+ return 0;
277
+ }
278
+ memcpy(p, orig + last, f->start - last);
279
+ p += f->start - last;
280
+ memcpy(p, f->data, f->len);
281
+ last = f->end;
282
+ p += f->len;
283
+ f++;
284
+ }
285
+ memcpy(p, orig + last, len - last);
286
+ return 1;
287
+ }
288
+
289
+ /* recursively generate a patch of all bins between start and end */
290
+ static struct flist *fold(VALUE bins, int start, int end)
291
+ {
292
+ int len;
293
+ int blen;
294
+ const char *buffer;
295
+ VALUE str;
296
+
297
+ if (start + 1 == end) {
298
+ /* trivial case, output a decoded list */
299
+ VALUE tmp = rb_ary_entry(bins, start);
300
+ if (!tmp)
301
+ return NULL;
302
+ str = rb_str_new3(tmp);
303
+ if (!str || str == Qnil)
304
+ return NULL;
305
+ blen = RSTRING_LEN(str);
306
+ buffer = RSTRING_PTR(str);
307
+ return decode(buffer, blen);
308
+ }
309
+
310
+ /* divide and conquer, memory management is elsewhere */
311
+ len = (end - start) / 2;
312
+ return combine(fold(bins, start, start + len),
313
+ fold(bins, start + len, end));
314
+ }
315
+
316
+ static VALUE amp_mpatch_apply_patches(VALUE self, VALUE text, VALUE bins)
317
+ {
318
+ VALUE result;
319
+ struct flist *patch;
320
+ const char *in;
321
+ char *out;
322
+ int len, outlen;
323
+ int inlen;
324
+
325
+ len = RARRAY_LEN(bins);
326
+ if (!len) {
327
+ /* nothing to do */
328
+ return text;
329
+ }
330
+
331
+ in = RSTRING_PTR(text);
332
+ inlen = RSTRING_LEN(text);
333
+
334
+ patch = fold(bins, 0, len);
335
+ if (!patch)
336
+ return Qnil;
337
+
338
+ outlen = calcsize(inlen, patch);
339
+ if (outlen < 0) {
340
+ result = Qnil;
341
+ goto cleanup;
342
+ }
343
+ result = rb_str_new(NULL, outlen);
344
+ if (!result) {
345
+ result = Qnil;
346
+ goto cleanup;
347
+ }
348
+ out = RSTRING_PTR(result);
349
+ if (!apply(out, in, inlen, patch)) {
350
+ result = Qnil;
351
+ }
352
+ cleanup:
353
+ lfree(patch);
354
+ return result;
355
+ }
356
+
357
+ static VALUE amp_mpatch_patched_size(VALUE self, VALUE orig_r, VALUE bin_r)
358
+ {
359
+ uint32_t orig, start, end, len, outlen = 0, last = 0;
360
+ int patchlen;
361
+ char *bin, *binend, *data;
362
+ char decode[12]; /* for dealing with alignment issues */
363
+
364
+ orig = FIX2INT(orig_r);
365
+ bin = RSTRING_PTR(bin_r);
366
+ patchlen = RSTRING_LEN(bin_r);
367
+
368
+ binend = bin + patchlen;
369
+ data = bin + 12;
370
+
371
+ while (data <= binend) {
372
+ memcpy(decode, bin, 12);
373
+ start = (uint32_t)ntohl(*(uint32_t *)decode);
374
+ end = (uint32_t)ntohl(*(uint32_t *)(decode + 4));
375
+ len = (uint32_t)ntohl(*(uint32_t *)(decode + 8));
376
+ if (start > end)
377
+ break; /* sanity check */
378
+ bin = data + len;
379
+ if (bin < data)
380
+ break; /* big data + big (bogus) len can wrap around */
381
+ data = bin + 12;
382
+ outlen += start - last;
383
+ last = end;
384
+ outlen += len;
385
+ }
386
+
387
+ if (bin != binend) {
388
+ rb_raise(rb_eStandardError, "patch cannot be decoded");
389
+ return Qnil;
390
+ }
391
+
392
+ outlen += orig - last;
393
+ return INT2FIX(outlen);
394
+ }
395
+
396
+
397
+ void Init_MercurialPatch() {
398
+
399
+ rb_mAmp = rb_define_module("Amp");
400
+ rb_mDiffs = rb_define_module_under(rb_mAmp, "Diffs");
401
+ rb_mMercurialPatch = rb_define_module_under(rb_mDiffs, "MercurialPatch");
402
+
403
+ rb_define_singleton_method(rb_mMercurialPatch, "patched_size", amp_mpatch_patched_size, 2);
404
+ rb_define_singleton_method(rb_mMercurialPatch, "apply_patches", amp_mpatch_apply_patches, 2);
405
+ }