mirror of
https://github.com/facebook/sapling.git
synced 2024-10-12 09:48:05 +03:00
a3e8a19f3c
Summary: pull in the following revisions from the copy of this code we had under fbsource/scm/hgext: 2f7e4f11e002cf33e4878df77d6a0472adf31245 D6099388 e2a5a711e36c7392129b8753bea37c89a5d73a9c D6099754 77b975dcde28cd7c3d4ae2302bddb625682d1994 D6099753 Reviewed By: simpkins Differential Revision: D6792967 fbshipit-source-id: e91a74329cddaf322172d3c7d9e1a05b3b6cba02
53 lines
1.5 KiB
C++
53 lines
1.5 KiB
C++
// Copyright (c) 2004-present, Facebook, Inc.
|
|
// All Rights Reserved.
|
|
//
|
|
// This software may be used and distributed according to the terms of the
|
|
// GNU General Public License version 2 or any later version.
|
|
|
|
// deltachain.cpp - c++ implementation of deltachain and related classes
|
|
// no-check-code
|
|
|
|
#include "hgext/extlib/cstore/deltachain.h"
|
|
|
|
DeltaChainIterator::~DeltaChainIterator()
|
|
{
|
|
}
|
|
|
|
DeltaChainLink DeltaChainIterator::next() {
|
|
std::shared_ptr<DeltaChain> chain = _chains.back();
|
|
|
|
if (_index >= chain->linkcount()) {
|
|
// If we're not at the end, and we have a callback to fetch more, do the
|
|
// fetch.
|
|
bool refreshed = false;
|
|
if (chain->linkcount() > 0) {
|
|
DeltaChainLink result = chain->getlink(_index - 1);
|
|
|
|
const uint8_t *deltabasenode = result.deltabasenode();
|
|
if (memcmp(deltabasenode, NULLID, BIN_NODE_SIZE) != 0) {
|
|
Key key(result.filename(), result.filenamesz(),
|
|
(const char*)deltabasenode, BIN_NODE_SIZE);
|
|
|
|
std::shared_ptr<DeltaChain> newChain = this->getNextChain(key);
|
|
if (newChain->status() == GET_DELTA_CHAIN_OK) {
|
|
// Do not free the old chain, since the iterator consumer may
|
|
// still be holding references to it.
|
|
_chains.push_back(newChain);
|
|
chain = _chains.back();
|
|
_index = 0;
|
|
refreshed = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!refreshed) {
|
|
return DeltaChainLink(NULL);
|
|
}
|
|
}
|
|
|
|
DeltaChainLink result = chain->getlink(_index);
|
|
_index++;
|
|
|
|
return result;
|
|
}
|