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,431 +0,0 @@
|
|
1
|
-
module Amp
|
2
|
-
module Repositories
|
3
|
-
##
|
4
|
-
# This module adds verification to Mercurial repositories.
|
5
|
-
#
|
6
|
-
# The main public method provided is #verify. The rest are support methods that
|
7
|
-
# will keep to themselves.
|
8
|
-
#
|
9
|
-
# This is directly ported from verify.py from the Mercurial source. This is for
|
10
|
-
# the simple reason that, because we are re-implementing Mercurial, we should
|
11
|
-
# rely on their verification over our own. If we discover bugs in their
|
12
|
-
# verification, we'll patch them and send in the patches to selenic, but for now, we'll
|
13
|
-
# trust that theirs is on the money.
|
14
|
-
module Verification
|
15
|
-
|
16
|
-
##
|
17
|
-
# Runs a verification sweep on the repository.
|
18
|
-
#
|
19
|
-
# @return [VerificationResult] the results of the verification, which
|
20
|
-
# includes error messages, warning counts, and so on.
|
21
|
-
def verify
|
22
|
-
result = Verifier.new(self).verify
|
23
|
-
end
|
24
|
-
|
25
|
-
##
|
26
|
-
# Handles all logic for verifying a single repository and collecting the results.
|
27
|
-
#
|
28
|
-
# Public interface: initialize with a repository and run #verify.
|
29
|
-
class Verifier
|
30
|
-
attr_accessor :repository
|
31
|
-
alias_method :repo, :repository
|
32
|
-
|
33
|
-
attr_reader :changelog, :manifest
|
34
|
-
|
35
|
-
##
|
36
|
-
# Creates a new Verifier. The Verifier can verify a Mercurial repository.
|
37
|
-
#
|
38
|
-
# @param [Repository] repo the repository this verifier will examine
|
39
|
-
def initialize(repo)
|
40
|
-
@repository = repo
|
41
|
-
@result = VerificationResult.new(0, 0, 0, 0, 0)
|
42
|
-
|
43
|
-
@bad_revisions = {}
|
44
|
-
@changelog = repo.changelog
|
45
|
-
@manifest = repo.manifest
|
46
|
-
end
|
47
|
-
|
48
|
-
##
|
49
|
-
# Runs a verification sweep on the repository this verifier is handling.
|
50
|
-
#
|
51
|
-
# @return [VerificationResult] the results of the verification, which
|
52
|
-
# includes error messages, warning counts, and so on.
|
53
|
-
def verify
|
54
|
-
# Maps manifest node IDs to the link revision to which they belong
|
55
|
-
manifest_linkrevs = Hash.new {|h,k| h[k] = []}
|
56
|
-
|
57
|
-
# Maps filenames to a list of link revisions (global revision #s) in which
|
58
|
-
# that file was changed
|
59
|
-
file_linkrevs = Hash.new {|h, k| h[k] = []}
|
60
|
-
|
61
|
-
# file_node_ids stores a hash for each file. The hash stored maps that file's node IDs
|
62
|
-
# (the node stored in the file log itself) to the global "link revision index" - the
|
63
|
-
# revision index in the changelog (and the one the user always sees)
|
64
|
-
file_node_ids = Hash.new {|h, k| h[k] = {}}
|
65
|
-
|
66
|
-
verify_changelog(manifest_linkrevs, file_linkrevs)
|
67
|
-
verify_manifest(manifest_linkrevs, file_node_ids)
|
68
|
-
verify_crosscheck(manifest_linkrevs, file_linkrevs, file_node_ids)
|
69
|
-
UI.status("checking files")
|
70
|
-
store_files = verify_store
|
71
|
-
verify_files(file_linkrevs, file_node_ids, store_files)
|
72
|
-
@result
|
73
|
-
end
|
74
|
-
|
75
|
-
##
|
76
|
-
# Verifies the changelog. Updates acceptable file_linkrevs and manifest_linkrevs
|
77
|
-
# along the way, since the changelog knows which files have been changed when,
|
78
|
-
# and which manifest entries go with which changelog entries.
|
79
|
-
#
|
80
|
-
# @param [Hash] manifest_linkrevs the mapping between manifest node IDs and changelog
|
81
|
-
# revision numbers
|
82
|
-
# @param [Hash] file_linkrevs a mapping between filenames and a list of changelog
|
83
|
-
# revision numbers where the file was modified, added, or deleted.
|
84
|
-
def verify_changelog(manifest_linkrevs, file_linkrevs)
|
85
|
-
Amp::UI.status("checking changelog...")
|
86
|
-
check_revlog(@changelog, "changelog")
|
87
|
-
seen = {}
|
88
|
-
# can't use the nice #each because it assumes functioning changelog and whatnot
|
89
|
-
@changelog.size.times do |idx|
|
90
|
-
node = @changelog.node_id_for_index idx
|
91
|
-
check_entry(@changelog, idx, node, seen, [idx], "changelog")
|
92
|
-
begin
|
93
|
-
changelog_entry = @changelog.read(node)
|
94
|
-
manifest_linkrevs[changelog_entry.first] << idx
|
95
|
-
changelog_entry[3].each {|f| file_linkrevs[f] << idx}
|
96
|
-
rescue Exception => err
|
97
|
-
exception(idx, "unpacking changeset #{node.short_hex}:", err, "changelog")
|
98
|
-
end
|
99
|
-
end
|
100
|
-
@result.changesets = @changelog.size
|
101
|
-
end
|
102
|
-
|
103
|
-
##
|
104
|
-
# Verifies the manifest and its nodes. Also updates file_node_ids to store the
|
105
|
-
# node ID of files at given points in the manifest's history.
|
106
|
-
#
|
107
|
-
# @param [Hash] manifest_linkrevs the mapping between manifest node IDs and changelog
|
108
|
-
# revision numbers
|
109
|
-
# @param [Hash] file_node_ids maps filenames to a mapping from file node IDs to global
|
110
|
-
# link revisions.
|
111
|
-
def verify_manifest(manifest_linkrevs, file_node_ids)
|
112
|
-
Amp::UI.status("checking manifests...")
|
113
|
-
check_revlog(@manifest, "manifest")
|
114
|
-
seen = {}
|
115
|
-
|
116
|
-
@manifest.size.times do |idx|
|
117
|
-
node = @manifest.node_id_for_index idx
|
118
|
-
link_rev = check_entry(@manifest, idx, node, seen, manifest_linkrevs[node], "manifest")
|
119
|
-
manifest_linkrevs.delete node
|
120
|
-
|
121
|
-
begin
|
122
|
-
@manifest.read_delta(node).each do |filename, file_node|
|
123
|
-
if filename.empty?
|
124
|
-
error(link_rev, "file without name in manifest")
|
125
|
-
elsif filename != "/dev/null"
|
126
|
-
file_node_map = file_node_ids[filename]
|
127
|
-
file_node_map[file_node] ||= idx
|
128
|
-
end
|
129
|
-
end
|
130
|
-
rescue Exception => err
|
131
|
-
exception(idx, "reading manfiest delta #{node.short_hex}", err, "manifest")
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
##
|
137
|
-
# Crosschecks the changelog agains the manifest and vice-versa. There should be no
|
138
|
-
# remaining unmatched manifest node IDs, nor any files not in file_node_map.
|
139
|
-
# A few other checks, too.
|
140
|
-
#
|
141
|
-
# @param [Hash] manifest_linkrevs the mapping between manifest node IDs and changelog
|
142
|
-
# revision numbers
|
143
|
-
# @param [Hash] file_linkrevs a mapping between filenames and a list of changelog
|
144
|
-
# revision numbers where the file was modified, added, or deleted.
|
145
|
-
# @param [Hash] file_node_ids maps filenames to a mapping from file node IDs to global
|
146
|
-
# link revisions.
|
147
|
-
def verify_crosscheck(manifest_linkrevs, file_linkrevs, file_node_ids)
|
148
|
-
Amp::UI.status("crosschecking files in changesets and manifests")
|
149
|
-
|
150
|
-
# Check for node IDs found in the changelog, but not the manifest
|
151
|
-
if @manifest.any?
|
152
|
-
# check for any manifest node IDs we found in changesets, but not in the manifest
|
153
|
-
manifest_linkrevs.map {|node, idx| [idx, node]}.sort.each do |idx, node|
|
154
|
-
error(idx, "changeset refers to unknown manifest #{node.short_hex}")
|
155
|
-
end
|
156
|
-
|
157
|
-
# check for any file node IDs we found in the changeset, but not in the manifest
|
158
|
-
file_linkrevs.sort.each do |file, _|
|
159
|
-
if file_node_ids[file].empty?
|
160
|
-
error(file_linkrevs[file].first, "in changeset but not in manifest", file)
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
# Check for node IDs found in the manifest, but not the changelog.
|
166
|
-
if @changelog.any?
|
167
|
-
file_node_ids.map {|file,_| file}.sort.each do |file|
|
168
|
-
unless file_linkrevs[file]
|
169
|
-
begin
|
170
|
-
filelog = @repository.file(file)
|
171
|
-
link_rev = file_node_ids[file].map {|node| filelog.link_revision_for_index(filelog.revision_index_for_node(node))}.min
|
172
|
-
rescue
|
173
|
-
link_rev = nil
|
174
|
-
end
|
175
|
-
error(link_rev, "in manifest but not in changeset", file)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
##
|
182
|
-
# Verifies the store, and returns a hash with names of files that are OK
|
183
|
-
#
|
184
|
-
# @return [Hash<String => Boolean>] a hash with filenames as keys and "true" or "false"
|
185
|
-
# as values, indicating whether the file exists and is accessible
|
186
|
-
def verify_store
|
187
|
-
store_files = {}
|
188
|
-
@repository.store.datafiles.each do |file, encoded_filename, size|
|
189
|
-
if file.nil? || file.empty?
|
190
|
-
error(nil, "can't decode filename from store: #{encoded_filename}")
|
191
|
-
elsif size > 0
|
192
|
-
store_files[file] = true
|
193
|
-
end
|
194
|
-
end
|
195
|
-
store_files
|
196
|
-
end
|
197
|
-
|
198
|
-
##
|
199
|
-
# Verifies the individual file logs one by one.
|
200
|
-
#
|
201
|
-
# @param [Hash] file_linkrevs a mapping between filenames and a list of changelog
|
202
|
-
# revision numbers where the file was modified, added, or deleted.
|
203
|
-
# @param [Hash] file_node_ids maps filenames to a mapping from file node IDs to global
|
204
|
-
# link revisions.
|
205
|
-
# @param [Hash] store_files a mapping keeping track of which file logs are in the store
|
206
|
-
def verify_files(file_linkrevs, file_node_ids, store_files)
|
207
|
-
files = (file_node_ids.keys + file_linkrevs.keys).uniq.sort
|
208
|
-
@result.files = files.size
|
209
|
-
files.each do |file|
|
210
|
-
link_rev = file_linkrevs[file].first
|
211
|
-
|
212
|
-
begin
|
213
|
-
file_log = @repository.file(file)
|
214
|
-
rescue Exception => err
|
215
|
-
error(link_rev, "broken revlog! (#{err})", file)
|
216
|
-
next
|
217
|
-
end
|
218
|
-
|
219
|
-
file_log.files.each do |ff|
|
220
|
-
unless store_files.delete(ff)
|
221
|
-
error(link_rev, "missing revlog!", ff)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
verify_filelog(file, file_log, file_linkrevs, file_node_ids)
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
##
|
230
|
-
# Verifies a single file log. This is a complicated process - we need to cross-
|
231
|
-
# check a lot of data, which is why this has been extracted into its own method.
|
232
|
-
#
|
233
|
-
# @param [String] filename the name of the file we're verifying
|
234
|
-
# @param [FileLog] file_log the file log we're verifying
|
235
|
-
# @param [Hash] file_linkrevs a mapping between filenames and a list of changelog
|
236
|
-
# revision numbers where the file was modified, added, or deleted.
|
237
|
-
# @param [Hash] file_node_ids maps filenames to a mapping from file node IDs to global
|
238
|
-
# link revisions.
|
239
|
-
def verify_filelog(file, file_log, file_linkrevs, file_node_ids)
|
240
|
-
check_revlog(file_log, file)
|
241
|
-
seen = {}
|
242
|
-
file_log.index_size.times do |idx|
|
243
|
-
@result.revisions += 1
|
244
|
-
node = file_log.node_id_for_index(idx)
|
245
|
-
link_rev = check_entry(file_log, idx, node, seen, file_linkrevs[file], file)
|
246
|
-
|
247
|
-
# Make sure that one of the manifests referenced the node ID. If not, one of our
|
248
|
-
# manifests is wrong!
|
249
|
-
if file_node_ids[file]
|
250
|
-
if @manifest.any? && !file_node_ids[file][node]
|
251
|
-
error(link_rev, "#{node.short_hex} not found in manifests", file)
|
252
|
-
else
|
253
|
-
file_node_ids[file].delete node
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
# Make sure the size of the uncompressed file is correct.
|
258
|
-
begin
|
259
|
-
text = file_log.read node
|
260
|
-
rename_info = file_log.renamed? node
|
261
|
-
if text.size != file_log.uncompressed_size_for_index(idx)
|
262
|
-
if file_log.decompress_revision(node).size != file_log.uncompressed_size_for_index(idx)
|
263
|
-
error(link_rev, "unpacked size is #{text.size}, #{file_log.size(idx)} expected", file)
|
264
|
-
end
|
265
|
-
end
|
266
|
-
rescue Exception => err
|
267
|
-
exception(link_rev, "unpacking #{node.short_hex}", err, file)
|
268
|
-
end
|
269
|
-
|
270
|
-
# Check if we screwed up renaming a file (like lost the source revlog or something)
|
271
|
-
begin
|
272
|
-
if rename_info && rename_info.any?
|
273
|
-
filelog_src = @repository.file(rename_info.first)
|
274
|
-
if filelog_src.index_size == 0
|
275
|
-
error(link_rev, "empty or missing copy source revlog "+
|
276
|
-
"#{rename_info[0]}, #{rename_info[1].short_hex}", file)
|
277
|
-
elsif rename_info[1] == RevlogSupport::Node::NULL_ID
|
278
|
-
warn("#{file}@#{link_rev}: copy source revision is NULL_ID "+
|
279
|
-
"#{rename_info[0]}:#{rename_info[1].short_hex}", file)
|
280
|
-
else
|
281
|
-
rev = filelog_src.revision_index_for_node(rename_info[1])
|
282
|
-
end
|
283
|
-
end
|
284
|
-
rescue Exception => err
|
285
|
-
exception(link_rev, "checking rename of #{node.short_hex}", err, file)
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
# Final cross-check
|
290
|
-
if file_node_ids[file] && file_node_ids[file].any?
|
291
|
-
file_node_ids[file].map { |node, link_rev|
|
292
|
-
[@manifest.link_revision_for_index(link_rev), node]
|
293
|
-
}.sort.each do |link_rev, node|
|
294
|
-
error(link_rev, "#{node.short_hex} in manifests not found", file)
|
295
|
-
end
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
private
|
300
|
-
|
301
|
-
##
|
302
|
-
# Checks a revlog for inconsistencies with the main format, such as
|
303
|
-
# having trailing bytes or incorrect formats
|
304
|
-
#
|
305
|
-
# @param [Revlog] log the log we will be verifying
|
306
|
-
# @param [String] name the name of the file this log is stored in
|
307
|
-
def check_revlog(log, name)
|
308
|
-
#p name
|
309
|
-
if log.empty? && (@changelog.any? || @revlog.any?)
|
310
|
-
return error(0, "#{name} is empty or missing")
|
311
|
-
end
|
312
|
-
|
313
|
-
size_diffs = log.checksize
|
314
|
-
# checksize returns a hash with these keys: index_diff, data_diff
|
315
|
-
if size_diffs[:data_diff] != 0
|
316
|
-
error(nil, "data size off by #{size_diffs[:data_diff]} bytes", name)
|
317
|
-
end
|
318
|
-
if size_diffs[:index_diff] != 0
|
319
|
-
error(nil, "index off by #{size_diffs[:index_diff]} bytes", name)
|
320
|
-
end
|
321
|
-
|
322
|
-
v0 = RevlogSupport::Support::REVLOG_VERSION_0
|
323
|
-
if log.index.version != v0
|
324
|
-
warn("#{name} uses revlog format 1. changelog uses format 0.") if @changelog.index.version == v0
|
325
|
-
elsif log.index.version == v0
|
326
|
-
warn("#{name} uses revlog format 0. that's really old.")
|
327
|
-
end
|
328
|
-
end
|
329
|
-
|
330
|
-
##
|
331
|
-
# Checks a single entry in a revision log for inconsistencies.
|
332
|
-
#
|
333
|
-
# @param [Revlog] log the revision log we're examining
|
334
|
-
# @param [Fixnum] revision the index # of the revision being examined
|
335
|
-
# @param [String] node the node ID of the revision being examined
|
336
|
-
# @param [Hash] seen the list of node IDs we've already seen
|
337
|
-
# @param [Array] ok_link_revisions the acceptable link revisions for the given entry
|
338
|
-
# @param [String] filename the name of the file containing the revlog
|
339
|
-
def check_entry(log, revision, node, seen, ok_link_revisions, filename)
|
340
|
-
link_rev = log.link_revision_for_index log.revision_index_for_node(node)
|
341
|
-
# is the link_revision invalid?
|
342
|
-
if link_rev < 0 || (changelog.any? && ! ok_link_revisions.include?(link_rev))
|
343
|
-
problem = (link_rev < 0 || link_rev >= changelog.size) ? "nonexistent" : "unexpected"
|
344
|
-
error(nil, "revision #{revision} points to #{problem} changeset #{link_rev}", filename)
|
345
|
-
|
346
|
-
if ok_link_revisions.any?
|
347
|
-
warn("(expected #{ok_link_revisions.join(" ")})")
|
348
|
-
end
|
349
|
-
link_rev = nil # don't use this link_revision, because it's clearly wrong.
|
350
|
-
end
|
351
|
-
|
352
|
-
begin
|
353
|
-
log.parents_for_node(node).each do |parent|
|
354
|
-
if !seen[parent] && parent != RevlogSupport::Node::NULL_ID
|
355
|
-
error(link_rev, "unknown parent #{parent.short_hex} of #{node.short_hex}", filename)
|
356
|
-
end
|
357
|
-
end
|
358
|
-
rescue StandardError => e
|
359
|
-
# TODO: do real exception handling
|
360
|
-
exception(link_rev, "error checking parents of #{node.short_hex}: ", e, filename)
|
361
|
-
end
|
362
|
-
|
363
|
-
if seen[node]
|
364
|
-
error(link_rev, "duplicate revision #{revision} (#{seen[node]})", filename)
|
365
|
-
end
|
366
|
-
seen[node] = revision
|
367
|
-
return link_rev
|
368
|
-
end
|
369
|
-
|
370
|
-
##
|
371
|
-
# Produce an error based on an exception. Matches mercurial's.
|
372
|
-
#
|
373
|
-
# @param [Fixnum] revision the link-revision the error is associated with
|
374
|
-
# @param [String, #to_s] message the message to print with the error
|
375
|
-
# @param [Exception] exception the exception that raised this error
|
376
|
-
# @param [String, #to_s] filename (nil) the name of the file with an error.
|
377
|
-
# nil for changelog/manifest
|
378
|
-
def exception(revision, message, exception, filename)
|
379
|
-
if exception.kind_of?(Interrupt)
|
380
|
-
UI.warn("interrupted")
|
381
|
-
raise
|
382
|
-
end
|
383
|
-
error(revision, "#{message} #{exception}\n", filename)
|
384
|
-
end
|
385
|
-
|
386
|
-
##
|
387
|
-
# Produce an error that looks like Mercurial's
|
388
|
-
# meh compatibility makes me sad
|
389
|
-
#
|
390
|
-
# @param [Fixnum] revision the link-revision the error is associated with
|
391
|
-
# @param [String, #to_s] message the message to print with the error
|
392
|
-
# @param [String, #to_s] filename (nil) the name of the file with an error.
|
393
|
-
# nil for changelog/manifest
|
394
|
-
def error(revision, message, filename = nil)
|
395
|
-
if revision
|
396
|
-
@bad_revisions[revision] = true
|
397
|
-
else
|
398
|
-
revision = "?"
|
399
|
-
end
|
400
|
-
new_message = "#{revision}: #{message}"
|
401
|
-
new_message = "#{filename}@#{new_message}" if filename
|
402
|
-
UI.say new_message
|
403
|
-
@result.errors += 1
|
404
|
-
end
|
405
|
-
|
406
|
-
##
|
407
|
-
# Adds a warning to the results
|
408
|
-
#
|
409
|
-
# @param [String, #to_s] message the user's warning
|
410
|
-
def warn(message)
|
411
|
-
UI.say "warning: #{message}"
|
412
|
-
@result.warnings += 1
|
413
|
-
end
|
414
|
-
end
|
415
|
-
|
416
|
-
##
|
417
|
-
# Simple struct that handles the results of a verification.
|
418
|
-
class VerificationResult < Struct.new(:warnings, :errors, :revisions, :files, :changesets)
|
419
|
-
def initialize(*args)
|
420
|
-
super(*args)
|
421
|
-
@warnings = 0
|
422
|
-
@errors = 0
|
423
|
-
@revisions = 0
|
424
|
-
@files = 0
|
425
|
-
@changesets = 0
|
426
|
-
end
|
427
|
-
end
|
428
|
-
|
429
|
-
end
|
430
|
-
end
|
431
|
-
end
|
@@ -1,475 +0,0 @@
|
|
1
|
-
|
2
|
-
module Amp
|
3
|
-
|
4
|
-
##
|
5
|
-
# This class allows you to access a file at a given revision in the repo's
|
6
|
-
# history. You can compare them, sort them, access the changeset, and
|
7
|
-
# all sorts of stuff.
|
8
|
-
class VersionedFile
|
9
|
-
include RevlogSupport::Node
|
10
|
-
|
11
|
-
attr_accessor :file_id
|
12
|
-
attr_writer :path
|
13
|
-
attr_writer :change_id
|
14
|
-
|
15
|
-
##
|
16
|
-
# Creates a new {VersionedFile}. You need to pass in the repo and the path
|
17
|
-
# to the file, as well as one of the following: a revision index/ID, the
|
18
|
-
# node_id of the file's revision in the filelog, or a changeset at a given
|
19
|
-
# index.
|
20
|
-
#
|
21
|
-
# @param [Repository] repo The repo we're working with
|
22
|
-
# @param [String] path the path to the file
|
23
|
-
# @param [Hash] opts the options to customize how we load this file
|
24
|
-
# @option [FileLog] opts :file_log (nil) The FileLog to use for loading data
|
25
|
-
# @option [String] opts :change_id (nil) The revision ID/index to use to
|
26
|
-
# figure out which revision we're working with
|
27
|
-
# @option [Changeset] opts :changeset (nil) the changeset to use to figure
|
28
|
-
# which revision we're working with
|
29
|
-
# @option [String] opts :file_id (nil) perhaps the ID of the revision in
|
30
|
-
# the file_log to use?
|
31
|
-
def initialize(repo, path, opts={})
|
32
|
-
@repo, @path = repo, path
|
33
|
-
raise StandardError.new("specify a revision!") unless opts[:change_id] ||
|
34
|
-
opts[:file_id] ||
|
35
|
-
opts[:changeset]
|
36
|
-
@file_log = opts[:file_log] if opts[:file_log]
|
37
|
-
@change_id = opts[:change_id] if opts[:change_id]
|
38
|
-
@changeset = opts[:changeset] if opts[:changeset]
|
39
|
-
@file_id = opts[:file_id] if opts[:file_id]
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
def <=>(other)
|
44
|
-
to_i <=> other.to_i
|
45
|
-
end
|
46
|
-
|
47
|
-
def to_i
|
48
|
-
change_id
|
49
|
-
end
|
50
|
-
|
51
|
-
##
|
52
|
-
# Returns the changeset that this file belongs to
|
53
|
-
#
|
54
|
-
# @return [Changeset] the changeset this file belongs to
|
55
|
-
def changeset
|
56
|
-
@changeset ||= Changeset.new @repo, change_id
|
57
|
-
end
|
58
|
-
|
59
|
-
##
|
60
|
-
# Dunno why this is here
|
61
|
-
#
|
62
|
-
def repo_path
|
63
|
-
@path
|
64
|
-
end
|
65
|
-
|
66
|
-
##
|
67
|
-
# The file log that tracks this file
|
68
|
-
#
|
69
|
-
# @return [FileLog] The revision log tracking this file
|
70
|
-
def file_log
|
71
|
-
@file_log ||= @repo.file @path
|
72
|
-
end
|
73
|
-
|
74
|
-
##
|
75
|
-
# The revision index into the history of the repository. Could also
|
76
|
-
# be a node_id
|
77
|
-
def change_id
|
78
|
-
@change_id ||= @changeset.revision if @changeset
|
79
|
-
@change_id ||= file_log[file_rev].link_rev unless @changeset
|
80
|
-
@change_id
|
81
|
-
end
|
82
|
-
|
83
|
-
def file_node
|
84
|
-
@file_node ||= file_log.lookup_id(@file_id) if @file_id
|
85
|
-
@file_node ||= changeset.file_node(@path) unless @file_id
|
86
|
-
@file_node ||= NULL_ID
|
87
|
-
end
|
88
|
-
|
89
|
-
##
|
90
|
-
# Returns the index into the file log's history for this file
|
91
|
-
def file_rev
|
92
|
-
@file_rev ||= file_log.rev(file_node)
|
93
|
-
end
|
94
|
-
|
95
|
-
##
|
96
|
-
# Is this a null version?
|
97
|
-
def nil?
|
98
|
-
file_node.nil?
|
99
|
-
end
|
100
|
-
|
101
|
-
##
|
102
|
-
# String representation.
|
103
|
-
def to_s
|
104
|
-
"#{path}@#{node.hexlify[0..11]}"
|
105
|
-
end
|
106
|
-
|
107
|
-
##
|
108
|
-
# IRB Inspector string representation
|
109
|
-
def inspect
|
110
|
-
"#<Versioned File: #{to_s}>"
|
111
|
-
end
|
112
|
-
|
113
|
-
##
|
114
|
-
# Hash value for sticking this fucker in a hash
|
115
|
-
def hash
|
116
|
-
return (path + file_id.to_s).hash
|
117
|
-
end
|
118
|
-
|
119
|
-
##
|
120
|
-
# Equality! Compares paths and revision indexes
|
121
|
-
def ==(other)
|
122
|
-
return false unless @path && @file_id && other.path && other.file_id
|
123
|
-
@path == other.path && @file_id == other.file_id
|
124
|
-
end
|
125
|
-
|
126
|
-
##
|
127
|
-
# Retrieves the file with a different ID
|
128
|
-
#
|
129
|
-
# @param file_id a new file ID... still not sure what a file_id is
|
130
|
-
def file(file_id)
|
131
|
-
self.class.new @repo, @path, :file_id => file_id, :file_log => file_log
|
132
|
-
end
|
133
|
-
|
134
|
-
# Gets the flags for this file (x and l)
|
135
|
-
def flags; changeset.flags(@path); end
|
136
|
-
|
137
|
-
# Returns the revision index
|
138
|
-
def revision
|
139
|
-
return changeset.rev if @changeset || @change_id
|
140
|
-
file_log[file_rev].link_rev
|
141
|
-
end
|
142
|
-
|
143
|
-
# Link-revision index
|
144
|
-
def linkrev; file_log[file_rev].link_rev; end
|
145
|
-
# Node ID for this file's revision
|
146
|
-
def node; changeset.node; end
|
147
|
-
# User who committed this revision to this file
|
148
|
-
def user; changeset.user; end
|
149
|
-
# Date this revision to this file was committed
|
150
|
-
def date; changeset.date; end
|
151
|
-
# All files in this changeset that this revision of this file was committed
|
152
|
-
def files; changeset.files; end
|
153
|
-
# The description of the commit that contained this file revision
|
154
|
-
def description; changeset.description; end
|
155
|
-
# The branch this tracked file belongs to
|
156
|
-
def branch; changeset.branch; end
|
157
|
-
# THe manifest that this file revision is from
|
158
|
-
def manifest; changeset.manifest; end
|
159
|
-
# The data in this file
|
160
|
-
def data; file_log.read(file_node); end
|
161
|
-
# The path to this file
|
162
|
-
def path; @path; end
|
163
|
-
# The size of this file
|
164
|
-
def size; file_log.size(file_rev); end
|
165
|
-
|
166
|
-
##
|
167
|
-
# Compares to a bit of text.
|
168
|
-
# Returns true if different, false for the same.
|
169
|
-
# (much like <=> == 0 for the same)
|
170
|
-
def cmp(text)
|
171
|
-
file_log.cmp(file_node, text)
|
172
|
-
end
|
173
|
-
|
174
|
-
##
|
175
|
-
# Just the opposite of #cmp
|
176
|
-
#
|
177
|
-
# @param [VersionedFile] other what to compare to
|
178
|
-
# @return [Boolean] true if the two are the same
|
179
|
-
def ===(other)
|
180
|
-
!self.cmp(other.data)
|
181
|
-
end
|
182
|
-
|
183
|
-
##
|
184
|
-
# Has this file been renamed? If so, return some useful info
|
185
|
-
def renamed
|
186
|
-
renamed = file_log.renamed(file_node)
|
187
|
-
return renamed unless renamed
|
188
|
-
|
189
|
-
return renamed if rev == linkrev
|
190
|
-
|
191
|
-
name = path
|
192
|
-
fnode = file_node
|
193
|
-
changeset.parents.each do |p|
|
194
|
-
pnode = p.filenode(name)
|
195
|
-
next if pnode.nil?
|
196
|
-
return nil if fnode == pnode
|
197
|
-
end
|
198
|
-
renamed
|
199
|
-
end
|
200
|
-
|
201
|
-
##
|
202
|
-
# What are this revised file's parents? Return them as {VersionedFile}s.
|
203
|
-
def parents
|
204
|
-
p = @path
|
205
|
-
fl = file_log
|
206
|
-
pl = file_log.parents(file_node).map {|n| [p, n, fl]}
|
207
|
-
|
208
|
-
r = file_log.renamed(file_node)
|
209
|
-
pl[0] = [r[0], r[1], nil] if r
|
210
|
-
|
211
|
-
pl.select {|parent,n,l| n != NULL_ID}.map do |parent, n, l|
|
212
|
-
VersionedFile.new(@repo, parent, :file_id => n, :file_log => l)
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
##
|
217
|
-
# What are this file's children?
|
218
|
-
def children
|
219
|
-
c = file_log.children(file_node)
|
220
|
-
c.map do |x|
|
221
|
-
VersionedFile.new(@repo, @path, :file_id => x, :file_log => file_log)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
def annotate_decorate(text, revision, line_number = false)
|
226
|
-
if line_number
|
227
|
-
size = text.split("\n").size
|
228
|
-
retarr = [nil,text]
|
229
|
-
retarr[0] = (1..size).map {|i| [revision, i]}
|
230
|
-
else
|
231
|
-
retarr = [nil, text]
|
232
|
-
retarr[0] = [[revision, false]] * text.split("\n").size
|
233
|
-
end
|
234
|
-
retarr
|
235
|
-
end
|
236
|
-
|
237
|
-
def annotate_diff_pair(parent, child)
|
238
|
-
Diffs::BinaryDiff.blocks_as_array(parent[1], child[1]).each do |a1,a2,b1,b2|
|
239
|
-
child[0][b1..(b2-1)] = parent[0][a1..(a2-1)]
|
240
|
-
end
|
241
|
-
child
|
242
|
-
end
|
243
|
-
|
244
|
-
def annotate_get_file(path, file_id)
|
245
|
-
log = (path == @path) ? file_log : @repo.get_file(path)
|
246
|
-
return VersionedFile.new(@repo, path, :file_id => file_id, :file_log => log)
|
247
|
-
end
|
248
|
-
|
249
|
-
def annotate_parents_helper(file, follow_copies = false)
|
250
|
-
path = file.path
|
251
|
-
if file.file_rev.nil?
|
252
|
-
parent_list = file.parents.map {|n| [n.path, n.file_rev]}
|
253
|
-
else
|
254
|
-
parent_list = file.file_log.parent_indices_for_index(file.file_rev)
|
255
|
-
parent_list.map! {|n| [path, n]}
|
256
|
-
end
|
257
|
-
if follow_copies
|
258
|
-
r = file.renamed
|
259
|
-
pl[0] = [r[0], @repo.get_file(r[0]).revision(r[1])] if r
|
260
|
-
end
|
261
|
-
return parent_list.select {|p, n| n != NULL_REV}.
|
262
|
-
map {|p, n| annotate_get_file(p, n)}
|
263
|
-
end
|
264
|
-
|
265
|
-
def annotate(follow_copies = false, line_number = false)
|
266
|
-
base = (revision != linkrev) ? file(file_rev) : self
|
267
|
-
|
268
|
-
needed = {base => 1}
|
269
|
-
counters = {(base.path + base.file_id.to_s) => 1}
|
270
|
-
visit = [base]
|
271
|
-
files = [base.path]
|
272
|
-
|
273
|
-
while visit.any?
|
274
|
-
file = visit.shift
|
275
|
-
annotate_parents_helper(file).each do |p|
|
276
|
-
unless needed.include? p
|
277
|
-
needed[p] = 1
|
278
|
-
counters[p.path + p.file_id.to_s] = 1
|
279
|
-
visit << p
|
280
|
-
files << p.path unless files.include? p.path
|
281
|
-
end
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
visit = []
|
286
|
-
files.each do |f|
|
287
|
-
filenames = needed.keys.select {|k| k.path == f}.map {|n| [n.revision, n]}
|
288
|
-
visit += filenames
|
289
|
-
end
|
290
|
-
|
291
|
-
hist = {}
|
292
|
-
lastfile = ""
|
293
|
-
visit.sort.each do |rev, file_ann|
|
294
|
-
curr = annotate_decorate(file_ann.data, file_ann, line_number)
|
295
|
-
annotate_parents_helper(file_ann).each do |p|
|
296
|
-
next if p.file_id == NULL_ID
|
297
|
-
curr = annotate_diff_pair(hist[p.path + p.file_id.to_s], curr)
|
298
|
-
counters[p.path + p.file_id.to_s] -= 1
|
299
|
-
hist.delete(p.path + p.file_id.to_s) if counters[p.path + p.file_id.to_s] == 0
|
300
|
-
end
|
301
|
-
hist[file_ann.path+file_ann.file_id.to_s] = curr
|
302
|
-
lastfile = file_ann
|
303
|
-
end
|
304
|
-
returnarr = []
|
305
|
-
hist[lastfile.path+lastfile.file_id.to_s].inspect # force all lazy-loading to stoppeth
|
306
|
-
ret = hist[lastfile.path+lastfile.file_id.to_s][0].each_with_index do |obj, i|
|
307
|
-
returnarr << obj + [hist[lastfile.path+lastfile.file_id.to_s][1].split_newlines[i]]
|
308
|
-
end
|
309
|
-
# hist[lastfile.path+lastfile.file_id.to_s][0][i] + hist[lastfile.path+lastfile.file_id.to_s][1].split_newlines[i]
|
310
|
-
# end
|
311
|
-
ret = hist[lastfile.path+lastfile.file_id.to_s][0].zip(hist[lastfile.path+lastfile.file_id.to_s][1].split_newlines)
|
312
|
-
returnarr
|
313
|
-
end
|
314
|
-
|
315
|
-
def get_parents_helper(vertex, ancestor_cache, filelog_cache)
|
316
|
-
return ancestor_cache[vertex] if ancestor_cache[vertex]
|
317
|
-
file, node = vertex
|
318
|
-
filelog_cache[file] = @repo.get_file(file) unless filelog_cache[file]
|
319
|
-
|
320
|
-
filelog = filelog_cache[file]
|
321
|
-
parent_list = filelog.parents(node).select {|p| p != NULL_ID}.map {|p| [file, p]}
|
322
|
-
|
323
|
-
has_renamed = filelog.renamed(node)
|
324
|
-
|
325
|
-
parent_list << has_renamed if has_renamed
|
326
|
-
ancestor_cache[vertex] = parent_list
|
327
|
-
parent_list
|
328
|
-
end
|
329
|
-
|
330
|
-
def ancestor(file_2)
|
331
|
-
ancestor_cache = {}
|
332
|
-
[self, file_2].each do |c|
|
333
|
-
if c.file_rev == NULL_REV || c.file_rev.nil?
|
334
|
-
parent_list = c.parents.map {|n| [n.path, n.file_node]}
|
335
|
-
ancestor_cache[[c.path, c.file_node]] = parent_list
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
filelog_cache = {repo_path => file_log, file_2.repo_path => file_2.file_log}
|
340
|
-
a, b = [path, file_node], [file_2.path, file_2.file_node]
|
341
|
-
parents_proc = proc {|vertex| get_parents_helper(vertex, ancestor_cache, filelog_cache)}
|
342
|
-
|
343
|
-
v = Graphs::AncestorCalculator.ancestors(a, b, parents_proc)
|
344
|
-
if v
|
345
|
-
file, node = v
|
346
|
-
return VersionedFile.new(@repo, file, :file_id => node, :file_log => filelog_cache[file])
|
347
|
-
end
|
348
|
-
return nil
|
349
|
-
end
|
350
|
-
|
351
|
-
end
|
352
|
-
|
353
|
-
##
|
354
|
-
# This is a VersionedFile, except it's in the working directory, so its data
|
355
|
-
# is stored on disk in the actual file. Other than that, it's basically the
|
356
|
-
# same in its interface!
|
357
|
-
class VersionedWorkingFile < VersionedFile
|
358
|
-
|
359
|
-
##
|
360
|
-
# Initializes a new working dir file - slightly different semantics here
|
361
|
-
def initialize(repo, path, opts={})
|
362
|
-
@repo, @path = repo, path
|
363
|
-
@change_id = nil
|
364
|
-
@file_rev, @file_node = nil, nil
|
365
|
-
|
366
|
-
@file_log = opts[:file_log] if opts[:file_log]
|
367
|
-
@changeset = opts[:working_changeset]
|
368
|
-
end
|
369
|
-
|
370
|
-
##
|
371
|
-
# Gets the working directory changeset
|
372
|
-
def changeset
|
373
|
-
@changeset ||= WorkingDirectoryChangeset.new(@repo)
|
374
|
-
end
|
375
|
-
|
376
|
-
##
|
377
|
-
# Dunno why this is here
|
378
|
-
def repo_path
|
379
|
-
@repo.dirstate.copy_map[@path] || @path
|
380
|
-
end
|
381
|
-
|
382
|
-
##
|
383
|
-
# Gets the file log?
|
384
|
-
def file_log
|
385
|
-
@repo.file(repo_path)
|
386
|
-
end
|
387
|
-
|
388
|
-
##
|
389
|
-
# String representation
|
390
|
-
def to_s
|
391
|
-
"#{path}@#{@changeset}"
|
392
|
-
end
|
393
|
-
|
394
|
-
##
|
395
|
-
# Returns the file at a different revision
|
396
|
-
def file(file_id)
|
397
|
-
VersionedFile.new(@repo, repo_path, :file_id => file_id, :file_log => file_log)
|
398
|
-
end
|
399
|
-
|
400
|
-
##
|
401
|
-
# Get what revision this is
|
402
|
-
def revision
|
403
|
-
return @changeset.revision if @changeset
|
404
|
-
file_log[@file_rev].link_rev
|
405
|
-
end
|
406
|
-
|
407
|
-
##
|
408
|
-
# Get the contents of this file
|
409
|
-
def data
|
410
|
-
data = @repo.working_read(@path)
|
411
|
-
data
|
412
|
-
end
|
413
|
-
|
414
|
-
##
|
415
|
-
# Has this file been renamed? If so give some good info.
|
416
|
-
def renamed
|
417
|
-
rp = repo_path
|
418
|
-
return nil if rp == @path
|
419
|
-
[rp, (self.changeset.parents[0].manifest[rp] || NULL_ID)]
|
420
|
-
end
|
421
|
-
|
422
|
-
##
|
423
|
-
# The working directory's parents are the heads, so get this file in
|
424
|
-
# the previous revision.
|
425
|
-
def parents
|
426
|
-
p = @path
|
427
|
-
rp = repo_path
|
428
|
-
pcl = @changeset.parents
|
429
|
-
fl = file_log
|
430
|
-
pl = [[rp, pcl[0].manifest[rp] || NULL_ID, fl]]
|
431
|
-
if pcl.size > 1
|
432
|
-
if rp != p
|
433
|
-
fl = nil
|
434
|
-
end
|
435
|
-
pl << [p, pcl[1].manifest[p] || NULL_ID, fl]
|
436
|
-
end
|
437
|
-
pl.select {|_, n, __| n != NULL_ID}.map do |parent, n, l|
|
438
|
-
VersionedFile.new(@repo, parent, :file_id => n, :file_log => l)
|
439
|
-
end
|
440
|
-
end
|
441
|
-
|
442
|
-
##
|
443
|
-
# Working directory has no children!
|
444
|
-
def children; []; end
|
445
|
-
|
446
|
-
##
|
447
|
-
# Returns the current size of the file
|
448
|
-
#
|
449
|
-
def size
|
450
|
-
File.stat(@repo.join(@path)).size
|
451
|
-
end
|
452
|
-
|
453
|
-
##
|
454
|
-
# Returns the date that this file was last modified.
|
455
|
-
def date
|
456
|
-
t, tz = changeset.date
|
457
|
-
begin
|
458
|
-
return [FileUtils.lstat(@repo.join(@path)).mtime, tz]
|
459
|
-
rescue Errno::ENOENT
|
460
|
-
return [t, tz]
|
461
|
-
end
|
462
|
-
end
|
463
|
-
|
464
|
-
##
|
465
|
-
# Compares to the given text. Overridden because this file is
|
466
|
-
# stored on disk in the actual working directory.
|
467
|
-
#
|
468
|
-
# @param [String] text the text to compare to
|
469
|
-
# @return [Boolean] true if the two are different
|
470
|
-
def cmp(text)
|
471
|
-
@repo.working_read(@path) != text
|
472
|
-
end
|
473
|
-
|
474
|
-
end
|
475
|
-
end
|