amp 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (232) hide show
  1. data/.gitignore +12 -0
  2. data/.hgignore +3 -0
  3. data/AUTHORS +1 -1
  4. data/Manifest.txt +99 -38
  5. data/README.md +3 -3
  6. data/Rakefile +53 -18
  7. data/SCHEDULE.markdown +5 -1
  8. data/TODO.markdown +120 -149
  9. data/ampfile.rb +3 -1
  10. data/bin/amp +4 -1
  11. data/ext/amp/bz2/extconf.rb +1 -1
  12. data/ext/amp/mercurial_patch/extconf.rb +1 -1
  13. data/ext/amp/mercurial_patch/mpatch.c +4 -3
  14. data/ext/amp/priority_queue/extconf.rb +1 -1
  15. data/ext/amp/support/extconf.rb +1 -1
  16. data/ext/amp/support/support.c +1 -1
  17. data/lib/amp.rb +125 -67
  18. data/lib/amp/commands/command.rb +12 -10
  19. data/lib/amp/commands/command_support.rb +8 -1
  20. data/lib/amp/commands/commands/help.rb +2 -20
  21. data/lib/amp/commands/commands/init.rb +14 -2
  22. data/lib/amp/commands/commands/templates.rb +6 -4
  23. data/lib/amp/commands/commands/version.rb +15 -1
  24. data/lib/amp/commands/commands/workflow.rb +3 -3
  25. data/lib/amp/commands/commands/workflows/git/add.rb +3 -3
  26. data/lib/amp/commands/commands/workflows/git/copy.rb +1 -1
  27. data/lib/amp/commands/commands/workflows/git/rm.rb +4 -2
  28. data/lib/amp/commands/commands/workflows/hg/add.rb +1 -1
  29. data/lib/amp/commands/commands/workflows/hg/addremove.rb +2 -2
  30. data/lib/amp/commands/commands/workflows/hg/annotate.rb +8 -2
  31. data/lib/amp/commands/commands/workflows/hg/bisect.rb +253 -0
  32. data/lib/amp/commands/commands/workflows/hg/branch.rb +1 -1
  33. data/lib/amp/commands/commands/workflows/hg/branches.rb +3 -3
  34. data/lib/amp/commands/commands/workflows/hg/bundle.rb +3 -3
  35. data/lib/amp/commands/commands/workflows/hg/clone.rb +4 -5
  36. data/lib/amp/commands/commands/workflows/hg/commit.rb +37 -1
  37. data/lib/amp/commands/commands/workflows/hg/copy.rb +2 -1
  38. data/lib/amp/commands/commands/workflows/hg/debug/index.rb +1 -1
  39. data/lib/amp/commands/commands/workflows/hg/diff.rb +3 -8
  40. data/lib/amp/commands/commands/workflows/hg/forget.rb +5 -4
  41. data/lib/amp/commands/commands/workflows/hg/identify.rb +6 -6
  42. data/lib/amp/commands/commands/workflows/hg/import.rb +1 -1
  43. data/lib/amp/commands/commands/workflows/hg/incoming.rb +2 -2
  44. data/lib/amp/commands/commands/workflows/hg/log.rb +5 -4
  45. data/lib/amp/commands/commands/workflows/hg/merge.rb +1 -1
  46. data/lib/amp/commands/commands/workflows/hg/move.rb +5 -3
  47. data/lib/amp/commands/commands/workflows/hg/outgoing.rb +1 -1
  48. data/lib/amp/commands/commands/workflows/hg/push.rb +6 -7
  49. data/lib/amp/commands/commands/workflows/hg/remove.rb +2 -2
  50. data/lib/amp/commands/commands/workflows/hg/resolve.rb +6 -23
  51. data/lib/amp/commands/commands/workflows/hg/root.rb +1 -2
  52. data/lib/amp/commands/commands/workflows/hg/status.rb +21 -12
  53. data/lib/amp/commands/commands/workflows/hg/tag.rb +2 -2
  54. data/lib/amp/commands/commands/workflows/hg/untrack.rb +12 -0
  55. data/lib/amp/commands/commands/workflows/hg/verify.rb +13 -3
  56. data/lib/amp/commands/commands/workflows/hg/what_changed.rb +18 -0
  57. data/lib/amp/commands/dispatch.rb +12 -13
  58. data/lib/amp/dependencies/amp_support.rb +1 -1
  59. data/lib/amp/dependencies/amp_support/ruby_amp_support.rb +1 -0
  60. data/lib/amp/dependencies/maruku.rb +136 -0
  61. data/lib/amp/dependencies/maruku/attributes.rb +227 -0
  62. data/lib/amp/dependencies/maruku/defaults.rb +71 -0
  63. data/lib/amp/dependencies/maruku/errors_management.rb +92 -0
  64. data/lib/amp/dependencies/maruku/helpers.rb +260 -0
  65. data/lib/amp/dependencies/maruku/input/charsource.rb +326 -0
  66. data/lib/amp/dependencies/maruku/input/extensions.rb +69 -0
  67. data/lib/amp/dependencies/maruku/input/html_helper.rb +189 -0
  68. data/lib/amp/dependencies/maruku/input/linesource.rb +111 -0
  69. data/lib/amp/dependencies/maruku/input/parse_block.rb +615 -0
  70. data/lib/amp/dependencies/maruku/input/parse_doc.rb +234 -0
  71. data/lib/amp/dependencies/maruku/input/parse_span_better.rb +746 -0
  72. data/lib/amp/dependencies/maruku/input/rubypants.rb +225 -0
  73. data/lib/amp/dependencies/maruku/input/type_detection.rb +147 -0
  74. data/lib/amp/dependencies/maruku/input_textile2/t2_parser.rb +163 -0
  75. data/lib/amp/dependencies/maruku/maruku.rb +33 -0
  76. data/lib/amp/dependencies/maruku/output/to_ansi.rb +223 -0
  77. data/lib/amp/dependencies/maruku/output/to_html.rb +991 -0
  78. data/lib/amp/dependencies/maruku/output/to_markdown.rb +164 -0
  79. data/lib/amp/dependencies/maruku/output/to_s.rb +56 -0
  80. data/lib/amp/dependencies/maruku/string_utils.rb +191 -0
  81. data/lib/amp/dependencies/maruku/structures.rb +167 -0
  82. data/lib/amp/dependencies/maruku/structures_inspect.rb +87 -0
  83. data/lib/amp/dependencies/maruku/structures_iterators.rb +61 -0
  84. data/lib/amp/dependencies/maruku/textile2.rb +1 -0
  85. data/lib/amp/dependencies/maruku/toc.rb +199 -0
  86. data/lib/amp/dependencies/maruku/usage/example1.rb +33 -0
  87. data/lib/amp/dependencies/maruku/version.rb +40 -0
  88. data/lib/amp/dependencies/priority_queue.rb +2 -1
  89. data/lib/amp/dependencies/python_config.rb +2 -1
  90. data/lib/amp/graphs/ancestor.rb +2 -1
  91. data/lib/amp/graphs/copies.rb +236 -233
  92. data/lib/amp/help/entries/__default__.erb +31 -0
  93. data/lib/amp/help/entries/commands.erb +6 -0
  94. data/lib/amp/help/entries/mdtest.md +35 -0
  95. data/lib/amp/help/entries/silly +3 -0
  96. data/lib/amp/help/help.rb +288 -0
  97. data/lib/amp/profiling_hacks.rb +5 -3
  98. data/lib/amp/repository/abstract/abstract_changeset.rb +97 -0
  99. data/lib/amp/repository/abstract/abstract_local_repo.rb +181 -0
  100. data/lib/amp/repository/abstract/abstract_staging_area.rb +180 -0
  101. data/lib/amp/repository/abstract/abstract_versioned_file.rb +100 -0
  102. data/lib/amp/repository/abstract/common_methods/changeset.rb +75 -0
  103. data/lib/amp/repository/abstract/common_methods/local_repo.rb +277 -0
  104. data/lib/amp/repository/abstract/common_methods/staging_area.rb +233 -0
  105. data/lib/amp/repository/abstract/common_methods/versioned_file.rb +71 -0
  106. data/lib/amp/repository/generic_repo_picker.rb +78 -0
  107. data/lib/amp/repository/git/repo_format/changeset.rb +336 -0
  108. data/lib/amp/repository/git/repo_format/staging_area.rb +192 -0
  109. data/lib/amp/repository/git/repo_format/versioned_file.rb +119 -0
  110. data/lib/amp/repository/git/repositories/local_repository.rb +164 -0
  111. data/lib/amp/repository/git/repository.rb +41 -0
  112. data/lib/amp/repository/mercurial/encoding/mercurial_diff.rb +382 -0
  113. data/lib/amp/repository/mercurial/encoding/mercurial_patch.rb +1 -0
  114. data/lib/amp/repository/mercurial/encoding/patch.rb +294 -0
  115. data/lib/amp/repository/mercurial/encoding/pure_ruby/ruby_mercurial_patch.rb +124 -0
  116. data/lib/amp/repository/mercurial/merging/merge_ui.rb +327 -0
  117. data/lib/amp/repository/mercurial/merging/simple_merge.rb +452 -0
  118. data/lib/amp/repository/mercurial/repo_format/branch_manager.rb +266 -0
  119. data/lib/amp/repository/mercurial/repo_format/changeset.rb +768 -0
  120. data/lib/amp/repository/mercurial/repo_format/dir_state.rb +716 -0
  121. data/lib/amp/repository/mercurial/repo_format/journal.rb +218 -0
  122. data/lib/amp/repository/mercurial/repo_format/lock.rb +210 -0
  123. data/lib/amp/repository/mercurial/repo_format/merge_state.rb +228 -0
  124. data/lib/amp/repository/mercurial/repo_format/staging_area.rb +367 -0
  125. data/lib/amp/repository/mercurial/repo_format/store.rb +487 -0
  126. data/lib/amp/repository/mercurial/repo_format/tag_manager.rb +322 -0
  127. data/lib/amp/repository/mercurial/repo_format/updatable.rb +543 -0
  128. data/lib/amp/repository/mercurial/repo_format/updater.rb +848 -0
  129. data/lib/amp/repository/mercurial/repo_format/verification.rb +433 -0
  130. data/lib/amp/repository/mercurial/repositories/bundle_repository.rb +216 -0
  131. data/lib/amp/repository/mercurial/repositories/http_repository.rb +386 -0
  132. data/lib/amp/repository/mercurial/repositories/local_repository.rb +2034 -0
  133. data/lib/amp/repository/mercurial/repository.rb +119 -0
  134. data/lib/amp/repository/mercurial/revlogs/bundle_revlogs.rb +249 -0
  135. data/lib/amp/repository/mercurial/revlogs/changegroup.rb +217 -0
  136. data/lib/amp/repository/mercurial/revlogs/changelog.rb +339 -0
  137. data/lib/amp/repository/mercurial/revlogs/file_log.rb +152 -0
  138. data/lib/amp/repository/mercurial/revlogs/index.rb +500 -0
  139. data/lib/amp/repository/mercurial/revlogs/manifest.rb +201 -0
  140. data/lib/amp/repository/mercurial/revlogs/node.rb +20 -0
  141. data/lib/amp/repository/mercurial/revlogs/revlog.rb +1026 -0
  142. data/lib/amp/repository/mercurial/revlogs/revlog_support.rb +129 -0
  143. data/lib/amp/repository/mercurial/revlogs/versioned_file.rb +597 -0
  144. data/lib/amp/repository/repository.rb +11 -88
  145. data/lib/amp/server/extension/amp_extension.rb +3 -3
  146. data/lib/amp/server/fancy_http_server.rb +1 -1
  147. data/lib/amp/server/fancy_views/_browser.haml +1 -1
  148. data/lib/amp/server/fancy_views/_diff_file.haml +1 -8
  149. data/lib/amp/server/fancy_views/changeset.haml +2 -2
  150. data/lib/amp/server/fancy_views/file.haml +1 -1
  151. data/lib/amp/server/fancy_views/file_diff.haml +1 -1
  152. data/lib/amp/support/amp_ui.rb +13 -29
  153. data/lib/amp/support/generator.rb +1 -1
  154. data/lib/amp/support/loaders.rb +1 -2
  155. data/lib/amp/support/logger.rb +10 -16
  156. data/lib/amp/support/match.rb +18 -4
  157. data/lib/amp/support/mercurial/ignore.rb +151 -0
  158. data/lib/amp/support/openers.rb +8 -3
  159. data/lib/amp/support/support.rb +91 -46
  160. data/lib/amp/templates/{blank.commit.erb → mercurial/blank.commit.erb} +0 -0
  161. data/lib/amp/templates/{blank.log.erb → mercurial/blank.log.erb} +0 -0
  162. data/lib/amp/templates/{default.commit.erb → mercurial/default.commit.erb} +0 -0
  163. data/lib/amp/templates/{default.log.erb → mercurial/default.log.erb} +0 -0
  164. data/lib/amp/templates/template.rb +18 -18
  165. data/man/amp.1 +51 -0
  166. data/site/src/about/commands.haml +1 -1
  167. data/site/src/css/amp.css +1 -1
  168. data/site/src/index.haml +3 -3
  169. data/tasks/man.rake +39 -0
  170. data/tasks/stats.rake +1 -10
  171. data/tasks/yard.rake +1 -50
  172. data/test/dirstate_tests/test_dir_state.rb +10 -8
  173. data/test/functional_tests/annotate.out +31 -0
  174. data/test/functional_tests/test_functional.rb +155 -63
  175. data/test/localrepo_tests/ampfile.rb +12 -0
  176. data/test/localrepo_tests/test_local_repo.rb +56 -57
  177. data/test/manifest_tests/test_manifest.rb +3 -5
  178. data/test/merge_tests/test_merge.rb +3 -3
  179. data/test/revlog_tests/test_revlog.rb +14 -6
  180. data/test/store_tests/test_fncache_store.rb +19 -19
  181. data/test/test_19_compatibility.rb +46 -0
  182. data/test/test_base85.rb +2 -2
  183. data/test/test_bdiff.rb +2 -2
  184. data/test/test_changegroup.rb +59 -0
  185. data/test/test_commands.rb +2 -2
  186. data/test/test_difflib.rb +2 -2
  187. data/test/test_generator.rb +34 -0
  188. data/test/test_ignore.rb +203 -0
  189. data/test/test_journal.rb +18 -13
  190. data/test/test_match.rb +2 -2
  191. data/test/test_mdiff.rb +3 -3
  192. data/test/test_mpatch.rb +3 -3
  193. data/test/test_multi_io.rb +40 -0
  194. data/test/test_support.rb +18 -2
  195. data/test/test_templates.rb +38 -0
  196. data/test/test_ui.rb +79 -0
  197. data/test/testutilities.rb +56 -0
  198. metadata +168 -49
  199. data/ext/amp/bz2/mkmf.log +0 -38
  200. data/lib/amp/encoding/mercurial_diff.rb +0 -378
  201. data/lib/amp/encoding/mercurial_patch.rb +0 -1
  202. data/lib/amp/encoding/patch.rb +0 -292
  203. data/lib/amp/encoding/pure_ruby/ruby_mercurial_patch.rb +0 -123
  204. data/lib/amp/merges/merge_state.rb +0 -164
  205. data/lib/amp/merges/merge_ui.rb +0 -322
  206. data/lib/amp/merges/simple_merge.rb +0 -450
  207. data/lib/amp/repository/branch_manager.rb +0 -234
  208. data/lib/amp/repository/dir_state.rb +0 -950
  209. data/lib/amp/repository/journal.rb +0 -203
  210. data/lib/amp/repository/lock.rb +0 -207
  211. data/lib/amp/repository/repositories/bundle_repository.rb +0 -214
  212. data/lib/amp/repository/repositories/http_repository.rb +0 -377
  213. data/lib/amp/repository/repositories/local_repository.rb +0 -2661
  214. data/lib/amp/repository/store.rb +0 -485
  215. data/lib/amp/repository/tag_manager.rb +0 -319
  216. data/lib/amp/repository/updatable.rb +0 -532
  217. data/lib/amp/repository/verification.rb +0 -431
  218. data/lib/amp/repository/versioned_file.rb +0 -475
  219. data/lib/amp/revlogs/bundle_revlogs.rb +0 -246
  220. data/lib/amp/revlogs/changegroup.rb +0 -217
  221. data/lib/amp/revlogs/changelog.rb +0 -338
  222. data/lib/amp/revlogs/changeset.rb +0 -521
  223. data/lib/amp/revlogs/file_log.rb +0 -165
  224. data/lib/amp/revlogs/index.rb +0 -493
  225. data/lib/amp/revlogs/manifest.rb +0 -195
  226. data/lib/amp/revlogs/node.rb +0 -18
  227. data/lib/amp/revlogs/revlog.rb +0 -1045
  228. data/lib/amp/revlogs/revlog_support.rb +0 -126
  229. data/lib/amp/support/ignore.rb +0 -144
  230. data/site/Rakefile +0 -38
  231. data/test/test_amp.rb +0 -9
  232. data/test/test_helper.rb +0 -15
