mirror of
https://github.com/facebook/sapling.git
synced 2024-10-12 01:39:21 +03:00
31bcfbe58e
Summary: They're actively fighting against the clang-format config and don't have an auto-fix. Reviewed By: quark-zju Differential Revision: D8283622 fbshipit-source-id: 2de45f50e6370a5ed14915c6ff23dc843ff14e8a
82 lines
2.0 KiB
C++
82 lines
2.0 KiB
C++
// pythondatastore.h - c++ declarations for a python data store
|
|
//
|
|
// Copyright 2017 Facebook, Inc.
|
|
//
|
|
// This software may be used and distributed according to the terms of the
|
|
// GNU General Public License version 2 or any later version.
|
|
//
|
|
// no-check-code
|
|
|
|
// The PY_SSIZE_T_CLEAN define must be defined before the Python.h include,
|
|
// as per the documentation.
|
|
|
|
#ifndef FBHGEXT_PYTHONDATASTORE_H
|
|
#define FBHGEXT_PYTHONDATASTORE_H
|
|
|
|
#define PY_SSIZE_T_CLEAN
|
|
#include <Python.h>
|
|
#include <memory>
|
|
|
|
#include "hgext/extlib/cstore/datastore.h"
|
|
#include "hgext/extlib/cstore/key.h"
|
|
#include "hgext/extlib/cstore/pythonutil.h"
|
|
|
|
/*
|
|
* Wrapper around python delta chain
|
|
*/
|
|
class PyDeltaChain : public DeltaChain {
|
|
private:
|
|
std::shared_ptr<std::vector<DeltaChainLink>> _chain;
|
|
std::shared_ptr<std::vector<PythonObj>> _pythonChainLinks;
|
|
|
|
public:
|
|
PyDeltaChain(
|
|
std::shared_ptr<std::vector<DeltaChainLink>> chain,
|
|
std::shared_ptr<std::vector<PythonObj>> pythonChainLinks)
|
|
: _chain(chain), _pythonChainLinks(pythonChainLinks) {}
|
|
|
|
// Default destructor is used, because the destructor of _chain
|
|
// and _tuples objects will free the allocated memory automatically.
|
|
~PyDeltaChain() {}
|
|
|
|
const DeltaChainLink getlink(const size_t idx) const override {
|
|
return _chain->at(idx);
|
|
}
|
|
|
|
size_t linkcount() const override {
|
|
return _chain->size();
|
|
}
|
|
|
|
get_delta_chain_code_t status() const override {
|
|
if (_chain->size()) {
|
|
return GET_DELTA_CHAIN_OK;
|
|
} else {
|
|
return GET_DELTA_CHAIN_NOT_FOUND;
|
|
}
|
|
}
|
|
};
|
|
|
|
class PythonDataStore : public DataStore {
|
|
private:
|
|
PythonObj _store; // pointer to python object
|
|
|
|
public:
|
|
PythonDataStore(PythonObj store);
|
|
|
|
~PythonDataStore() = default;
|
|
|
|
PythonObj getStore();
|
|
|
|
DeltaChainIterator getDeltaChain(const Key& key) override;
|
|
|
|
std::shared_ptr<KeyIterator> getMissing(KeyIterator& missing) override;
|
|
|
|
std::shared_ptr<DeltaChain> getDeltaChainRaw(const Key& key) override;
|
|
|
|
bool contains(const Key& key) override;
|
|
|
|
void markForRefresh() override;
|
|
};
|
|
|
|
#endif // FBHGEXT_PYTHONDATASTORE_H
|