build: remove //eden/scm:cstore

Summary: This is unused, let's remove it.

Reviewed By: DurhamG

Differential Revision: D24037722

fbshipit-source-id: bc8a272809cb1f20f54d651a39ee42ff57169534
This commit is contained in:
Xavier Deguillard 2020-10-02 10:43:21 -07:00 committed by Facebook GitHub Bot
parent 5672facb89
commit c16ab69c6a
6 changed files with 0 additions and 593 deletions

View File

@ -1,54 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
// py-cstore.cpp - C++ implementation of a store
// no-check-code
// The PY_SSIZE_T_CLEAN define must be defined before the Python.h include,
// as per the documentation.
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "edenscm/hgext/extlib/cstore/py-datapackstore.h"
#include "edenscm/hgext/extlib/cstore/py-treemanifest.h"
static PyMethodDef mod_methods[] = {{NULL, NULL}};
static char mod_description[] =
"Module containing a native store implementation";
PyMODINIT_FUNC initcstore(void) {
PyObject* mod;
mod = Py_InitModule3("cstore", mod_methods, mod_description);
// Init treemanifest
treemanifestType.tp_new = PyType_GenericNew;
if (PyType_Ready(&treemanifestType) < 0) {
return;
}
Py_INCREF(&treemanifestType);
PyModule_AddObject(mod, "treemanifest", (PyObject*)&treemanifestType);
// Init datapackstore
datapackstoreType.tp_new = PyType_GenericNew;
if (PyType_Ready(&datapackstoreType) < 0) {
return;
}
Py_INCREF(&datapackstoreType);
PyModule_AddObject(mod, "datapackstore", (PyObject*)&datapackstoreType);
// Init datapackstore
uniondatapackstoreType.tp_new = PyType_GenericNew;
if (PyType_Ready(&uniondatapackstoreType) < 0) {
return;
}
Py_INCREF(&uniondatapackstoreType);
PyModule_AddObject(
mod, "uniondatapackstore", (PyObject*)&uniondatapackstoreType);
}

View File

@ -1,134 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
// pythondatastore.cpp - implementation of a python data store
// no-check-code
#include "edenscm/hgext/extlib/cstore/pythondatastore.h"
#include "edenscm/hgext/extlib/cstore/pythonkeyiterator.h"
PythonDataStore::PythonDataStore(PythonObj store) : _store(store) {}
DeltaChainIterator PythonDataStore::getDeltaChain(const Key& key) {
std::shared_ptr<DeltaChain> chain = getDeltaChainRaw(key);
return DeltaChainIterator(chain);
}
std::shared_ptr<DeltaChain> PythonDataStore::getDeltaChainRaw(const Key& key) {
// Extract the delta chain from the list of tuples
// and build a DeltaChain object from them
std::shared_ptr<std::vector<DeltaChainLink>> links =
std::make_shared<std::vector<DeltaChainLink>>();
std::shared_ptr<std::vector<PythonObj>> tuples =
std::make_shared<std::vector<PythonObj>>();
// Build (name, node) tuple and call getdeltachain
// method of the underlying store
PythonObj pyKey = Py_BuildValue(
"(s#s#)", (key.name).c_str(), (key.name).size(), key.node, 20);
PythonObj list;
try {
list = _store.callmethod("getdeltachain", pyKey);
} catch (const pyexception& ex) {
if (PyErr_ExceptionMatches(PyExc_KeyError)) {
// Clear the exception, otherwise next method call will exit immediately
PyErr_Clear();
// Return empty Delta Chain which status is GET_DELTA_CHAIN_NOT_FOUND
return std::make_shared<PyDeltaChain>(links, tuples);
} else {
// If this is not a KeyError exception then rethrow it
throw;
}
}
PythonObj iter = PyObject_GetIter(list);
PyObject* item;
while ((item = PyIter_Next(iter)) != NULL) {
PythonObj tuple(item);
const char *filename, *deltabasefilename;
const uint8_t *node, *deltabasenode, *delta;
uint16_t filenamesz, deltabasefilenamesz;
uint64_t deltasz, nodesz, deltabasenodesz;
if (!PyArg_ParseTuple(
tuple,
"s#z#s#z#z#",
&filename,
&filenamesz,
&node,
&nodesz,
&deltabasefilename,
&deltabasefilenamesz,
&deltabasenode,
&deltabasenodesz,
&delta,
&deltasz)) {
throw pyexception();
}
links->push_back(DeltaChainLink(
filename,
deltabasefilename,
node,
deltabasenode,
delta,
filenamesz,
deltabasefilenamesz,
deltasz));
tuples->push_back(tuple);
}
return std::make_shared<PyDeltaChain>(links, tuples);
}
std::shared_ptr<KeyIterator> PythonDataStore::getMissing(KeyIterator& missing) {
PythonObj list = PyList_New(0);
Key* key;
while ((key = missing.next()) != NULL) {
PythonObj pyKey = Py_BuildValue(
"(s#s#)", key->name.c_str(), key->name.size(), key->node, 20);
if (PyList_Append(list, (PyObject*)pyKey)) {
throw pyexception();
}
}
PythonObj arg = Py_BuildValue("(O)", (PyObject*)list);
PythonObj keys = _store.callmethod("getmissing", arg);
PythonObj iter = PyObject_GetIter((PyObject*)keys);
return std::make_shared<PythonKeyIterator>(iter);
}
void PythonDataStore::markForRefresh() {
PythonObj args = Py_BuildValue("");
_store.callmethod("markforrefresh", args);
}
class Single : public KeyIterator {
public:
Key* _k;
Single(Key* k) : _k(k) {}
Key* next() override {
Key* tmp = _k;
_k = NULL;
return tmp;
}
};
bool PythonDataStore::contains(const Key& key) {
Single iter((Key*)&key);
std::shared_ptr<KeyIterator> it = getMissing(iter);
return (!it->next());
}
PythonObj PythonDataStore::getStore() {
return this->_store;
}

