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,123 +0,0 @@
|
|
1
|
-
|
2
|
-
module Amp
|
3
|
-
module Diffs
|
4
|
-
|
5
|
-
##
|
6
|
-
# This handles applying patches in mercurial. yay!!!!
|
7
|
-
module MercurialPatch
|
8
|
-
|
9
|
-
##
|
10
|
-
# This attempts to apply a series of patches in time proportional to
|
11
|
-
# the total size of the patches, rather than patches * len(text). This
|
12
|
-
# means rather than shuffling strings around, we shuffle around
|
13
|
-
# pointers to fragments with fragment lists.
|
14
|
-
#
|
15
|
-
# When the fragment lists get too long, we collapse them. To do this
|
16
|
-
# efficiently, we do all our operations inside a buffer created by
|
17
|
-
# mmap and simply use memmove. This avoids creating a bunch of large
|
18
|
-
# temporary string buffers.
|
19
|
-
#
|
20
|
-
# UPDATE 2AM BEFORE I GO BACK TO SCHOOL
|
21
|
-
# I FUCKING HATE PYTHON
|
22
|
-
def self.apply_patches(source, patches)
|
23
|
-
return source if patches.empty?
|
24
|
-
patch_lens = patches.map {|patch| patch.size}
|
25
|
-
pl = patch_lens.sum
|
26
|
-
bl = source.size + pl
|
27
|
-
tl = bl + bl + pl
|
28
|
-
b1, b2 = 0, bl
|
29
|
-
|
30
|
-
return a if tl == 0 #empty patches. lame.
|
31
|
-
|
32
|
-
output = StringIO.new "",(ruby_19? ? "r+:ASCII-8BIT" : "r+")
|
33
|
-
output.write source
|
34
|
-
|
35
|
-
frags = [[source.size, b1]]
|
36
|
-
|
37
|
-
pos = b2 + bl
|
38
|
-
output.seek pos
|
39
|
-
patches.each {|patch| output.write(patch)}
|
40
|
-
patch_lens.each do |plen|
|
41
|
-
if frags.size > 128
|
42
|
-
b2, b1 = b1, b2
|
43
|
-
frags = [self.collect(output,b1,frags)]
|
44
|
-
end
|
45
|
-
newarr = []
|
46
|
-
endpt = pos + plen
|
47
|
-
last = 0
|
48
|
-
while pos < endpt
|
49
|
-
output.seek pos
|
50
|
-
p1, p2, l = output.read(12).unpack("NNN")
|
51
|
-
self.pull(newarr, frags, p1 - last)
|
52
|
-
self.pull([], frags, p2 - p1)
|
53
|
-
newarr << [l, pos + 12]
|
54
|
-
pos += l + 12
|
55
|
-
last = p2
|
56
|
-
end
|
57
|
-
frags = newarr + frags
|
58
|
-
end
|
59
|
-
|
60
|
-
t = self.collect output, b2, frags
|
61
|
-
output.seek t[1]
|
62
|
-
output.read t[0]
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
def self.patched_size(orig, delta)
|
67
|
-
outlen, last, bin = 0, 0, 0
|
68
|
-
binend = delta.size
|
69
|
-
data = 12 # size of the delta instruction values (3 longs)
|
70
|
-
while data <= binend
|
71
|
-
decode = delta[bin..(bin+11)]
|
72
|
-
start, endpt, length = decode.unpack("NNN")
|
73
|
-
break if start > endpt
|
74
|
-
|
75
|
-
bin = data + length
|
76
|
-
data = bin + 12
|
77
|
-
outlen += start - last
|
78
|
-
last = endpt
|
79
|
-
outlen += length
|
80
|
-
end
|
81
|
-
|
82
|
-
raise "patch cannot be decoded" if bin != binend
|
83
|
-
|
84
|
-
outlen += orig - last
|
85
|
-
outlen
|
86
|
-
end
|
87
|
-
|
88
|
-
def self.copy_block(io, destination, source, count)
|
89
|
-
io.seek(source)
|
90
|
-
buf = io.read(count)
|
91
|
-
io.seek(destination)
|
92
|
-
io.write(buf)
|
93
|
-
end
|
94
|
-
|
95
|
-
##
|
96
|
-
#
|
97
|
-
def self.pull(dst, src, l)
|
98
|
-
until l == 0
|
99
|
-
f = src.shift
|
100
|
-
if f[0] > l
|
101
|
-
src.unshift [f[0] - l, f[1] + l]
|
102
|
-
dst << [l, f[1]]
|
103
|
-
return
|
104
|
-
end
|
105
|
-
dst << f
|
106
|
-
l -= f[0]
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
##
|
111
|
-
# Takes the fragments we've accumulated and applies them all to the IO.
|
112
|
-
def self.collect(io, buf, list)
|
113
|
-
start = buf
|
114
|
-
list.each do |l, p|
|
115
|
-
self.copy_block(io, buf, p, l)
|
116
|
-
buf += l
|
117
|
-
end
|
118
|
-
[buf - start, start]
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
@@ -1,164 +0,0 @@
|
|
1
|
-
module Amp
|
2
|
-
module Merges
|
3
|
-
|
4
|
-
##
|
5
|
-
# = MergeState
|
6
|
-
# MergeState handles the merge/ directory in the repository, in order
|
7
|
-
# to keep track of how well the current merge is progressing. There is
|
8
|
-
# a file called merge/state that lists all the files that need merging
|
9
|
-
# and a little info about whether it has beeen merged or not.
|
10
|
-
#
|
11
|
-
# You can add a file to the mergestate, iterate over all of them, quickly
|
12
|
-
# look up to see if a file is still dirty, and so on.
|
13
|
-
class MergeState
|
14
|
-
include Enumerable
|
15
|
-
|
16
|
-
##
|
17
|
-
# Initializes a new mergestate with the given repo, and reads in all the
|
18
|
-
# information from merge/state.
|
19
|
-
#
|
20
|
-
# @param repo the repository being inspected
|
21
|
-
def initialize(repo)
|
22
|
-
@repo = repo
|
23
|
-
read!
|
24
|
-
end
|
25
|
-
|
26
|
-
##
|
27
|
-
# Resets the merge status, by clearing all merge information and files
|
28
|
-
#
|
29
|
-
# @param node the node we're working with? seems kinda useless
|
30
|
-
def reset(node = nil)
|
31
|
-
@state = {}
|
32
|
-
@local = node if node
|
33
|
-
FileUtils.rm_rf @repo.join("merge")
|
34
|
-
end
|
35
|
-
alias_method :reset!, :reset
|
36
|
-
|
37
|
-
##
|
38
|
-
# Returns whether the file is part of a merge or not
|
39
|
-
#
|
40
|
-
# @return [Boolean] if the dirty file in our state and not nil?
|
41
|
-
def include?(dirty_file)
|
42
|
-
not @state[dirty_file].nil?
|
43
|
-
end
|
44
|
-
|
45
|
-
##
|
46
|
-
# Accesses the the given file's merge status - can be "u" for unmerged,
|
47
|
-
# or other stuff we haven't figured out yet.
|
48
|
-
#
|
49
|
-
# @param [String] dirty_file the path to the file for merging.
|
50
|
-
# @return [String] the status as a letter - so far "u" means unmerged or "r"
|
51
|
-
# for resolved.
|
52
|
-
def [](dirty_file)
|
53
|
-
@state[dirty_file] ? @state[dirty_file][0, 1] : ""
|
54
|
-
end
|
55
|
-
|
56
|
-
##
|
57
|
-
# Adds a file to the mergestate, which creates a separate file
|
58
|
-
# in the merge directory with all the information. I don't know
|
59
|
-
# what these parameters are for yet.
|
60
|
-
def add(fcl, fco, fca, fd, flags)
|
61
|
-
hash = Digest::SHA1.new.update(fcl.path).hexdigest
|
62
|
-
@repo.open("merge/#{hash}", "w") do |file|
|
63
|
-
file.write fcl.data
|
64
|
-
end
|
65
|
-
@state[fd] = ["u", hash, fcl.path, fca.path, fca.file_node.hexlify,
|
66
|
-
fco.path, flags]
|
67
|
-
save
|
68
|
-
end
|
69
|
-
|
70
|
-
##
|
71
|
-
# Iterates over all the files that are involved in the current
|
72
|
-
# merging transaction.
|
73
|
-
#
|
74
|
-
# @yield each file, sorted by filename, that needs merging.
|
75
|
-
# @yieldparam file the filename that needs (or has been) merged.
|
76
|
-
# @yieldparam state all the information about the current merge with
|
77
|
-
# this file.
|
78
|
-
def each
|
79
|
-
@state.keys.sort.each do |key|
|
80
|
-
yield(key, @state[key])
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
##
|
85
|
-
# Marks the given file with a given state, which is 1 letter. "u" means
|
86
|
-
# unmerged, "r" means resolved.
|
87
|
-
#
|
88
|
-
# @param [String] dirty_file the file path for marking
|
89
|
-
# @param [String] state the state - "u" for unmerged, "r" for resolved.
|
90
|
-
def mark(dirty_file, state)
|
91
|
-
@state[dirty_file][0] = state
|
92
|
-
save
|
93
|
-
end
|
94
|
-
|
95
|
-
##
|
96
|
-
# Resolves the given file for a merge between 2 changesets.
|
97
|
-
#
|
98
|
-
# @param dirty_file the path to the file for merging
|
99
|
-
# @param working_changeset the current changeset that is the destination
|
100
|
-
# of the merge
|
101
|
-
# @param other_changeset the newer changeset, which we're merging to
|
102
|
-
def resolve(dirty_file, working_changeset, other_changeset)
|
103
|
-
return 0 if self[dirty_file] == "r"
|
104
|
-
state, hash, lfile, afile, anode, ofile, flags = @state[dirty_file]
|
105
|
-
r = true
|
106
|
-
@repo.open("merge/#{hash}") do |file|
|
107
|
-
@repo.working_write(dirty_file, file.read, flags)
|
108
|
-
working_file = working_changeset[dirty_file]
|
109
|
-
other_file = other_changeset[ofile]
|
110
|
-
ancestor_file = @repo.versioned_file(afile, :file_id => anode)
|
111
|
-
r = UI.file_merge(@repo, @local, lfile, working_file, other_file, ancestor_file)
|
112
|
-
end
|
113
|
-
|
114
|
-
mark(dirty_file, "r") if r.nil? || r == false
|
115
|
-
return r
|
116
|
-
end
|
117
|
-
|
118
|
-
##
|
119
|
-
# Public access to writing the file.
|
120
|
-
def save
|
121
|
-
write!
|
122
|
-
end
|
123
|
-
alias_method :save!, :save
|
124
|
-
|
125
|
-
private
|
126
|
-
|
127
|
-
##
|
128
|
-
# Reads in the merge state and sets up all our instance variables.
|
129
|
-
#
|
130
|
-
def read!
|
131
|
-
@state = {}
|
132
|
-
ignore_missing_files do
|
133
|
-
local_node = nil
|
134
|
-
@repo.open("merge/state") do |file|
|
135
|
-
get_node = true
|
136
|
-
file.each_line do |line|
|
137
|
-
if get_node
|
138
|
-
local_node = line.chomp
|
139
|
-
get_node = false
|
140
|
-
else
|
141
|
-
parts = line.chomp.split("\0")
|
142
|
-
@state[parts[0]] = parts[1..-1]
|
143
|
-
end
|
144
|
-
end
|
145
|
-
@local = local_node.unhexlify
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
##
|
151
|
-
# Saves the merge state to disk.
|
152
|
-
#
|
153
|
-
def write!
|
154
|
-
@repo.open("merge/state","w") do |file|
|
155
|
-
file.write @local.hexlify + "\n"
|
156
|
-
@state.each do |key, val|
|
157
|
-
file.write "#{([key] + val).join("\0")}\n"
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
data/lib/amp/merges/merge_ui.rb
DELETED
@@ -1,322 +0,0 @@
|
|
1
|
-
require 'tempfile'
|
2
|
-
|
3
|
-
module Amp
|
4
|
-
module Merges
|
5
|
-
|
6
|
-
##
|
7
|
-
# This module handles figuring out how to merge files using the user's
|
8
|
-
# preferences. It is mixed into the UI class. The UI class must implement
|
9
|
-
# the "config" method.
|
10
|
-
module MergeUI
|
11
|
-
|
12
|
-
##
|
13
|
-
# Performs a 3-way merge in the working directory from vf_local to vf_other,
|
14
|
-
# using the common ancestor vf_ancestor.
|
15
|
-
#
|
16
|
-
# @todo change 1s and 0s to bools
|
17
|
-
# @todo consistent return type
|
18
|
-
#
|
19
|
-
# @param [Repository] repo the repository in which we are merging files
|
20
|
-
# @param [String] parent_node the node_id of the parent node before the merge
|
21
|
-
# @param [String] original_fn the original local filename before the merge
|
22
|
-
# @param [WorkingVersionedFile] vf_local the current, working-directory versioned file
|
23
|
-
# @param [VersionedFile] vf_other the file's changeset to which we are migrating
|
24
|
-
# @param [VersionedFile] vf_ancestor the common ancestor between vf_local and vf_other
|
25
|
-
# @return [Boolean] true if there were conflicts during the merge
|
26
|
-
def file_merge(repo, parent_node, original_fn, vf_local, vf_other, vf_ancestor)
|
27
|
-
is_binary = proc {|ctx| ctx.data.binary? rescue false}
|
28
|
-
|
29
|
-
return nil if !(vf_other.cmp vf_local.data)
|
30
|
-
|
31
|
-
path = vf_local.path
|
32
|
-
binary = is_binary[vf_local] || is_binary[vf_other] || is_binary[vf_ancestor]
|
33
|
-
symlink = (vf_local.flags + vf_other.flags).include? "l"
|
34
|
-
|
35
|
-
tool, tool_path = pick_tool(repo, path, binary, symlink)
|
36
|
-
UI.status("Picked tool #{tool} for #{path} (binary #{binary} symlink #{symlink})")
|
37
|
-
|
38
|
-
unless tool
|
39
|
-
tool = "internal:local"
|
40
|
-
if UI.ask("no tool found to merge #{path}\n"+
|
41
|
-
"keep (l)ocal or take (o)ther?") != "l"
|
42
|
-
tool = "internal:other"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
case tool
|
47
|
-
when "internal:local"
|
48
|
-
return 0
|
49
|
-
when "internal:other"
|
50
|
-
repo.working_write(path, vf_other.data, vf_other.flags)
|
51
|
-
return 0
|
52
|
-
when "internal:fail"
|
53
|
-
return 1
|
54
|
-
end
|
55
|
-
|
56
|
-
a = repo.working_join(path)
|
57
|
-
b_file = save_versioned_file_temp("base", vf_ancestor)
|
58
|
-
c_file = save_versioned_file_temp("other", vf_other)
|
59
|
-
b, c = b_file.path, c_file.path
|
60
|
-
|
61
|
-
out = ""
|
62
|
-
back = a + ".orig" + File.extname(a)
|
63
|
-
File.copy(a, back)
|
64
|
-
|
65
|
-
if original_fn != vf_other.path
|
66
|
-
UI.status("merging #{original_fn} and #{vf_other.path} to #{path}")
|
67
|
-
else
|
68
|
-
UI.status("merging #{path}")
|
69
|
-
end
|
70
|
-
|
71
|
-
if tool_setting(tool, "premerge", !(binary || symlink))
|
72
|
-
ret = ThreeWayMerger.three_way_merge(a, b, c, :quiet => true)
|
73
|
-
unless ret
|
74
|
-
UI.debug("premerge successful")
|
75
|
-
File.unlink(back)
|
76
|
-
File.safe_unlink(b)
|
77
|
-
File.safe_unlink(c)
|
78
|
-
return false
|
79
|
-
end
|
80
|
-
File.copy(back, a) # restore frmo backup and try again
|
81
|
-
end
|
82
|
-
|
83
|
-
environment = {"HG_FILE" => path,
|
84
|
-
"HG_MY_NODE" => parent_node.hexlify[0..11],
|
85
|
-
"HG_OTHER_NODE" => vf_other.changeset.to_s,
|
86
|
-
"HG_MY_ISLINK" => vf_local.flags.include?("l"),
|
87
|
-
"HG_OTHER_ISLINK" => vf_other.flags.include?("l"),
|
88
|
-
"HG_BASE_ISLINK" => vf_ancestor.flags.include?("l")}
|
89
|
-
if tool == "internal:merge"
|
90
|
-
ret = ThreeWayMerger.three_way_merge(a, b, c, :label => ['local', 'other'])
|
91
|
-
else
|
92
|
-
args = tool_setting_string(tool, "args", "$local $base $other")
|
93
|
-
if args.include?("$output")
|
94
|
-
out, a = a, back # read input from backup, write to original
|
95
|
-
end
|
96
|
-
replace = {"local" => a, "base" => b, "other" => c, "output" => out}
|
97
|
-
args.gsub!(/\$(local|base|other|output)/) { replace[$1]}
|
98
|
-
# shelling out
|
99
|
-
ret = Amp::Support::system(tool_path+" "+args, :chdir => repo.root, :environ => environment)
|
100
|
-
end
|
101
|
-
ret = (ret == true ? 1 : (ret == false ? 0 : ret))
|
102
|
-
if ret == 0 && tool_setting(tool, "checkconflicts")
|
103
|
-
if vf_local.data =~ /^(<<<<<<< .*|=======|>>>>>>> .*)$/
|
104
|
-
ret = 1
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
if ret == 0 && tool_setting(tool, "checkchanged")
|
109
|
-
if File.stat(repo.working_join(path)) === File.stat(back)
|
110
|
-
if UI::yes_or_no "output file #{path} appears unchanged\nwas merge successful?"
|
111
|
-
r = 1
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
fix_end_of_lines(repo.working_join(path), back) if tool_setting(tool, "fixeol")
|
117
|
-
|
118
|
-
if ret == 1
|
119
|
-
UI::warn "merging #{path} failed!"
|
120
|
-
else
|
121
|
-
File.unlink back
|
122
|
-
end
|
123
|
-
File.unlink b
|
124
|
-
File.unlink c
|
125
|
-
|
126
|
-
!ret.zero? # return
|
127
|
-
end
|
128
|
-
|
129
|
-
private
|
130
|
-
|
131
|
-
def save_versioned_file_temp(prefix, versioned_file)
|
132
|
-
prefix = "#{File.basename versioned_file.path}~#{prefix}"
|
133
|
-
|
134
|
-
tempfile = Tempfile.new prefix
|
135
|
-
path = tempfile.path
|
136
|
-
tempfile.write versioned_file.data
|
137
|
-
tempfile.close false # DON'T unlink it
|
138
|
-
|
139
|
-
tempfile
|
140
|
-
end
|
141
|
-
|
142
|
-
##
|
143
|
-
# Converts the end-of-line characters in a file to match the original file.
|
144
|
-
# Thus, if we merge from our copy to a new one, and there foreign
|
145
|
-
# end-of-line characters got merged in, we want to nuke them and put in our own!
|
146
|
-
#
|
147
|
-
# @param [String] new_file the path to the newly merged file
|
148
|
-
# @param [String] original_file the path to the original file
|
149
|
-
def fix_end_of_lines(new_file, original_file)
|
150
|
-
new_eol = guess_end_of_line(File.read(original_file))
|
151
|
-
if new_eol
|
152
|
-
data = File.read(new_file)
|
153
|
-
old_eol = guess_end_of_line(data)
|
154
|
-
if old_eol
|
155
|
-
new_data = data.gsub(old_eol, new_eol)
|
156
|
-
|
157
|
-
File.open(file, "w") {|f| f.write new_data } if new_data != data
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
|
163
|
-
##
|
164
|
-
# Guesses the end-of-line character for a file in a very lazy fashion.
|
165
|
-
#
|
166
|
-
# @param [String] data the file data to guess from
|
167
|
-
# @return [String, nil] the guessed end-of-line character(s).
|
168
|
-
def guess_end_of_line(data)
|
169
|
-
return nil if data.include?("\0") # binary
|
170
|
-
return "\r\n" if data.include?("\r\n") # windows
|
171
|
-
return "\r" if data.include?("\r") # old mac
|
172
|
-
return "\n" if data.include?("\n") # *nix
|
173
|
-
return nil # wtf?
|
174
|
-
end
|
175
|
-
|
176
|
-
##
|
177
|
-
# Picks a merge tool based on the user's settings in hgrc files and environment
|
178
|
-
# variables. Returns a hash specifying both the name and path of the
|
179
|
-
# merge tool's executable.
|
180
|
-
#
|
181
|
-
# @todo merge-patterns, line 56 of filemerge.py
|
182
|
-
# @param [Repository] repo the repository we are performing a merge upon
|
183
|
-
# @param [String] path the path to the file we're merging
|
184
|
-
# @param [Boolean] binary is the file a binary file?
|
185
|
-
# @param [Boolean] symlink is the file a symlink?
|
186
|
-
# @return [Hash] keyed as follows:
|
187
|
-
# :name => the name of the chosen tool
|
188
|
-
# :path => the path to the tool (if an executable is to be used)
|
189
|
-
def pick_tool(repo, path, binary, symlink)
|
190
|
-
hgmerge = ENV["HGMERGE"]
|
191
|
-
return [hgmerge, hgmerge] if hgmerge
|
192
|
-
|
193
|
-
# @todo: add merge-patterns support
|
194
|
-
|
195
|
-
# scan the merge-tools section
|
196
|
-
tools = {}
|
197
|
-
config["merge-tools"].each do |k, v|
|
198
|
-
t = k.split(".").first
|
199
|
-
unless tools[t]
|
200
|
-
tools[t] = tool_setting_string(t, "priority", "0").to_i
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
# go through the list of tools and sort by priority
|
205
|
-
tool_names = tools.keys
|
206
|
-
tools = tools.map {|tool, prio| [-prio, tool]}.sort
|
207
|
-
# check the [ui] section for a "merge" setting
|
208
|
-
uimerge = config["ui","merge"]
|
209
|
-
if uimerge
|
210
|
-
unless tool_names.include?(uimerge)
|
211
|
-
return [uimerge, uimerge]
|
212
|
-
end
|
213
|
-
tools.unshift([nil, uimerge]) # highest priority
|
214
|
-
end
|
215
|
-
|
216
|
-
# add the "hgmerge" binary
|
217
|
-
tools << [nil, "hgmerge"] # the old default, if found
|
218
|
-
# check everything in our list, and if we actually find one that works,
|
219
|
-
# return it
|
220
|
-
tools.each do |priority, tool|
|
221
|
-
if check_tool(tool, nil, symlink, binary)
|
222
|
-
tool_path = find_tool(tool)
|
223
|
-
return [tool, "\"#{tool_path}\""]
|
224
|
-
end
|
225
|
-
end
|
226
|
-
# last but not least, do a simple_merge.
|
227
|
-
return (!symlink && !binary) ? "internal:merge" : [nil, nil]
|
228
|
-
end
|
229
|
-
|
230
|
-
##
|
231
|
-
# Quick access to the merge-tools section of the configuration files.
|
232
|
-
# A merge tool will set it up with data like this:
|
233
|
-
# [merge-tools]
|
234
|
-
# awesometool.executable = /usr/bin/awesometool
|
235
|
-
# awesometool.regkey = HKEY_USELESS_INFO
|
236
|
-
# and so on. This method abstracts away the scheme for encoding this information
|
237
|
-
# gets string values from the configuration.
|
238
|
-
#
|
239
|
-
# @param [String] tool the name of the tool to look up data for
|
240
|
-
# @param [String] part the specific information about the tool to look up
|
241
|
-
# @param [String] default the default value, if the configuration setting
|
242
|
-
# can't be found
|
243
|
-
# @return [String] the setting for the given merge tool we're looking up, as
|
244
|
-
# as a string.
|
245
|
-
def tool_setting_string(tool, part, default="")
|
246
|
-
config["merge-tools", "#{tool}.#{part}", String, default]
|
247
|
-
end
|
248
|
-
|
249
|
-
##
|
250
|
-
# Quick access to the merge-tools section of the configuration files.
|
251
|
-
# Returns boolean values.
|
252
|
-
#
|
253
|
-
# @see check_tool_string
|
254
|
-
# @param [String] tool the name of the tool to look up data for
|
255
|
-
# @param [String] part the specific information about the tool to look up
|
256
|
-
# @param [Boolean] default the default value, if the configuration setting
|
257
|
-
# can't be found
|
258
|
-
# @return [Boolean] the setting for the given merge tool we're looking up, as
|
259
|
-
# as a string.
|
260
|
-
def tool_setting(tool, part, default=false)
|
261
|
-
config["merge-tools", "#{tool}.#{part}", Boolean, default]
|
262
|
-
end
|
263
|
-
|
264
|
-
##
|
265
|
-
# Given the name of a merge tool, attempt to locate an executable file
|
266
|
-
# for the tool.
|
267
|
-
#
|
268
|
-
# @param [String] tool the name of the merge tool to locate
|
269
|
-
# @return [String] the path to the executable for the merge tool, or nil
|
270
|
-
# if the tool cannot be found
|
271
|
-
def find_tool(tool)
|
272
|
-
if ["internal:fail", "internal:local", "internal:other"].include?(tool)
|
273
|
-
return tool
|
274
|
-
end
|
275
|
-
# windows stuff
|
276
|
-
k = tool_setting_string(tool, "regkey")
|
277
|
-
if k && k.any?
|
278
|
-
p = File.amp_lookup_reg(k, tool_setting_string(tool, "regname"))
|
279
|
-
if p && p.any?
|
280
|
-
p = File.amp_find_executable(p + check_tool_string(tool, "regappend"))
|
281
|
-
if p
|
282
|
-
return p
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
286
|
-
# normal *nix lookup
|
287
|
-
return File.amp_find_executable(tool_setting_string(tool, "executable", tool))
|
288
|
-
end
|
289
|
-
|
290
|
-
##
|
291
|
-
# Checks to see if a given tool is available given the necessary settings.
|
292
|
-
#
|
293
|
-
# @todo add GUI check
|
294
|
-
# @param [String] tool the name of the tool we want to check
|
295
|
-
# @param [String] pat the pattern we matched to get here. Could be nil.
|
296
|
-
# @param [Boolean] symlink are we merging across a symlink here?
|
297
|
-
# @param [Boolean] binary are we merging a binary file? you crazy?!
|
298
|
-
# @return [Boolean] is the given tool available?
|
299
|
-
def check_tool(tool, pat, symlink, binary)
|
300
|
-
tool_msg = tool
|
301
|
-
tool_msg += " specified for " + pat if pat
|
302
|
-
|
303
|
-
if !(find_tool tool)
|
304
|
-
if pat
|
305
|
-
warn("couldn't find merge tool #{tool}")
|
306
|
-
else
|
307
|
-
note("couldn't find merge tool #{tool}")
|
308
|
-
end
|
309
|
-
elsif symlink && !(tool_setting(tool, "symlink"))
|
310
|
-
warn("tool #{tool} can't handle symlinks")
|
311
|
-
elsif binary && !(tool_setting(tool, "binary"))
|
312
|
-
warn("tool #{tool} can't handle binary files")
|
313
|
-
elsif false # TODO: add GUI check
|
314
|
-
else
|
315
|
-
return true
|
316
|
-
end
|
317
|
-
return false # we're here if any of the previous checks created a warning
|
318
|
-
end
|
319
|
-
|
320
|
-
end
|
321
|
-
end
|
322
|
-
end
|