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
83 lines
2.5 KiB
C++
83 lines
2.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.
|
|
|
|
// datapackstore.h - c++ declarations for a data pack store
|
|
// no-check-code
|
|
|
|
#ifndef FBHGEXT_DATAPACKSTORE_H
|
|
#define FBHGEXT_DATAPACKSTORE_H
|
|
|
|
extern "C" {
|
|
#include "lib/cdatapack/cdatapack.h"
|
|
}
|
|
|
|
#include <ctime>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <unordered_set>
|
|
#include <vector>
|
|
|
|
#include "hgext/extlib/cstore/datastore.h"
|
|
#include "hgext/extlib/cstore/key.h"
|
|
#include "lib/clib/portability/portability.h"
|
|
|
|
const clock_t PACK_REFRESH_RATE = 0.1 * CLOCKS_PER_SEC;
|
|
|
|
class DatapackStore;
|
|
class DatapackStoreKeyIterator : public KeyIterator {
|
|
private:
|
|
DatapackStore &_store;
|
|
KeyIterator &_missing;
|
|
|
|
public:
|
|
DatapackStoreKeyIterator(DatapackStore &store, KeyIterator &missing) :
|
|
_store(store),
|
|
_missing(missing) {}
|
|
|
|
Key *next() override;
|
|
};
|
|
|
|
/* Manages access to a directory of datapack files. */
|
|
class DatapackStore : public DataStore {
|
|
private:
|
|
std::string path_;
|
|
clock_t lastRefresh_;
|
|
bool removeOnRefresh_;
|
|
std::unordered_map<std::string, std::shared_ptr<datapack_handle_t>> packs_;
|
|
|
|
std::shared_ptr<datapack_handle_t> addPack(const std::string &path);
|
|
std::vector<std::shared_ptr<datapack_handle_t>> refresh();
|
|
|
|
public:
|
|
~DatapackStore();
|
|
/** Initialize the store for the specified path.
|
|
* If removeDeadPackFilesOnRefresh is set to true (NOT the default),
|
|
* then the refresh() method can choose to unmap pack files that
|
|
* have been deleted. Since the DataStore API doesn't provide
|
|
* for propagating ownership out through the DeltaChain and DeltaChain
|
|
* iterator, it is not safe to removeDeadPackFilesOnRefresh if the calling
|
|
* code is keeping longlived references to those values; it is the
|
|
* responsibility of the calling code to ensure that the lifetime is
|
|
* managed correctly as it cannot be enforced automatically without
|
|
* restructing this API.
|
|
*/
|
|
explicit DatapackStore(const std::string &path,
|
|
bool removeDeadPackFilesOnRefresh = false);
|
|
|
|
DeltaChainIterator getDeltaChain(const Key &key);
|
|
|
|
std::shared_ptr<KeyIterator> getMissing(KeyIterator &missing);
|
|
|
|
std::shared_ptr<DeltaChain> getDeltaChainRaw(const Key &key);
|
|
|
|
bool contains(const Key &key);
|
|
|
|
void markForRefresh();
|
|
};
|
|
|
|
#endif // FBHGEXT_DATAPACKSTORE_H
|