View File

@ -1,82 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
// pythondatastore.h - c++ declarations for a python data store
// 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 "edenscm/hgext/extlib/cstore/datastore.h"
#include "edenscm/hgext/extlib/cstore/key.h"
#include "edenscm/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

View File

@ -1,184 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
// pythonutil.cpp - utilities to glue C++ code to python
// no-check-code
#include "pythonutil.h"
PythonObj::PythonObj() : obj(NULL) {}
PythonObj::PythonObj(PyObject* obj) {
if (!obj) {
if (!PyErr_Occurred()) {
PyErr_SetString(
PyExc_RuntimeError, "attempted to construct null PythonObj");
}
throw pyexception();
}
this->obj = obj;
}
PythonObj::PythonObj(const PythonObj& other) {
this->obj = other.obj;
Py_XINCREF(this->obj);
}
PythonObj::~PythonObj() {
Py_XDECREF(this->obj);
}
PythonObj& PythonObj::operator=(const PythonObj& other) {
Py_XDECREF(this->obj);
this->obj = other.obj;
Py_XINCREF(this->obj);
return *this;
}
bool PythonObj::operator==(const PythonObj& other) const {
return this->obj == other.obj;
}
PythonObj::operator PyObject*() const {
return this->obj;
}
PythonObj::operator bool() const {
return this->obj != NULL;
}
/**
* Function used to obtain a return value that will persist beyond the life
* of the PythonObj. This is useful for returning objects to Python C apis
* and letting them manage the remaining lifetime of the object.
*/
PyObject* PythonObj::returnval() {
Py_XINCREF(this->obj);
return this->obj;
}
/**
* Invokes getattr to retrieve the attribute from the python object.
*/
PythonObj PythonObj::getattr(const char* name) {
return PyObject_GetAttrString(this->obj, name);
}
/**
* Executes the current callable object if it's callable.
*/
PythonObj PythonObj::call(const PythonObj& args) {
PyObject* result = PyEval_CallObject(this->obj, args);
return PythonObj(result);
}
/**
* Invokes the specified method on this instance.
*/
PythonObj PythonObj::callmethod(const char* name, const PythonObj& args) {
PythonObj function = this->getattr(name);
return PyObject_CallObject(function, args);
}
PythonStore::PythonStore(PythonObj store)
: _get(store.getattr("get")), _storeObj(store) {}
PythonStore::PythonStore(const PythonStore& store)
: _get(store._get), _storeObj(store._storeObj) {}
ConstantStringRef PythonStore::get(const Key& key) {
PythonObj arglist = Py_BuildValue(
"s#s#",
key.name.c_str(),
(Py_ssize_t)key.name.size(),
key.node,
(Py_ssize_t)BIN_NODE_SIZE);
PyObject* result = PyEval_CallObject(_get, arglist);
if (!result) {
if (PyErr_Occurred()) {
throw pyexception();
}
PyErr_Format(
PyExc_RuntimeError,
"unable to find tree '%.*s:...'",
(int)key.name.size(),
key.name.c_str());
throw pyexception();
}
PythonObj resultobj(result);
char* path;
Py_ssize_t pathlen;
if (PyString_AsStringAndSize((PyObject*)result, &path, &pathlen)) {
throw pyexception();
}
return ConstantStringRef(path, pathlen);
}
bool PythonMatcher::matches(const std::string& path) {
PythonObj matchArgs =
Py_BuildValue("(s#)", path.c_str(), (Py_ssize_t)path.size());
PythonObj matched = this->_matcherObj.call(matchArgs);
return PyObject_IsTrue(matched) == 1;
}
bool PythonMatcher::matches(const char* path, const size_t pathlen) {
PythonObj matchArgs = Py_BuildValue("(s#)", path, (Py_ssize_t)pathlen);
PythonObj matched = this->_matcherObj.call(matchArgs);
return PyObject_IsTrue(matched) == 1;
}
bool PythonMatcher::visitdir(const std::string& path) {
Py_ssize_t size = path.size();
if (size > 1 && path[size - 1] == '/') {
size--;
}
PythonObj matchArgs = Py_BuildValue("(s#)", path.c_str(), (Py_ssize_t)size);
PythonObj matched = this->_matcherObj.callmethod("visitdir", matchArgs);
return PyObject_IsTrue(matched) == 1;
}
void PythonDiffResult::add(
const std::string& path,
const char* beforeNode,
const char* beforeFlag,
const char* afterNode,
const char* afterFlag) {
Py_ssize_t beforeLen = beforeNode != NULL ? BIN_NODE_SIZE : 0;
Py_ssize_t afterLen = afterNode != NULL ? BIN_NODE_SIZE : 0;
PythonObj entry = Py_BuildValue(
"((s#s#)(s#s#))",
beforeNode,
beforeLen,
(beforeFlag == NULL) ? MAGIC_EMPTY_STRING : beforeFlag,
Py_ssize_t(beforeFlag ? 1 : 0),
afterNode,
afterLen,
(afterFlag == NULL) ? MAGIC_EMPTY_STRING : afterFlag,
Py_ssize_t(afterFlag ? 1 : 0));
PythonObj pathObj = PyString_FromStringAndSize(path.c_str(), path.length());
if (PyDict_SetItem(this->_diff, pathObj, entry)) {
throw pyexception();
}
}
void PythonDiffResult::addclean(const std::string& path) {
PythonObj pathObj = PyString_FromStringAndSize(path.c_str(), path.length());
Py_INCREF(Py_None);
if (PyDict_SetItem(this->_diff, pathObj, Py_None)) {
throw pyexception();
}
}

