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,5 @@
1
+ require 'mkmf'
2
+ if RUBY_VERSION =~ /1.9/ then
3
+ $CPPFLAGS += " -DRUBY_19"
4
+ end
5
+ create_makefile("Support")
@@ -0,0 +1,250 @@
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include "ruby.h"
4
+
5
+ static int little_endian = -1;
6
+
7
+ // these defines are taken from the mercurial source. They're relatively standard for
8
+ // byte-swapping, but credit goes where credit's due.
9
+ #ifdef _WIN32
10
+ # ifdef _MSC_VER
11
+ /* msvc 6.0 has problems */
12
+ # define inline __inline
13
+ typedef unsigned long uint32_t;
14
+ typedef unsigned __int64 uint64_t;
15
+ # else
16
+ # include <stdint.h>
17
+ # endif
18
+ static uint32_t ntohl(uint32_t x)
19
+ {
20
+ return ((x & 0x000000ffUL) << 24) |
21
+ ((x & 0x0000ff00UL) << 8) |
22
+ ((x & 0x00ff0000UL) >> 8) |
23
+ ((x & 0xff000000UL) >> 24);
24
+ }
25
+ #else
26
+ /* not windows */
27
+ # include <sys/types.h>
28
+ # if defined __BEOS__ && !defined __HAIKU__
29
+ # include <ByteOrder.h>
30
+ # else
31
+ # include <arpa/inet.h>
32
+ # endif
33
+ # include <inttypes.h>
34
+ #endif
35
+
36
+ /**
37
+ * Byte-swaps a 64-bit fixnum.
38
+ * Bignum arithmetic is quite, quite slow. By implementing this in C, we save ourselves
39
+ * innumerable cycles. Also, our result will usually end up being a bignum, even though we
40
+ * start as a fixnum.
41
+ *
42
+ * @param self [in] the bignum that needs byte swapping
43
+ * @return the byte-swapped number (or not swapped if host is big-endian)
44
+ */
45
+ static VALUE amp_fixnum_byte_swap_64(VALUE self) {
46
+ VALUE result = self;
47
+ if (little_endian) {
48
+ uint64_t val = (uint64_t)FIX2ULONG(self);
49
+ val = (((val >> 56)) | ((val & 0x00FF000000000000ll) >> 40) |
50
+ ((val & 0x0000FF0000000000ll) >> 24) | ((val & 0x000000FF00000000ll) >> 8) |
51
+ ((val & 0x00000000FF000000ll) << 8 ) | ((val & 0x0000000000FF0000ll) << 24) |
52
+ ((val & 0x000000000000FF00ll) << 40) | ((val & 0x00000000000000FFll) << 56));
53
+ result = rb_ull2inum(val);
54
+ }
55
+ return result;
56
+ }
57
+
58
+ /**
59
+ * Converts an unsigned, 16-bit fixnum to a signed, 16-bit value.
60
+ * Converts an unsigned, 16-bit number to its signed equivalent.
61
+ * Since Ruby doesn't have signed values readily available, this is much
62
+ * much faster in C.
63
+ *
64
+ * @param self [in] the 16-bit unsigned short to make signed
65
+ * @return the 16-bit signed equivalent
66
+ */
67
+ static VALUE amp_fixnum_to_signed_16(VALUE self) {
68
+ signed short val = (int16_t)FIX2INT(self);
69
+ VALUE result = rb_int_new(val);
70
+ return result;
71
+ }
72
+
73
+ /**
74
+ * Converts a fixnum to a signed, 32-bit value.
75
+ * Converts an unsigned, 32-bit number to its signed equivalent. Since Ruby
76
+ * doesn't have signed values readily available, this is much much faster in
77
+ * C. This will only be called if the number being converted is smaller than
78
+ * the fixnum max.
79
+ *
80
+ * @param self [in] the 32-bit unsigned long to make signed
81
+ * @return the 32-bit signed equivalent
82
+ */
83
+ static VALUE amp_fixnum_to_signed_32(VALUE self) {
84
+ VALUE result = rb_int_new((int32_t)FIX2LONG(self));
85
+ return result;
86
+ }
87
+
88
+ /**
89
+ * Byte-swaps a 64-bit bignum.
90
+ * Bignum arithmetic is quite, quite slow. By implementing this in C, we save ourselves
91
+ * innumerable cycles.
92
+ *
93
+ * @param self [in] the bignum that needs byte swapping
94
+ * @return the byte-swapped bignum (or not swapped if host is big-endian)
95
+ */
96
+ static VALUE amp_bignum_byte_swap_64(VALUE self) {
97
+ VALUE result = self;
98
+ if (little_endian) {
99
+ uint64_t val = rb_big2ull(self);
100
+ val = (((val >> 56)) | ((val & 0x00FF000000000000ull) >> 40) |
101
+ ((val & 0x0000FF0000000000ull) >> 24) | ((val & 0x000000FF00000000ull) >> 8) |
102
+ ((val & 0x00000000FF000000) << 8 ) | ((val & 0x0000000000FF0000) << 24) |
103
+ ((val & 0x000000000000FF00) << 40) | ((val & 0x00000000000000FF) << 56));
104
+ result = rb_ull2inum(val);
105
+ }
106
+ return result;
107
+ }
108
+
109
+ /**
110
+ * Converts a bignum to a signed, 32-bit value.
111
+ * Converts an unsigned, 32-bit number to its signed equivalent. Since Ruby
112
+ * doesn't have signed values readily available, this is much much faster in
113
+ * C.
114
+ *
115
+ * @param self [in] the 32-bit unsigned long to make signed
116
+ * @return the 32-bit signed equivalent
117
+ */
118
+ static VALUE amp_bignum_to_signed_32(VALUE self) {
119
+ VALUE result = rb_int_new((int32_t)rb_big2ulong(self));
120
+ return result;
121
+ }
122
+
123
+ /**
124
+ * Converts a bignum to a signed, 16-bit value.
125
+ * Converts an unsigned, 16-bit number to its signed equivalent.
126
+ * This should actually never be called, because bignums shouldn't
127
+ * ever be used for 16-bit values. However, it's provided just to be safe.
128
+ * Since Ruby doesn't have signed values readily available, this is much
129
+ * much faster in C.
130
+ *
131
+ * @param self [in] the 16-bit unsigned short to make signed
132
+ * @return the 16-bit signed equivalent
133
+ */
134
+ static VALUE amp_bignum_to_signed_16(VALUE self) {
135
+ signed short val = (int16_t)rb_big2ulong(self); // cut off bytes
136
+ VALUE result = rb_int_new(val);
137
+ return result;
138
+ }
139
+
140
+ // constant symbols that our dirstate would like
141
+ static VALUE rb_sRemoved, rb_sUntracked, rb_sNormal, rb_sMerged, rb_sAdded;
142
+
143
+ /**
144
+ * Converts an ascii value to a dirstate status symbol.
145
+ * Converts a fixnum, which is an ascii value, to a symbol representing
146
+ * a dirstate entry's status. Since we don't like passing around 'n', and
147
+ * want to pass around :normal, we need a fast lookup for ascii value ->
148
+ * symbol. The price we pay.
149
+ *
150
+ * @param self [in] the integer ascii value to convert
151
+ * @return a symbol representation of the dirstate status
152
+ */
153
+ static VALUE amp_integer_to_dirstate_symbol(VALUE self) {
154
+ int val = NUM2INT(self);
155
+ switch (val) {
156
+ case 110: return rb_sNormal; // 'n'
157
+ case 63: return rb_sUntracked; // '?'
158
+ case 97: return rb_sAdded; // 'a'
159
+ case 109: return rb_sMerged; // 'm'
160
+ case 114: return rb_sRemoved; // 'r'
161
+ }
162
+ rb_raise(rb_eStandardError, "no known hg value for %d", val);
163
+ }
164
+
165
+ /**
166
+ * Converts a string of hexademical into its binary representation.
167
+ * Method on strings. When the data in the string is hexademical
168
+ * (such as "DEADBEEF"), this method decodes the hex and converts
169
+ * every 2 bytes into its 1-byte binary representation.
170
+ *
171
+ * @example "414243".unhexlify == "ABC"
172
+ * @param self [in] the string object to unhexlify
173
+ * @return A decoded, binary string
174
+ */
175
+ static VALUE amp_string_unhexlify(VALUE self) {
176
+ // lengths of our strings
177
+ unsigned int len, out_len;
178
+ VALUE out;
179
+ // byte buffers that we'll work with when unhexlifying
180
+ char *out_buf, *in_buf;
181
+ char chk;
182
+
183
+ len = RSTRING_LEN(self);
184
+ // 2 hex bytes -> 1 unhexlified byte
185
+ out_len = len / 2;
186
+ out = rb_str_new(NULL, out_len);
187
+
188
+ // mark it as modified otherwise the GC will wig out at us
189
+ rb_str_modify(out);
190
+ // snag some pointers so we can do bad things
191
+ in_buf = RSTRING_PTR(self);
192
+ out_buf = RSTRING_PTR(out);
193
+
194
+ while (len) {
195
+ // first byte is multiplied by 16
196
+ chk = *in_buf++;
197
+ if (chk >= '0' && chk <= '9')
198
+ *out_buf = 16 * (chk - '0');
199
+ else if (chk >= 'A' && chk <= 'F')
200
+ *out_buf = 16 * (chk - 'A' + 10);
201
+ else if (chk >= 'a' && chk <= 'f')
202
+ *out_buf = 16 * (chk - 'a' + 10);
203
+ // second byte is just added to result
204
+ chk = *in_buf++;
205
+ if (chk >= '0' && chk <= '9')
206
+ *out_buf += (chk - '0');
207
+ else if (chk >= 'A' && chk <= 'F')
208
+ *out_buf += (chk - 'A' + 10);
209
+ else if (chk >= 'a' && chk <= 'f')
210
+ *out_buf += (chk - 'a' + 10);
211
+ out_buf++;
212
+ // 2 hex bytes down
213
+ len -= 2;
214
+ }
215
+ return out;
216
+ }
217
+
218
+ /**
219
+ * Initializes the Support module's C extension.
220
+ * This function is the entry point to the module - when the code is require'd,
221
+ * this function is run. All we need to do is add the new methods, and look up the
222
+ * symbols for to_dirstate_symbol.
223
+ */
224
+ void Init_Support() {
225
+ if (little_endian == -1) little_endian = (ntohl(8) != 8);
226
+
227
+ // methods added to String class
228
+ rb_define_method(rb_cString, "unhexlify", amp_string_unhexlify, 0);
229
+
230
+ // methods added to the Bignum class
231
+ rb_define_method(rb_cBignum, "byte_swap_64", amp_bignum_byte_swap_64, 0);
232
+ rb_define_method(rb_cBignum, "to_signed_32", amp_bignum_to_signed_32, 0);
233
+ rb_define_method(rb_cBignum, "to_signed_16", amp_bignum_to_signed_16, 0);
234
+
235
+ // methods added to the Fixnum class
236
+ rb_define_method(rb_cFixnum, "byte_swap_64", amp_fixnum_byte_swap_64, 0);
237
+ rb_define_method(rb_cFixnum, "to_signed_32", amp_fixnum_to_signed_32, 0);
238
+ rb_define_method(rb_cFixnum, "to_signed_16", amp_fixnum_to_signed_16, 0);
239
+
240
+ // Since symbols are only ever created once, let's look them up now, and never
241
+ // look them up again!
242
+ rb_sRemoved = ID2SYM(rb_intern("removed"));
243
+ rb_sUntracked = ID2SYM(rb_intern("untracked"));
244
+ rb_sNormal = ID2SYM(rb_intern("normal"));
245
+ rb_sMerged = ID2SYM(rb_intern("merged"));
246
+ rb_sAdded = ID2SYM(rb_intern("added"));
247
+
248
+ // method added to the Integer class
249
+ rb_define_method(rb_cInteger, "to_dirstate_symbol", amp_integer_to_dirstate_symbol, 0);
250
+ }
@@ -0,0 +1,200 @@
1
+ module Amp; end
2
+ # The root directory of this application
3
+ Amp::CODE_ROOT = File.expand_path File.dirname(__FILE__)
4
+ $: << Amp::CODE_ROOT # now we don't need to do `require "#{curdir}..."
5
+
6
+ # Timing variable
7
+ $start ||= Time.now
8
+ # Should we display anything?
9
+ $display ||= false
10
+ # Should we use pure ruby? Default to no.
11
+ $USE_RUBY ||= false
12
+ # Are we a command-line app? Default to no.
13
+ $cl ||= false
14
+
15
+ require "amp/support/loaders.rb"
16
+
17
+ #require 'profile'
18
+ require 'fileutils'
19
+ require 'stringio'
20
+
21
+ local_start = Time.now
22
+
23
+
24
+ ###############
25
+ # The Amp Magic
26
+ ###############
27
+ module Amp
28
+
29
+ autoload :Hook, "amp/commands/hooks.rb"
30
+ autoload :Generator, "amp/support/generator.rb"
31
+ autoload :Opener, "amp/support/openers.rb"
32
+ autoload :Match, "amp/support/match.rb"
33
+ autoload :Ignore, "amp/support/ignore.rb"
34
+ autoload :AmpConfig, "amp/support/amp_config.rb"
35
+ autoload :UI, "amp/support/amp_ui.rb"
36
+
37
+ autoload :Journal, "amp/repository/journal.rb"
38
+ autoload :VersionedFile, "amp/repository/versioned_file.rb"
39
+ autoload :VersionedWorkingFile, "amp/repository/versioned_file.rb"
40
+
41
+ autoload :Revlog, "amp/revlogs/revlog.rb"
42
+ autoload :Manifest, "amp/revlogs/manifest.rb"
43
+ autoload :FileLog, "amp/revlogs/file_log.rb"
44
+ autoload :Changeset, "amp/revlogs/changeset.rb"
45
+ autoload :WorkingDirectoryChangeset, "amp/revlogs/changeset.rb"
46
+ autoload :ChangeGroup, "amp/revlogs/changegroup.rb"
47
+ autoload :ChangeLog, "amp/revlogs/changelog.rb"
48
+
49
+ module Bundles
50
+ autoload :BundleChangeLog, "amp/revlogs/bundle_revlogs.rb"
51
+ autoload :BundleFileLog, "amp/revlogs/bundle_revlogs.rb"
52
+ autoload :BundleManifest, "amp/revlogs/bundle_revlogs.rb"
53
+ autoload :BundleRevlog, "amp/revlogs/bundle_revlogs.rb"
54
+ end
55
+
56
+ module Encoding
57
+ autoload :Base85, "amp/encoding/base85.rb"
58
+ end
59
+
60
+ module Diffs
61
+ autoload :BinaryDiff, "amp/encoding/binary_diff.rb"
62
+ autoload :MercurialDiff, "amp/encoding/mercurial_diff.rb"
63
+ autoload :MercurialPatch, "amp/encoding/mercurial_patch.rb"
64
+ autoload :SequenceMatcher, "amp/encoding/difflib.rb"
65
+ end
66
+
67
+ module Graphs
68
+ autoload :AncestorCalculator, "amp/graphs/ancestor.rb"
69
+ autoload :CopyCalculator, "amp/graphs/copies.rb"
70
+ end
71
+
72
+ module Merges
73
+ autoload :MergeState, "amp/merges/merge_state.rb"
74
+ autoload :MergeUI, "amp/merges/merge_ui.rb"
75
+ autoload :ThreeWayMerger, "amp/merges/simple_merge.rb"
76
+ end
77
+
78
+ module Repositories
79
+ autoload :BranchManager, "amp/repository/branch_manager.rb"
80
+ autoload :BundleRepository, "amp/repository/repositories/bundle_repository.rb"
81
+ autoload :DirState, "amp/repository/dir_state.rb"
82
+ autoload :HTTPRepository, "amp/repository/repositories/http_repository.rb"
83
+ autoload :HTTPSRepository, "amp/repository/repositories/http_repository.rb"
84
+ autoload :LocalRepository, "amp/repository/repositories/local_repository.rb"
85
+ autoload :Lock, "amp/repository/lock.rb"
86
+ autoload :Stores, "amp/repository/store.rb"
87
+ autoload :TagManager, "amp/repository/tag_manager.rb"
88
+ autoload :Updatable, "amp/repository/updatable.rb"
89
+ autoload :Verification, "amp/repository/verification.rb"
90
+ end
91
+
92
+ module RevlogSupport
93
+ autoload :ChangeGroup, "amp/revlogs/changegroup.rb"
94
+ autoload :Index, "amp/revlogs/index.rb"
95
+ autoload :IndexInlineNG, "amp/revlogs/index.rb"
96
+ autoload :IndexVersion0, "amp/revlogs/index.rb"
97
+ autoload :IndexVersionNG, "amp/revlogs/index.rb"
98
+ autoload :Node, "amp/revlogs/node.rb"
99
+ autoload :Support, "amp/revlogs/revlog_support.rb"
100
+ end
101
+
102
+ module Servers
103
+ autoload :FancyHTTPServer, "amp/server/fancy_http_server.rb"
104
+ autoload :HTTPServer, "amp/server/http_server.rb"
105
+ autoload :HTTPAuthorizedServer, "amp/server/http_server.rb"
106
+ autoload :RepoUserManagement, "amp/server/repo_user_management.rb"
107
+ autoload :User, "amp/server/amp_user.rb"
108
+ end
109
+
110
+ module Support
111
+ autoload :Logger, "amp/support/logger.rb"
112
+ autoload :MultiIO, "amp/support/multi_io.rb"
113
+ autoload :Template, "amp/templates/template.rb"
114
+ end
115
+ end
116
+
117
+ #######################
118
+ # Sinatra modifications
119
+ #######################
120
+ module Sinatra
121
+ autoload :Amp, "amp/server/extension/amp_extension.rb"
122
+ end
123
+
124
+
125
+ ###########################
126
+ # Globally accessible tools
127
+ ###########################
128
+ autoload :Archive, "amp/dependencies/minitar.rb"
129
+ autoload :Zip, "amp/dependencies/zip/zip.rb"
130
+ autoload :PriorityQueue, "amp/dependencies/priority_queue.rb"
131
+
132
+ #############################
133
+ # Files we need to just *run*
134
+ #############################
135
+ require "amp/dependencies/trollop.rb"
136
+ require "amp/dependencies/python_config.rb"
137
+ require "amp/dependencies/amp_support.rb"
138
+ require "amp/support/ruby_19_compatibility.rb"
139
+ require "amp/support/support.rb"
140
+ require "amp/templates/template.rb"
141
+
142
+ if $cl # if it's a command line app
143
+ include Amp::KernelMethods
144
+ require "amp/commands/command.rb"
145
+ require_dir { "amp/commands/*.rb" }
146
+ require_dir { "amp/commands/commands/*.rb" }
147
+
148
+ else
149
+ # it's not a command line app
150
+ require 'amp/support/docs.rb' # live documentation access
151
+ end
152
+ require "amp/repository/repository.rb"
153
+
154
+ module Amp
155
+ VERSION = '0.5.0'
156
+ VERSION_TITLE = "John Locke"
157
+
158
+ def self.new_irb_session(bndng)
159
+ require 'irb'
160
+
161
+ # Alter IRB appropriately
162
+ # http://jameskilton.com/2009/04/02/embedding-irb-into-your-ruby-application/
163
+ ::IRB.class_eval do
164
+ def self.start_session(binding)
165
+ unless @__initialized
166
+ args = ARGV
167
+ ARGV.replace(ARGV.dup)
168
+ IRB.setup(nil)
169
+ ARGV.replace(args)
170
+ @__initialized = true
171
+ end
172
+
173
+ workspace = WorkSpace.new(binding)
174
+
175
+ irb = Irb.new(workspace)
176
+
177
+ @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
178
+ @CONF[:MAIN_CONTEXT] = irb.context
179
+
180
+ catch(:IRB_EXIT) do
181
+ irb.eval_input
182
+ end
183
+ end
184
+ end
185
+
186
+ IRB::start_session bndng
187
+ end
188
+
189
+ end
190
+
191
+ if ENV["TESTING"] == "true"
192
+ paused = Time.now
193
+ Amp::UI.debug "Time taken to load all files: #{paused - $start} seconds"
194
+ Amp::UI.debug "\t\t local files: #{paused - local_start} seconds"
195
+ Amp::UI.debug
196
+ Amp::UI.debug
197
+ end
198
+
199
+ # Benchmarking stuff
200
+ #need { 'amp/profiling_hacks' }