mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
Merge pull request #36568 from overleaf/bg-add-ranges-hash-to-add-file-operation-find-blob-hashes
include range hashes in findBlobHashes for AddFileOperation GitOrigin-RevId: 5d31f7efbe409b8c0433607152f66262f99cb94c
This commit is contained in:
@@ -55,7 +55,9 @@ class AddFileOperation extends Operation {
|
||||
/** @inheritdoc */
|
||||
findBlobHashes(blobHashes) {
|
||||
const hash = this.file.getHash()
|
||||
const rangesHash = this.file.getRangesHash()
|
||||
if (hash) blobHashes.add(hash)
|
||||
if (rangesHash) blobHashes.add(rangesHash)
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
|
||||
@@ -38,6 +38,28 @@ describe('Change', function () {
|
||||
expect(blobHashes.size).to.equal(1)
|
||||
expect(blobHashes.has(File.EMPTY_FILE_HASH)).to.be.true
|
||||
})
|
||||
|
||||
it('finds blob hashes from operations with ranges', function () {
|
||||
const blobHashes = new Set()
|
||||
const fileHash = 'a5675307b61ec2517330622a6e649b4ca1ee5612'
|
||||
const rangesHash = '380de212d09bf8498065833dbf242aaf11184316'
|
||||
|
||||
const change = Change.fromRaw({
|
||||
operations: [],
|
||||
timestamp: '2015-03-05T12:03:53.035Z',
|
||||
authors: [null],
|
||||
})
|
||||
|
||||
// AddFile with file and ranges hashes.
|
||||
change.pushOperation(
|
||||
Operation.addFile('c.txt', File.fromHash(fileHash, rangesHash))
|
||||
)
|
||||
change.findBlobHashes(blobHashes)
|
||||
// Both file and ranges hashes should be found
|
||||
expect(blobHashes.size).to.equal(2)
|
||||
expect(blobHashes.has(fileHash)).to.be.true
|
||||
expect(blobHashes.has(rangesHash)).to.be.true
|
||||
})
|
||||
})
|
||||
|
||||
describe('RestoreFileOrigin', function () {
|
||||
|
||||
@@ -10,7 +10,7 @@ const Snapshot = core.Snapshot
|
||||
|
||||
describe('History', function () {
|
||||
describe('findBlobHashes', function () {
|
||||
it('finds blob hashes from snapshot and changes', function () {
|
||||
it('finds blob and ranges hashes from snapshot and changes', function () {
|
||||
const history = new History(new Snapshot(), [])
|
||||
|
||||
const blobHashes = new Set()
|
||||
@@ -22,20 +22,49 @@ describe('History', function () {
|
||||
history.findBlobHashes(blobHashes)
|
||||
expect(Array.from(blobHashes)).to.have.members([File.EMPTY_FILE_HASH])
|
||||
|
||||
// Add a file with a hash and ranges hash to the snapshot.
|
||||
const snapshotRangesHash = '0'.repeat(40)
|
||||
history
|
||||
.getSnapshot()
|
||||
.addFile(
|
||||
'foo-with-ranges',
|
||||
File.fromHash(File.EMPTY_FILE_HASH, snapshotRangesHash)
|
||||
)
|
||||
history.findBlobHashes(blobHashes)
|
||||
expect(Array.from(blobHashes)).to.have.members([
|
||||
File.EMPTY_FILE_HASH,
|
||||
snapshotRangesHash,
|
||||
])
|
||||
|
||||
// Add a file with a hash to the changes.
|
||||
const testHash = 'a'.repeat(40)
|
||||
const change = Change.fromRaw({
|
||||
const change1 = Change.fromRaw({
|
||||
operations: [],
|
||||
timestamp: '2015-03-05T12:03:53.035Z',
|
||||
authors: [null],
|
||||
})
|
||||
change.pushOperation(Operation.addFile('bar', File.fromHash(testHash)))
|
||||
change1.pushOperation(Operation.addFile('bar', File.fromHash(testHash)))
|
||||
|
||||
history.pushChanges([change])
|
||||
// Add a file with a hash and ranges hash to the changes.
|
||||
const fileHash = 'b'.repeat(40)
|
||||
const rangesHash = 'c'.repeat(40)
|
||||
const change2 = Change.fromRaw({
|
||||
operations: [],
|
||||
timestamp: '2015-03-05T12:04:53.035Z',
|
||||
authors: [null],
|
||||
})
|
||||
change2.pushOperation(
|
||||
Operation.addFile('bar', File.fromHash(fileHash, rangesHash))
|
||||
)
|
||||
|
||||
history.pushChanges([change1, change2])
|
||||
history.findBlobHashes(blobHashes)
|
||||
expect(Array.from(blobHashes)).to.have.members([
|
||||
File.EMPTY_FILE_HASH,
|
||||
snapshotRangesHash,
|
||||
testHash,
|
||||
fileHash,
|
||||
rangesHash,
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user