View File

@ -1,134 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
// pythonutil.h - utilities to glue C++ code to python
// no-check-code
#ifndef FBHGEXT_CSTORE_PYTHONUTIL_H
#define FBHGEXT_CSTORE_PYTHONUTIL_H
// The PY_SSIZE_T_CLEAN define must be defined before the Python.h include,
// as per the documentation.
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <exception>
// Py_BuildValue treats NULL as NONE, so we have to have a non-null pointer.
#define MAGIC_EMPTY_STRING ""
#include "edenscm/hgext/extlib/cstore/key.h"
#include "edenscm/hgext/extlib/cstore/match.h"
#include "edenscm/hgext/extlib/cstore/store.h"
#include "edenscm/hgext/extlib/ctreemanifest/treemanifest.h"
/**
* C++ exception that represents an issue at the python C api level.
* When this is thrown, it's assumed that the python error message has been set
* and that the catcher of the exception should just return an error code value
* to the python API.
*/
class pyexception : public std::exception {
public:
pyexception() {}
};
/**
* Wrapper class for PyObject pointers.
* It is responsible for managing the Py_INCREF and Py_DECREF calls.
*/
class PythonObj {
private:
PyObject* obj;
public:
PythonObj();
PythonObj(PyObject* obj);
PythonObj(const PythonObj& other);
~PythonObj();
PythonObj& operator=(const PythonObj& other);
bool operator==(const PythonObj& other) const;
operator PyObject*() const;
operator bool() const;
/**
* Function used to obtain a return value that will persist beyond the life
* of the PythonObj. This is useful for returning objects to Python C apis
* and letting them manage the remaining lifetime of the object.
*/
PyObject* returnval();
/**
* Invokes getattr to retrieve the attribute from the python object.
*/
PythonObj getattr(const char* name);
/**
* Executes the current callable object if it's callable.
*/
PythonObj call(const PythonObj& args);
/**
* Invokes the specified method on this instance.
*/
PythonObj callmethod(const char* name, const PythonObj& args);
};
class PythonStore : public Store {
private:
PythonObj _get;
PythonObj _storeObj;
public:
PythonStore(PythonObj store);
PythonStore(const PythonStore& store);
virtual ~PythonStore() {}
ConstantStringRef get(const Key& key);
};
class PythonMatcher : public Matcher {
private:
PythonObj _matcherObj;
public:
PythonMatcher(PythonObj matcher) : _matcherObj(matcher) {}
virtual ~PythonMatcher() {}
bool matches(const std::string& path);
bool matches(const char* path, const size_t pathlen);
bool visitdir(const std::string& path);
};
class PythonDiffResult : public DiffResult {
private:
PythonObj _diff;
public:
PythonDiffResult(PythonObj diff) : _diff(diff) {}
virtual void add(
const std::string& path,
const char* beforeNode,
const char* beforeFlag,
const char* afterNode,
const char* afterFlag);
virtual void addclean(const std::string& path);
PythonObj getDiff() {
return this->_diff;
}
};
#endif // FBHGEXT_CSTORE_PYTHONUTIL_H

