amp 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/.hgignore +3 -0
- data/AUTHORS +1 -1
- data/Manifest.txt +99 -38
- data/README.md +3 -3
- data/Rakefile +53 -18
- data/SCHEDULE.markdown +5 -1
- data/TODO.markdown +120 -149
- data/ampfile.rb +3 -1
- data/bin/amp +4 -1
- data/ext/amp/bz2/extconf.rb +1 -1
- data/ext/amp/mercurial_patch/extconf.rb +1 -1
- data/ext/amp/mercurial_patch/mpatch.c +4 -3
- data/ext/amp/priority_queue/extconf.rb +1 -1
- data/ext/amp/support/extconf.rb +1 -1
- data/ext/amp/support/support.c +1 -1
- data/lib/amp.rb +125 -67
- data/lib/amp/commands/command.rb +12 -10
- data/lib/amp/commands/command_support.rb +8 -1
- data/lib/amp/commands/commands/help.rb +2 -20
- data/lib/amp/commands/commands/init.rb +14 -2
- data/lib/amp/commands/commands/templates.rb +6 -4
- data/lib/amp/commands/commands/version.rb +15 -1
- data/lib/amp/commands/commands/workflow.rb +3 -3
- data/lib/amp/commands/commands/workflows/git/add.rb +3 -3
- data/lib/amp/commands/commands/workflows/git/copy.rb +1 -1
- data/lib/amp/commands/commands/workflows/git/rm.rb +4 -2
- data/lib/amp/commands/commands/workflows/hg/add.rb +1 -1
- data/lib/amp/commands/commands/workflows/hg/addremove.rb +2 -2
- data/lib/amp/commands/commands/workflows/hg/annotate.rb +8 -2
- data/lib/amp/commands/commands/workflows/hg/bisect.rb +253 -0
- data/lib/amp/commands/commands/workflows/hg/branch.rb +1 -1
- data/lib/amp/commands/commands/workflows/hg/branches.rb +3 -3
- data/lib/amp/commands/commands/workflows/hg/bundle.rb +3 -3
- data/lib/amp/commands/commands/workflows/hg/clone.rb +4 -5
- data/lib/amp/commands/commands/workflows/hg/commit.rb +37 -1
- data/lib/amp/commands/commands/workflows/hg/copy.rb +2 -1
- data/lib/amp/commands/commands/workflows/hg/debug/index.rb +1 -1
- data/lib/amp/commands/commands/workflows/hg/diff.rb +3 -8
- data/lib/amp/commands/commands/workflows/hg/forget.rb +5 -4
- data/lib/amp/commands/commands/workflows/hg/identify.rb +6 -6
- data/lib/amp/commands/commands/workflows/hg/import.rb +1 -1
- data/lib/amp/commands/commands/workflows/hg/incoming.rb +2 -2
- data/lib/amp/commands/commands/workflows/hg/log.rb +5 -4
- data/lib/amp/commands/commands/workflows/hg/merge.rb +1 -1
- data/lib/amp/commands/commands/workflows/hg/move.rb +5 -3
- data/lib/amp/commands/commands/workflows/hg/outgoing.rb +1 -1
- data/lib/amp/commands/commands/workflows/hg/push.rb +6 -7
- data/lib/amp/commands/commands/workflows/hg/remove.rb +2 -2
- data/lib/amp/commands/commands/workflows/hg/resolve.rb +6 -23
- data/lib/amp/commands/commands/workflows/hg/root.rb +1 -2
- data/lib/amp/commands/commands/workflows/hg/status.rb +21 -12
- data/lib/amp/commands/commands/workflows/hg/tag.rb +2 -2
- data/lib/amp/commands/commands/workflows/hg/untrack.rb +12 -0
- data/lib/amp/commands/commands/workflows/hg/verify.rb +13 -3
- data/lib/amp/commands/commands/workflows/hg/what_changed.rb +18 -0
- data/lib/amp/commands/dispatch.rb +12 -13
- data/lib/amp/dependencies/amp_support.rb +1 -1
- data/lib/amp/dependencies/amp_support/ruby_amp_support.rb +1 -0
- data/lib/amp/dependencies/maruku.rb +136 -0
- data/lib/amp/dependencies/maruku/attributes.rb +227 -0
- data/lib/amp/dependencies/maruku/defaults.rb +71 -0
- data/lib/amp/dependencies/maruku/errors_management.rb +92 -0
- data/lib/amp/dependencies/maruku/helpers.rb +260 -0
- data/lib/amp/dependencies/maruku/input/charsource.rb +326 -0
- data/lib/amp/dependencies/maruku/input/extensions.rb +69 -0
- data/lib/amp/dependencies/maruku/input/html_helper.rb +189 -0
- data/lib/amp/dependencies/maruku/input/linesource.rb +111 -0
- data/lib/amp/dependencies/maruku/input/parse_block.rb +615 -0
- data/lib/amp/dependencies/maruku/input/parse_doc.rb +234 -0
- data/lib/amp/dependencies/maruku/input/parse_span_better.rb +746 -0
- data/lib/amp/dependencies/maruku/input/rubypants.rb +225 -0
- data/lib/amp/dependencies/maruku/input/type_detection.rb +147 -0
- data/lib/amp/dependencies/maruku/input_textile2/t2_parser.rb +163 -0
- data/lib/amp/dependencies/maruku/maruku.rb +33 -0
- data/lib/amp/dependencies/maruku/output/to_ansi.rb +223 -0
- data/lib/amp/dependencies/maruku/output/to_html.rb +991 -0
- data/lib/amp/dependencies/maruku/output/to_markdown.rb +164 -0
- data/lib/amp/dependencies/maruku/output/to_s.rb +56 -0
- data/lib/amp/dependencies/maruku/string_utils.rb +191 -0
- data/lib/amp/dependencies/maruku/structures.rb +167 -0
- data/lib/amp/dependencies/maruku/structures_inspect.rb +87 -0
- data/lib/amp/dependencies/maruku/structures_iterators.rb +61 -0
- data/lib/amp/dependencies/maruku/textile2.rb +1 -0
- data/lib/amp/dependencies/maruku/toc.rb +199 -0
- data/lib/amp/dependencies/maruku/usage/example1.rb +33 -0
- data/lib/amp/dependencies/maruku/version.rb +40 -0
- data/lib/amp/dependencies/priority_queue.rb +2 -1
- data/lib/amp/dependencies/python_config.rb +2 -1
- data/lib/amp/graphs/ancestor.rb +2 -1
- data/lib/amp/graphs/copies.rb +236 -233
- data/lib/amp/help/entries/__default__.erb +31 -0
- data/lib/amp/help/entries/commands.erb +6 -0
- data/lib/amp/help/entries/mdtest.md +35 -0
- data/lib/amp/help/entries/silly +3 -0
- data/lib/amp/help/help.rb +288 -0
- data/lib/amp/profiling_hacks.rb +5 -3
- data/lib/amp/repository/abstract/abstract_changeset.rb +97 -0
- data/lib/amp/repository/abstract/abstract_local_repo.rb +181 -0
- data/lib/amp/repository/abstract/abstract_staging_area.rb +180 -0
- data/lib/amp/repository/abstract/abstract_versioned_file.rb +100 -0
- data/lib/amp/repository/abstract/common_methods/changeset.rb +75 -0
- data/lib/amp/repository/abstract/common_methods/local_repo.rb +277 -0
- data/lib/amp/repository/abstract/common_methods/staging_area.rb +233 -0
- data/lib/amp/repository/abstract/common_methods/versioned_file.rb +71 -0
- data/lib/amp/repository/generic_repo_picker.rb +78 -0
- data/lib/amp/repository/git/repo_format/changeset.rb +336 -0
- data/lib/amp/repository/git/repo_format/staging_area.rb +192 -0
- data/lib/amp/repository/git/repo_format/versioned_file.rb +119 -0
- data/lib/amp/repository/git/repositories/local_repository.rb +164 -0
- data/lib/amp/repository/git/repository.rb +41 -0
- data/lib/amp/repository/mercurial/encoding/mercurial_diff.rb +382 -0
- data/lib/amp/repository/mercurial/encoding/mercurial_patch.rb +1 -0
- data/lib/amp/repository/mercurial/encoding/patch.rb +294 -0
- data/lib/amp/repository/mercurial/encoding/pure_ruby/ruby_mercurial_patch.rb +124 -0
- data/lib/amp/repository/mercurial/merging/merge_ui.rb +327 -0
- data/lib/amp/repository/mercurial/merging/simple_merge.rb +452 -0
- data/lib/amp/repository/mercurial/repo_format/branch_manager.rb +266 -0
- data/lib/amp/repository/mercurial/repo_format/changeset.rb +768 -0
- data/lib/amp/repository/mercurial/repo_format/dir_state.rb +716 -0
- data/lib/amp/repository/mercurial/repo_format/journal.rb +218 -0
- data/lib/amp/repository/mercurial/repo_format/lock.rb +210 -0
- data/lib/amp/repository/mercurial/repo_format/merge_state.rb +228 -0
- data/lib/amp/repository/mercurial/repo_format/staging_area.rb +367 -0
- data/lib/amp/repository/mercurial/repo_format/store.rb +487 -0
- data/lib/amp/repository/mercurial/repo_format/tag_manager.rb +322 -0
- data/lib/amp/repository/mercurial/repo_format/updatable.rb +543 -0
- data/lib/amp/repository/mercurial/repo_format/updater.rb +848 -0
- data/lib/amp/repository/mercurial/repo_format/verification.rb +433 -0
- data/lib/amp/repository/mercurial/repositories/bundle_repository.rb +216 -0
- data/lib/amp/repository/mercurial/repositories/http_repository.rb +386 -0
- data/lib/amp/repository/mercurial/repositories/local_repository.rb +2034 -0
- data/lib/amp/repository/mercurial/repository.rb +119 -0
- data/lib/amp/repository/mercurial/revlogs/bundle_revlogs.rb +249 -0
- data/lib/amp/repository/mercurial/revlogs/changegroup.rb +217 -0
- data/lib/amp/repository/mercurial/revlogs/changelog.rb +339 -0
- data/lib/amp/repository/mercurial/revlogs/file_log.rb +152 -0
- data/lib/amp/repository/mercurial/revlogs/index.rb +500 -0
- data/lib/amp/repository/mercurial/revlogs/manifest.rb +201 -0
- data/lib/amp/repository/mercurial/revlogs/node.rb +20 -0
- data/lib/amp/repository/mercurial/revlogs/revlog.rb +1026 -0
- data/lib/amp/repository/mercurial/revlogs/revlog_support.rb +129 -0
- data/lib/amp/repository/mercurial/revlogs/versioned_file.rb +597 -0
- data/lib/amp/repository/repository.rb +11 -88
- data/lib/amp/server/extension/amp_extension.rb +3 -3
- data/lib/amp/server/fancy_http_server.rb +1 -1
- data/lib/amp/server/fancy_views/_browser.haml +1 -1
- data/lib/amp/server/fancy_views/_diff_file.haml +1 -8
- data/lib/amp/server/fancy_views/changeset.haml +2 -2
- data/lib/amp/server/fancy_views/file.haml +1 -1
- data/lib/amp/server/fancy_views/file_diff.haml +1 -1
- data/lib/amp/support/amp_ui.rb +13 -29
- data/lib/amp/support/generator.rb +1 -1
- data/lib/amp/support/loaders.rb +1 -2
- data/lib/amp/support/logger.rb +10 -16
- data/lib/amp/support/match.rb +18 -4
- data/lib/amp/support/mercurial/ignore.rb +151 -0
- data/lib/amp/support/openers.rb +8 -3
- data/lib/amp/support/support.rb +91 -46
- data/lib/amp/templates/{blank.commit.erb → mercurial/blank.commit.erb} +0 -0
- data/lib/amp/templates/{blank.log.erb → mercurial/blank.log.erb} +0 -0
- data/lib/amp/templates/{default.commit.erb → mercurial/default.commit.erb} +0 -0
- data/lib/amp/templates/{default.log.erb → mercurial/default.log.erb} +0 -0
- data/lib/amp/templates/template.rb +18 -18
- data/man/amp.1 +51 -0
- data/site/src/about/commands.haml +1 -1
- data/site/src/css/amp.css +1 -1
- data/site/src/index.haml +3 -3
- data/tasks/man.rake +39 -0
- data/tasks/stats.rake +1 -10
- data/tasks/yard.rake +1 -50
- data/test/dirstate_tests/test_dir_state.rb +10 -8
- data/test/functional_tests/annotate.out +31 -0
- data/test/functional_tests/test_functional.rb +155 -63
- data/test/localrepo_tests/ampfile.rb +12 -0
- data/test/localrepo_tests/test_local_repo.rb +56 -57
- data/test/manifest_tests/test_manifest.rb +3 -5
- data/test/merge_tests/test_merge.rb +3 -3
- data/test/revlog_tests/test_revlog.rb +14 -6
- data/test/store_tests/test_fncache_store.rb +19 -19
- data/test/test_19_compatibility.rb +46 -0
- data/test/test_base85.rb +2 -2
- data/test/test_bdiff.rb +2 -2
- data/test/test_changegroup.rb +59 -0
- data/test/test_commands.rb +2 -2
- data/test/test_difflib.rb +2 -2
- data/test/test_generator.rb +34 -0
- data/test/test_ignore.rb +203 -0
- data/test/test_journal.rb +18 -13
- data/test/test_match.rb +2 -2
- data/test/test_mdiff.rb +3 -3
- data/test/test_mpatch.rb +3 -3
- data/test/test_multi_io.rb +40 -0
- data/test/test_support.rb +18 -2
- data/test/test_templates.rb +38 -0
- data/test/test_ui.rb +79 -0
- data/test/testutilities.rb +56 -0
- metadata +168 -49
- data/ext/amp/bz2/mkmf.log +0 -38
- data/lib/amp/encoding/mercurial_diff.rb +0 -378
- data/lib/amp/encoding/mercurial_patch.rb +0 -1
- data/lib/amp/encoding/patch.rb +0 -292
- data/lib/amp/encoding/pure_ruby/ruby_mercurial_patch.rb +0 -123
- data/lib/amp/merges/merge_state.rb +0 -164
- data/lib/amp/merges/merge_ui.rb +0 -322
- data/lib/amp/merges/simple_merge.rb +0 -450
- data/lib/amp/repository/branch_manager.rb +0 -234
- data/lib/amp/repository/dir_state.rb +0 -950
- data/lib/amp/repository/journal.rb +0 -203
- data/lib/amp/repository/lock.rb +0 -207
- data/lib/amp/repository/repositories/bundle_repository.rb +0 -214
- data/lib/amp/repository/repositories/http_repository.rb +0 -377
- data/lib/amp/repository/repositories/local_repository.rb +0 -2661
- data/lib/amp/repository/store.rb +0 -485
- data/lib/amp/repository/tag_manager.rb +0 -319
- data/lib/amp/repository/updatable.rb +0 -532
- data/lib/amp/repository/verification.rb +0 -431
- data/lib/amp/repository/versioned_file.rb +0 -475
- data/lib/amp/revlogs/bundle_revlogs.rb +0 -246
- data/lib/amp/revlogs/changegroup.rb +0 -217
- data/lib/amp/revlogs/changelog.rb +0 -338
- data/lib/amp/revlogs/changeset.rb +0 -521
- data/lib/amp/revlogs/file_log.rb +0 -165
- data/lib/amp/revlogs/index.rb +0 -493
- data/lib/amp/revlogs/manifest.rb +0 -195
- data/lib/amp/revlogs/node.rb +0 -18
- data/lib/amp/revlogs/revlog.rb +0 -1045
- data/lib/amp/revlogs/revlog_support.rb +0 -126
- data/lib/amp/support/ignore.rb +0 -144
- data/site/Rakefile +0 -38
- data/test/test_amp.rb +0 -9
- data/test/test_helper.rb +0 -15
@@ -1,246 +0,0 @@
|
|
1
|
-
module Amp
|
2
|
-
module Bundles
|
3
|
-
##
|
4
|
-
# This module handles revlogs passed to our client (or server)
|
5
|
-
# through the bundle file format. Thing is, this revision log
|
6
|
-
# spans both a physical filelog, and a bundle (the new revisions),
|
7
|
-
# and we might need to get stuff from both. It's kind of like the
|
8
|
-
# DelayedOpener/FakeAppender for changelogs.
|
9
|
-
module BundleRevlog
|
10
|
-
include RevlogSupport::Node
|
11
|
-
BUNDLED_INDEX_ENTRY_SIZE = 80
|
12
|
-
|
13
|
-
##
|
14
|
-
# Initializes a bundle revlog. Takes, in addition to the normal
|
15
|
-
# revlog arguments, a bundle_file. This is any IO we can read
|
16
|
-
# from that will give us additional revisions, aside from the
|
17
|
-
# revisions stored in the real Revlog. It also takes a link_mapper
|
18
|
-
# that will connect things to the changelog revisions (including
|
19
|
-
# changelog revisions in the bundle).
|
20
|
-
#
|
21
|
-
# @param [Opener] opener the opener to use for openinf up the index_file
|
22
|
-
# @param [String] index_file the name of the file containing the revlog's
|
23
|
-
# index
|
24
|
-
# @param [IO] bundle_file an IO that we can #read from
|
25
|
-
# @param [Proc, #call] link_mapper a function that will give us the link-index
|
26
|
-
# to connect revisions to changelog revisions based on node_ids
|
27
|
-
def bundle_initialize(opener, index_file, bundle_file, link_mapper = nil)
|
28
|
-
@bundle_file = bundle_file
|
29
|
-
@base_map = {}
|
30
|
-
|
31
|
-
num_revs = self.index_size
|
32
|
-
previous = nil
|
33
|
-
all_chunk_positions do |chunk, start|
|
34
|
-
chunk_size = chunk.size
|
35
|
-
|
36
|
-
# each chunk starts with 4 node IDs: the new node's ID, its 2 parent node IDs,
|
37
|
-
# and the node ID of the corresponding revision in the changelog. In that order.
|
38
|
-
# If we have less than 80 bytes (BUNDLED_INDEX_ENTRY_SIZE), then we're fucked.
|
39
|
-
if chunk_size < BUNDLED_INDEX_ENTRY_SIZE
|
40
|
-
raise abort("invalid changegroup")
|
41
|
-
end
|
42
|
-
|
43
|
-
start += BUNDLED_INDEX_ENTRY_SIZE
|
44
|
-
chunk_size -= BUNDLED_INDEX_ENTRY_SIZE
|
45
|
-
|
46
|
-
# Get the aforementioned node IDs
|
47
|
-
node, parent_1, parent_2, changeset = chunk[0..79].unpack("a20a20a20a20")
|
48
|
-
|
49
|
-
# Do we already have this node? Skip it.
|
50
|
-
if @index.has_node? node
|
51
|
-
previous = node
|
52
|
-
next
|
53
|
-
end
|
54
|
-
|
55
|
-
# make sure we have the new node's parents, or all of our operations will fail!
|
56
|
-
# at least, the interesting ones.
|
57
|
-
[parent_1, parent_2].each do |parent|
|
58
|
-
unless @index.has_node? parent
|
59
|
-
raise abort("Unknown parent: #{parent}@#{index_file}")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
link_rev = (link_mapper && link_mapper[changeset]) || num_revs
|
64
|
-
previous ||= parent_1
|
65
|
-
|
66
|
-
@index << [RevlogSupport::Support.offset_version(start, 0), chunk_size, -1, -1, link_rev,
|
67
|
-
revision_index_for_node(parent_1), revision_index_for_node(parent_2),
|
68
|
-
node]
|
69
|
-
|
70
|
-
@index.node_map[node] = num_revs
|
71
|
-
@base_map[num_revs] = previous
|
72
|
-
|
73
|
-
previous = node
|
74
|
-
num_revs += 1
|
75
|
-
end
|
76
|
-
end
|
77
|
-
alias_method :bundle_revlog_initialize, :initialize
|
78
|
-
##
|
79
|
-
# Returns whether the revision index is in the bundle part of this revlog,
|
80
|
-
# or if it's in the actual, stored revlog file.
|
81
|
-
#
|
82
|
-
# @param [Fixnum] revision the revision index to lookup
|
83
|
-
# @return [Boolean] is the revision in the bundle section?
|
84
|
-
def bundled_revision?(revision)
|
85
|
-
return false if revision < 0
|
86
|
-
!!@base_map[revision]
|
87
|
-
end
|
88
|
-
|
89
|
-
##
|
90
|
-
# Returns the base revision for the revision at the given index, while being
|
91
|
-
# cognizant of the bundle-ness of this revlog.
|
92
|
-
#
|
93
|
-
# @param [Fixnum] revision the revision index to lookup the base-revision of
|
94
|
-
# @return [String] the revision node ID of the base for the requested revision
|
95
|
-
def bundled_base_revision_for_index(revision)
|
96
|
-
@base_map[revision] || base_revision_for_index(revision)
|
97
|
-
end
|
98
|
-
alias_method :bundled_base, :bundled_base_revision_for_index
|
99
|
-
|
100
|
-
##
|
101
|
-
# Gets a chunk of data from the datafile (or, if inline, from the index
|
102
|
-
# file). Just give it a revision index and which data file to use. Only difference
|
103
|
-
# is that this will check the bundlefile if necessary.
|
104
|
-
#
|
105
|
-
# @param [Fixnum] rev the revision index to extract
|
106
|
-
# @param [IO] data_file The IO file descriptor for loading data
|
107
|
-
# @return [String] the raw data from the index (posssibly compressed)
|
108
|
-
def get_chunk(revision, datafile=nil, cache_len = 4096)
|
109
|
-
# Warning: in case of bundle, the diff is against bundlebase, not against
|
110
|
-
# rev - 1
|
111
|
-
# TODO: could use some caching
|
112
|
-
unless bundled_revision?(revision)
|
113
|
-
return super(revision, datafile)
|
114
|
-
end
|
115
|
-
@bundle_file.seek data_start_for_index(revision)
|
116
|
-
@bundle_file.read self[revision].compressed_len
|
117
|
-
end
|
118
|
-
|
119
|
-
##
|
120
|
-
# Diffs 2 revisions, based on their indices. They are returned in
|
121
|
-
# BinaryDiff format.
|
122
|
-
#
|
123
|
-
# @param [Fixnum] rev1 the index of the source revision
|
124
|
-
# @param [Fixnum] rev2 the index of the destination revision
|
125
|
-
# @return [String] The diff of the 2 revisions.
|
126
|
-
def revision_diff(rev1, rev2)
|
127
|
-
both_bundled = bundled_revision?(rev1) && bundled_revision?(rev2)
|
128
|
-
if both_bundled
|
129
|
-
# super-quick path if both are bundled and rev2 == rev1 + 1 diff
|
130
|
-
revision_base = self.revision_index_for_node bundled_base_revision_for_index(rev2)
|
131
|
-
if revision_base == rev1
|
132
|
-
# if rev2 = rev1 + a diff, just get the diff!
|
133
|
-
return get_chunk(revision2)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
# normal style
|
137
|
-
return super(rev1, rev2)
|
138
|
-
end
|
139
|
-
|
140
|
-
##
|
141
|
-
# Given a node ID, extracts that revision and decompresses it. What you get
|
142
|
-
# back will the pristine revision data! Checks for bundle-ness when we access
|
143
|
-
# a node.
|
144
|
-
#
|
145
|
-
# @param [String] node the Node ID of the revision to extract.
|
146
|
-
# @return [String] the pristine revision data.
|
147
|
-
def decompress_revision(node)
|
148
|
-
return "" if node == NULL_ID
|
149
|
-
|
150
|
-
text = nil
|
151
|
-
chain = []
|
152
|
-
iter_node = node
|
153
|
-
rev = revision_index_for_node(node)
|
154
|
-
# walk backwards down the chain. Every single node is going
|
155
|
-
# to be a diff, because it's from a bundle.
|
156
|
-
while bundled_revision? rev
|
157
|
-
if @index.cache && @index.cache[0] == iter_node
|
158
|
-
text = @index.cache[2]
|
159
|
-
break
|
160
|
-
end
|
161
|
-
chain << rev
|
162
|
-
iter_node = bundled_base_revision_for_index rev
|
163
|
-
rev = revision_index_for_node iter_node
|
164
|
-
end
|
165
|
-
# done walking back, see if we have a stored cache!
|
166
|
-
text = super(iter_node) if text.nil? || text.empty?
|
167
|
-
|
168
|
-
while chain.any?
|
169
|
-
delta = get_chunk(chain.pop)
|
170
|
-
text = Diffs::MercurialPatch.apply_patches(text, [delta])
|
171
|
-
end
|
172
|
-
p1, p2 = parents_for_node node
|
173
|
-
|
174
|
-
if node != RevlogSupport::Support.history_hash(text, p1, p2)
|
175
|
-
raise RevlogSupport::RevlogError.new("integrity check failed on %s:%d, data:%s" %
|
176
|
-
[(@index.inline? ? @index_file : @data_file), rev(node), text.inspect])
|
177
|
-
end
|
178
|
-
|
179
|
-
@index.cache = [node, revision_index_for_node(node), text]
|
180
|
-
text
|
181
|
-
end
|
182
|
-
|
183
|
-
##
|
184
|
-
# Give an error to enforce read-only behavior
|
185
|
-
def add_revision(text, transaction, link, p1, p2, d=nil, index_file_handle = nil)
|
186
|
-
raise NotImplementedError.new
|
187
|
-
end
|
188
|
-
|
189
|
-
##
|
190
|
-
# Give an error to enforce read-only behavior
|
191
|
-
def add_group(revisions, link_mapper, journal)
|
192
|
-
raise NotImplementedError.new
|
193
|
-
end
|
194
|
-
|
195
|
-
|
196
|
-
private
|
197
|
-
|
198
|
-
def all_chunk_positions
|
199
|
-
results = []
|
200
|
-
RevlogSupport::ChangeGroup.each_chunk(@bundle_file) do |chunk|
|
201
|
-
if block_given?
|
202
|
-
yield(chunk, @bundle_file.tell - chunk.size)
|
203
|
-
else
|
204
|
-
results << [chunk, @bundle_file.tell - chunk.size]
|
205
|
-
end
|
206
|
-
end
|
207
|
-
results unless block_given?
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
class BundleChangeLog < ChangeLog
|
212
|
-
include BundleRevlog
|
213
|
-
def initialize(opener, bundle_file)
|
214
|
-
# This is the changelog initializer
|
215
|
-
super(opener)
|
216
|
-
# This is the bundle initializer
|
217
|
-
bundle_initialize(opener, @index_file, bundle_file)
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
class BundleManifest < Manifest
|
222
|
-
include BundleRevlog
|
223
|
-
|
224
|
-
def initialize(opener, bundle_file, link_mapper)
|
225
|
-
# This is the manifest initializer
|
226
|
-
super(opener)
|
227
|
-
# This is the bundle initializer
|
228
|
-
bundle_initialize(opener, @index_file, bundle_file, link_mapper)
|
229
|
-
end
|
230
|
-
|
231
|
-
end
|
232
|
-
|
233
|
-
class BundleFileLog < FileLog
|
234
|
-
include BundleRevlog
|
235
|
-
|
236
|
-
def initialize(opener, path, bundle_file, link_mapper)
|
237
|
-
# This is the manifest initializer
|
238
|
-
super(opener, path)
|
239
|
-
# This is the bundle initializer
|
240
|
-
bundle_initialize(opener, @index_file, bundle_file, link_mapper)
|
241
|
-
end
|
242
|
-
|
243
|
-
end
|
244
|
-
|
245
|
-
end
|
246
|
-
end
|
@@ -1,217 +0,0 @@
|
|
1
|
-
require 'tempfile'
|
2
|
-
module Amp
|
3
|
-
module RevlogSupport
|
4
|
-
|
5
|
-
##
|
6
|
-
# This class handles changegroups - most specifically, packaging up a bunch
|
7
|
-
# of revisions into a single bundled file.
|
8
|
-
#
|
9
|
-
module ChangeGroup
|
10
|
-
BUNDLE_HEADERS = {
|
11
|
-
"" => "",
|
12
|
-
"HG10UN" => "HG10UN",
|
13
|
-
"HG10BZ" => "HG10",
|
14
|
-
"HG10GZ" => "HG10GZ"
|
15
|
-
}
|
16
|
-
FORMAT_PRIORITIES = BUNDLE_TYPES = ["HG10GZ", "HG10BZ", "HG10UN"]
|
17
|
-
class ChangeGroupError < StandardError; end
|
18
|
-
|
19
|
-
##
|
20
|
-
# Loads a single chunk of data from a changegroup. Each chunk is stored in the
|
21
|
-
# changegroup as:
|
22
|
-
# (uint32_t) length <-- less than 4 if we should terminate
|
23
|
-
# (length * char) body
|
24
|
-
# Example:
|
25
|
-
# 00 00 00 05 h e l l o
|
26
|
-
#
|
27
|
-
# @param [IO, #read] source the source stream with all the data that we'll be
|
28
|
-
# working on.
|
29
|
-
# @return [String] the data read in. Will be either nil or the empty string if
|
30
|
-
# no data was read.
|
31
|
-
def self.get_chunk(source)
|
32
|
-
data = source.read 4
|
33
|
-
return "" if data.nil? || data.empty?
|
34
|
-
l = data.unpack("N")[0]
|
35
|
-
return "" if l <= 4
|
36
|
-
data = source.read(l - 4)
|
37
|
-
if data.size < l - 4
|
38
|
-
raise ChangeGroupError.new("premature EOF when reading changegroup:" +
|
39
|
-
"(got #{data.size} bytes, expected #{l-4})")
|
40
|
-
end
|
41
|
-
return data
|
42
|
-
end
|
43
|
-
|
44
|
-
##
|
45
|
-
# Loads each chunk, in a row, until we run out of chunks in the changegroup.
|
46
|
-
# Yields the data to the caller. This will run until we hit a terminating chunk.
|
47
|
-
#
|
48
|
-
# @param [IO, #read] source The stream from which we will read the data in sequence
|
49
|
-
# @yield Each chunk of data will be yielded to be processed
|
50
|
-
# @yieldparam [String] chunk the chunk that is yielded
|
51
|
-
def self.each_chunk(source)
|
52
|
-
begin
|
53
|
-
c = self.get_chunk(source) # get a chunk
|
54
|
-
yield c unless c.empty? # yield if not empty
|
55
|
-
end until c.empty? # keep going if we have more!
|
56
|
-
end
|
57
|
-
|
58
|
-
##
|
59
|
-
# If we have data of size +size+, then return the encoded header for the chunk
|
60
|
-
#
|
61
|
-
# @param [Integer] size the size of the chunk we wish to encode
|
62
|
-
# @return [String] the encoded header for the chunk
|
63
|
-
def self.chunk_header(size)
|
64
|
-
[size + 4].pack("N")
|
65
|
-
end
|
66
|
-
|
67
|
-
##
|
68
|
-
# The terminating chunk that indicates the end of a chunk sequence
|
69
|
-
#
|
70
|
-
# @return [String] the encoded terminating chunk
|
71
|
-
def self.closing_chunk
|
72
|
-
"\000\000\000\000" # [0].pack("N")
|
73
|
-
end
|
74
|
-
|
75
|
-
##
|
76
|
-
# Returns a compressing stream based on the header for a changegroup bundle.
|
77
|
-
# The bundle header will specify that the contents should be either uncompressed,
|
78
|
-
# BZip compressed, or GZip compressed. This will return a stream that responds
|
79
|
-
# to #<< and #flush, where #flush will return the unread, decompressed data,
|
80
|
-
# and #<< will input uncompressed data.
|
81
|
-
#
|
82
|
-
# @param [String] header the header for the changegroup bundle. Can be either
|
83
|
-
# HG10UN, HG10GZ, or HG10BZ, or HG10.
|
84
|
-
# @return [IO, #<<, #flush] an IO stream that accepts uncompressed data via #<< or
|
85
|
-
# #write, and returns compressed data by #flush.
|
86
|
-
def self.compressor_by_type(header)
|
87
|
-
case header
|
88
|
-
when "HG10UN", ""
|
89
|
-
# new StringIO
|
90
|
-
result = StringIO.new "",(ruby_19? ? "w+:ASCII-8BIT" : "w+")
|
91
|
-
# have to fix the fact that StringIO doesn't conform to the other streams,
|
92
|
-
# and give it a #flush method. Kind of hackish.
|
93
|
-
class << result
|
94
|
-
def flush
|
95
|
-
ret = self.string.dup # get the current read-in string
|
96
|
-
self.string.replace "" # erase our contents
|
97
|
-
self.rewind # rewind the IO
|
98
|
-
self.tell
|
99
|
-
ret # return the string
|
100
|
-
end
|
101
|
-
end
|
102
|
-
#return the altered StringIO
|
103
|
-
result
|
104
|
-
when "HG10GZ"
|
105
|
-
# lazy-load Zlib
|
106
|
-
require 'zlib'
|
107
|
-
# Return a deflating stream (compressor)
|
108
|
-
Zlib::Deflate.new
|
109
|
-
when "HG10BZ", "HG10"
|
110
|
-
# lazy load BZip
|
111
|
-
need { '../../../ext/amp/bz2/bz2' }
|
112
|
-
# Return a compressing BZip stream
|
113
|
-
BZ2::Writer.new
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
##
|
118
|
-
# Returns a stream that will decompress the IO pointed to by file_handle,
|
119
|
-
# when #read is called upon it. Note: file_handle doesn't have to be a file!
|
120
|
-
#
|
121
|
-
# @param [String] header the header of the stream. Specifies which compression
|
122
|
-
# to handle
|
123
|
-
# @param [IO, #read] file_handle the input stream that will provide the compressed
|
124
|
-
# data.
|
125
|
-
# @return [IO, #read] an IO object that we can #read to get uncompressed data
|
126
|
-
def self.unbundle(header, file_handle)
|
127
|
-
# uncompressed? just return the input IO!
|
128
|
-
return file_handle if header == "HG10UN"
|
129
|
-
# if we have no header, we're uncompressed
|
130
|
-
if !header.start_with?("HG")
|
131
|
-
# append the header to it. meh
|
132
|
-
headerio = StringIO.new(header, (ruby_19? ? "w+:ASCII-8BIT" : "w+"))
|
133
|
-
Amp::Support::MultiIO.new(headerio, file_handle)
|
134
|
-
# WOW we have legacy support already
|
135
|
-
elsif header == "HG10GZ"
|
136
|
-
# Get a gzip reader
|
137
|
-
Zlib::GzipReader.new(file_handle)
|
138
|
-
elsif header == "HG10BZ"
|
139
|
-
# get a BZip reader, but it has to decompress "BZ" first. Meh.
|
140
|
-
headerio = StringIO.new("BZ", (ruby_19? ? "w+:ASCII-8BIT" : "w+"))
|
141
|
-
input = Amp::Support::MultiIO.new(headerio, file_handle)
|
142
|
-
BZ2::Reader.new(input)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
##
|
147
|
-
# Writes a set of changegroups to a bundle. If no IO is specified, a new StringIO
|
148
|
-
# is created, and the bundle is written to that (i.e., memory). the IO used is returned.
|
149
|
-
#
|
150
|
-
# @param [IO, #read, #seek] changegroup A stream that will feed in an uncompressed
|
151
|
-
# changegroup
|
152
|
-
# @param [String] bundletype A specified compression type - either "HG10UN", "HG10GZ",
|
153
|
-
# or "HG10BZ". The empty string defaults to "HG10UN".
|
154
|
-
# @param [IO, #write] fh (StringIO.new) An output stream to write to, such as a File
|
155
|
-
# or a socket. If not specified, a StringIO is created and returned.
|
156
|
-
# @return [IO, #write] the output IO stream is returned, even if a new one is not
|
157
|
-
# created on the fly.
|
158
|
-
def self.write_bundle(changegroup, bundletype, fh = StringIO.new("", (ruby_19? ? "w+:ASCII-8BIT" : "w+")))
|
159
|
-
# rewind the changegroup to start at the beginning
|
160
|
-
changegroup.rewind
|
161
|
-
# pick out our header
|
162
|
-
header = BUNDLE_HEADERS[bundletype]
|
163
|
-
# get a compressing stream
|
164
|
-
compressor = compressor_by_type header
|
165
|
-
# output the header (uncompressed)
|
166
|
-
fh.write header
|
167
|
-
|
168
|
-
# These 2 variables are for checking to see if #changegroup has been fully
|
169
|
-
# read in or not.
|
170
|
-
empty = false
|
171
|
-
count = 0
|
172
|
-
|
173
|
-
# Do at least 2 changegroups (changelog + manifest), then go until we're empty
|
174
|
-
while !empty || count <= 2
|
175
|
-
# Set empty to true for this particular file (each iteration of this loop
|
176
|
-
# represents compressing 1 file's changesets into changegroups in the bundle)
|
177
|
-
empty = true
|
178
|
-
# Add 1 to the number of files we've comrpessed
|
179
|
-
count += 1
|
180
|
-
# For each chunk in the changegroup (i.e. each changeset)
|
181
|
-
inner_count = 0
|
182
|
-
self.each_chunk(changegroup) do |chunk|
|
183
|
-
|
184
|
-
#puts "\t\twrite_bundle inner loop count #{inner_count}"
|
185
|
-
inner_count += 1
|
186
|
-
empty = false
|
187
|
-
# Compress the chunk header
|
188
|
-
compressor << chunk_header(chunk.size)
|
189
|
-
# Write the chunk header
|
190
|
-
fh.write(compressor.flush)
|
191
|
-
|
192
|
-
# compress the actual chunk 1 megabyte at a time
|
193
|
-
step_amt = 1048576
|
194
|
-
(0..chunk.size).step(step_amt) do |pos|
|
195
|
-
compressor << chunk[pos..(pos+step_amt-1)]
|
196
|
-
fh.write(compressor.flush)
|
197
|
-
fh.flush
|
198
|
-
end
|
199
|
-
end
|
200
|
-
# Compress the terminating chunk - this indicates that there are no more changesets
|
201
|
-
# for the current file
|
202
|
-
compressor << closing_chunk
|
203
|
-
# Write the terminating chunk out!
|
204
|
-
fh.write compressor.flush
|
205
|
-
fh.flush
|
206
|
-
end
|
207
|
-
|
208
|
-
# Write anything left over in that there compressor
|
209
|
-
fh.write compressor.flush
|
210
|
-
# Kill the compressor
|
211
|
-
compressor.close
|
212
|
-
# Return the IO we wrote to (in case we instantiated it)
|
213
|
-
return fh
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|