sapling/hgext/extlib/cstore/deltachain.cpp
Durham Goode f0d99a2e09 hg: clang format the cstore code
Summary: The linters complain about this now, so let's format everything.

Reviewed By: ryanmce

Differential Revision: D7057989

fbshipit-source-id: 987ad0dcaa2f4e8fb74b3aa19c496f378765a533
2018-04-13 21:51:17 -07:00

54 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;
}