View File

@ -20,15 +20,10 @@ New errors are not allowed. Warnings are strongly discouraged.
Skipping edenscm/hgext/extlib/cstore/deltachain.h it has no-che?k-code (glob)
Skipping edenscm/hgext/extlib/cstore/key.h it has no-che?k-code (glob)
Skipping edenscm/hgext/extlib/cstore/match.h it has no-che?k-code (glob)
Skipping edenscm/hgext/extlib/cstore/py-cstore.cpp it has no-che?k-code (glob)
Skipping edenscm/hgext/extlib/cstore/py-datapackstore.h it has no-che?k-code (glob)
Skipping edenscm/hgext/extlib/cstore/py-structs.h it has no-che?k-code (glob)
Skipping edenscm/hgext/extlib/cstore/py-treemanifest.h it has no-che?k-code (glob)
Skipping edenscm/hgext/extlib/cstore/pythondatastore.cpp it has no-che?k-code (glob)
Skipping edenscm/hgext/extlib/cstore/pythondatastore.h it has no-che?k-code (glob)
Skipping edenscm/hgext/extlib/cstore/pythonkeyiterator.h it has no-che?k-code (glob)
Skipping edenscm/hgext/extlib/cstore/pythonutil.cpp it has no-che?k-code (glob)
Skipping edenscm/hgext/extlib/cstore/pythonutil.h it has no-che?k-code (glob)
Skipping edenscm/hgext/extlib/cstore/store.h it has no-che?k-code (glob)
Skipping edenscm/hgext/extlib/cstore/uniondatapackstore.cpp it has no-che?k-code (glob)
Skipping edenscm/hgext/extlib/cstore/uniondatapackstore.h it has no-che?k-code (glob)