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 @@
1
+ amp_c_extension '../../../ext/amp/mercurial_patch/MercurialPatch', 'pure_ruby/ruby_mercurial_patch'
@@ -0,0 +1,292 @@
1
+ # I have seen few files so poorly organized such as patch.py
2
+ # What. The. Fuck. This is going to take so long to make.
3
+ module Amp
4
+ module Patch
5
+
6
+ class PatchError < StandardError; end
7
+ class NoHunkError < PatchError; end
8
+
9
+ class Patch
10
+
11
+ ##
12
+ # The filename of the patch
13
+ attr_accessor :file_name
14
+
15
+ ##
16
+ # The opener used to open the patch
17
+ attr_accessor :opener
18
+
19
+ ##
20
+ # @todo - add comment
21
+ attr_accessor :lines
22
+
23
+ ##
24
+ # does the patch exist?
25
+ attr_accessor :exists
26
+ alias_method :exists?, :exists
27
+
28
+ ##
29
+ # Is the file in the filesystem
30
+ attr_accessor :missing
31
+ alias_method :missing?, :missing
32
+
33
+ ##
34
+ # @todo - add comment
35
+ attr_accessor :hash
36
+
37
+ ##
38
+ # Is this dirty and does it need to be resynced with something?
39
+ attr_accessor :dirty
40
+ alias_method :dirty?, :dirty
41
+
42
+ ##
43
+ # @todo - add comment
44
+ attr_accessor :offset
45
+
46
+ ##
47
+ # has this been printed? (duh)
48
+ attr_accessor :printed
49
+ alias_method :printed?, :printed
50
+
51
+ ##
52
+ # @todo - add comment
53
+ attr_accessor :hunks
54
+
55
+ def initialize(file_name, opener, missing=false)
56
+ @file_name = file_name
57
+ @opener = opener
58
+ @lines = []
59
+ @exists = false
60
+ @hash = {}
61
+ @dirty = false
62
+ @offset = 0
63
+ @rejected = []
64
+ @printed = false
65
+ @hunks = 0
66
+
67
+ ##
68
+ # If the patch is in the filesystem
69
+ # then we should read it and accurately set its existence
70
+ unless @missing = missing
71
+ begin
72
+ readlines!
73
+ @exists = true
74
+ rescue IOError
75
+ end
76
+ else
77
+ UI::warn "unable to find '#{@file_name}' for patching"
78
+ end
79
+ end
80
+
81
+ ##
82
+ # Loads up the patch info from +@file_name+
83
+ # into +@lines+
84
+ def readlines!
85
+ @opener.open @file_name do |f|
86
+ @lines = f.readlines
87
+ end
88
+ end
89
+
90
+ ##
91
+ # Mysteriously and safely disappear...
92
+ #
93
+ # @return [Boolean] success marker
94
+ def unlink; File.safe_unlink @file_name; end
95
+
96
+ ##
97
+ # Print out the patch to STDOUT, or STDERR if +warn+ is true.
98
+ #
99
+ # @param [Boolean] warn should we be printing to STDERR?
100
+ def print(warn=false)
101
+ return if printed? # no need to print it twice
102
+
103
+ @printed = true if warn
104
+ message = "patching file #{@file_name}"
105
+ warn ? UI::warn message : UI::note message
106
+ end
107
+
108
+ ##
109
+ # From the Python: looks through the hash and finds candidate lines. The
110
+ # result is a list of line numbers sorted based on distance from linenum.
111
+ #
112
+ # I wish I knew how to make sense of that sentence.
113
+ #
114
+ # @todo Look into removing an unnecessary `- number`.
115
+ # @param [String] line
116
+ # @param [Integer] number the line number
117
+ # @return [Array] the lines that matchish.
118
+ def find_lines(line, number)
119
+ return [] unless @hash.include? line
120
+
121
+ # really, we're just getting the lines and sorting them
122
+ # is the `- number` even necessary?
123
+ @hash[line].sort {|a, b| (a - number).abs <=> (b - number).abs }
124
+ end
125
+
126
+ ##
127
+ # I have no clue what song I am listening to but it is SOOOOO GOOD!!!!!!!!
128
+ # "This time baby, I'll be bullet proof"
129
+ # If I had working internet now, I'd be googling the lyrics.
130
+ #
131
+ # Oh right, the method. I don't know what this does... YET
132
+ #
133
+ # @todo Figure out what this does
134
+ def hash_lines
135
+ @hash = Hash.new {|h, k| h[k] = [] }
136
+ (0 ... @lines.size).each do |x|
137
+ s = @lines[x]
138
+ @hash[s] << x
139
+ end
140
+ end
141
+
142
+ ##
143
+ # our rejects are a little different from patch(1). This always
144
+ # creates rejects in the same form as the original patch. A file
145
+ # header is inserted so that you can run the reject through patch again
146
+ # without having to type the filename.
147
+ def write_rejects
148
+ return if @rejects.empty?
149
+ fname = @file_name + '.rej'
150
+
151
+ UI::warn("#{@rejects.size} out of #{@hunks} hunks FAILED --" +
152
+ "saving rejects to file #{fname}")
153
+
154
+ # i have never written code as horrid as this
155
+ # please help me
156
+ lz = []
157
+ base = File.dirname @file_name
158
+ lz << "--- #{base}\n+++ #{base}\n"
159
+ @rejects.each do |r|
160
+ r.hunk.each do |l|
161
+ lz << l
162
+ lz << "\n\n" if l.last.chr != "\n"
163
+ end
164
+ end
165
+
166
+ write fname, lz, true
167
+ end
168
+
169
+ ##
170
+ # Write +linez+ to +fname+. We won't be doing any writing if
171
+ # nothing has been changed, but this can be overridden with the
172
+ # force parameter.
173
+ #
174
+ # @param [String] dest the filename to write to
175
+ # @param [Array<String>] linez an array of the lines to write
176
+ # @param [Boolean] force force a write
177
+ def write(dest=@file_name, linez=@lines, force=false)
178
+ return unless dirty? || force
179
+
180
+ @opener.open dest, 'w' do |f|
181
+ f.write linez.join("\n")
182
+ end
183
+ end
184
+
185
+ ##
186
+ # A more restrictive version of {write}
187
+ def write_patch
188
+ write @file_name, @lines, true
189
+ end
190
+
191
+ ##
192
+ # Closing rites. Write the patch and then write the rejects.
193
+ def close
194
+ write_patch
195
+ write_rejects
196
+ end
197
+
198
+ ##
199
+ # Apply the current hunk +hunk+. Also, should we reverse the hunk? Consult +reverse+.
200
+ #
201
+ # @param
202
+ # @param
203
+ def apply(hunk, reverse)
204
+ unless hunk.complete?
205
+ raise PatchError.new("bad hunk #%d %s (%d %d %d %d)" %
206
+ [hunk.number, hunk.desc, hunk.a.size,
207
+ hunk.len_a, hunk.b.size, hunk.len_b])
208
+ end
209
+
210
+ @hunks += 1 # It's clear we're adding a new hunk.
211
+
212
+ # Obey reversal rules.
213
+ hunk.reverse if reverse
214
+
215
+ # Does the file already exist? Better tell someone
216
+ UI::warn "file #{@file_name} already exists" if exists? && hunk.create_file?
217
+
218
+ # Is this a misfit?
219
+ (@rejects << hunk; return -1) if missing? || (exists? && hunk.create_file?)
220
+
221
+ # Deal with GitHunks
222
+ if hunk.is_a? GitHunk
223
+ if hunk.remove_file?
224
+ File.safe_unlink @file_name
225
+ else
226
+ @lines = hunk.new
227
+ @offset += hunk.new.size
228
+ @dirty = true
229
+ end
230
+
231
+ return 0
232
+ end
233
+
234
+ # fast case first, no offsets, no fuzz
235
+ old = hunk.old
236
+
237
+ # patch starts counting at 1 unless we are adding the file
238
+ start = hunk.start_a == 0 ? 0 : h.start_a + @offset - 1
239
+
240
+ orig_start = start
241
+ if DiffHelpers::test_hunk(old, @lines, start) == 0
242
+ if hunk.remove_file?
243
+ File.safe_unlink @file_name
244
+ else
245
+ @lines[start .. (start + hunk.len_a)] = hunk.new
246
+ @offset += hunk.len_b - hunk.len_a
247
+ @dirty = true
248
+ end
249
+
250
+ return 0
251
+ end # end if
252
+ end # end def
253
+
254
+ # Ok, We couldn't match the hunk. Let's look for offsets and fuzz it
255
+ # as well as use proper punctuation for the 'let us' contraction.
256
+ hash_lines
257
+
258
+ # if the hunk tried to put something at the bottom of the file
259
+ # then override the start line and use eof here
260
+ search_start = hunk[-1][0].chr != ' ' ? @lines.size : orig_start
261
+
262
+ 0.upto(2) do |fuzz_len|
263
+ [true, false].each do |top_only|
264
+ old = hunk.old fuzz_len, top_only
265
+ # Continue at patch.py:407
266
+ # ...
267
+ # ...
268
+ end
269
+ end # end upto
270
+
271
+ end # end class Patch
272
+
273
+ class PatchMeta
274
+ end
275
+
276
+ class Hunk
277
+ end
278
+
279
+ class GitHunk
280
+ end
281
+
282
+ class BinaryHunk
283
+ end
284
+
285
+ class SymLinkHunk
286
+ end
287
+
288
+ class LineReader
289
+ end
290
+
291
+ end
292
+ end
@@ -0,0 +1,123 @@
1
+
2
+ module Amp
3
+ module Diffs
4
+
5
+ ##
6
+ # This handles applying patches in mercurial. yay!!!!
7
+ module MercurialPatch
8
+
9
+ ##
10
+ # This attempts to apply a series of patches in time proportional to
11
+ # the total size of the patches, rather than patches * len(text). This
12
+ # means rather than shuffling strings around, we shuffle around
13
+ # pointers to fragments with fragment lists.
14
+ #
15
+ # When the fragment lists get too long, we collapse them. To do this
16
+ # efficiently, we do all our operations inside a buffer created by
17
+ # mmap and simply use memmove. This avoids creating a bunch of large
18
+ # temporary string buffers.
19
+ #
20
+ # UPDATE 2AM BEFORE I GO BACK TO SCHOOL
21
+ # I FUCKING HATE PYTHON
22
+ def self.apply_patches(source, patches)
23
+ return source if patches.empty?
24
+ patch_lens = patches.map {|patch| patch.size}
25
+ pl = patch_lens.sum
26
+ bl = source.size + pl
27
+ tl = bl + bl + pl
28
+ b1, b2 = 0, bl
29
+
30
+ return a if tl == 0 #empty patches. lame.
31
+
32
+ output = StringIO.new "",(ruby_19? ? "r+:ASCII-8BIT" : "r+")
33
+ output.write source
34
+
35
+ frags = [[source.size, b1]]
36
+
37
+ pos = b2 + bl
38
+ output.seek pos
39
+ patches.each {|patch| output.write(patch)}
40
+ patch_lens.each do |plen|
41
+ if frags.size > 128
42
+ b2, b1 = b1, b2
43
+ frags = [self.collect(output,b1,frags)]
44
+ end
45
+ newarr = []
46
+ endpt = pos + plen
47
+ last = 0
48
+ while pos < endpt
49
+ output.seek pos
50
+ p1, p2, l = output.read(12).unpack("NNN")
51
+ self.pull(newarr, frags, p1 - last)
52
+ self.pull([], frags, p2 - p1)
53
+ newarr << [l, pos + 12]
54
+ pos += l + 12
55
+ last = p2
56
+ end
57
+ frags = newarr + frags
58
+ end
59
+
60
+ t = self.collect output, b2, frags
61
+ output.seek t[1]
62
+ output.read t[0]
63
+ end
64
+
65
+
66
+ def self.patched_size(orig, delta)
67
+ outlen, last, bin = 0, 0, 0
68
+ binend = delta.size
69
+ data = 12 # size of the delta instruction values (3 longs)
70
+ while data <= binend
71
+ decode = delta[bin..(bin+11)]
72
+ start, endpt, length = decode.unpack("NNN")
73
+ break if start > endpt
74
+
75
+ bin = data + length
76
+ data = bin + 12
77
+ outlen += start - last
78
+ last = endpt
79
+ outlen += length
80
+ end
81
+
82
+ raise "patch cannot be decoded" if bin != binend
83
+
84
+ outlen += orig - last
85
+ outlen
86
+ end
87
+
88
+ def self.copy_block(io, destination, source, count)
89
+ io.seek(source)
90
+ buf = io.read(count)
91
+ io.seek(destination)
92
+ io.write(buf)
93
+ end
94
+
95
+ ##
96
+ #
97
+ def self.pull(dst, src, l)
98
+ until l == 0
99
+ f = src.shift
100
+ if f[0] > l
101
+ src.unshift [f[0] - l, f[1] + l]
102
+ dst << [l, f[1]]
103
+ return
104
+ end
105
+ dst << f
106
+ l -= f[0]
107
+ end
108
+ end
109
+
110
+ ##
111
+ # Takes the fragments we've accumulated and applies them all to the IO.
112
+ def self.collect(io, buf, list)
113
+ start = buf
114
+ list.each do |l, p|
115
+ self.copy_block(io, buf, p, l)
116
+ buf += l
117
+ end
118
+ [buf - start, start]
119
+ end
120
+
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,41 @@
1
+ namespace :ditz do
2
+
3
+ command :close do |c|
4
+ c.desc "Close a Ditz bug and commit saying that it has been closed"
5
+
6
+ c.opt :message, "Any notes concerning this bug", :short => '-m', :type => :string, :default => ''
7
+
8
+ c.on_run do |opts, args|
9
+ repo = opts[:repository]
10
+ msg = opts[:message]
11
+ issue = args.shift
12
+
13
+ system "ditz close #{issue}"
14
+
15
+ repo.commit :message => "Closed Bug ##{issue}#{msg.empty? ? '' : ": #{msg}"}"
16
+ end
17
+ end
18
+
19
+ command :add do |c|
20
+ c.desc "Add a Ditz bug and commit saying that it has been opened"
21
+
22
+ c.opt :message, "Any notes concerning this bug", :short => '-m', :type => :string, :default => ''
23
+
24
+ c.on_run do |opts, args|
25
+ repo = opts[:repository]
26
+ msg = opts[:message]
27
+
28
+ system "ditz add"
29
+
30
+ # seydar: *sigh* i hate taking advantage of side effects
31
+ # File.read('.ditz-config') =~ /^issue_dir:(.+)$/
32
+ # bugs = $1.strip
33
+ # adgar: then don't use them!
34
+ bugs = File.read('.ditz-config').match(/^issue_dir:(.+)$/)[1].strip
35
+
36
+ Amp::Command[:add].run opts, [bugs]
37
+ repo.commit :message => "Added Bugs"
38
+ end
39
+ end
40
+
41
+ end