From c16ab69c6a9c8b27d715bcdb7b8d0ee3bd5a100d Mon Sep 17 00:00:00 2001 From: Xavier Deguillard Date: Fri, 2 Oct 2020 10:43:21 -0700 Subject: [PATCH] build: remove //eden/scm:cstore Summary: This is unused, let's remove it. Reviewed By: DurhamG Differential Revision: D24037722 fbshipit-source-id: bc8a272809cb1f20f54d651a39ee42ff57169534 --- .../edenscm/hgext/extlib/cstore/py-cstore.cpp | 54 ----- .../hgext/extlib/cstore/pythondatastore.cpp | 134 ------------- .../hgext/extlib/cstore/pythondatastore.h | 82 -------- .../hgext/extlib/cstore/pythonutil.cpp | 184 ------------------ .../edenscm/hgext/extlib/cstore/pythonutil.h | 134 ------------- eden/scm/tests/test-check-code.t | 5 - 6 files changed, 593 deletions(-) delete mode 100644 eden/scm/edenscm/hgext/extlib/cstore/py-cstore.cpp delete mode 100644 eden/scm/edenscm/hgext/extlib/cstore/pythondatastore.cpp delete mode 100644 eden/scm/edenscm/hgext/extlib/cstore/pythondatastore.h delete mode 100644 eden/scm/edenscm/hgext/extlib/cstore/pythonutil.cpp delete mode 100644 eden/scm/edenscm/hgext/extlib/cstore/pythonutil.h diff --git a/eden/scm/edenscm/hgext/extlib/cstore/py-cstore.cpp b/eden/scm/edenscm/hgext/extlib/cstore/py-cstore.cpp deleted file mode 100644 index 8de903dca6..0000000000 --- a/eden/scm/edenscm/hgext/extlib/cstore/py-cstore.cpp +++ /dev/null @@ -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 - -#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); -} diff --git a/eden/scm/edenscm/hgext/extlib/cstore/pythondatastore.cpp b/eden/scm/edenscm/hgext/extlib/cstore/pythondatastore.cpp deleted file mode 100644 index 3c3aef6ee6..0000000000 --- a/eden/scm/edenscm/hgext/extlib/cstore/pythondatastore.cpp +++ /dev/null @@ -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 chain = getDeltaChainRaw(key); - return DeltaChainIterator(chain); -} - -std::shared_ptr PythonDataStore::getDeltaChainRaw(const Key& key) { - // Extract the delta chain from the list of tuples - // and build a DeltaChain object from them - std::shared_ptr> links = - std::make_shared>(); - - std::shared_ptr> tuples = - std::make_shared>(); - - // 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(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(links, tuples); -} - -std::shared_ptr 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(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 it = getMissing(iter); - return (!it->next()); -} - -PythonObj PythonDataStore::getStore() { - return this->_store; -} diff --git a/eden/scm/edenscm/hgext/extlib/cstore/pythondatastore.h b/eden/scm/edenscm/hgext/extlib/cstore/pythondatastore.h deleted file mode 100644 index deec72173e..0000000000 --- a/eden/scm/edenscm/hgext/extlib/cstore/pythondatastore.h +++ /dev/null @@ -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 -#include - -#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> _chain; - std::shared_ptr> _pythonChainLinks; - - public: - PyDeltaChain( - std::shared_ptr> chain, - std::shared_ptr> 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 getMissing(KeyIterator& missing) override; - - std::shared_ptr getDeltaChainRaw(const Key& key) override; - - bool contains(const Key& key) override; - - void markForRefresh() override; -}; - -#endif // FBHGEXT_PYTHONDATASTORE_H diff --git a/eden/scm/edenscm/hgext/extlib/cstore/pythonutil.cpp b/eden/scm/edenscm/hgext/extlib/cstore/pythonutil.cpp deleted file mode 100644 index 2e60d8b5ef..0000000000 --- a/eden/scm/edenscm/hgext/extlib/cstore/pythonutil.cpp +++ /dev/null @@ -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(); - } -} diff --git a/eden/scm/edenscm/hgext/extlib/cstore/pythonutil.h b/eden/scm/edenscm/hgext/extlib/cstore/pythonutil.h deleted file mode 100644 index 571247ae8d..0000000000 --- a/eden/scm/edenscm/hgext/extlib/cstore/pythonutil.h +++ /dev/null @@ -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 -#include - -// 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 diff --git a/eden/scm/tests/test-check-code.t b/eden/scm/tests/test-check-code.t index 6e53589e26..a679761684 100644 --- a/eden/scm/tests/test-check-code.t +++ b/eden/scm/tests/test-check-code.t @@ -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)