@@ -1,38 +0,0 @@
1
- have_library: checking for BZ2_bzWriteOpen() in -lbz2... -------------------- yes
2
-
3
- "gcc -o conftest -I/usr/local/include/ruby1.9-1.9.1/i386-darwin10.0.0 -I/usr/local/include/ruby1.9-1.9.1/ruby/backward -I/usr/local/include/ruby1.9-1.9.1 -I/Users/michaeledgar/mygems/amp/ext/amp/bz2 -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -DRUBY_19 -O2 -g -Wall -Wno-parentheses -pipe -fno-common conftest.c -L. -L/usr/local/lib -L. -L/usr/local/lib -lruby1.9-static -lpthread -ldl -lobjc "
4
- checked program was:
5
- /* begin */
6
- 1: #include "ruby.h"
7
- 2:
8
- 3: int main() {return 0;}
9
- /* end */
10
-
11
- "gcc -o conftest -I/usr/local/include/ruby1.9-1.9.1/i386-darwin10.0.0 -I/usr/local/include/ruby1.9-1.9.1/ruby/backward -I/usr/local/include/ruby1.9-1.9.1 -I/Users/michaeledgar/mygems/amp/ext/amp/bz2 -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -DRUBY_19 -O2 -g -Wall -Wno-parentheses -pipe -fno-common conftest.c -L. -L/usr/local/lib -L. -L/usr/local/lib -lruby1.9-static -lbz2 -lpthread -ldl -lobjc "
12
- conftest.c: In function ‘t’:
13
- conftest.c:5: error: ‘BZ2_bzWriteOpen’ undeclared (first use in this function)
14
- conftest.c:5: error: (Each undeclared identifier is reported only once
15
- conftest.c:5: error: for each function it appears in.)
16
- checked program was:
17
- /* begin */
18
- 1: #include "ruby.h"
19
- 2:
20
- 3: /*top*/
21
- 4: int main() {return 0;}
22
- 5: int t() { void ((*volatile p)()); p = (void ((*)()))BZ2_bzWriteOpen; return 0; }
23
- /* end */
24
-
25
- "gcc -o conftest -I/usr/local/include/ruby1.9-1.9.1/i386-darwin10.0.0 -I/usr/local/include/ruby1.9-1.9.1/ruby/backward -I/usr/local/include/ruby1.9-1.9.1 -I/Users/michaeledgar/mygems/amp/ext/amp/bz2 -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -DRUBY_19 -O2 -g -Wall -Wno-parentheses -pipe -fno-common conftest.c -L. -L/usr/local/lib -L. -L/usr/local/lib -lruby1.9-static -lbz2 -lpthread -ldl -lobjc "
26
- conftest.c: In function ‘t’:
27
- conftest.c:5: warning: implicit declaration of function ‘BZ2_bzWriteOpen’
28
- checked program was:
29
- /* begin */
30
- 1: #include "ruby.h"
31
- 2:
32
- 3: /*top*/
33
- 4: int main() {return 0;}
34
- 5: int t() { BZ2_bzWriteOpen(); return 0; }
35
- /* end */
36
-
37
- --------------------
38
-
@@ -1,378 +0,0 @@
1
- module Amp
2
- module Diffs
3
- ##
4
- # = MercurialDiff
5
- # Mercurial has it's own implementation of the unified diff, because windows
6
- # boxes don't have diff -u. Plus code is faster than the shell.
7
- # Lame. That's ok, it's pretty easy to do. And we can also add flags and
8
- # change default settings.
9
- #
10
- # Mainly, you're only going to use MercurialDiff.unified_diff(). It's usage
11
- # is described below.
12
- module MercurialDiff
13
- extend self
14
- ##
15
- # These are the default options you can modify. Grab them, clone them,
16
- # change them. Notice: You have to *clone* this when you use it, or
17
- # you will be changing the default options!
18
- DEFAULT_OPTIONS = {:context => 3, :text => false, :show_func => false,
19
- :git => false, :no_dates => false, :ignore_ws => false,
20
- :ignore_ws_amount => false, :ignore_blank_lines => false,
21
- :pretty => false}
22
-
23
- ##
24
- # Clear up whitespace in the text if we have any options relating
25
- # to getting rid of whitespace.
26
- #
27
- # @param [String] text the text to modify
28
- # @param [Hash] options the options to use when deciding how to clean text
29
- # @option [Boolean] options :ignore_ws (false) do we ignore all whitespace?
30
- # this has the net effect of removing all whitespace.
31
- # @option [Boolean] options :ignore_ws_amount (false) when this option is
32
- # true, we only remove "excessive" whitespace - more than 1 space or tab.
33
- # we then substitute it all with 1 space.
34
- # @option [Boolean] options :ignore_blank_lines (false) when this option
35
- # is true, we remove all extra blank lines.
36
- def whitespace_clean(text, options=DEFAULT_OPTIONS)
37
- if options[:ignore_ws]
38
- text.gsub!(/[ \t]+/, "") #warnings made me use parens
39
- elsif options[:ignore_ws_amount]
40
- text.gsub!(/[ \t]+/, ' ')
41
- text.gsub!(/[ \t]+\n/, "\n")
42
- end
43
- text.gsub!(/\n+/, '') if options[:ignore_blank_lines]
44
- text
45
- end
46
-
47
- ##
48
- # Given a line, returns a string that represents "adding that line" in a diff,
49
- # based on the options.
50
- #
51
- # @param [String] input the input line
52
- # @return [String] the output line, in a format indicating it is "added"
53
- def add_line(input, options)
54
- options[:pretty] ? "+#{input.chomp}".green+"\n" : "+#{input}"
55
- end
56
-
57
- ##
58
- # Given a line, returns a string that represents "removing that line" in a diff,
59
- # based on the options.
60
- #
61
- # @param [String] input the input line
62
- # @return [String] the output line, in a format indicating it is "removed"
63
- def remove_line(input, options)
64
- options[:pretty] ? "-#{input.chomp}".red+"\n" : "-#{input}"
65
- end
66
-
67
- ##
68
- # Creates a header or something? Not sure what this is used for, no code
69
- # references it. I think it's for git or something. eh.
70
- def diff_line(revisions, a, b, options=DEFAULT_OPTIONS)
71
- options = DEFAULT_OPTIONS.merge options
72
- parts = ['diff']
73
-
74
- parts << '--git' if options[:git]
75
- parts << revisions.map {|r| "-r #{r}"}.join(' ') if revisions && !options[:git]
76
- if options[:git]
77
- parts << "a/#{a}"
78
- parts << "b/#{b}"
79
- else
80
- parts << a
81
- end
82
- parts.join(' ') + "\n"
83
- end
84
-
85
- ##
86
- # Creates a date tag appropriate for diffs. Not all diff types use
87
- # dates though (namely git, apparently), so the options matter.
88
- #
89
- # @param [Time] date the time that we want to make a spiffy date line for
90
- # @param [String] fn1 the filename of the file being stamped. Only
91
- # used if the addtab option is on.
92
- # @param [Boolean] addtab (false) whether or not to add a tab in the
93
- # line or not. Only used if we're in git mode or no-date mode.
94
- # @param options the options to use while creating the date line.
95
- # @option [Boolean] options :git (false) are we creating a git diff?
96
- # this will deactivate dates.
97
- # @option options [Boolean] :nodates (false) should we never print dates?
98
- def date_tag(date, fn1, addtab = true, options = DEFAULT_OPTIONS)
99
- return "\t#{date.to_diff}\n" if !(options[:git]) && !(options[:nodates])
100
- return "\t\n" if addtab && fn1 =~ / /
101
- return "\n"
102
- end
103
-
104
- ##
105
- # Returns a unified diff based on the 2 blocks of text, their modification
106
- # times, their filenames, and the options.
107
- #
108
- # This is a self-contained replacement for diffs.
109
- #
110
- # @param a the original text
111
- # @param [Time] ad the modification timestamp for the old file
112
- # @param b the new text
113
- # @param [Time] bd the modification timestamp for the new file
114
- # @param fn1 the old filename
115
- # @param fn2 the new filename
116
- # @param r not sure what this does
117
- # @param options the options we will be using. There's a lot of settings,
118
- # see the descriptions for {whitespace_clean} and {date_tag}.
119
- def unified_diff(a, ad, b, bd, fn1, fn2, r=nil, options=DEFAULT_OPTIONS)
120
- return "" if (a.nil? || a.empty?) && (b.nil? || b.empty?)
121
- epoch = Time.at(0)
122
- if !options[:text] && (!a.nil? && a.binary? || !b.nil? && b.binary?)
123
- return "" if a.any? && b.any? && a.size == b.size && a == b #DERR
124
- l = ["Binary file #{fn1} has changed\n"]
125
- elsif a.nil? || a.empty?
126
- b = b.split_lines_better
127
- header = []
128
- if options[:pretty]
129
- l1 = a.nil? ? "Added file " : "Changed file "
130
- l1 += "#{fn2} at #{date_tag(bd,fn1,true,options)}"
131
- l1 = l1.cyan
132
- header << l1
133
- else
134
- if a.nil?
135
- header << "--- /dev/null#{date_tag(epoch, fn1, false, options)}"
136
- else
137
- header << "--- #{"a/" + fn1}#{date_tag(ad,fn1,true,options)}"
138
- end
139
- header << "+++ #{"b/" + fn2}#{date_tag(bd,fn1,true,options)}"
140
- header << "@@ -0,0 +1,#{b.size} @@\n"
141
- end
142
- l = header + (b.map {|line| add_line(line, options)})
143
- elsif b.nil? || b.empty?
144
- a = b.split_lines_better
145
- header = []
146
- if options[:pretty]
147
- l1 = b.nil? ? "Removed file " : "Changed file "
148
- l1 += "#{fn2} at #{date_tag(bd,fn1,true,options)}"
149
- l1 = l1.cyan
150
- header << l1
151
- else
152
- header << "--- #{"a/" + fn1}#{date_tag(ad,fn1,true,options)}"
153
- if b.nil?
154
- header << "+++ /dev/null#{date_tag(epoch, fn1, false, options)}"
155
- else
156
- header << "+++ #{"b/" + fn2}#{date_tag(bd,fn1,true,options)}"
157
- end
158
- header << "@@ -1,#{a.size} +0,0 @@\n"
159
- end
160
- l = header + (a.map {|line| remove_line(line, options)})
161
- else
162
- al = a.split_lines_better
163
- bl = b.split_lines_better
164
- l = bunidiff(a, b, al, bl, "a/"+fn1, "b/"+fn2, options)
165
- return "" if l.nil? || l.empty?
166
- if options[:pretty]
167
- l.shift
168
- if fn1 == fn2
169
- l[0] = "Changed file #{fn1.cyan} at #{date_tag(bd,fn1,true,options).lstrip}"
170
- else
171
- l[0] = "Moved file from #{fn1.cyan} to #{fn2.cyan}"
172
- end
173
- else
174
- l[0] = "#{l[0][0 .. -3]}#{date_tag(ad,fn1,true,options)}"
175
- l[1] = "#{l[1][0 .. -3]}#{date_tag(bd,fn1,true,options)}"
176
- end
177
- end
178
-
179
- l.size.times do |ln|
180
- if l[ln][-1,1] != "\n"
181
- l[ln] << "\n\\n"
182
- end
183
- end
184
-
185
- if r
186
- l.unshift diff_line(r, fn1, fn2, options)
187
- end
188
-
189
- l.join
190
- end
191
-
192
- ##
193
- # Starts a block ending context for a change - part of the unified diff
194
- # format.
195
- def context_end(l, len, options)
196
- ret = l + options[:context]
197
- ret = len if ret > len
198
- ret
199
- end
200
-
201
- ##
202
- # Starts a block starting context for a change - part of the unified diff
203
- # format.
204
- def context_start(l, options)
205
- ret = l - options[:context]
206
- return 0 if ret < 0
207
- ret
208
- end
209
-
210
- ##
211
- # Given a hunk of changes, yield each line we need to write to the diff.
212
- #
213
- # @param [Hash] hunk specifies a block of lines that changed between
214
- # the two files.
215
- # @param header the header for the block, if we have one.
216
- # @param l1 the original lines - used for context (unified diff format)
217
- # @param delta the lines that have changed thus far
218
- # @param options settings for the unified diff action. unused mostly here.
219
- def yield_hunk(hunk, header, l1, delta, options)
220
- header.each {|x| yield x} if header && header.any?
221
- delta = hunk[:delta]
222
- astart, a2, bstart, b2 = hunk[:start_a], hunk[:end_a], hunk[:start_b], hunk[:end_b]
223
- aend = context_end(a2,l1.size,options)
224
- alen = aend - astart
225
- blen = b2 - bstart + aend - a2
226
-
227
- # i seriously don't know what this does.
228
- func = ""
229
- if options[:show_func]
230
- (astart - 1).downto(0) do |x|
231
- t = l1[x].rstrip
232
- if t =~ /\w/
233
- func = ' ' + t[0 .. 39]
234
- break
235
- end
236
- end
237
- end
238
-
239
- # yield the header
240
- if options[:pretty]
241
- yield "From original lines #{astart + 1}-#{alen+astart+1}".yellow + "\n"
242
- else
243
- yield "@@ -%d,%d +%d,%d @@%s\n" % [astart + 1, alen,
244
- bstart + 1, blen, func]
245
- end
246
-
247
- # then yield each line of changes
248
- delta.each {|x| yield x}
249
- # then yield some context or something?
250
- a2.upto(aend-1) {|x| yield ' ' + l1[x] }
251
- end
252
-
253
- ##
254
- # Helper method for creating unified diffs.
255
- #
256
- # @param [String] t1 original text
257
- # @param [String] t2 new text
258
- # @param [String] l1 the original text broke into lines?
259
- # @param [String] l2 the new etxt broken into lines?
260
- # @param [String] header1 the original file's header
261
- # @param [String] header2 the new file's header
262
- # @param opts options for the method
263
- def bunidiff(t1,t2, l1, l2, header1, header2, opts=DEFAULT_OPTIONS)
264
- header = [ "--- #{header1}\t\n", "+++ #{header2}\t\n" ]
265
-
266
- diff = BinaryDiff.blocks(t1,t2)
267
- hunk = nil
268
- return_hunks = []
269
- saved_delta = []
270
- delta = []
271
- diff.size.times do |i|
272
- s = (i > 0) ? diff[i-1] : {:start_a => 0, :end_a => 0, :start_b => 0, :end_b => 0}
273
- saved_delta += delta unless delta.empty?
274
- delta = []
275
- s1 = diff[i]
276
- a1 = s[:end_a]
277
- a2 = s1[:start_a]
278
- b1 = s[:end_b]
279
- b2 = s1[:start_b]
280
-
281
- old = (a2 == 0) ? [] : l1[a1..(a2-1)]
282
- newb = (b2 == 0) ? [] : l2[b1..(b2-1)] #stands for new "b"
283
-
284
- next if old.empty? && newb.empty?
285
- if opts[:ignore_ws] || opts[:ignore_blank_lines] || opts[:ignore_ws_amount]
286
- next if whitespace_clean(old.join,opts) == whitespace_clean(newb.join,opts)
287
- end
288
-
289
- astart = context_start(a1,opts)
290
- bstart = context_start(b1,opts)
291
- prev = nil
292
- if hunk
293
- if astart < hunk[:end_a] + opts[:context] + 1
294
- prev = hunk
295
- astart = hunk[:end_a]
296
- bstart = hunk[:end_b]
297
- else
298
- yield_hunk(hunk, header, l1, delta, opts) {|x| return_hunks << x}
299
-
300
- header = nil
301
- end
302
- end
303
- # move this inside previous nested if statements
304
- if prev
305
- hunk[:end_a] = a2
306
- hunk[:end_b] = b2
307
- delta = hunk[:delta]
308
- else
309
- hunk = {:start_a => astart, :end_a => a2, :start_b => bstart, :end_b => b2, :delta => delta}
310
- end
311
-
312
- hunk[:delta] += l1[astart..(a1-1)].map {|x| ' ' + x } if a1 > 0
313
- hunk[:delta] += old.map {|x| remove_line(x, opts) }
314
- hunk[:delta] += newb.map {|x| add_line(x, opts) }
315
-
316
- end
317
- saved_delta += delta
318
-
319
- yield_hunk(hunk, header, l1, saved_delta, opts) {|x| return_hunks << x} if hunk
320
- return_hunks
321
- end
322
-
323
- ##
324
- # Unpacks a binary-compressed patch.
325
- #
326
- # @param [String] binary the packed binary text to unpack
327
- def patch_text(binary)
328
- pos = 0
329
- t = []
330
- while pos < binary.size
331
- p1, p2, l = binary[pos..(pos+11)].unpack("NNN")
332
- pos += 12
333
- t << binary[pos..(pos + l - 1)]
334
- pos += l
335
- end
336
- t.join
337
- end
338
-
339
- ##
340
- # Applies the patch _bin_ to the text _a_.
341
- #
342
- # @param [String] a the text to patch
343
- # @param [String] bin the binary patch to apply
344
- def patch(a, bin)
345
- MercurialPatch.apply_patches(a, [bin])
346
- end
347
-
348
- ##
349
- # Gets the matching blocks between the two texts.
350
- #
351
- # @param [String] a the original text
352
- # @param [String] b the final text
353
- # @return [[Hash]] The blocks of changes between the two
354
- def get_matching_blocks(a, b)
355
- an = a.split_lines_better
356
- bn = b.split_lines_better
357
-
358
- SequenceMatcher.new(an, bn).get_matching_blocks
359
- end
360
-
361
- ##
362
- # Returns the obvious header for when we create a new file
363
- #
364
- # @param [Fixnum] length the length of the file
365
- # @return [String] the obvious header
366
- def trivial_diff_header(length)
367
- [0, 0, length].pack("NNN")
368
- end
369
-
370
- ##
371
- # Returns a text diff between a and b. This returns the packed, binary
372
- # kind of diff.
373
- def text_diff a,b
374
- BinaryDiff.bdiff a,b
375
- end
376
- end
377
- end
378
- end
@@ -1 +0,0 @@
1
- amp_c_extension '../../../ext/amp/mercurial_patch/MercurialPatch', 'pure_ruby/ruby_mercurial_patch'
@@ -1,292 +0,0 @@
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