lib/amp/revlogs/revlog.rb in amp-0.5.1 vs lib/amp/revlogs/revlog.rb in amp-0.5.2
- old
+ new
@@ -46,10 +46,11 @@
if @index.index.empty? || @index.is_a?(RevlogSupport::LazyIndex) ||
@index.index[-1].node_id.not_null?
# the use of @index.index is deliberate!
@index.index << RevlogSupport::IndexEntry.new(0,0,0,-1,-1,-1,-1,NULL_ID)
end
+
end
alias_method :revlog_initialize, :initialize
##
# Actually opens the file.
@@ -716,10 +717,11 @@
end
trindex = trinfo[:data]
data_offset = data_start_for_index trindex
tr.add @data_file, data_offset
df = open(@data_file, 'w')
+
begin
calc = @index.entry_size
self.size.times do |r|
start = data_start_for_index(r) + (r + 1) * calc
length = self[r].compressed_len
@@ -728,15 +730,27 @@
df.write d
end
ensure
df.close
end
+
fp.close
- ############ TODO
- # FINISH THIS METHOD
- ############ TODO
+ open(@index_file, 'w') do |fp| # automatically atomic
+ @version &= ~ RevlogSupport::Support::REVLOG_NG_INLINE_DATA
+ @inline = false
+ each do |i|
+ # THE FOLLOWING LINE IS NOT CORRECT
+ # IT IS DIRECTLY TRANSLATED PYTHON CODE
+ # I HAVE NO IDEA HOW WE DID THIS BEFORE
+ e = @io.pack_entry @index[i], @node, @version, i
+ fp.write e
+ end
+ end
+
+ tr.replace @index_file, trindex * calc
+ @chunk_cache = nil # reset the cache
end
##
# add a revision to the log
#
@@ -752,25 +766,28 @@
return node if @index.node_map[node]
curr = index_size
prev = curr - 1
base = self[prev].base_rev
offset = data_end_for_index prev
+
if curr > 0
if d.nil? || d.empty?
ptext = decompress_revision node_id_for_index(prev)
d = Diffs::MercurialDiff.text_diff(ptext, text)
end
data = RevlogSupport::Support.compress d
len = data[:compression].size + data[:text].size
dist = len + offset - data_start_for_index(base)
end
+
# Compressed diff > size of actual file
if curr == 0 || dist > text.size * 2
data = RevlogSupport::Support.compress text
len = data[:compression].size + data[:text].size
base = curr
end
+
entry = RevlogSupport::IndexEntry.new(RevlogSupport::Support.offset_version(offset, 0),
len, text.size, base, link, rev(p1), rev(p2), node)
@index << entry
@index.node_map[node] = curr
@index.write_entry(@index_file, entry, transaction, data, index_file_handle)
@@ -918,13 +935,10 @@
else
text = Diffs::MercurialPatch.apply_patches(text, [delta])
end
chk = add_revision(text, journal, link, parent1, parent2,
nil, index_file_handle)
- # if (! data_file_handle) && (! @index.inline?)
- # data_file_handle = open(@data_file, "a")
- # index_file_handle = open(@index_file, "a")
- # end
+
if chk != node
raise RevlogSupport::RevlogError.new("consistency error "+
"adding group")
end
text_len = text.size